少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-16 fc714208ff3a320c3bb52bddd5ea3d91f647a206
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Snxxz.UI;
using System.Collections.Generic;
using System;
using System.Linq;
 
 
namespace Snxxz.UI
{
    public class BuyPetMatInfoWin : Window
    {
        [SerializeField] RectTransform bgObj;
 
        [SerializeField] ModelShowPerfab modelShow;
        [Header("顶部UI")]
        [SerializeField] GameObject topPart;
        [SerializeField]Text nameText;
        [SerializeField] List<Text> attrNamelist = new List<Text>();
        [SerializeField] List<Text> attrValuelist = new List<Text>();
        [SerializeField] Button closeBtn;
        [SerializeField] RectTransform skillContent;
        [Header("中部UI")]
        [SerializeField] GameObject midPart;
        [SerializeField]
        List<PetSkillCell> skillCelllist = new List<PetSkillCell>();
 
        [SerializeField]
        GameObject bottomPart;
 
        [SerializeField]
        RectTransform numberGo;
 
        [SerializeField]
        Text vipInfoText;
 
        [SerializeField]
        Text buyCountText;
 
        [SerializeField]
        Text buyPriceText;
 
        [SerializeField]
        RectTransform moneyRect;
 
        [SerializeField]
        Image moneyIcon;
 
        [SerializeField]
        Button reduceBtn;
 
        [SerializeField]
        Button plusBtn;
 
        [SerializeField]
        Button buyCountBtn;
 
        [SerializeField]
        Button buyBtn;
 
        [SerializeField] Text buyBtnText;
 
        [SerializeField]
        NumKeyBoard numKeyboard;
 
        [SerializeField]
        CanvasGroup tipAlpha;
 
        ItemTipsModel _itemTipsModel;
        ItemTipsModel itemTipsModel
        {
            get
            {
                return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
            }
        }
        StoreModel _storeModel;
        StoreModel m_storeModel
        {
            get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
        }
        PetModel petmodel { get { return ModelCenter.Instance.GetModel<PetModel>(); } }
        MountModel mountModel { get { return ModelCenter.Instance.GetModel<MountModel>(); } }
 
        BuyItemPopModel buyItem;
        BuyShopItemLimit shopItemLimit;
        int canBuyCnt = 0;
        int buyCnt = 0;
        int curVipIndex = -1;
        bool isVipBuy = false;
        Dictionary<int, int> petSkillDict;
        Dictionary<int, List<int>> mountSkillDict;
 
        Color32 conditionColor = new Color32(255, 244, 205, 255);
        Color32 conditionRedColor = new Color32(255, 1, 1, 255);
        PetMatType matType = PetMatType.None;
 
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            closeBtn.AddListener(OnClickCloseBtn);
            buyBtn.AddListener(OnClickBuyBtn);
            reduceBtn.onClick.AddListener(OnClickReduceBuyNum);
            plusBtn.onClick.AddListener(OnClickPlusBuyNum);
            buyCountBtn.onClick.AddListener(OnClickCountBtn);
            numKeyboard.onConfirm.AddListener(OnClickConfirmBtn);
            numKeyboard.onValueChange.AddListener(OnClickNum);
        }
        protected override void OnPreOpen()
        {
            buyItem = BuyItemPopModel.Instance;
            shopItemLimit = m_storeModel.GetBuyShopLimit((uint)buyItem.storeConfig.ID);
            tipAlpha.alpha = 0;
            topPart.SetActive(false);
            bottomPart.SetActive(false);
            midPart.SetActive(false);
            InitUI();
        }
        protected override void OnAfterOpen()
        {
            StartCoroutine(SetTopShow());
        }
 
