| using System.Collections.Generic; | 
| using UnityEngine; | 
|   | 
| /// <summary> | 
| /// 首充每日奖励显示组件 | 
| /// 负责显示首充活动每天的奖励内容和领取状态 | 
| /// </summary> | 
| 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<ItemCell> itemCellCount4 = new List<ItemCell>(); | 
|     [SerializeField] List<ItemCell> itemCellCount3 = new List<ItemCell>(); | 
|     [SerializeField] List<ItemCell> itemCellCount2 = new List<ItemCell>(); | 
|     [SerializeField] ItemCell itemCellCount1 = new ItemCell(); | 
|   | 
|     // 奖励已领取遮罩图片 | 
|     [SerializeField] List<ImageEx> imgHaveCount4 = new List<ImageEx>(); | 
|     [SerializeField] List<ImageEx> imgHaveCount3 = new List<ImageEx>(); | 
|     [SerializeField] List<ImageEx> imgHaveCount2 = new List<ImageEx>(); | 
|     [SerializeField] ImageEx imgHaveCount1 = new ImageEx(); | 
|   | 
|     /// <summary> | 
|     /// 显示指定首充ID和天数的奖励信息 | 
|     /// </summary> | 
|     /// <param name="firstId">首充配置ID</param> | 
|     /// <param name="day">第几天(1-3)</param> | 
|     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; | 
|         } | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 根据天数获取对应的奖励列表 | 
|     /// </summary> | 
|     /// <param name="config">首充配置</param> | 
|     /// <param name="day">天数</param> | 
|     /// <returns>奖励列表</returns> | 
|     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; | 
|         } | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 显示单个奖励物品 | 
|     /// </summary> | 
|     /// <param name="awardList">奖励列表</param> | 
|     /// <param name="awardState">奖励状态</param> | 
|     /// <param name="firstId">首充ID</param> | 
|     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); | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 显示两个奖励物品 | 
|     /// </summary> | 
|     /// <param name="awardList">奖励列表</param> | 
|     /// <param name="awardState">奖励状态</param> | 
|     private void ShowAwardsForCount2(int[][] awardList, int awardState) | 
|     { | 
|         transCount2.SetActive(true); | 
|         ShowAwardsCommonLogic(awardList, awardState, itemCellCount2, imgHaveCount2); | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 显示三个奖励物品 | 
|     /// </summary> | 
|     /// <param name="awardList">奖励列表</param> | 
|     /// <param name="awardState">奖励状态</param> | 
|     private void ShowAwardsForCount3(int[][] awardList, int awardState) | 
|     { | 
|         transCount3.SetActive(true); | 
|         ShowAwardsCommonLogic(awardList, awardState, itemCellCount3, imgHaveCount3); | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 显示四个奖励物品 | 
|     /// </summary> | 
|     /// <param name="awardList">奖励列表</param> | 
|     /// <param name="awardState">奖励状态</param> | 
|     private void ShowAwardsForCount4(int[][] awardList, int awardState) | 
|     { | 
|         transCount4.SetActive(true); | 
|         ShowAwardsCommonLogic(awardList, awardState, itemCellCount4, imgHaveCount4); | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 统一处理物品点击事件 | 
|     /// </summary> | 
|     /// <param name="itemId">物品ID</param> | 
|     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<FirstChargeHeroInfoWin>(); | 
|         } | 
|         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); | 
|         } | 
|     } | 
|   | 
|     /// <summary> | 
|     /// 通用奖励显示逻辑 | 
|     /// </summary> | 
|     /// <param name="awardList">奖励列表</param> | 
|     /// <param name="awardState">奖励状态</param> | 
|     /// <param name="itemCells">物品显示单元列表</param> | 
|     /// <param name="haveImages">已领取遮罩图片列表</param> | 
|     private void ShowAwardsCommonLogic<T>(int[][] awardList, int awardState, List<T> itemCells, List<ImageEx> 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); | 
|             } | 
|         } | 
|     } | 
| } |