87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
using Assets.MyGame.Scripts.Net;
|
|
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
|
|
using Assets.MyGame.Scripts.Net.APIResponses;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIHome_BY_JiGuHuiLiPanel : SubUIBase
|
|
{
|
|
public Text txt_MaxCoin;//text=每日返还上限n
|
|
public Text txt_currCoin;//text=今日可领取m
|
|
public Text txt_currCoinNum;//text=xm
|
|
public Button btn_Award;//领取按钮
|
|
|
|
private FishingReturnConfig returnCfg;
|
|
private FishingReturnDto returnInfo;
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
btn_Award.interactable = false;
|
|
btn_Award.onClick.AddListener(OnClaimClick);
|
|
}
|
|
|
|
protected override void OnShow(object args = null)
|
|
{
|
|
base.OnShow(args);
|
|
RefreshPanel();
|
|
}
|
|
|
|
private void RefreshPanel()
|
|
{
|
|
APIRequestList.GetFishingReturnConfig(cfg =>
|
|
{
|
|
returnCfg = cfg;
|
|
APIRequestList.GetFishingReturnInfo(info =>
|
|
{
|
|
returnInfo = info;
|
|
UpdatePanel();
|
|
});
|
|
});
|
|
}
|
|
|
|
private void UpdatePanel()
|
|
{
|
|
if (returnCfg == null || returnInfo == null) return;
|
|
|
|
txt_MaxCoin.text = returnCfg.dailyMaxReturn > 0
|
|
? $"每日返还上限{FormatGold(returnCfg.dailyMaxReturn)}"
|
|
: "每日返还上限无上限";
|
|
|
|
txt_currCoin.text = $"今日可领取{FormatGold(returnInfo.canClaimGold)}";
|
|
txt_currCoinNum.text = FormatGold(returnInfo.canClaimGold);
|
|
|
|
btn_Award.interactable = returnCfg.isEnabled
|
|
&& !returnInfo.isClaimed
|
|
&& returnInfo.canClaimGold > 0;
|
|
}
|
|
|
|
private void OnClaimClick()
|
|
{
|
|
btn_Award.interactable = false;
|
|
APIRequestList.ClaimFishingReturn(res =>
|
|
{
|
|
UIManager.Instance.ShowBoardError(res.gold > 0
|
|
? $"领取成功,获得{FormatGold(res.gold)}金币"
|
|
: "领取成功");
|
|
APIRequestList.GetUser(user =>
|
|
{
|
|
GameManager.Instance.UpdataUserData(user);
|
|
RefreshPanel();
|
|
});
|
|
});
|
|
}
|
|
|
|
/// <summary>金币数值格式化(万/亿单位)</summary>
|
|
private static string FormatGold(long gold)
|
|
{
|
|
if (gold >= 100000000) // 亿
|
|
return $"{(gold / 100000000f):F1}亿";
|
|
if (gold >= 10000) // 万
|
|
return $"{(gold / 10000f):F1}万";
|
|
return gold.ToString("N0");
|
|
}
|
|
}
|