        protected override void OnPreClose()
        {
          
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        private void InitUI()
        {
            petSkillDict = null;
            mountSkillDict = null;
            matType = PetMatType.None;
            if (itemTipsModel.curAttrData == null) return;
 
            if (itemTipsModel.unlockPetDict.ContainsKey(itemTipsModel.curAttrData.itemId))
            {
                matType = PetMatType.Pet;
            }
            else if (itemTipsModel.unlockMountDict.ContainsKey(itemTipsModel.curAttrData.itemId))
            {
                matType = PetMatType.Mount;
            }
 
            SetTopUI();
            SetMidUI();
            skillContent.localPosition = Vector3.zero;
        }
 
        private void SetTopUI()
        {
            Dictionary<int, int> itemEffectDict = null;
            switch (matType)
            {
                case PetMatType.Pet:
                    PetInfoConfig petInfo = itemTipsModel.unlockPetDict[itemTipsModel.curAttrData.itemId];
                    itemEffectDict = petmodel.GetPetAttrAddDict(petInfo.ID);
                    break;
                case PetMatType.Mount:
                    HorseConfig horseConfig = itemTipsModel.unlockMountDict[itemTipsModel.curAttrData.itemId];
                    itemEffectDict = mountModel.GetMountAttrAddDict(horseConfig.HorseID);
                    break;
            }
 
            nameText.color = UIHelper.GetUIColor(itemTipsModel.curAttrData.itemConfig.ItemColor);
            nameText.text = itemTipsModel.curAttrData.itemConfig.ItemName;
          
            List<int> attrIdlist = itemEffectDict.Keys.ToList();
            for (int i = 0; i < attrNamelist.Count; i++)
            {
                attrNamelist[i].gameObject.SetActive(false);
                attrValuelist[i].gameObject.SetActive(false);
            }
 
            int code = 0;
            for (int i = 0; i < attrIdlist.Count; i++)
            {
                string attrName = "";
                string attrValue = "";
                string minAtkName = "";
                string minAtkValue = "";
                attrNamelist[code].gameObject.SetActive(true);
                attrValuelist[code].gameObject.SetActive(true);
                switch ((PropertyType)attrIdlist[i])
                {
                    case PropertyType.MinAtk:
                        break;
                    case PropertyType.PetMinAtk:
                        break;
                    case PropertyType.PetMaxAtk:
                    case PropertyType.MaxAtk:
                        itemTipsModel.SetPetAttrStr(attrIdlist[i - 1], itemEffectDict[attrIdlist[i - 1]], out minAtkName, out minAtkValue);
                        itemTipsModel.SetPetAttrStr(attrIdlist[i], itemEffectDict[attrIdlist[i]], out attrName, out attrValue, minAtkValue);
                        code += 1;
                        break;
                    default:
                        itemTipsModel.SetPetAttrStr(attrIdlist[i], itemEffectDict[attrIdlist[i]], out attrName, out attrValue);
                        code += 1;
                        break;
                }
 
                if (code > 0)
                {
                    attrNamelist[code - 1].text = UIHelper.GetSuitNameByName(attrName);
                    attrValuelist[code - 1].text = attrValue;
                }
            }
        }
 
        private void SetMidUI()
        {
            switch (matType)
            {
                case PetMatType.Pet:
                    PetInfoConfig petInfo = itemTipsModel.unlockPetDict[itemTipsModel.curAttrData.itemId];
                    petSkillDict = itemTipsModel.GetPetSkillDict(itemTipsModel.curAttrData.itemId);
                    modelShow.SetModelShow(petInfo.ID, ModelShowType.pet, Language.Get("TreasureEffect103"), petInfo.ShowFightPower);
                    break;
                case PetMatType.Mount:
                    HorseConfig horseConfig = itemTipsModel.unlockMountDict[itemTipsModel.curAttrData.itemId];
                    mountSkillDict = itemTipsModel.GetMountSkillDict(itemTipsModel.curAttrData.itemId);
                    modelShow.SetModelShow(horseConfig.Model, ModelShowType.mount, Language.Get("TreasureEffect103"), horseConfig.ShowFightPower);
                    break;
            }
 
            List<int> unlockLvlist = null;
            if (petSkillDict != null)
            {
                unlockLvlist = petSkillDict.Keys.ToList();
            }
            else if (mountSkillDict != null)
            {
                unlockLvlist = mountSkillDict.Keys.ToList();
            }
 
            for (int i = 0; i < skillCelllist.Count; i++)
            {
                skillCelllist[i].gameObject.SetActive(false);
            }
 
            int code = 0;
            for (int i = 0; i < unlockLvlist.Count; i++)
            {
                if (petSkillDict != null)
                {
                    skillCelllist[code].gameObject.SetActive(true);
                    skillCelllist[code].SetModel(petSkillDict[unlockLvlist[i]], unlockLvlist[i]);
                    code += 1;
                }
                else if (mountSkillDict != null)
                {
                    for (int j = 0; j < mountSkillDict[unlockLvlist[i]].Count; j++)
                    {
                        skillCelllist[code].gameObject.SetActive(true);
                        skillCelllist[code].SetModel(mountSkillDict[unlockLvlist[i]][j], unlockLvlist[i]);
                        code += 1;
                    }
                }
            }
        }
 
        IEnumerator SetTopShow()
        {
            yield return null;
            topPart.SetActive(true);
            StartCoroutine(SetMidShow());
        }
 
        IEnumerator SetMidShow()
        {
            yield return null;
            midPart.SetActive(true);
            StartCoroutine(ShowBottomPart());
        }
 
        IEnumerator ShowBottomPart()
        {
            yield return null;
            SetBottomUI();
            StartCoroutine(SetPanelScale());
        }
 
        IEnumerator SetPanelScale()
        {
            yield return null;
            tipAlpha.alpha = 1;
        }
 
        private void SetBottomUI()
        {
            bottomPart.gameObject.SetActive(true);
            numKeyboard.gameObject.SetActive(false);
            curVipIndex = -1;
            int nextVipIndex = -1;
            isVipBuy = buyItem.CheckIsVipBuy(buyItem.storeConfig,out curVipIndex,out nextVipIndex);
            canBuyCnt = 0;
            int addBuyCnt = 0;
            bool isLimitCnt = buyItem.CheckIsLimitBuyCnt(buyItem.storeConfig,out canBuyCnt,out addBuyCnt);
            bool isReachUpper = false;
            buyCnt = buyItem.GetCurBuyCnt(1, buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy), out isReachUpper);
            buyBtn.gameObject.SetActive(true);
 
            if (isVipBuy)
            {
                if(nextVipIndex != -1)
                {
                    vipInfoText.gameObject.SetActive(true);
                    vipInfoText.text = Language.Get("StoreWin108",canBuyCnt, StringUtility.Contact("V",buyItem.storeConfig.VIPLV[nextVipIndex]),addBuyCnt);
                }
                else
                {
                    vipInfoText.gameObject.SetActive(false);
                }
 
                if(curVipIndex != -1)
                {
                    
                }
                else
                {
                    buyBtn.gameObject.SetActive(false);
                    buyCnt = buyItem.GetCurBuyCnt(0, canBuyCnt, out isReachUpper);
                }
            }
            else
            {
                vipInfoText.gameObject.SetActive(false);
            }
 
            if(buyItem.storeConfig.LimitValue != 0)
            {
                int unionLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
                switch (m_storeModel.storeFuncType)
                {
                    case StoreFunc.MysteryStore:
                        break;
                    case StoreFunc.CommonStore:
                        break;
                    case StoreFunc.GrowStrongerStore:
                        break;
                    case StoreFunc.BindStore:
                        break;
                    case StoreFunc.IntegralStore:
                        break;
                    case StoreFunc.BagStore:
                        break;
                    case StoreFunc.RuneStore:
                        break;
                    case StoreFunc.ToolStore:
                        if(unionLv < buyItem.storeConfig.LimitValue)
                        {
                            buyBtn.gameObject.SetActive(false);
                        }
                        break;
                    case StoreFunc.MountStoneStore:
                        if (unionLv < buyItem.storeConfig.LimitValue)
                        {
                            buyBtn.gameObject.SetActive(false);
                        }
                        break;
                    case StoreFunc.MountSkillBookStore:
                        if (unionLv < buyItem.storeConfig.LimitValue)
                        {
                            buyBtn.gameObject.SetActive(false);
                        }
                        break;
                }
            }
 
            buyCountText.text = buyCnt.ToString();
            RefreshBuyPrice(buyCnt);
            moneyIcon.SetIconWithMoneyType(buyItem.storeConfig.MoneyType);
        }
 
 
 
