1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using System.Collections;
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);
            }
        }
    }
}