lcy
2 天以前 2dd1841d03a730d3d369092c2a3ad656cee4bf64
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
//--------------------------------------------------------
//    [Author]:           玩个游戏
//    [  Date ]:           Tuesday, July 24, 2018
//--------------------------------------------------------
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
 
////开服盛典
public class OSGalaBaseWin : UIBase
{
    [SerializeField] Transform moneyTrans2;
    [SerializeField] Transform galaTrans;
    [SerializeField] ScrollerController tabScroller;
    [SerializeField] Image processImg;
    [SerializeField] Text galaTimeText;
    [SerializeField] Text totalScoreText;
    [SerializeField] ItemCell[] itemCells;
    [SerializeField] Image[] gotImgs;
    [SerializeField] Text[] scoreTexts;
    [SerializeField] UIEffectPlayer[] effectPlayers;
 
    [SerializeField] Transform totalRechargeTrans;
    [SerializeField] Text totalRechargeTimeText;
    [SerializeField] ItemCell totalRechargeItemCell;
    [SerializeField] Text totalRechargeScoreText;
    [SerializeField] RotationTween totalRechargeRotationTween;
    [SerializeField] Image totalRechargeFreeRedImage;
    [SerializeField] Image totalRechargeHaveImage;
 
    [SerializeField] Transform totDayRechargeTrans;
    [SerializeField] Text totDayRechargeTimeText;
    [SerializeField] ItemCell totDayRechargeItemCell;
    [SerializeField] Text totDayRechargeScoreText;
    [SerializeField] RotationTween totDayRechargeRotationTween;
    [SerializeField] Image totDayRechargeFreeRedImage;
    [SerializeField] Image totDayRechargeHaveImage;
 
    private int nowTabId = 0;
    private UIBase currentSubUI;
    private List<int> tabIdList = new List<int> { 0, 1, 2, 3, 4 };
    private Dictionary<int, string> tabTitleKeys = new Dictionary<int, string>
    {
        { 0, "DayMission1" },
        { 1, "OSActivity9" },
        { 2, "OSActivity3" },
        { 3, "TotalRecharge04" },
        { 4, "TotalRecharge05" },
    };
    private Dictionary<int, int> tabRedpointKeys = new Dictionary<int, int>
    {
        { 0, 1131 },
        { 1, 1132 },
        { 2, 1133 },
        { 3, 1135 },
        { 4, 1136 },
    };
 
    protected override void OnPreOpen()
    {
        tabScroller.OnRefreshCell += OnRefreshTabCell;
        OSActivityManager.Instance.OnOSGalaDataChangeEvent += OnOSGalaDataChangeEvent;
        GlobalTimeEvent.Instance.secondEvent += ShowTime;
        StoreModel.Instance.RefreshBuyShopLimitEvent += OnRefreshBuyShopLimitEvent;
        TotalRechargeManager.Instance.OnTotalRechargePlayerInfoEvent += OnTotalRechargePlayerInfoEvent;
        TotDayRechargeManager.Instance.OnTotDayRechargePlayerInfoEvent += OnTotDayRechargePlayerInfoEvent;
        CreateTabScroller();
        Display();
    }
 
    protected override void OnPreClose()
    {
        tabScroller.OnRefreshCell -= OnRefreshTabCell;
        OSActivityManager.Instance.OnOSGalaDataChangeEvent -= OnOSGalaDataChangeEvent;
        GlobalTimeEvent.Instance.secondEvent -= ShowTime;
        StoreModel.Instance.RefreshBuyShopLimitEvent -= OnRefreshBuyShopLimitEvent;
        TotalRechargeManager.Instance.OnTotalRechargePlayerInfoEvent -= OnTotalRechargePlayerInfoEvent;
        TotDayRechargeManager.Instance.OnTotDayRechargePlayerInfoEvent -= OnTotDayRechargePlayerInfoEvent;
        CloseCurrentSubUI();
    }
 
    private void OnTotDayRechargePlayerInfoEvent()
    {
        tabScroller.m_Scorller.RefreshActiveCellViews();
        RefreshRechargeTransData();
        Display();
    }
 
    private void OnTotalRechargePlayerInfoEvent()
    {
        tabScroller.m_Scorller.RefreshActiveCellViews();
        RefreshRechargeTransData();
        Display();
    }
 
    private void OnRefreshBuyShopLimitEvent()
    {
        tabScroller.m_Scorller.RefreshActiveCellViews();
        RefreshRechargeTransData();
        Display();
    }
 
