少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-20 a87120c155c48fa45b20a97c1a58bdbeb77318b7
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 22, 2017
//--------------------------------------------------------
 
using EnhancedUI.EnhancedScroller;
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class MarketDealWin : Window
    {
        [SerializeField] RectTransform m_ContainerSelect;
        [SerializeField] RectTransform m_ContainerView;
        [SerializeField] RectTransform m_NoSatifyItemTip;
        [SerializeField] Text m_CostNumTxt;
        [SerializeField] Text m_SelectTitleTxt;
        [SerializeField] InputField m_SearchInput;
        [SerializeField] Button m_SearchBtn;
        [SerializeField] Button m_SinglePriceBtn;
        [SerializeField] Button m_TotalPriceBtn;
        [SerializeField] ScrollerController m_TypeController;
        [SerializeField] ScrollerController m_ItemController;
        [SerializeField] List<Button> m_FitterBtns;
        [SerializeField] List<Text> m_FitterTxts;
        [SerializeField] List<Image> m_FitterImgs;
        private int presentFitterIndex = 0;
        private bool m_ClickSinglePrice = false;
        private bool m_ClickTotalPrice = false;
 
        private bool uintPricePositiveSequence = false;
        private bool allPricePositiveSequence = false;
        private Dictionary<int, string> fitterTypeDic = new Dictionary<int, string>();
        private Dictionary<MarketDealFitterType, int> fitterDic = new Dictionary<MarketDealFitterType, int>();
        private MarketDealFitterType presentFitterType = MarketDealFitterType.Algebra;
        private bool m_Searching = false;
        MarketModel m_Model = null;
        MarketModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<MarketModel>());
            }
        }
 
        RolePromoteModel promoteModel
        {
            get { return ModelCenter.Instance.GetModel<RolePromoteModel>(); }
        }
        #region Built-in
        protected override void BindController()
        {
        }
        protected override void AddListeners()
        {
            m_TypeController.lockType = EnhanceLockType.KeepVertical;
            m_SearchBtn.onClick.AddListener(OnSearchBtn);
            m_TypeController.OnRefreshCell += OnTypeRefreshCell;
            m_ItemController.OnRefreshCell += OnItemRefreshCell;
            m_SinglePriceBtn.onClick.AddListener(OnUintPriceSortBtn);
            m_TotalPriceBtn.onClick.AddListener(OnAllPriceSortBtn);
            for (int i = 0; i < m_FitterBtns.Count; i++)
            {
                var _index = i;
                m_FitterBtns[i].onClick.AddListener(() =>
                {
                    OnFitterClick(_index);
                });
            }
        }
 
        protected override void OnPreOpen()
        {
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent += OnRefreshPlayerInfo;
            FitterWin.FitterAction = OnFitterTypeClick;
            FitterWin.fitterClose = OnFitterClose;
            model.OnRefreshQueryMarketItem += OnRefreshQueryMarketItem;
            model.RefreshSelectTypeEvent += InitType;
 
            model.presentItemType = -1;
            m_SearchInput.text = string.Empty;
 
            InitInfo();
            InitType();
            RefreshCostItem();
            RefreshSelectTitleText();
        }
 
        private void OnFitterClose()
        {
            m_FitterImgs[presentFitterIndex].rectTransform.localEulerAngles = Vector3.zero;
        }
 
        private void OnRefreshQueryMarketItem()
        {
            if (model.presentItemType == -1 && !m_Searching)
            {
                return;
            }
            m_ItemController.m_Scorller.spacing = 14;
            m_ItemController.Refresh();
            List<MarketItemData> list = null;
            m_NoSatifyItemTip.gameObject.SetActive(true);
            if (m_Searching)
            {
                model.queryMarketItemList.TryGetValue(1, out list);
                FitterMarketItem(list);
                if (list != null && list.Count > 0) m_NoSatifyItemTip.gameObject.SetActive(false);
                for (int i = 0; i < model.marketDealItems.Count; i++)
                {
                    m_ItemController.AddCell(ScrollerDataType.Normal, i);
                }
            }
            else
            {
                if (model.presentItemType >= 0)
                {
                    model.queryMarketItemList.TryGetValue((uint)model.presentItemType, out list);
                    FitterMarketItem(list);
                    if (list != null && list.Count > 0) m_NoSatifyItemTip.gameObject.SetActive(false);
                    for (int i = 0; i < model.marketDealItems.Count; i++)
                    {
                        m_ItemController.AddCell(ScrollerDataType.Normal, i);
                    }
                }
            }
            m_ItemController.Restart();
        }
 
        private void FitterMarketItem(List<MarketItemData> list)
        {
            model.marketDealItems.Clear();
            if (list != null && list.Count > 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    bool throughFitter = true;
                    foreach (MarketDealFitterType type in fitterDic.Keys)
                    {
                        switch (type)
                        {
                            case MarketDealFitterType.Password:
                                {
                                    if (fitterDic[type] == 1)
                                    {
                                        if (list[i].NeadPwd != 1) throughFitter = false;
                                    }
                                    else if (fitterDic[type] == 2)
                                    {
                                        if (list[i].NeadPwd == 1) throughFitter = false;
                                    }
                                }
                                break;
                            case MarketDealFitterType.Quality:
                                {
                                    if (fitterDic[type] >= 0)
                                    {
                                        MarketConfig cfg = model.marketCfgDict[model.presentType];
                                        ItemConfig itemCfg = ItemConfig.Get((int)list[i].ItemTypeID);
                                        if (model.presentItemType == cfg.queryType[0])
                                        {
                                            if (Math.Pow(itemCfg.ItemColor, itemCfg.StarLevel) != fitterDic[type]) throughFitter = false;
                                        }
                                        else
                                        {
                                            if (itemCfg.ItemColor != fitterDic[type]) throughFitter = false;
                                        }
                                    }
                                }
                                break;
                            case MarketDealFitterType.Level:
                                {
                                    if (fitterDic[type] >= 0)
                                    {
                                        ItemConfig cfg = ItemConfig.Get((int)list[i].ItemTypeID);
                                        if (cfg != null)
                                        {
                                            if (cfg.LV != fitterDic[type]) throughFitter = false;
                                        }
                                    }
                                }
                                break;
                            case MarketDealFitterType.Algebra:
                                {
                                    if (fitterDic[type] >= 0)
                                    {
                                        var config = ItemConfig.Get((int)list[i].ItemTypeID);
                                        if (config != null)
                                        {
                                            if (!promoteModel.wingLv2GenerDict.ContainsKey(config.LV)
                                                || promoteModel.wingLv2GenerDict[config.LV] != fitterDic[type])
                                            {
                                                throughFitter = false;
                                            }
                                        }
                                    }
                                }
                                break;
                        }
                    }
                    if (!throughFitter)
                    {
                        continue;
                    }
                    model.marketDealItems.Add(list[i]);
                }
                model.marketDealItems.Sort(Compare);
            }
        }
 
        protected override void OnAfterOpen()
        {
 
        }
 
        protected override void OnPreClose()
        {
            m_Searching = false;
            model.RefreshSelectTypeEvent -= InitType;
        }
 
        protected override void OnAfterClose()
        {
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnRefreshPlayerInfo;
            FitterWin.FitterAction = null;
            FitterWin.fitterClose = null;
            model.OnRefreshQueryMarketItem -= OnRefreshQueryMarketItem;
            model.presentType = -1;
        }
        #endregion
        private void OnSearchBtn()
        {
            if (m_SearchInput.text.Equals(string.Empty))
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("Market_Text_41"));
                return;
            }
            m_Searching = true;
            model.presentType = 1000;
            m_TypeController.m_Scorller.RefreshActiveCellViews();
            RefreshSelectTitleText();
 
            m_ContainerSelect.gameObject.SetActive(false);
            m_ContainerView.gameObject.SetActive(true);
            OnRefreshQueryMarketItem();
 
            CB503_tagCGPYQueryBourseItemOnSale putawaypack = new CB503_tagCGPYQueryBourseItemOnSale();
            putawaypack.QueryType = 1;
            putawaypack.ItemName = m_SearchInput.text;
            putawaypack.ItemID = 0;
            GameNetSystem.Instance.SendInfo(putawaypack);
 
            InitViewFrame();
        }
 
        private void OnTypeRefreshCell(ScrollerDataType type, CellView cell)
        {
            int index = cell.index;
            var _leftTypeCell = cell as MarketLeftTypeCell;
            _leftTypeCell.Display(model.marketCfgDict[index].name, model.presentType == index);
        }
 
        private void OnLeftTypeClick(CellView cell)
        {
            m_Searching = false;
            model.presentType = cell.index;
            model.presentItemType = -1;
            InitType();
            m_TypeController.m_Scorller.RefreshActiveCellViews();
        }
 
        private void RefreshSelectTitleText()
        {
            if (model.marketCfgDict.ContainsKey(model.presentType))
            {
                m_SelectTitleTxt.gameObject.SetActive(true);
                m_SelectTitleTxt.text = Language.Get("Market_Select1", model.marketCfgDict[model.presentType].name);
            }
            else
            {
                m_SelectTitleTxt.gameObject.SetActive(false);
            }
        }
 
        private void OnItemRefreshCell(ScrollerDataType type, CellView cell)
        {
            switch (type)
            {
                case ScrollerDataType.Header:
                    {
                        var _page = cell.index;
                        var _cell = cell as MarketRightTypeCell;
                        _cell.Display(_page);
                    }
                    break;
                case ScrollerDataType.Normal:
                    {
                        int index = cell.index;
                        var _cell = cell as MarketDealItemCell;
                        _cell.Display(index);
                    }
                    break;
            }
        }
        private void OnUintPriceSortBtn()
        {
            m_ClickSinglePrice = true;
            m_ClickTotalPrice = false;
            uintPricePositiveSequence = !uintPricePositiveSequence;
            m_SinglePriceBtn.image.rectTransform.localEulerAngles = uintPricePositiveSequence ? new Vector3(0, 0, 180) : Vector3.zero;
            OnRefreshQueryMarketItem();
        }
 
        private void OnAllPriceSortBtn()
        {
            m_ClickSinglePrice = false;
            m_ClickTotalPrice = true;
            allPricePositiveSequence = !allPricePositiveSequence;
            m_TotalPriceBtn.image.rectTransform.localEulerAngles = allPricePositiveSequence ? new Vector3(0, 0, 180) : Vector3.zero;
            OnRefreshQueryMarketItem();
        }
 
        private void OnFitterClick(int id)
        {
            if (model.presentType == 1000)
            {
                OpenPwdFitterWin();
                return;
            }
            MarketQueryConfig queryConfig = MarketQueryConfig.Get(model.presentItemType);
            int type = queryConfig.ChooseType[id];
            var config = model.marketCfgDict[model.presentType];
            int[] intarray = null;
            if (id == 0)
            {
                intarray = config.ChooseItem1;
            }
            else if (id == 1)
            {
                intarray = config.ChooseItem2;
            }
            else if (id == 2)
            {
                intarray = config.ChooseItem3;
            }
            fitterTypeDic.Clear();
            presentFitterType = (MarketDealFitterType)type;
            presentFitterIndex = id;
            switch ((MarketDealFitterType)type)
            {
                case MarketDealFitterType.Password:
                    {
                        if (intarray != null && intarray.Length > 0)
                        {
                            for (int i = 0; i < intarray.Length; i++)
                            {
                                if (i == 0) fitterTypeDic.Add(-1, Language.Get("LoginWin_PassWord_Text_1"));
                                else if (i == 1) fitterTypeDic.Add(i, Language.Get("Market_Has_Pwd"));
                                else if (i == 2) fitterTypeDic.Add(i, Language.Get("Market_No_Pwd"));
                            }
                        }
                    }
                    break;
                case MarketDealFitterType.Quality:
                    {
                        if (model.presentItemType == config.queryType[0])
                        {
                            fitterTypeDic.Add(-1, Language.Get("Market_Text_53"));
                            if (model.fitters != null)
                            {
                                for (int i = 0; i < model.fitters.Count; i++)
                                {
                                    KeyValuePair<int, int> pair = model.fitters[i];
                                    fitterTypeDic.Add((int)Mathf.Pow(pair.Key, pair.Value), Language.Get(string.Format("Market_Text_{0}", 45 + pair.Key), pair.Value));
                                }
                            }
                        }
                        else
                        {
                            fitterTypeDic.Add(-1, Language.Get("Market_Text_52"));
                            if (intarray != null && intarray.Length > 0)
                            {
                                for (int i = 0; i < intarray.Length; i++)
                                {
                                    fitterTypeDic.Add(intarray[i], Language.Get(string.Format("Market_Text_4{0}", intarray[i] + 1)));
                                }
                            }
                        }
                    }
                    break;
                case MarketDealFitterType.Level:
                    {
                        fitterTypeDic.Add(-1, Language.Get("Market_Fitter_Level"));
                        if (intarray != null && intarray.Length > 0)
                        {
                            for (int i = 0; i < intarray.Length; i++)
                            {
                                fitterTypeDic.Add(intarray[i], Language.Get("EquipSuitLV", intarray[i]));
                            }
                        }
                    }
                    break;
                case MarketDealFitterType.Algebra:
                    {
                        fitterTypeDic.Add(-1, Language.Get("Market_Text_54"));
                        if (intarray != null && intarray.Length > 0)
                        {
                            for (int i = 0; i < intarray.Length; i++)
                            {
                                fitterTypeDic.Add(intarray[i], Language.Get("Market_Text_55", Language.Get(string.Format("Num_CHS_{0}", intarray[i]))));
                            }
                        }
                    }
                    break;
            }
            FitterWin.fitterTypes = fitterTypeDic;
            FitterWin.FitterAction = OnFitterTypeClick;
            FitterWin.target = m_FitterImgs[id].transform.parent as RectTransform;
            m_FitterImgs[id].rectTransform.localEulerAngles = new Vector3(0, 0, 180);
            WindowCenter.Instance.Open<FitterWin>();
        }
 
        private void OpenPwdFitterWin()
        {
            fitterTypeDic.Clear();
            presentFitterType = MarketDealFitterType.Password;
            presentFitterIndex = 0;
            fitterTypeDic.Add(0, Language.Get("LoginWin_PassWord_Text_1"));
            fitterTypeDic.Add(1, Language.Get("Market_Has_Pwd"));
            fitterTypeDic.Add(2, Language.Get("Market_No_Pwd"));
            FitterWin.fitterTypes = fitterTypeDic;
            FitterWin.FitterAction = OnFitterTypeClick;
            FitterWin.target = m_FitterImgs[0].transform.parent as RectTransform;
            WindowCenter.Instance.Open<FitterWin>();
        }
 
        private void InitInfo()
        {
            m_TypeController.Refresh();
            foreach (var _key in model.marketCfgDict.Keys)
            {
                var _cfg = model.marketCfgDict[_key];
                if (PlayerDatas.Instance.baseData.LV >= _cfg.limitLv)
                {
                    if (model.presentType == -1)
                    {
                        model.presentType = _cfg.type;
                    }
                    m_TypeController.AddCell(ScrollerDataType.Header, _cfg.type, OnLeftTypeClick);
                }
            }
            m_TypeController.Restart();
        }
 
        private void RefreshCostItem()
        {
            m_CostNumTxt.text = PlayerDatas.Instance.baseData.Gold.ToString();
        }
 
        private void InitType()
        {
            if (model.presentItemType == -1 && model.marketCfgDict.ContainsKey(model.presentType))
            {
                m_ContainerSelect.gameObject.SetActive(true);
                m_ContainerView.gameObject.SetActive(false);
                m_ItemController.m_Scorller.spacing = 20;
                m_ItemController.Refresh();
                int[] itemTypeArray = model.marketCfgDict[model.presentType].queryType;
                if (itemTypeArray != null)
                {
                    int page = Mathf.CeilToInt((float)itemTypeArray.Length / 3);
                    for (int i = 0; i < page; i++)
                    {
                        m_ItemController.AddCell(ScrollerDataType.Header, i);
                    }
                }
                m_ItemController.Restart();
 
                RefreshSelectTitleText();
            }
            else
            {
                m_ContainerSelect.gameObject.SetActive(false);
                m_ContainerView.gameObject.SetActive(true);
                OnRefreshQueryMarketItem();
 
                InitViewFrame();
            }
        }
 
        private void OnRefreshPlayerInfo(PlayerDataRefresh refreshType)
        {
            switch (refreshType)
            {
                case PlayerDataRefresh.LV:
                    {
                        InitInfo();
                    }
                    break;
                case PlayerDataRefresh.Gold:
                    {
                        RefreshCostItem();
                    }
                    break;
            }
        }
 
        private void InitViewFrame()
        {
            if (model.presentType == 1000)
            {
                fitterDic.Clear();
                for (int i = 0; i < m_FitterImgs.Count; i++)
                {
                    if (i == 0)
                    {
                        m_FitterImgs[i].transform.parent.gameObject.SetActive(true);
                        fitterDic.Add(MarketDealFitterType.Password, 0);
                        m_FitterImgs[i].rectTransform.localEulerAngles = Vector3.zero;
                        m_FitterTxts[i].text = Language.Get("LoginWin_PassWord_Text_1");
                    }
                    else
                    {
                        m_FitterImgs[i].transform.parent.gameObject.SetActive(false);
                    }
                }
            }
            else
            {
                MarketConfig config = model.marketCfgDict[model.presentType];
                MarketQueryConfig queryConfig = MarketQueryConfig.Get(model.presentItemType);
                fitterDic.Clear();
                for (int i = 0; i < m_FitterImgs.Count; i++)
                {
                    if (i < queryConfig.ChooseType.Length)
                    {
                        if (queryConfig.ChooseType[i] != 0)
                        {
                            fitterDic.Add((MarketDealFitterType)queryConfig.ChooseType[i], -1);
                            m_FitterImgs[i].transform.parent.gameObject.SetActive(true);
                            switch ((MarketDealFitterType)queryConfig.ChooseType[i])
                            {
                                case MarketDealFitterType.Password:
                                    m_FitterTxts[i].text = config.ChooseName[i];
                                    break;
                                case MarketDealFitterType.Quality:
                                    if (model.presentItemType == config.queryType[0])
                                    {
                                        m_FitterTxts[i].text = Language.Get("Market_Text_53");
                                    }
                                    else
                                    {
                                        m_FitterTxts[i].text = Language.Get("Market_Text_52");
                                    }
                                    break;
                                case MarketDealFitterType.Level:
                                    m_FitterTxts[i].text = Language.Get("Market_Fitter_Level");
                                    break;
                                case MarketDealFitterType.Algebra:
                                    m_FitterTxts[i].text = Language.Get("Market_Text_54");
                                    break;
                            }
                            m_FitterImgs[i].rectTransform.localEulerAngles = Vector3.zero;
                            continue;
                        }
                    }
                    m_FitterImgs[i].transform.parent.gameObject.SetActive(false);
                }
            }
            m_ClickTotalPrice = false;
            m_ClickSinglePrice = false;
            uintPricePositiveSequence = false;
            allPricePositiveSequence = false;
            m_SinglePriceBtn.image.rectTransform.localEulerAngles = uintPricePositiveSequence ? new Vector3(0, 0, 180) : Vector3.zero;
            m_TotalPriceBtn.image.rectTransform.localEulerAngles = uintPricePositiveSequence ? new Vector3(0, 0, 180) : Vector3.zero;
        }
 
        private void OnFitterTypeClick(int obj)
        {
            if (fitterDic.ContainsKey(presentFitterType))
            {
                fitterDic[presentFitterType] = obj;
            }
            m_FitterTxts[presentFitterIndex].text = fitterTypeDic[obj];
            m_FitterImgs[presentFitterIndex].rectTransform.localEulerAngles = Vector3.zero;
            OnRefreshQueryMarketItem();
        }
 
        public enum MarketDealFitterType
        {
            Password = 1,//密码
            Quality = 2,//品质
            Level = 3,//阶数
            Algebra = 4,//代数
        }
 
        private int Compare(MarketItemData x, MarketItemData y)
        {
            if (!m_ClickSinglePrice && !m_ClickTotalPrice)
            {
                return -1;
            }
            if (m_ClickSinglePrice)
            {
                int uintpricex = (int)x.PriceCount / x.Count;
                int uintpricey = (int)y.PriceCount / y.Count;
                var _up = uintPricePositiveSequence ? 1 : -1;
                return _up * uintpricex.CompareTo(uintpricey);
            }
            if (m_ClickTotalPrice)
            {
                var _up = allPricePositiveSequence ? 1 : -1;
                return _up * x.PriceCount.CompareTo(y.PriceCount);
            }
            return -1;
        }
    }
 
}