少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 f1f2599ba0e6b64358ffef7ae5c9f9af3ed8b8b4
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, August 17, 2018
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
//神兽强化右侧材料吸收列表
namespace Snxxz.UI
{
    public class GodBeastBagClass
    {
        public int ItemId;//ID
        public int Index;//下标
        public int IsEquipment;//是否装备0水晶,1装备
        public int Color;//品质颜色
        public int Star;//星级
        public int LV;//等级
        public int Proficiency;//熟练度
        public int EquipScore;//装备评分
        public int Part;//装备位
        public int Count;//数量
    }
 
    public class GodBeastSlidingList : MonoBehaviour
    {
        [SerializeField] ScrollerController m_ScrollerController;
 
        [SerializeField] Text m_Label;
        [SerializeField] Button m_Arrow;
        [SerializeField] GameObject m_ScrollViewFirst;
        [SerializeField] Button m_ButtonAll;//所有
        [SerializeField] Button m_ButtonCrystal;//水晶
        [SerializeField] Button m_ButtonBlue;//蓝
        [SerializeField] Button m_ButtonPurple;//紫色
        [SerializeField] Button m_ButtonOrange;//橙色
 
        [SerializeField] Toggle m_ToggleAll;
        public int LINE = 10;
        private List<GodBeastBagClass> GodBeastBagList = new List<GodBeastBagClass>();
        private List<int> DeleteIndexList = new List<int>();
        private int Quality = 10;
        private int GetJumpIndex = 0;//获取跳转下标
        PackModel _playerPack;
        PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
        GodBeastModel godBeastModel { get { return ModelCenter.Instance.GetModel<GodBeastModel>(); } }
        private void Awake()
        {
 
        }
        private void Start()
        {
            m_Arrow.AddListener(OnClickArrow);
            m_ButtonAll.AddListener(() =>
            {
                OnClickSwith(10);
                if (m_ToggleAll.isOn)
                {
                    m_ToggleAll.isOn = false;
                }
                GetGodBeastBag();//获取神兽背包数据排序
                FilterQuality();//分类筛选
                godBeastModel.AbsorbEventUpdate();
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
            });
            m_ButtonCrystal.AddListener(() =>
            {
                OnClickSwith(0);
                if (m_ToggleAll.isOn)
                {
                    m_ToggleAll.isOn = false;
                }
                GetGodBeastBag();//获取神兽背包数据排序
                FilterQuality();//分类筛选
                godBeastModel.AbsorbEventUpdate();
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
            });
            m_ButtonBlue.AddListener(() =>
            {
                OnClickSwith(2);
                if (m_ToggleAll.isOn)
                {
                    m_ToggleAll.isOn = false;
                }
                GetGodBeastBag();//获取神兽背包数据排序
                FilterQuality();//分类筛选
                godBeastModel.AbsorbEventUpdate();
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见    
            });
            m_ButtonPurple.AddListener(() =>
            {
                OnClickSwith(3);
                if (m_ToggleAll.isOn)
                {
                    m_ToggleAll.isOn = false;
                }
                GetGodBeastBag();//获取神兽背包数据排序
                FilterQuality();//分类筛选
                godBeastModel.AbsorbEventUpdate();
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
            });
            m_ButtonOrange.AddListener(() =>
            {
                OnClickSwith(4);
                if (m_ToggleAll.isOn)
                {
                    m_ToggleAll.isOn = false;
                }
                GetGodBeastBag();//获取神兽背包数据排序
                FilterQuality();//分类筛选
                godBeastModel.AbsorbEventUpdate();
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
            });
            m_ToggleAll.onValueChanged.AddListener(OnClickToggle);
        }
        private void OnEnable()
        {
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent += MakeItemAnswerEvent;
            godBeastModel.AbsorbEvent += AbsorbEvent;
            playerPack.itemCntAddEvent += RefreshItemCountAct;
        }
 
 
 