        private ulong _price;
        private void RefreshBuyPrice(int buyCnt)
        {
            if(buyCnt < 1)
            {
                _price = (ulong)buyItem.storeConfig.MoneyNumber;
            }
            else
            {
                _price = (ulong)buyItem.GetBuyPrice(buyItem.storeConfig,buyCnt);
            }
 
            if (!m_storeModel.MoneyIsEnough(buyItem.storeConfig.MoneyType, _price))
            {
                buyPriceText.text = UIHelper.AppendColor(TextColType.Red, _price.ToString());
            }
            else
            {
                buyPriceText.text = UIHelper.AppendColor(TextColType.Green, _price.ToString());
            }
 
            if (_price <= 0)
            {
                moneyRect.gameObject.SetActive(false);
                buyBtnText.text = Language.Get("MailReceive");
            }
            else
            {
                buyBtnText.text = Language.Get("ItemHandle_buy");
                moneyRect.gameObject.SetActive(true);
            }
 
            if (_price <= 0 || itemTipsModel.curAttrData.itemConfig.PackCount < 2)
            {
                numberGo.gameObject.SetActive(false);
             
            }
            else
            {
                numberGo.gameObject.SetActive(true);
             
            }
        }
        #region 点击事件
      
        private void OnClickCountBtn()
        {
            numKeyboard.gameObject.SetActive(true);
        }
 
