少年修仙传客户端代码仓库
hch
2025-03-03 28785d6ddf9c08e49527ede9405c7b6c93c6ed32
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, April 18, 2019
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class RechargeGiftActWin : Window
    {
        [SerializeField] Text buyCountGiftText;
        [SerializeField] Slider buyCountGiftSlider;
        [SerializeField] Text buyCountGiftSliderText;
        [SerializeField] List<ItemCell> buyCountGiftItems;
        [SerializeField] Button buyCountGiftBtn;
        [SerializeField] Image gotYetImg;
        [SerializeField] ScrollerController m_Controller;
        [SerializeField] Text actTime;
        [SerializeField] Text resetTip;
        RechargeGiftActModel model { get { return ModelCenter.Instance.GetModel<RechargeGiftActModel>(); } }
        VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
 
        StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
        #region Built-in
        protected override void BindController()
        {
 
 
        }
 
        protected override void AddListeners()
        {
            
        }
 
        protected override void OnPreOpen()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            model.UpdateRechargeGiftActEvent += DisplayAward;
            GlobalTimeEvent.Instance.secondEvent += secondEvent;
            vipModel.rechargeCountEvent += VipModel_rechargeCountEvent;
            storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
            DisplayScroll(); 
            DisplayAward();
            secondEvent();
        }
 
        private void VipModel_rechargeCountEvent(int obj)
        {
            m_Controller.m_Scorller.RefreshActiveCellViews();
            DisplayAward();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            m_Controller.OnRefreshCell -= OnRefreshCell;
            model.UpdateRechargeGiftActEvent -= DisplayAward;
            GlobalTimeEvent.Instance.secondEvent -= secondEvent;
            vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
            storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
 
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void RefreshBuyShopLimitEvent()
        {
            m_Controller.m_Scorller.RefreshActiveCellViews();
        }
 
 
        void DisplayScroll()
        {
            m_Controller.Refresh();
            OperationRechargeGiftAct act;
            OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act);
 
            List<StoreConfig> _list = null;
            StoreConfig.TryGetStoreConfigs(act.shopType, out _list);
 
            int totaleCnt = (_list == null ? 0 : _list.Count) + act.ctgIDs.Count;
 
            for (int i = 0; i < totaleCnt; i++)
            {
                m_Controller.AddCell(ScrollerDataType.Header, i);
            }
            m_Controller.Restart();
            m_Controller.m_Scorller.RefreshActiveCellViews();
            m_Controller.JumpIndex(GetDefaultSelect());
 
            //取一档商品识别 是否有商品的每日重置,与活动的每日重置判断显示
            var config = CTGConfig.Get(act.ctgIDs[0]);
            resetTip.SetActive(!act.dayReset && config.DailyBuyCount != 0);
        }
 
        void DisplayAward()
        { 
            int index = GetAwardShowIndex();
            OperationRechargeGiftAct act;
            OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act);
 
            int totalBuyCnt = model.GetBuyTotalCnt();
            var awardInfo = act.buyCountGifts[index];
            if (awardInfo.NeedBuyCount == 0)
            {
                //免费领取
                buyCountGiftText.text = Language.Get("Z2014");
                buyCountGiftSlider.value = 1;
                buyCountGiftSliderText.text = string.Empty;
            }
            else
            {
                buyCountGiftText.text = Language.Get("RechargeGiftActWin1", Math.Max(0,awardInfo.NeedBuyCount - totalBuyCnt));
                buyCountGiftSlider.value = totalBuyCnt / (float)awardInfo.NeedBuyCount;
                buyCountGiftSliderText.text = string.Format("{0}/{1}", totalBuyCnt, awardInfo.NeedBuyCount);
            }
            var awards = awardInfo.AwardItemList;
            for (int i = 0; i < buyCountGiftItems.Count; i++)
            {
                if (i < awards.Length)
                {
                    var award = awards[i];
                    buyCountGiftItems[i].SetActive(true);
                    var itemData = new ItemCellModel((int)award.ItemID, false, award.ItemCount);
                    buyCountGiftItems[i].Init(itemData);
                    buyCountGiftItems[i].button.SetListener(() =>
                    {
                        ItemTipUtility.Show((int)award.ItemID);
                    });
                }
                else
                {
                    buyCountGiftItems[i].SetActive(false);
                }
            }
 
            buyCountGiftBtn.SetColorful(null, totalBuyCnt >= awardInfo.NeedBuyCount);
            buyCountGiftBtn.interactable = totalBuyCnt >= awardInfo.NeedBuyCount;
            buyCountGiftBtn.SetListener(() =>
            {
                model.SendGetAward(awardInfo.NeedBuyCount);
            });
 
            if (index == act.buyCountGifts.Count - 1 && model.GetBuyGiftState(awardInfo.NeedBuyCount) == 2)
            {
                gotYetImg.SetActive(true);
                buyCountGiftBtn.SetActive(false);
            }
            else
            {
                gotYetImg.SetActive(false);
                buyCountGiftBtn.SetActive(true);
            }
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            if (type != ScrollerDataType.Header) return;
 
            var _cell = cell as RechargeGiftActCell;
            
            _cell.Display(_cell.index);
 
 
        }
        
 
        int GetDefaultSelect()
        {
            OperationRechargeGiftAct act;
            OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act);
 
            List<StoreConfig> _list = null;
            StoreConfig.TryGetStoreConfigs(act.shopType, out _list);
 
            int storeCnt = _list == null ? 0 : _list.Count;
 
            for (int i = 0; i < storeCnt; i++)
            {
                int remainNum;
                storeModel.TryGetIsSellOut(_list[i], out remainNum);
                if (remainNum > 0)
                    return i;
            }
 
            //跳过已购买
            for (int i = 0; i < act.ctgIDs.Count; i++)
            {
                int ctgID = act.ctgIDs[i];
                var countInfo = model.GetBuyCntInfo(ctgID);
 
                if (countInfo.x < countInfo.y)
                    return i + storeCnt;
            }
            return 0;
            
        }
 
        void secondEvent()
        {
            OperationRechargeGiftAct act;
            OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act);
            actTime.text = Language.Get("BossFHLanguage2", TimeUtility.SecondsToHMS(act.GetResetSurplusTime()));
        }
 
        int GetAwardShowIndex()
        {
            OperationRechargeGiftAct act;
            OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act);
            if (act == null) return 0;
 
            for (int i = 0; i < act.buyCountGifts.Count; i++)
            {
                if (model.GetBuyGiftState(act.buyCountGifts[i].NeedBuyCount) != 2)
                {
                    return i;
                }
            }
            return act.buyCountGifts.Count - 1;
        }
    }
}