        private void OnDisable()
        {
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent -= MakeItemAnswerEvent;
            godBeastModel.AbsorbEvent -= AbsorbEvent;
            playerPack.itemCntAddEvent -= RefreshItemCountAct;
        }
 
 
 
        public void Init()
        {
            Quality = 10;
            LINE = Mathf.CeilToInt((float)100 / 3);
            ContentSelect(Quality);
            if (m_ScrollViewFirst.activeSelf)
            {
                m_ScrollViewFirst.SetActive(false);
            }
            if (m_ToggleAll.isOn)
            {
                m_ToggleAll.isOn = false;
            }
            GetGodBeastBag();//获取神兽背包数据排序
            FilterQuality();//分类筛选
            godBeastModel.AbsorbEventUpdate();
            m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
            OnCreateGridLineCell(m_ScrollerController);
 
        }
 
        public void Unit()
        {
            m_ScrollerController.OnRefreshCell -= OnRefreshGridCell;
        }
        private void MakeItemAnswerEvent(H0721_tagMakeItemAnswer obj)
        {
            if ((int)obj.MakeType == (int)MakeType.DogzEquipPlus)
            {
 
            }
        }
        private void RefreshItemCountAct(PackType arg1, int arg2, int arg3)
        {
            if (arg1 == PackType.DogzItem)
            {
                if (m_ToggleAll.isOn)
                {
                    m_ToggleAll.isOn = false;
                }
                GetGodBeastBag();
                FilterQuality();
                godBeastModel.AbsorbEventUpdate();
                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
            }
        }
        private void AbsorbEvent()
        {
            m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
        }
        private void GetGodBeastBag()//获取神兽背包数据排序
        {
            GodBeastBagList.Clear();
            if (playerPack.GetSinglePack(PackType.DogzItem) == null)
            {
                return;
            }
            Dictionary<int, ItemModel> BackpackDic = playerPack.GetSinglePack(PackType.DogzItem).GetAllItems();
            foreach (var key in BackpackDic.Keys)
            {
                var itemModel = BackpackDic[key];
                GodBeastBagClass godBeastBagClass = new GodBeastBagClass();
                godBeastBagClass.ItemId = itemModel.itemId;
                if (itemModel.itemId == 5417)
                {
                    continue;
                }
                godBeastBagClass.Index = key;
                if (itemModel.config.Type != 70)
                {
                    godBeastBagClass.IsEquipment = 1;
                }
                else
                {
                    godBeastBagClass.IsEquipment = 0;
                }
                godBeastBagClass.Color = itemModel.config.ItemColor;
                godBeastBagClass.Star = itemModel.config.StarLevel;
                godBeastBagClass.EquipScore = itemModel.score;
                godBeastBagClass.Part = itemModel.config.EquipPlace;
                godBeastBagClass.Count = itemModel.count;
                var IudetDogzEquipPlus = itemModel.GetUseData((int)ItemUseDataKey.dogzEquipPlus);// 神兽装备强化信息列表 [强化等级, 强化熟练度]
                if (IudetDogzEquipPlus == null)
                {
                    godBeastBagClass.LV = 0;
                    godBeastBagClass.Proficiency = 0;
 
                }
                else
                {
                    godBeastBagClass.LV = IudetDogzEquipPlus[0];
                    godBeastBagClass.Proficiency = IudetDogzEquipPlus[1];
                }
 
                GodBeastBagList.Add(godBeastBagClass);
            }
            GodBeastBagList.Sort(Compare);
        }
        int Compare(GodBeastBagClass x, GodBeastBagClass y)
        {
            if (x.IsEquipment.CompareTo(y.IsEquipment) != 0)//是否强化水晶
            {
                return x.IsEquipment.CompareTo(y.IsEquipment);
            }
            if (x.Proficiency.CompareTo(y.Proficiency) != 0)//强化熟练度
            {
                return -x.Proficiency.CompareTo(y.Proficiency);
            }
            if (x.Color.CompareTo(y.Color) != 0)//品质
            {
                return -x.Color.CompareTo(y.Color);
            }
            if (x.Star.CompareTo(y.Star) != 0)//星级
            {
                return -x.Star.CompareTo(y.Star);
            }
            if (x.Part.CompareTo(y.Part) != 0)//装备位
            {
                return x.Part.CompareTo(y.Part);
            }
            if (x.EquipScore.CompareTo(y.EquipScore) != 0)//装备评分
            {
                return x.EquipScore.CompareTo(y.EquipScore);
            }
            return 1;
        }
 