        private void OnClickNum()
        {
            bool isReachUpper = false;
            buyCnt = buyItem.GetCurBuyCnt(int.Parse(numKeyboard.Value), buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy),out isReachUpper);
            RefreshBuyPrice(buyCnt);
            numKeyboard.Value = buyCnt.ToString();
            if (isReachUpper)
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("StoreWin109"));
            }
        }
 
        private void OnClickConfirmBtn(bool arg0)
        {
            if (arg0)
            {
                buyCountText.text = buyCnt.ToString();
                numKeyboard.gameObject.SetActive(false);
            }
        }
 
        private void OnClickPlusBuyNum()
        {
            buyCnt += 1;
            bool isReachUpper = false;
            buyCnt = buyItem.GetCurBuyCnt(buyCnt, buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy), out isReachUpper);
            buyCountText.text = buyCnt.ToString();
            RefreshBuyPrice(buyCnt);
            if (isReachUpper)
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("StoreWin109"));
            }
        }
 
        private void OnClickReduceBuyNum()
        {
            buyCnt -= 1;
            bool isReachUpper = false;
            buyCnt = buyItem.GetCurBuyCnt(buyCnt, buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy),out isReachUpper);
            buyCountText.text = buyCnt.ToString();
            RefreshBuyPrice(buyCnt);
        }
 
        private void OnClickBuyBtn()
        {
            if (shopItemLimit != null)
            {
                int remainNum = 0;
                if(isVipBuy)
                {
                    remainNum = buyItem.storeConfig.PurchaseNumber[curVipIndex] - shopItemLimit.BuyCnt;
                }
                else
                {
                    remainNum = buyItem.storeConfig.PurchaseNumber[0] - shopItemLimit.BuyCnt;
                } 
                if (remainNum < 1)
                {
                    ServerTipDetails.DisplayNormalTip(Language.Get("StoreWin109"));
                    return;
                }
 
            }
            m_storeModel.SendBuyShopItem(buyItem.storeConfig,buyCnt);
            OnClickCloseBtn();
        }
 
        private void OnClickCloseBtn()
        {
            CloseImmediately();
        }
        #endregion
    }
}