83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using Assets.MyGame.Scripts.Net;
|
||
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class UIHome_BY_JJJPanel : SubUIBase
|
||
{
|
||
public Button btn_Receive;
|
||
public Image img_DisReceive;
|
||
public TextMeshProUGUI txt_coinsNum;
|
||
public TextMeshProUGUI txt_TimeNum;
|
||
public TextMeshProUGUI txt_JieShao;
|
||
|
||
[Header("救济金次数项")]
|
||
public Transform tra_itemParent;
|
||
public JJJItem jJJItemPrefab;
|
||
|
||
private ReliefConfig reliefCfg;
|
||
|
||
public override void Awake()
|
||
{
|
||
base.Awake();
|
||
btn_Receive.onClick.AddListener(() =>
|
||
{
|
||
APIRequestList.GetRelief((callback) =>
|
||
{
|
||
UIManager.Instance.ShowBoardError("救济金领取成功");
|
||
RefreshPanel();
|
||
});
|
||
});
|
||
}
|
||
|
||
protected override void OnShow(object args = null)
|
||
{
|
||
base.OnShow(args);
|
||
RefreshPanel();
|
||
}
|
||
|
||
private void RefreshPanel()
|
||
{
|
||
APIRequestList.GetReliefConfig(jjjData =>
|
||
{
|
||
reliefCfg = jjjData;
|
||
var user = GameManager.Instance.user;
|
||
long userGold = user.assets.gold;
|
||
int totalCount = reliefCfg.count;
|
||
int remaining = user.@static.reliefGoldCount;
|
||
int claimed = totalCount - remaining;
|
||
txt_JieShao.text = $"1.金币低于{reliefCfg.limit}可以领取{reliefCfg.gold}\r\n2.每天可以领取{reliefCfg.count}次\r\n3.剩余00:00:00刷新领取次数";
|
||
txt_coinsNum.text = "金币" + reliefCfg.gold.ToString();
|
||
txt_TimeNum.text = $"剩余次数:{remaining}";
|
||
|
||
bool canReceive = reliefCfg.isOpen
|
||
&& remaining > 0
|
||
&& userGold < reliefCfg.limit;
|
||
|
||
img_DisReceive.gameObject.SetActive(!canReceive);
|
||
btn_Receive.interactable = canReceive;
|
||
|
||
BuildTimesList(totalCount, claimed, canReceive);
|
||
});
|
||
}
|
||
|
||
private void BuildTimesList(int totalCount, int claimedCount, bool canReceive)
|
||
{
|
||
for (int i = tra_itemParent.childCount - 1; i >= 0; i--)
|
||
Destroy(tra_itemParent.GetChild(i).gameObject);
|
||
|
||
for (int i = 0; i < totalCount; i++)
|
||
{
|
||
var item = Instantiate(jJJItemPrefab, tra_itemParent);
|
||
item.gameObject.SetActive(true);
|
||
|
||
bool isClaimed = i < claimedCount;
|
||
bool isCanClaim = !isClaimed && i == claimedCount && canReceive;
|
||
bool isLocked = !isClaimed && !isCanClaim;
|
||
|
||
item.Init(isClaimed, isCanClaim, isLocked, reliefCfg.gold);
|
||
}
|
||
}
|
||
}
|