1
This commit is contained in:
@@ -35,6 +35,7 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
public List<GameObject> img_VIPNumBG;
|
||||
|
||||
private int vipLevel = 0;
|
||||
private int currentDisplayLevel = 0; // 当前正在查看的等级(用于数据刷新后还原显示)
|
||||
private List<VipLevelConfig> vipConfigs;
|
||||
|
||||
public override void Awake()
|
||||
@@ -51,6 +52,9 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
private void OnUserDataChanged()
|
||||
{
|
||||
vipLevel = GameManager.Instance.user.assets.vipLevel;
|
||||
// 拉取到最新 UserToken 后,刷新当前查看等级的 UI(经验、进度条、按钮状态等)
|
||||
if (currentDisplayLevel > 0 && vipConfigs != null)
|
||||
UpdateVIPPanel(currentDisplayLevel);
|
||||
}
|
||||
|
||||
protected override void OnShow(object args = null)
|
||||
@@ -115,6 +119,8 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
var config = vipConfigs?.Find(v => v.level == level);
|
||||
if (config == null) return;
|
||||
|
||||
currentDisplayLevel = level;
|
||||
|
||||
txt_VIPLevel.text = $"{level}";
|
||||
txt_VIPContent.text = config.remark;
|
||||
|
||||
@@ -170,32 +176,38 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
}
|
||||
else
|
||||
{
|
||||
btn_Award_Get.gameObject.SetActive(true);
|
||||
btn_Award_GetEnd.SetActive(false);
|
||||
btn_Award_NotUnlock.SetActive(false);
|
||||
|
||||
btn_Award_Get.onClick.RemoveAllListeners();
|
||||
btn_Award_Get.onClick.AddListener(() =>
|
||||
// 按等级独立判断:vipGift 为未领取的 Vip 礼包等级集合,包含当前等级则可领取
|
||||
bool canReceive = assets?.vipGift != null && System.Array.IndexOf(assets.vipGift, level) >= 0;
|
||||
btn_Award_Get.gameObject.SetActive(canReceive);
|
||||
btn_Award_GetEnd.SetActive(!canReceive);
|
||||
|
||||
if (canReceive)
|
||||
{
|
||||
APIRequestList.GetVipDayGift(result =>
|
||||
btn_Award_Get.onClick.RemoveAllListeners();
|
||||
btn_Award_Get.onClick.AddListener(() =>
|
||||
{
|
||||
if (result != null)
|
||||
// 传入当前查看的等级,领取该等级的每日礼包
|
||||
APIRequestList.GetVipDayGift(level, result =>
|
||||
{
|
||||
UIManager.Instance.ShowBoardError("领取成功");
|
||||
|
||||
btn_Award_Get.gameObject.SetActive(false);
|
||||
btn_Award_GetEnd.SetActive(true);
|
||||
|
||||
var userId = GameManager.Instance?.user?.id;
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
APIRequestList.GetUser(userId, a => GameManager.Instance.UpdataUserData(a));
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.Instance.ShowBoardError("领取失败");
|
||||
}
|
||||
if (result != null)
|
||||
{
|
||||
UIManager.Instance.ShowBoardError("领取成功");
|
||||
// 拉取服务器最新 UserToken(含更新后的 vipGift),触发 OnUserDataChanged 刷新 UI
|
||||
APIRequestList.GetUser(user =>
|
||||
{
|
||||
if (user != null)
|
||||
GameManager.Instance.UpdataUserData(user);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.Instance.ShowBoardError("领取失败");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user