    private void CreateTabScroller()
    {
        tabScroller.Refresh();
        bool isOSGalaOpen = OSActivityManager.Instance.IsOpenedOSGala();
        bool isTotDayRechargeOpen = TotDayRechargeManager.Instance.IsOpen;
        bool isTotalRechargeOpen = TotalRechargeManager.Instance.IsOpen;
        List<int> visibleTabs = new List<int>();
        for (int i = 0; i < tabIdList.Count; i++)
        {
            int tabId = tabIdList[i];
            bool canShow = false;
            if (tabId == 0 || tabId == 1 || tabId == 2)
            {
                canShow = isOSGalaOpen;
            }
            else if (tabId == 3)
            {
                canShow = isTotalRechargeOpen;
            }
            else if (tabId == 4)
            {
                canShow = isTotDayRechargeOpen;
            }
            if (canShow)
            {
                visibleTabs.Add(tabId);
                tabScroller.AddCell(ScrollerDataType.Header, tabId);
            }
        }
        if (visibleTabs.Count > 0)
        {
            nowTabId = visibleTabs[0];
        }
        tabScroller.Restart();
        SelectBottomTab(nowTabId);
    }
 
    private void OnRefreshTabCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell.GetComponent<OSGalaTabCell>();
        string titleKey = tabTitleKeys.ContainsKey(cell.index) ? tabTitleKeys[cell.index] : "";
        int redpointId = tabRedpointKeys.ContainsKey(cell.index) ? tabRedpointKeys[cell.index] : 0;
        _cell?.Display(cell.index, nowTabId, titleKey, redpointId, OnTabClicked);
    }
 
    private void OnTabClicked(int index)
    {
        if (nowTabId == index)
        {
            return;
        }
        nowTabId = index;
        tabScroller.m_Scorller.RefreshActiveCellViews();
        SelectBottomTab(index);
    }
 
    private void SelectBottomTab(int index)
    {
        if (currentSubUI != null)
        {
            currentSubUI.CloseWindow();
            currentSubUI = null;
        }
 
        galaTrans.SetActive(index == 0 || index == 1 || index == 2);
        moneyTrans2.SetActive(index == 0 || index == 1 || index == 2);
 
        totalRechargeTrans.SetActive(index == 3);
        totDayRechargeTrans.SetActive(index == 4);
 
        switch (index)
        {
            case 0:
                currentSubUI = UIManager.Instance.OpenWindow<OSGalaMissionWin>();
                break;
            case 1:
                currentSubUI = UIManager.Instance.OpenWindow<OSGalaChangeWin>();
                break;
            case 2:
                currentSubUI = UIManager.Instance.OpenWindow<OSGalaGiftWin>();
                break;
            case 3:
                currentSubUI = UIManager.Instance.OpenWindow<TotalRechargeWin>();
 
                var data = TotalRechargeManager.Instance.GetStoreData();
                bool isReceived = TotalRechargeManager.Instance.IsReceived(data.shopId);
                totalRechargeItemCell.Init(new ItemCellModel(data.storeConfig.ItemID, false, data.storeConfig.ItemCnt));
                totalRechargeItemCell.button.SetListener(() =>
                {
                    if (!isReceived)
                    {
                        StoreModel.Instance.SendBuyShopItem(data.storeConfig, 1);
                    }
                    else
                    {
                        ItemTipUtility.Show(data.storeConfig.ItemID);
                    }
 
                });
 
                totalRechargeHaveImage.SetActive(isReceived);
                totalRechargeFreeRedImage.SetActive(!isReceived);
                totalRechargeTimeText.text = TotalRechargeManager.Instance.GetActTimeStr();
                totalRechargeScoreText.text = Language.Get("TotalRecharge06", TotalRechargeManager.Instance.coinTotal);
                if (!isReceived)
                {
                    totalRechargeRotationTween.Play();
                }
                else
                {
                    totalRechargeRotationTween.Stop();
                    totalRechargeRotationTween.SetStartState();
                }
                break;
            case 4:
                currentSubUI = UIManager.Instance.OpenWindow<TotDayRechargeWin>();
 
                var data1 = TotDayRechargeManager.Instance.GetStoreData();
                bool isReceived1 = TotDayRechargeManager.Instance.IsReceived(data1.shopId);
                totDayRechargeItemCell.Init(new ItemCellModel(data1.storeConfig.ItemID, false, data1.storeConfig.ItemCnt));
                totDayRechargeItemCell.button.SetListener(() =>
                {
                    if (!isReceived1)
                    {
                        StoreModel.Instance.SendBuyShopItem(data1.storeConfig, 1);
                    }
                    else
                    {
                        ItemTipUtility.Show(data1.storeConfig.ItemID);
                    }
 
                });
 
                totDayRechargeHaveImage.SetActive(isReceived1);
                totDayRechargeFreeRedImage.SetActive(!isReceived1);
                totDayRechargeTimeText.text = TotDayRechargeManager.Instance.GetActTimeStr();
                totDayRechargeScoreText.text = Language.Get("TotalRecharge07", TotDayRechargeManager.Instance.totalDays);
                if (!isReceived1)
                {
                    totDayRechargeRotationTween.Play();
                }
                else
                {
                    totDayRechargeRotationTween.Stop();
                    totDayRechargeRotationTween.SetStartState();
                }
                break;
        }
    }
 
    private void CloseCurrentSubUI()
    {
        if (currentSubUI != null)
        {
            currentSubUI.CloseWindow();
            currentSubUI = null;
        }
    }
 
    /// <summary>
    /// 刷新累计充值和每日充值界面的数据(不重新创建界面)
    /// </summary>
    private void RefreshRechargeTransData()
    {
        // 刷新累计充值数据(tab 3)
        if (nowTabId == 3)
        {
            var data = TotalRechargeManager.Instance.GetStoreData();
            bool isReceived = TotalRechargeManager.Instance.IsReceived(data.shopId);
            totalRechargeItemCell.Init(new ItemCellModel(data.storeConfig.ItemID, false, data.storeConfig.ItemCnt));
            totalRechargeHaveImage.SetActive(isReceived);
            totalRechargeFreeRedImage.SetActive(!isReceived);
            totalRechargeTimeText.text = TotalRechargeManager.Instance.GetActTimeStr();
            totalRechargeScoreText.text = Language.Get("TotalRecharge06", TotalRechargeManager.Instance.coinTotal);
            if (!isReceived)
            {
                totalRechargeRotationTween.Play();
            }
            else
            {
                totalRechargeRotationTween.Stop();
                totalRechargeRotationTween.SetStartState();
            }
        }
        // 刷新每日充值数据(tab 4)
        else if (nowTabId == 4)
        {
            var data1 = TotDayRechargeManager.Instance.GetStoreData();
            bool isReceived1 = TotDayRechargeManager.Instance.IsReceived(data1.shopId);
            totDayRechargeItemCell.Init(new ItemCellModel(data1.storeConfig.ItemID, false, data1.storeConfig.ItemCnt));
            totDayRechargeHaveImage.SetActive(isReceived1);
            totDayRechargeFreeRedImage.SetActive(!isReceived1);
            totDayRechargeTimeText.text = TotDayRechargeManager.Instance.GetActTimeStr();
            totDayRechargeScoreText.text = Language.Get("TotalRecharge07", TotDayRechargeManager.Instance.totalDays);
            if (!isReceived1)
            {
                totDayRechargeRotationTween.Play();
            }
            else
            {
                totDayRechargeRotationTween.Stop();
                totDayRechargeRotationTween.SetStartState();
            }
        }
    }
 
    private void OnOSGalaDataChangeEvent()
    {
        Display();
    }
 
    void Display()
    {
        var keys = OSActivityManager.Instance.osGalaScoreAwards.Keys.ToList();
        keys.Sort();
        // value 分段,按keys中的达标获取
        var addValue = 1.0f / keys.Count;
        var value = 0f;
        for (int i = 0; i < keys.Count; i++)
        {
            var score = keys[i];
            var award = OSActivityManager.Instance.osGalaScoreAwards[score];
            if (OSActivityManager.Instance.osGalaScore >= score)
            {
                value += addValue;
            }
            else
            {
                break;
            }
        }
        processImg.fillAmount = value;
        ShowTime();
        totalScoreText.text = Language.Get("OSActivity11") + OSActivityManager.Instance.osGalaScore.ToString();
 
        for (int i = 0; i < itemCells.Length; i++)
        {
            if (i < keys.Count)
            {
                itemCells[i].SetActive(true);
                int score = keys[i];
                int index = i;
                int itemID = OSActivityManager.Instance.osGalaScoreAwards[score][0][0];
                itemCells[i].Init(new ItemCellModel(itemID, false, OSActivityManager.Instance.osGalaScoreAwards[score][0][1]));
                itemCells[i].button.AddListener(() =>
                {
                    if (!OSActivityManager.Instance.CanGetAward(index, score))
                    {
                        ItemTipUtility.Show(itemID);
                        return;
                    }
 
                    var pack = new CA504_tagCMPlayerGetReward();
                    pack.RewardType = 9;
                    pack.DataEx = (uint)score;
                    GameNetSystem.Instance.SendInfo(pack);
                });
 
                gotImgs[i].SetActive(OSActivityManager.Instance.IsGotAward(i));
                scoreTexts[i].text = keys[i].ToString();
                if (OSActivityManager.Instance.CanGetAward(index, score))
                {
                    effectPlayers[i].Play();
                }
                else
                {
                    effectPlayers[i].Stop();
                }
            }
            else
            {
                itemCells[i].SetActive(false);
            }
        }
    }
 
    void ShowTime()
    {
        if (TimeUtility.OpenDay >= OSActivityManager.Instance.osGalaOpenDays)
        {
            galaTimeText.text = Language.Get("OSActivity6");
        }
        else
        {
            galaTimeText.text = Language.Get("OSActivity10") + TimeUtility.SecondsToShortDHMS(TimeUtility.GetRemindTimeByOpenDay(OSActivityManager.Instance.osGalaOpenDays));
        }
        totalRechargeTimeText.text = TotalRechargeManager.Instance.GetActTimeStr();
        totDayRechargeTimeText.text = TotDayRechargeManager.Instance.GetActTimeStr();
    }
}