少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, March 05, 2019
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    
    public class EquipGemWin : Window
    {
        [SerializeField] ScrollerController m_Controller;
        [SerializeField] RectTransform m_LevelContainer;
        [SerializeField] Transform m_ContainerGem;
        [SerializeField] Transform m_ContainerEmpty;
        [SerializeField] ItemCell m_EquipItem;
        [SerializeField] Text m_EquipStar;
        [SerializeField] EquipGemHoleBehaviour[] m_GemHoles;
        [SerializeField] Transform m_ContainerPro;
        [SerializeField] Transform m_ContainerProEmpty;
        [SerializeField] EquipGemPro[] m_EquipGemPro;
        [SerializeField] Button GemLVUP;
        [SerializeField] Button GemOff;
        [SerializeField] ScrollerController m_GemCostController;
 
        [SerializeField] Transform m_MoneyContainer;
        [SerializeField] Text m_Money;
 
        List<int> m_Sorts = new List<int>();
 
        EquipGemModel model
        {
            get { return ModelCenter.Instance.GetModel<EquipGemModel>(); }
        }
 
        EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        EquipStarModel equipStarModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
 
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            m_GemCostController.OnRefreshCell += OnCostRefreshCell;
            GemLVUP.SetListener(OnGemLVUP);
            GemOff.SetListener(OnGemOff);
        }
 
        protected override void OnPreOpen()
        {
 
            var selectEquip = SetDefaultSelect();
 
            Display();
 
            model.SelectHoleIndex = 0;
            m_Controller.JumpIndex(GetJumpIndex(model.selectLevel, model.selectEquipPlace));
            selectHoleRefresh();
 
            model.selectEquipRefresh += SelectEquipRefresh;
            model.selectLevelRefresh += SelectLevelRefresh;
            model.selectHoleRefresh += selectHoleRefresh;
            model.equipGemRefresh += EquipGemRefresh;
            model.equipGemLevelUp += EquipGemLevelUp;
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            model.selectEquipRefresh -= SelectEquipRefresh;
            model.selectLevelRefresh -= SelectLevelRefresh;
            model.selectHoleRefresh -= selectHoleRefresh;
            model.equipGemRefresh -= EquipGemRefresh;
            model.equipGemLevelUp -= EquipGemLevelUp;
 
            foreach (var equipGemHole in m_GemHoles)
            {
                equipGemHole.DisplayLevelUp(false);
            }
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        bool SetDefaultSelect()
        {
            if (!model.jumpEquipPosition.Equals(Int2.zero))
            {
                model.selectLevel = model.jumpEquipPosition.x;
                model.selectEquipPlace = model.jumpEquipPosition.y;
                model.jumpEquipPosition = Int2.zero;
                return true;
            }
 
            var equipSets = equipModel.GetAllEquipSets();
            foreach (var equipSet in equipSets)
            {
                var places = model.GetMosaicEquipPlaces();
                foreach (var place in places)
                {
                    EquipGemRedpoint equipGemRedpoint;
                    if (model.TryGetRedpoint(equipSet, place, out equipGemRedpoint)
                        && equipGemRedpoint.repoint.state == RedPointState.Simple)
                    {
                        model.selectLevel = equipSet;
                        model.selectEquipPlace = place;
                        return true;
                    }
                }
            }
 
            var maxInlayCount = 0;
            var maxSelect = Int2.zero;
            foreach (var level in equipSets)
            {
                var equipSet = equipModel.GetEquipSet(level);
                if (equipSet == null)
                {
                    continue;
                }
                model.selectLevel = level;
                var places = new List<int>(model.GetMosaicEquipPlaces());
                places.Sort(EquipCompare);
                if (maxSelect.x == 0)
                {
                    maxSelect = new Int2(level, places[0]);
                }
                foreach (var place in places)
                {
                    var count = model.GetEmptyGemHoleCount(level, place);
                    if (count > maxInlayCount)
                    {
                        maxInlayCount = count;
                        maxSelect.x = level;
                        maxSelect.y = place;
                    }
                }
            }
 
            model.selectLevel = maxSelect.x;
            model.selectEquipPlace = maxSelect.y;
            return maxInlayCount != 0;
        }
 
        int GetJumpIndex(int selectLevel, int selectPlace)
        {
            var jumpIndex = 0;
            var equipSet = equipModel.GetEquipSet(selectLevel);
            if (equipSet == null)
            {
                return jumpIndex;
            }
            if (equipSet.unLocked)
            {
                var slotCount = model.GetUnlockEquipSlotCount(selectLevel);
                if (slotCount > 0)
                {
                    foreach (var place in m_Sorts)
                    {
                        if (equipSet.IsSlotUnLocked(place))
                        {
                            if (selectPlace == place)
                            {
                                return jumpIndex;
                            }
                            jumpIndex++;
                        }
                    }
                }
                
            }
            return 0;
        }
 
        void Display()
        {
            DisplayGems();
            DisplayEquips();
        }
 
        void DisplayEquips()
        {
            var sets = equipModel.GetUnLockedEquipSetsByFuncID(-1);
            var behaviourCount = sets.Count;
            var behaviourGap = behaviourCount - model.EquipSetList.Count;
            for (var i = 0; i < behaviourGap; i++)
            {
                var instance = UIUtility.CreateWidget("EquipSetSelect", "EquipSetSelect");
                instance.transform.SetParentEx(m_LevelContainer, Vector3.zero, Quaternion.identity, Vector3.one);
                instance.transform.SetAsFirstSibling();
                model.EquipSetList.Insert(0, instance.GetComponent<EquipSetSelect>());
            }
 
            m_Controller.Refresh();
 
            for (var i = 0; i < model.EquipSetList.Count; i++)
            {
                var behaviour = model.EquipSetList[i];
                if (i < behaviourCount)
                {
                    behaviour.SetActive(true);
                    Redpoint redpoint;
                    model.TryGetRedpoint(sets[i], out redpoint);
                    behaviour.Display(sets[i], model.selectLevel == sets[i], redpoint.id);
                }
                else
                {
                    behaviour.SetActive(false);
                }
                if (model.selectLevel == sets[i])
                {
                    var equipSet = equipModel.GetEquipSet(sets[i]);
                    if (equipSet == null)
                    {
                        continue;
                    }
                    m_Sorts.Clear();
                    m_Sorts.AddRange(model.GetMosaicEquipPlaces());
                    m_Sorts.Sort(EquipCompare);
                    foreach (var place in m_Sorts)
                    {
                        if (equipSet.IsSlotUnLocked(place))
                        {
                            m_Controller.AddCell(ScrollerDataType.Header, sets[i] * 1000 + place);
                        }
                    }
 
                }
            }
            
            m_Controller.Restart();
        }
 
        private int EquipCompare(int x, int y)
        {
            // 按宝石 攻防会排序
            List<int> places = new List<int>() { 1, 2, 5, 8, 3, 4, 6, 7, 9, 10, 11, 12 };
 
            return places.IndexOf(x).CompareTo(places.IndexOf(y));
 
        }
 
        void DisplayGems()
        {
            if (model.selectLevel == -1)
            {
                m_ContainerEmpty.SetActive(true);
                m_ContainerGem.SetActive(false);
                return;
            }
 
            m_ContainerEmpty.SetActive(false);
            m_ContainerGem.SetActive(true);
 
            var equipPosition = new Int2(model.selectLevel, model.selectEquipPlace);
            var equipGuid = equipModel.GetEquip(equipPosition);
            var equip = packModel.GetItemByGuid(equipGuid);
            m_EquipItem.SetActive(equip != null);
            if (equip != null)
            {
                m_EquipItem.Init(equip);
                m_EquipItem.button.SetListener(() =>
                {
                    ItemTipUtility.Show(equipGuid);
                });
 
                var maxStar = EquipStarModel.GetMaxStarLevel(equip.config.ItemColor, equip.config.LV);
                var starLevel = Mathf.Min(maxStar, equipStarModel.GetStarLevel(equipPosition));
                m_EquipStar.text = starLevel == 0 ? string.Empty : Language.Get("EquipStarLevel", starLevel);
            }
 
            for (int i = 0; i < m_GemHoles.Length; i++)
            {
                m_GemHoles[i].DisplayEquipGem(model.selectLevel, model.selectEquipPlace, i);
            }
        }
 
        private void SelectEquipRefresh()
        {
            foreach (var equipGemHole in m_GemHoles)
            {
                equipGemHole.DisplayLevelUp(false);
            }
            model.SelectHoleIndex = 0;
            DisplayGems();
            m_Controller.m_Scorller.RefreshActiveCellViews();
        }
 
        private void SelectLevelRefresh()
        {
            DisplayEquips();
            if (model.selectLevel != -1)
            {
                model.selectEquipPlace = m_Sorts[0];
                model.SelectHoleIndex = 0;
            }
            DisplayGems();
        }
 
        private void selectHoleRefresh()
        {
            DisplayGems();
            DisplayPropertyEx();
        }
 
        private void EquipGemRefresh(int level, int place)
        {
            if (level == model.selectLevel && place == model.selectEquipPlace)
            {
                DisplayGems();
                DisplayPropertyEx();
                var index = level * 1000 + place;
                m_Controller.RefreshSingleCellView(index);
            }
        }
 
        private void EquipGemLevelUp(int level, int place, int hole)
        {
            if (level == model.selectLevel && place == model.selectEquipPlace)
            {
                if (hole < m_GemHoles.Length)
                {
                    m_GemHoles[hole].DisplayLevelUp(true);
                }
            }
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            switch (type)
            {
                case ScrollerDataType.Header:
                    var level = cell.index / 1000;
                    var place = cell.index % 1000;
                    var equipSelectCell = cell as EquipGemSelectBehaviour;
                    equipSelectCell.Display(level, place);
                    break;
            }
        }
 
        public static void DisplayProperty(int equipGem, PropertyBehaviour[] properties)
        {
            var config = ItemConfig.Get(equipGem);
            var index = 0;
 
            if (config.Effect2 != 0 && index < properties.Length)
            {
                properties[index].SetActive(true);
                properties[index].DisplayGem(config.Effect2, config.EffectValueA2);
                index++;
            }
 
            if (config.Effect3 != 0 && index < properties.Length)
            {
                properties[index].SetActive(true);
                properties[index].DisplayGem(config.Effect3, config.EffectValueA3);
                index++;
            }
 
            if (config.Effect4 != 0 && index < properties.Length)
            {
                properties[index].SetActive(true);
                properties[index].DisplayGem(config.Effect4, config.EffectValueA4);
                index++;
            }
 
            for (int i = index; i < properties.Length; i++)
            {
                properties[i].SetActive(false);
            }
        }
 
        public void DisplayPropertyEx()
        {
            int[] equipGems = null;
            m_ContainerPro.SetActive(false);
            m_ContainerProEmpty.SetActive(false);
            GemLVUP.SetActive(false);
            GemOff.SetActive(false);
            m_GemCostController.SetActive(false);
            m_MoneyContainer.SetActive(false);
            if (!model.TryGetEquipGems(model.selectLevel, model.selectEquipPlace, out equipGems))
            {
                //无数据
                m_ContainerProEmpty.SetActive(true);
                return;
            }
            if (equipGems[model.SelectHoleIndex] == 0)
            {
                //空孔
                m_ContainerProEmpty.SetActive(true);
                return;
            }
 
            m_ContainerPro.SetActive(true);
            foreach (var gemPro in m_EquipGemPro)
            {
                gemPro.SetActive(false);
            }
            var config = ItemConfig.Get(equipGems[model.SelectHoleIndex]);
            var upConfig = ItemConfig.Get(config.EffectValueC1);
            var index = 0;
 
            if (upConfig != null)
                GemLVUP.SetActive(true);
            GemOff.SetActive(true);
            //宝石名称
            m_EquipGemPro[index].SetActive(true);
            m_EquipGemPro[index].DisplayGemName(config);
            index++;
 
            //属性
            if ((config.Effect2 != 0 || (upConfig != null && upConfig.Effect2 != 0)))
            {
                m_EquipGemPro[index].SetActive(true);
                var nextValue = config.EffectValueC1 == 0 ? 0 : upConfig.EffectValueA2;
                var effectID = config.EffectValueC1 == 0 ? 0 : upConfig.Effect2;
                m_EquipGemPro[index].DisplayPro(Math.Max(config.Effect2, effectID), config.EffectValueA2, nextValue);
                index++;
            }
 
            if (config.Effect3 != 0 || (upConfig != null && upConfig.Effect3 != 0))
            {
                m_EquipGemPro[index].SetActive(true);
                var nextValue = config.EffectValueC1 == 0 ? 0 : upConfig.EffectValueA3;
                var effectID = config.EffectValueC1 == 0 ? 0 : upConfig.Effect3;
                m_EquipGemPro[index].DisplayPro(Math.Max(config.Effect3, effectID), config.EffectValueA3, nextValue);
                index++;
            }
 
            if (config.Effect4 != 0 || (upConfig != null && upConfig.Effect4 != 0))
            {
                m_EquipGemPro[index].SetActive(true);
                var nextValue = config.EffectValueC1 == 0 ? 0 : upConfig.EffectValueA4;
                var effectID = config.EffectValueC1 == 0 ? 0 : upConfig.Effect4;
                m_EquipGemPro[index].DisplayPro(Math.Max(config.Effect4, effectID), config.EffectValueA4, nextValue);
                index++;
            }
 
            OnShowGemCostList(config.EffectValueC1, equipGems[model.SelectHoleIndex]);
        }
 
        int needMoney = 0;
        Dictionary<int, List<int>> costDict;
        private void OnShowGemCostList(int makeID, int itemID)
        {
            m_GemCostController.SetActive(true);
            m_GemCostController.Refresh();
 
            costDict = model.GetComposeNeedGemList(makeID, itemID);
            needMoney = 0;
            foreach (var itemInfo in costDict)
            {
                if (itemInfo.Value[0] >= itemInfo.Value[1])
                    continue;
                m_GemCostController.AddCell(ScrollerDataType.Header, itemInfo.Key);
                var ItemConfig = StoreConfig.GetStoreCfgByItemIDEx(itemInfo.Key, 1);
                if (ItemConfig != null)
                {
                    needMoney = needMoney + ItemConfig.MoneyNumber*Math.Max(itemInfo.Value[1] - itemInfo.Value[0], 0);
                }
            }
 
            foreach (var itemInfo in costDict)
            {
                if (itemInfo.Value[0] < itemInfo.Value[1])
                    continue;
                m_GemCostController.AddCell(ScrollerDataType.Header, itemInfo.Key);
            }
 
 
            m_GemCostController.Restart();
            if (needMoney > 0)
            {
                m_MoneyContainer.SetActive(true);
                m_Money.text = UIHelper.AppendColor(needMoney > PlayerDatas.Instance.baseData.diamond ? TextColType.Red : TextColType.DarkGreen, 
                    needMoney.ToString());
            }
            else
            {
                m_MoneyContainer.SetActive(false);
            }
 
        }
 
        private void OnCostRefreshCell(ScrollerDataType type, CellView cell)
        {
            if (type != ScrollerDataType.Header)
                return;
 
            var itemID = cell.index;
            var costText = cell.transform.GetComponent<Text>();
            costText.text = UIHelper.AppendColor(costDict[itemID][1] > costDict[itemID][0] ? TextColType.Red : TextColType.DarkGreen,
                    Language.Get("GemHoleMal", itemID, costDict[itemID][0], costDict[itemID][1]), true);
        }
        
        private void OnGemLVUP()
        {
            LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(52, 1, needMoney, 2, 0);
            LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(26, 1, 1, 3, 0);
            if (PlayerDatas.Instance.baseData.diamond < needMoney)
            {
                if (VersionConfig.Get().isBanShu)
                {
                    SysNotifyMgr.Instance.ShowTip("GoldErr");
                    return;
                }
                
                WindowCenter.Instance.Open<RechargeTipWin>();
                return;
            }
 
            if (needMoney == 0  || DayRemind.Instance.GetDayRemind(DayRemind.EQUIPGEMUSEGOLD))
            {
                model.SendGemLevelUp(model.selectLevel, model.selectEquipPlace, model.SelectHoleIndex, 0);
                return;
            }
            
            ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"),
            Language.Get("EquipGemUseGold", needMoney),
            Language.Get("TodayNoNotify"), (bool ok, bool isToggle) =>
            {
                if (isToggle)
                {
                    DayRemind.Instance.SetDayRemind(DayRemind.EQUIPGEMUSEGOLD, true);
                }
 
                if (ok)
                {
                    model.SendGemLevelUp(model.selectLevel, model.selectEquipPlace, model.SelectHoleIndex, 0);
                }
            });
 
        }
 
        private void OnGemOff()
        {
            var equipPosition = new Int2(model.selectLevel, model.selectEquipPlace);
            var equipGuid = equipModel.GetEquip(equipPosition);
            if (string.IsNullOrEmpty(equipGuid))
            {
                return;
            }
 
            var _pak = new CA305_tagCMEquipStonePick();
            _pak.EquipIndex = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
            _pak.HoleIndex = model.SelectHoleIndex == 3 ? (byte)10 : (byte)model.SelectHoleIndex;
            GameNetSystem.Instance.SendInfo(_pak);
        }
 
    }
 
}