少年修仙传客户端代码仓库
client_Hale
2019-04-15 f99a0cd6ed9f5df666b19549e6a7de9bf9b9e9c8
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
 
using System.Linq;
 
namespace Snxxz.UI
{
    public class HappyXBGetItemWin : Window
    {
        [SerializeField] GameObject getItem;
        [SerializeField] RectTransform getItemParent;
        [SerializeField] Button backBtn;
        [SerializeField] Button xbBtn;
        [SerializeField] Text xbBtnText;
        [SerializeField] Text xbMoneyText;
        [SerializeField] Button xbManyBtn;
        [SerializeField] Text xbManyBtnText;
        [SerializeField] Text xbManyMoneyText;
        [SerializeField] Text xbScoreText;
        [SerializeField] Text freeXBTimeText;
        [SerializeField] float scaleTime = 0.2f;
        [Header("有寻宝道具")]
        [SerializeField] GameObject container_XBTool;
        [SerializeField] Text haveToolText;
        [SerializeField] Button makeUseToolBtn;
        [SerializeField] GameObject selectUseToolImg;
        [Header("消耗金钱或道具")]
        [SerializeField] GameObject costMoneyObj;
        [SerializeField] GameObject costToolObj;
        [SerializeField] GameObject costManyMoneyObj;
        [SerializeField] GameObject costManyToolObj;
        [SerializeField] Text costToolNumText;
        [SerializeField] Text costToolManyText;
 
        HappyXBModel XBModel { get { return ModelCenter.Instance.GetModel<HappyXBModel>(); } }
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        ItemTipsModel _itemTipsModel;
        ItemTipsModel itemTipsModel
        {
            get
            {
                return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
            }
        }
 
        bool isHaveFreeTime = false;
        List<GameObject> GetItemlist = new List<GameObject>();
        List<XBGetItemCell> getItemBasiclist = new List<XBGetItemCell>();
        List<XBGetItem> xbItemlist;
        int oneMoney = 0;
        int manyMoney = 0;
        bool isHaveXBTool = false;
        bool isCostToolMany = false;
        XBGetItemConfig xbItemConfig = null;
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            backBtn.AddListener(ClickBackBtn);
            xbBtn.AddListener(ClickXBBtn);
            xbManyBtn.AddListener(ClickXBManyBtn);
            makeUseToolBtn.AddListener(ClickMakeUseTool);
        }
 
        protected override void OnPreOpen()
        {
            XBModel.StartXBEvent += OnStartXB;
            getItem.SetActive(false);       
            isHaveFreeTime = XBModel.IsHaveFreeXBTime((int)XBModel.title);
            InitUI();
            TimeDownMgr.CoolTimeData data;
            switch (XBModel.title)
            {
                case HappXBTitle.Best:
                    XBModel.RefreshBestXBTimeAct += RefreshFreeTime;
                    if (TimeDownMgr.Instance.Get(TimeDownMgr.CoolTimeType.HappyFreeBestXB, out data))
                    {
                        data.func = RefreshFreeTime;
                        RefreshFreeTime(Mathf.CeilToInt(data.duration - data.time));
                    }
                    else
                    {
                        RefreshFreeTime(0);
                    }
                    break;
                case HappXBTitle.Rune:
                    XBModel.RefreshRuneXBTimeAct += RefreshFreeTime;
                    if (TimeDownMgr.Instance.Get(TimeDownMgr.CoolTimeType.HappyFreeRuneXB, out data))
                    {
                        data.func = RefreshFreeTime;
                        RefreshFreeTime(Mathf.CeilToInt(data.duration - data.time));
                    }
                    else
                    {
                        RefreshFreeTime(0);
                    }
                    break;
            }
            
        }
 
        protected override void OnAfterOpen()
        {
            CheckHaveXBTool();
            UpdateCostType();
        }
 
