1
This commit is contained in:
@@ -44,35 +44,28 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
private void OnUserDataChanged()
|
||||
{
|
||||
vipLevel = GameManager.Instance.user.assets.vipLevel;
|
||||
// 打开时 OnShow 会重建所有,这里不需要额外处理
|
||||
}
|
||||
|
||||
protected override void OnShow(object args = null)
|
||||
{
|
||||
base.OnShow(args);
|
||||
|
||||
vipConfigs = GameManager.Instance.gameConfig.vipLevelConfigs;
|
||||
if (vipConfigs == null || vipConfigs.Count == 0) return;
|
||||
|
||||
var assets = GameManager.Instance.user.assets;
|
||||
vipLevel = assets.vipLevel;
|
||||
vipLevel = GameManager.Instance.user.assets.vipLevel;
|
||||
|
||||
// 先清除旧选项再重建
|
||||
BuildLevelTabs();
|
||||
|
||||
// 通过设置 toggle.isOn 触发 onValueChanged → 自动调用 UpdateVIPPanel
|
||||
for (int i = 0; i < btn_LeaveItemParent.childCount; i++)
|
||||
{
|
||||
if (vipConfigs[i].level == vipLevel)
|
||||
{
|
||||
btn_LeaveItemParent.GetChild(i).GetComponent<Toggle>().isOn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 直接刷新一次 UI(避免 Toggle 不触发)
|
||||
UpdateVIPPanel(vipLevel);
|
||||
|
||||
// 再同步 Toggle 显示状态
|
||||
SyncToggleState();
|
||||
}
|
||||
|
||||
private void BuildLevelTabs()
|
||||
{
|
||||
// 清空旧选项
|
||||
for (int i = btn_LeaveItemParent.childCount - 1; i >= 0; i--)
|
||||
Destroy(btn_LeaveItemParent.GetChild(i).gameObject);
|
||||
|
||||
@@ -80,16 +73,30 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
{
|
||||
var toggle = Instantiate(btn_LeaveItemPrefab, btn_LeaveItemParent);
|
||||
int level = item.level;
|
||||
// child(1) 显示 "贵族n"
|
||||
|
||||
toggle.transform.GetChild(1).GetComponent<TextMeshProUGUI>().text = $"贵族{level}";
|
||||
|
||||
toggle.onValueChanged.RemoveAllListeners();
|
||||
toggle.onValueChanged.AddListener((isOn) =>
|
||||
{
|
||||
if (isOn) UpdateVIPPanel(level);
|
||||
if (isOn)
|
||||
UpdateVIPPanel(level);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncToggleState()
|
||||
{
|
||||
for (int i = 0; i < btn_LeaveItemParent.childCount; i++)
|
||||
{
|
||||
var tog = btn_LeaveItemParent.GetChild(i).GetComponent<Toggle>();
|
||||
bool isCurrent = vipConfigs[i].level == vipLevel;
|
||||
|
||||
// 不触发事件,仅同步显示
|
||||
tog.SetIsOnWithoutNotify(isCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateVIPPanel(int level)
|
||||
{
|
||||
var config = vipConfigs?.Find(v => v.level == level);
|
||||
@@ -98,7 +105,7 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
txt_VIPLevel.text = $"{level}";
|
||||
txt_VIPContent.text = config.remark;
|
||||
|
||||
// VIP等级背景切换
|
||||
// VIP背景
|
||||
for (int i = 0; i < img_VIPNumBG.Count; i++)
|
||||
{
|
||||
if (img_VIPNumBG[i] != null)
|
||||
@@ -108,36 +115,31 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
var assets = GameManager.Instance.user.assets;
|
||||
var staticInfo = GameManager.Instance.user.@static;
|
||||
|
||||
// 经验/进度
|
||||
double currentExp = staticInfo?.totalRecharge ?? 0;
|
||||
EXP.maxValue = config.expMax;
|
||||
EXP.minValue = config.expMin;
|
||||
EXP.value = (float)currentExp;
|
||||
txt_VIPEXP.text = $"{currentExp}/{config.expMax}";
|
||||
|
||||
// 再充金额
|
||||
double needAmount = config.expMax > currentExp ? config.expMax - currentExp : 0;
|
||||
txt_VIPUpLeaveLabel.text = $"再充值 <color=yellow>{needAmount}</color> 元即可升级至<color=yellow><size=36>贵族{level}</size></color>";
|
||||
txt_VIPUpLeaveLabel.text =
|
||||
$"再充值 <color=yellow>{needAmount}</color> 元即可升级至<color=yellow><size=36>贵族{level}</size></color>";
|
||||
|
||||
// 顶部一次性奖励
|
||||
txt_VIPNUnlock.text = $"贵族{level}解锁";
|
||||
ShowGiftItems(config.giftList, btn_AwardItemParent_Top);
|
||||
|
||||
// 底部每日免费礼包
|
||||
txt_VIPNFreeGift.text = $"贵族{level}免费礼包";
|
||||
ShowGiftItems(config.dailyGift, btn_AwardItemParent_Bottom);
|
||||
|
||||
// 领取按钮状态
|
||||
// 按钮状态
|
||||
if (level > vipLevel)
|
||||
{
|
||||
// 未解锁
|
||||
btn_Award_Get.gameObject.SetActive(false);
|
||||
btn_Award_GetEnd.SetActive(false);
|
||||
btn_Award_NotUnlock.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 已解锁 → 显示领取按钮
|
||||
btn_Award_Get.gameObject.SetActive(true);
|
||||
btn_Award_GetEnd.SetActive(false);
|
||||
btn_Award_NotUnlock.SetActive(false);
|
||||
@@ -150,10 +152,10 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
if (result != null)
|
||||
{
|
||||
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));
|
||||
@@ -176,7 +178,6 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
|
||||
private void ShowGiftItems(List<GiftConfig> gifts, Transform parent)
|
||||
{
|
||||
// 清空旧物品
|
||||
for (int i = parent.childCount - 1; i >= 0; i--)
|
||||
Destroy(parent.GetChild(i).gameObject);
|
||||
|
||||
@@ -186,17 +187,18 @@ public class UIHome_BY_VIPPanel : SubUIBase
|
||||
{
|
||||
var obj = Instantiate(btn_AwardItemPrefab.gameObject, parent);
|
||||
var item = obj.GetComponent<BackPackPropItem>();
|
||||
|
||||
int count = gift.isRandom ? gift.minCount : gift.count;
|
||||
|
||||
switch (gift.type)
|
||||
{
|
||||
case 1: // 金币
|
||||
case 1:
|
||||
item.Init("", count, PropEnum.none);
|
||||
break;
|
||||
case 2: // 钻石
|
||||
case 2:
|
||||
item.Init("", count, PropEnum.none);
|
||||
break;
|
||||
case 3: // 道具
|
||||
case 3:
|
||||
string url = gift.product != null ? APIManager.baseURL + gift.product.imageUrl : "";
|
||||
PropEnum propType = (PropEnum)gift.product.type;
|
||||
item.Init(url, count, propType);
|
||||
|
||||
Reference in New Issue
Block a user