using System.Collections.Generic; using UnityEngine; /// /// 首充每日奖励显示组件 /// 负责显示首充活动每天的奖励内容和领取状态 /// public class FirstChargeDayAward : MonoBehaviour { [SerializeField] ImageEx imgCanHaveBG; // 可领取背景高亮显示 [SerializeField] ImageEx imgDay; // 天数图片 [SerializeField] TextEx txtDay; // 天数文本 [SerializeField] Transform transCount4; // 4个奖励物品的容器 [SerializeField] Transform transCount3; // 3个奖励物品的容器 [SerializeField] Transform transCount2; // 2个奖励物品的容器 [SerializeField] Transform transCount1; // 1个奖励物品的容器 // 各数量级奖励物品显示单元 [SerializeField] List itemCellCount4 = new List(); [SerializeField] List itemCellCount3 = new List(); [SerializeField] List itemCellCount2 = new List(); [SerializeField] ItemCell itemCellCount1 = new ItemCell(); // 奖励已领取遮罩图片 [SerializeField] List imgHaveCount4 = new List(); [SerializeField] List imgHaveCount3 = new List(); [SerializeField] List imgHaveCount2 = new List(); [SerializeField] ImageEx imgHaveCount1 = new ImageEx(); /// /// 显示指定首充ID和天数的奖励信息 /// /// 首充配置ID /// 第几天(1-3) public void Display(int firstId, int day) { // 获取首充数据 if (!FirstChargeManager.Instance.TryGetFirstChargeDataByFirstId(firstId, out var firstChargeData)) return; // 获取奖励状态: 0-已领取, 1-不可领取, 2-可领取, 3-未知状态 int awardState = firstChargeData.GetHaveState(day); // 根据状态设置UI显示 imgCanHaveBG.SetActive(firstChargeData.IsBuy() && awardState == 2); txtDay.text = awardState == 0 ? Language.Get("L1129_2") : Language.Get("FirstCharge02", day); imgDay.gray = awardState == 0; // 已领取则置灰天数图标 // 隐藏所有奖励物品容器 transCount4.SetActive(false); transCount3.SetActive(false); transCount2.SetActive(false); transCount1.SetActive(false); // 检查配置是否存在 if (!FirstChargeConfig.HasKey(firstId)) return; FirstChargeConfig config = FirstChargeConfig.Get(firstId); int[][] awardList = GetAwardListByDay(config, day); // 检查奖励列表有效性 if (awardList == null || awardList.Length <= 0) { Debug.LogError($"首充表第{day}天奖励没配"); return; } if (awardList.Length > 4) { Debug.LogError($"首充表奖励物品不支持配大于4个"); return; } // 根据奖励数量显示对应的UI switch (awardList.Length) { case 1: ShowAwardsForCount1(awardList, awardState, firstId); break; case 2: ShowAwardsForCount2(awardList, awardState); break; case 3: ShowAwardsForCount3(awardList, awardState); break; case 4: ShowAwardsForCount4(awardList, awardState); break; } } /// /// 根据天数获取对应的奖励列表 /// /// 首充配置 /// 天数 /// 奖励列表 private int[][] GetAwardListByDay(FirstChargeConfig config, int day) { switch (day) { case 1: return config.AwardListDay1; case 2: return config.AwardListDay2; case 3: return config.AwardListDay3; default: Debug.LogError("FirstChargeItemCellShow传入天数大于3或小于0"); return null; } } /// /// 显示单个奖励物品 /// /// 奖励列表 /// 奖励状态 /// 首充ID private void ShowAwardsForCount1(int[][] awardList, int awardState, int firstId) { transCount1.SetActive(true); itemCellCount1.Init(new ItemCellModel((int)awardList[0][0], true, awardList[0][1])); itemCellCount1.button.SetListener(() => HandleItemClick((int)awardList[0][0], awardList[0][2])); imgHaveCount1.SetActive(awardState == 0); } /// /// 显示两个奖励物品 /// /// 奖励列表 /// 奖励状态 private void ShowAwardsForCount2(int[][] awardList, int awardState) { transCount2.SetActive(true); ShowAwardsCommonLogic(awardList, awardState, itemCellCount2, imgHaveCount2); } /// /// 显示三个奖励物品 /// /// 奖励列表 /// 奖励状态 private void ShowAwardsForCount3(int[][] awardList, int awardState) { transCount3.SetActive(true); ShowAwardsCommonLogic(awardList, awardState, itemCellCount3, imgHaveCount3); } /// /// 显示四个奖励物品 /// /// 奖励列表 /// 奖励状态 private void ShowAwardsForCount4(int[][] awardList, int awardState) { transCount4.SetActive(true); ShowAwardsCommonLogic(awardList, awardState, itemCellCount4, imgHaveCount4); } /// /// 统一处理物品点击事件 /// /// 物品ID private void HandleItemClick(int itemId, int customEquipId) { if (!ItemConfig.HasKey(itemId)) return; if (ItemConfig.Get(itemId).Type == 150) { FirstChargeManager.Instance.heroItemID = itemId; UIManager.Instance.OpenWindow(); } else if (ItemConfig.Get(itemId).Type >= 101 && ItemConfig.Get(itemId).Type <= 117 && customEquipId > 0 && AppointItemConfig.HasKey(customEquipId)) { ItemTipUtility.ShowCustomEquip(itemId, customEquipId); } else { ItemTipUtility.Show(itemId, true); } } /// /// 通用奖励显示逻辑 /// /// 奖励列表 /// 奖励状态 /// 物品显示单元列表 /// 已领取遮罩图片列表 private void ShowAwardsCommonLogic(int[][] awardList, int awardState, List itemCells, List haveImages) where T : ItemCell { for (int i = 0; i < awardList.Length; i++) { // 设置物品显示 if (i < itemCells.Count) { int index = i; // Lambda表达式中使用,需要创建局部副本 itemCells[i].SetActive(true); itemCells[i].Init(new ItemCellModel((int)awardList[i][0], true, awardList[i][1])); itemCells[i].button.SetListener(() => HandleItemClick((int)awardList[index][0], awardList[index][2])); } else { itemCells[i].SetActive(false); } // 设置已领取遮罩 if (awardState == 0 && i < haveImages.Count) { haveImages[i].SetActive(true); } else if (i < haveImages.Count) { haveImages[i].SetActive(false); } } } }