        private void FilterQuality()//分类筛选
        {
            DeleteIndexList.Clear();
            godBeastModel.Absorption_Dic.Clear();
            for (int i = 0; i < GodBeastBagList.Count; i++)
            {
                if (Quality <= 0)//只有水晶
                {
                    if (GodBeastBagList[i].IsEquipment != 0)
                    {
                        int type = i;
                        DeleteIndexList.Add(type);
                    }
                }
                else
                {
                    if (Quality < 10 && (GodBeastBagList[i].IsEquipment != 1 || GodBeastBagList[i].Color > Quality))//过滤掉只剩所选品质装备
                    {
                        int type = i;
                        DeleteIndexList.Add(type);
                    }
                }
            }
            for (int j = DeleteIndexList.Count; j > 0; j--)
            {
                int Inedex = DeleteIndexList[j - 1];
                if (Inedex <= GodBeastBagList.Count - 1)
                {
                    GodBeastBagList.RemoveAt(Inedex);
                }
            }
            if (m_ToggleAll.isOn)
            {
                for (int k = 0; k < GodBeastBagList.Count; k++)
                {
                    for (int j = 0; j < GodBeastBagList[k].Count; j++)
                    {
                        if (!godBeastModel.IsFullLevel())
                        {
                            if (!godBeastModel.Absorption_Dic.ContainsKey(GodBeastBagList[k].Index))
                            {
                                godBeastModel.Absorption_Dic.Add(GodBeastBagList[k].Index, 1);
                            }
                            else
                            {
                                int Type = j + 1;
                                godBeastModel.Absorption_Dic[GodBeastBagList[k].Index] = Type;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
 
        private void OnClickArrow()
        {
            m_ScrollViewFirst.SetActive(!m_ScrollViewFirst.activeSelf);
        }
 
        private void OnClickToggle(bool IsBool)
        {
            if (IsBool)
            {
 
            }
            else
            {
                if (godBeastModel.Absorption_Dic.Count != 0)
                {
                    godBeastModel.Absorption_Dic.Clear();
                }
            }
            GetGodBeastBag();
            FilterQuality();
            godBeastModel.AbsorbEventUpdate();
            m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
        }
        private void OnClickSwith(int Type)
        {
            Quality = Type;
            if (m_ScrollViewFirst.activeSelf)
            {
                m_ScrollViewFirst.SetActive(false);
            }
            ContentSelect(Quality);
        }
        private void ContentSelect(int Type)
        {
            switch (Type)
            {
                case 0:
                    m_Label.text = Language.Get("Crystal_SH");
                    break;
                case 2:
                    m_Label.text = Language.Get("BelowBlue_SH");
                    break;
                case 3:
                    m_Label.text = Language.Get("BelowPurple_SH");
                    break;
                case 4:
                    m_Label.text = Language.Get("BelowOrange_SH");
                    break;
                case 10:
                    m_Label.text = Language.Get("All_SH");
                    break;
                default:
                    break;
            }
 
        }
        void OnCreateGridLineCell(ScrollerController gridCtrl)
        {
            gridCtrl.Refresh();
            int code = 0;
            for (code = 0; code < LINE; code++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header, code);
            }
            gridCtrl.Restart();
        }
        private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            int gridlineIndex = cell.index;
            int childCode = 0;
            for (childCode = 0; childCode < cell.transform.childCount; childCode++)
            {
                int ItemPos = childCode + 1;
                GodBeastChildNodes GodBeastChildNodes = cell.transform.GetChild(childCode).GetComponent<GodBeastChildNodes>();
                int cellCount = (cell.transform.childCount) * gridlineIndex + (childCode + 1);
                if (cellCount > 100)
                {
                    GodBeastChildNodes.gameObject.SetActive(false);
                    continue;
                }
                GodBeastChildNodes.gameObject.SetActive(true);
                GodBeastChildNodes.ItemCell.gameObject.SetActive(false);
                GodBeastChildNodes.ChoosenImg.SetActive(false);
                GodBeastChildNodes.TextNumber.gameObject.SetActive(false);
                GodBeastChildNodes.NumberNow.gameObject.SetActive(false);
                GodBeastChildNodes.ButtonDown.RemoveAllListeners();
                if (cellCount - 1 < GodBeastBagList.Count)
                {
                    int index = cellCount - 1;                
                    GodBeastChildNodes.ItemCell.gameObject.SetActive(true);
                    GodBeastBagClass godBeastBagClass = GodBeastBagList[index];
                    ItemModel itemModel = playerPack.GetItemByIndex(PackType.DogzItem, godBeastBagClass.Index);
                    if (itemModel == null)
                    {
                        return;
                    }
 
                    if (godBeastModel.Absorption_Dic.ContainsKey(godBeastBagClass.Index))
                    {
                        GodBeastChildNodes.ChoosenImg.SetActive(true);
                        if (itemModel.config.EquipPlace <= 0 && itemModel.count > 1)
                        {
                            GodBeastChildNodes.NumberNow.gameObject.SetActive(true);
                            GodBeastChildNodes.NumberNow.text = godBeastModel.Absorption_Dic[godBeastBagClass.Index].ToString() + "/" + itemModel.count;
                        }
                    }
                    else
                    {
                        if (itemModel.config.EquipPlace <= 0 && itemModel.count > 1)
                        {
                            GodBeastChildNodes.NumberNow.gameObject.SetActive(true);
                            GodBeastChildNodes.NumberNow.text = itemModel.count.ToString();
                        }
                    }
                    GodBeastChildNodes.GetGodBeastIndex(godBeastBagClass.Index);
                    GodBeastChildNodes.ButtonDown.AddListener(() =>
                    {
                        if (itemModel.config.EquipPlace > 0)//选中的物品为装备
                        {
                            if (godBeastModel.Absorption_Dic.ContainsKey(godBeastBagClass.Index))
                            {
                                godBeastModel.Absorption_Dic.Remove(godBeastBagClass.Index);
                            }
                            else
                            {
                                godBeastModel.Absorption_Dic.Add(godBeastBagClass.Index, 1);
                            }
                            m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
                        }
                        else//选中的物品为水晶
                        {
                            if (itemModel.count <= 1)
                            {
                                if (godBeastModel.Absorption_Dic.ContainsKey(godBeastBagClass.Index))
                                {
                                    godBeastModel.Absorption_Dic.Remove(godBeastBagClass.Index);
                                }
                                else
                                {
                                    godBeastModel.Absorption_Dic.Add(godBeastBagClass.Index, 1);
                                }
                                m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
                            }
                            else
                            {
                                godBeastModel.Crystal_ItemModel = itemModel;
                                godBeastModel.ItemInde = godBeastBagClass.Index;
                                GetJumpIndex = godBeastBagClass.Index;
                                m_ScrollerController.JumpIndex(JumpIndex());
                                godBeastModel.ItemPos = ItemPos;
                                WindowCenter.Instance.Open<CrystalSelectionWin>();
                            }                          
                        }
                        godBeastModel.AbsorbEventUpdate();
                    });
                }
            }
        }
        private int JumpIndex()
        {
            int jumpIndex = 0;
            for (int i = 0; i < GodBeastBagList.Count; i++)
            {
                if (GodBeastBagList[i].Index == GetJumpIndex)
                {
                    jumpIndex= Mathf.CeilToInt((float)(i+1) / 3);
                }
            }
            if (jumpIndex >= 1)
            {
                jumpIndex -= 1;
            }
            return jumpIndex;
        }
    }
 
}