        protected override void OnPreClose()
        {
            switch (XBModel.title)
            {
                case HappXBTitle.Best:
                    XBModel.RefreshBestXBTimeAct -= RefreshFreeTime;
                    break;
                case HappXBTitle.Rune:
                    XBModel.RefreshRuneXBTimeAct -= RefreshFreeTime;
                    break;
            }
            XBModel.StartXBEvent -= OnStartXB;
            XBModel.rangelist.Clear();
            DestroyGetItemlist();
            GetItemlist.Clear();
            getItemBasiclist.Clear();
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        private void InitUI()
        {
            xbItemConfig = XBModel.GetXBItemConfigByType((int)XBModel.title);
            CreateGetItem();
            xbScoreText.text = XBModel.addXBScore.ToString();
            for(int i = 0; i < xbItemlist.Count; i++)
            {
                var xbItem = xbItemlist[i];
                int count = playerPack.GetItemCountByID(PackType.Treasure,xbItemlist[i].itemId);
                if(count > 0)
                {
                    XBModel.RefreshXBWarehouse();
                }
            }
        }
 
        private void ClickMakeUseTool()
        {
            bool isToolXB = !selectUseToolImg.activeInHierarchy;
            selectUseToolImg.SetActive(isToolXB);
            XBModel.SetUseToolXB(isToolXB);
            UpdateCostType();
        }
 
        private void CheckHaveXBTool()
        {
            int xbToolCnt = 0;
            int needToolCnt = 0;
            isHaveXBTool = XBModel.IsHaveManyXBTool((int)XBModel.title, out xbToolCnt, out needToolCnt);
            isCostToolMany = xbToolCnt >= needToolCnt;
            container_XBTool.SetActive(isHaveXBTool);
            selectUseToolImg.SetActive(XBModel.IsUseToolXB());
            haveToolText.text = StringUtility.Contact("x",xbToolCnt);
        }
 
        private void UpdateCostType()
        {
            bool isToolXB = selectUseToolImg.activeInHierarchy;
            costMoneyObj.SetActive(!isHaveXBTool || !isToolXB);
            costToolObj.SetActive(isHaveXBTool && isToolXB);
            costManyMoneyObj.SetActive(!isCostToolMany || !isToolXB);
            costManyToolObj.SetActive(isCostToolMany && isToolXB);
            XBFuncSet funcSet = XBModel.GetXBFuncSet((int)XBModel.title); 
            if (funcSet != null)
            {
                oneMoney = funcSet.xbPrices[0];
                manyMoney = funcSet.xbPrices[1];
                if (isHaveXBTool && isToolXB)
                {
                    xbBtnText.text = Language.Get("HappyXB107", funcSet.xbNums[0]);
                    costToolNumText.text = Language.Get("HappyXB108", funcSet.costToolNums[0]);
                }
                else
                {
                    xbBtnText.text = Language.Get("HappyXB103", funcSet.xbNums[0]);
                    xbMoneyText.text = oneMoney.ToString();
                   
                }
 
                if(isCostToolMany && isToolXB)
                {
                    xbManyBtnText.text = Language.Get("HappyXB107", funcSet.xbNums[1]);
                    costToolManyText.text = Language.Get("HappyXB108", funcSet.costToolNums[1]); ;
                }
                else
                {
                    xbManyBtnText.text = Language.Get("HappyXB103", funcSet.xbNums[1]);
                    xbManyMoneyText.text = manyMoney.ToString();
                }
            }
        }
 
        private void RefreshFreeTime(float time)
        {
            if (isHaveFreeTime)
            {
                if (XBModel.IsHaveFreeXB((int)XBModel.title))
                {
                    freeXBTimeText.gameObject.SetActive(false);
                }
                else
                {
                    freeXBTimeText.gameObject.SetActive(true);
                    freeXBTimeText.text = Language.Get("HappyXB102", TimeUtility.SecondsToHMSCHSRetain((int)time));
                }
            }
            else
            {
                freeXBTimeText.gameObject.SetActive(false);
            }
 
        }
 
        private void CreateGetItem()
        {
            xbItemlist = XBModel.rangelist;
            for (int i = 0; i < xbItemlist.Count; i++)
            {
                XBGetItem xbItem = xbItemlist[i];
                GameObject item = Instantiate(getItem);
                item.transform.SetParent(getItemParent);
                item.transform.localPosition = Vector3.zero;
                item.transform.localScale = Vector3.one;
                item.name = StringUtility.Contact("CommonItemCell", i);
                item.gameObject.SetActive(true);
                XBGetItemCell itemBasic = item.transform.Find("CommonItemCell").GetComponent<XBGetItemCell>();
                ItemCellModel cellModel = new ItemCellModel(xbItem.itemId, false, (ulong)xbItem.count);
                itemBasic.Init(cellModel);
                itemBasic.button.RemoveAllListeners();
                itemBasic.button.AddListener(() =>
                {
                    ItemAttrData attrData = new ItemAttrData(xbItem.itemId, false, (ulong)xbItem.count);
                    itemTipsModel.SetItemTipsModel(attrData);
 
                });
                itemBasic.transform.localScale = Vector3.zero;
                itemBasic.transform.localPosition = Vector3.zero;
                GetItemlist.Add(item);
                itemBasic.gameObject.SetActive(false);
                getItemBasiclist.Add(itemBasic);
            }
 
            ShowGetItemCtrl(0);
        }
 
        private void ShowGetItemCtrl(int index)
        {
            if (index < getItemBasiclist.Count)
            {
                getItemBasiclist[index].gameObject.SetActive(true);
                getItemBasiclist[index].transform.DOScale(new Vector3(1, 1, 1), scaleTime).OnComplete(() =>
                {
                    getItemBasiclist[index].SetUIEffect();
                    index += 1;
                    ShowGetItemCtrl(index);
                });
 
                var xbItem = xbItemlist[index];
                bool isJump = false;
                switch(XBModel.title)
                {
                    case HappXBTitle.Best:
                        if(XBModel.isJumpBestXB)
                        {
                            isJump = true;
                        }
                        break;
                    case HappXBTitle.Rune:
                        if (XBModel.isJumpRuneXB)
                        {
                            isJump = true;
                        }
                        break;
                }
                if (isJump 
                    && xbItem.gridIndex == xbItemConfig.LuckyGridNum)
                {
                    SoundPlayer.Instance.PlayUIAudio(67);
                }
            }
        }
 
        private void DestroyGetItemlist()
        {
            for(int i = 0; i < GetItemlist.Count; i++)
            {
                Destroy(GetItemlist[i]);
            }
        }
 
 
        private void ClickXBBtn()
        {
            SendXBQuest(0);
        }
 
        private void ClickXBManyBtn()
        {
            SendXBQuest(1);
        }
 
        public int GetCostType(int xbNum)
        {
            if(xbNum == 0)
            {
                bool isFreeXB = isHaveFreeTime && XBModel.IsHaveFreeXB((int)XBModel.title);
                if (isFreeXB) return 1;
                if (costMoneyObj.activeInHierarchy) return 0;
            }
            else
            {
                if (costManyMoneyObj.activeInHierarchy) return 0;
            }
 
            return 2;
        }
 
        public void SendXBQuest(int xbNum)
        {
            if (!XBModel.CheckIsEmptyGrid(PackType.Treasure)) return;
 
            int costType = GetCostType(xbNum);
            bool isMoneyEnough = true;
            if (xbNum == 0)
            {
                isMoneyEnough = UIHelper.GetMoneyCnt(1) >= (ulong)oneMoney;
            }
            else
            {
                isMoneyEnough = UIHelper.GetMoneyCnt(1) >= (ulong)manyMoney;
            }
 
            switch(costType)
            {
                case 0:
                    if (!isMoneyEnough)
                    {
                        WindowCenter.Instance.Open<RechargeTipWin>();
                        return;
                    }
                    break;
                case 1:
                case 2:
 
                    break;
            }
 
            switch (XBModel.title)
            {
                case HappXBTitle.Best:
                    XBModel.SendXBQuest(1, xbNum, costType);
                    break;
                case HappXBTitle.Rune:
                    XBModel.SendXBQuest(2, xbNum, costType);
                    break;
            }
        }
 
        private void OnStartXB(int oneOrMany)
        {
            ClickBackBtn();
        }
 
        private void ClickBackBtn()
        {
            CloseImmediately();
        }
 
    }
}