少年修仙传客户端代码仓库
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
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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using System.Linq;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    public class ComposeEquipWin : Window
    {
        [SerializeField]
        ScrollerController cellCtrl;
 
        [SerializeField]
        ScrollerController equipTypeLineCellCtrl;
 
        [SerializeField] GameObject increaseRateItem;
        [SerializeField] GameObject increaseGridCell;
 
        [SerializeField] GameObject three_ComposeEquip;
        [SerializeField] GameObject five_ComposeEquip;
        [Header("固定物品和三个非固定物品")]
        [SerializeField] List<ComposeMatCell> three_FixedAndUnfixeds = new List<ComposeMatCell>();
        [Header("固定物品和五个非固定物品")]
        [SerializeField] List<ComposeMatCell> five_FixedAndUnfixeds = new List<ComposeMatCell>();
 
        [Header("合成物品")]
        [SerializeField] List<ComposeMatCell> makeItems = new List<ComposeMatCell>();
        [Header("提高成功率")]
        [SerializeField] ComposeMatCell increaseRateMatCell;
        [SerializeField] Text increaseText;
        [SerializeField] PushSwitchBtn switchBtn;
 
        [SerializeField]
        Text successRateText;
 
        [SerializeField] Text dismantleText;
 
        [SerializeField]
        Button helpBtn;
 
        [SerializeField]
        Button composeBtn;
 
        [SerializeField]
        Button onekeyPutBtn;
 
        [SerializeField]
        GameObject notChooseBG;
 
        [SerializeField]
        GameObject chooseComposeEquip;
        [SerializeField] GameObject container_ComposeEquip;
        [SerializeField] UIEffect composeEffect_Three;
        [SerializeField] UIEffect composeEffect_Five;
        [SerializeField] UIEffect successEffect;
        [SerializeField] UIEffect failEffect;
 
        ComposeWinModel _composeWinModel;
        ComposeWinModel composeWinModel {
            get { return _composeWinModel ?? (_composeWinModel = ModelCenter.Instance.GetModel<ComposeWinModel>()); }
        }
 
        PackModel _playerPack;
        PackModel playerPack {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
        }
 
        ComposeWinModel.ComposeFirstTypeData firstTypeData;
        ComposeWinModel.ComposeSecondTypeData secondTypeData;
        ComposeWinModel.ComposeThirdTypeData thirdTypeData;
        Dictionary<int, List<int>> fixedItemIndexDict = new Dictionary<int, List<int>>();
 
        private int curSecondType = 0;
        private int curThirdType = 0;
        private int preSecondType = 0;
        private int preThirdType = 0;
        [SerializeField] int initSuccessRate = 0;
        private int curComposeEquipIndex = -1;
        public static int selectEquipPlace;
        ItemCompoundConfig compoundModel = null;
        bool isIncreaseRate = false;
        int successRate = 0;
        SelectEquipModel _selectModel;
        SelectEquipModel selectModel {
            get { return _selectModel ?? (_selectModel = ModelCenter.Instance.GetModel<SelectEquipModel>()); }
        }
        protected override void BindController()
        {
            cellCtrl.OnRefreshCell += RefreshTypeCell;
            cellCtrl.vertical = true;
            cellCtrl.lockType = EnhanceLockType.KeepVertical;
            equipTypeLineCellCtrl.OnRefreshCell += RefreshEquipTypeLineCell;
            composeWinModel.ResetModelEvent += ResetModel;
        }
 
        protected override void AddListeners()
        {
            composeBtn.AddListener(OnClickComposeBtn);
            onekeyPutBtn.AddListener(OnClickOnekeyPutBtn);
        }
 
        protected override void OnPreOpen()
        {
            composeWinModel.UpdateSendComposeEvent += UpdateSendCompose;
            composeWinModel.UpdateSecondTypeEvent += UpdateSecondType;
            composeWinModel.UpdateThirdTypeEvent += UpdateThirdType;
            composeWinModel.UpdateReduceEvent += UpdateReduce;
            selectModel.UpdateSelectEvent += UpdateSelect;
            composeWinModel.UpdateEquipTypeEvent += UpdateEquipType;
            DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnComposeAnswer;
            UIEventTrigger.Get(helpBtn.gameObject).OnDown = OnClickHelpBtn;
            UIEventTrigger.Get(helpBtn.gameObject).OnUp = OnDownUp;
            Display();
        }
 
        protected override void OnAfterOpen()
        {
            this.transform.SetAsLastSibling();
        }
 
        protected override void OnPreClose()
        {
            composeWinModel.UpdateSendComposeEvent -= UpdateSendCompose;
            composeWinModel.UpdateReduceEvent -= UpdateReduce;
            DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer;
            composeWinModel.UpdateSecondTypeEvent -= UpdateSecondType;
            composeWinModel.UpdateThirdTypeEvent -= UpdateThirdType;
            selectModel.UpdateSelectEvent -= UpdateSelect;
            composeWinModel.UpdateEquipTypeEvent -= UpdateEquipType;
            selectEquipPlace = -1;
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        #region 新的逻辑
        private void Display()
        {
            composeWinModel.TryGetFirstTypeData((int)ComposeFuncType.Equip, out firstTypeData);
            if (firstTypeData == null) return;
 
            isIncreaseRate = false;
            successRate = 0;
            DefaultSelect();
            CreateTypeCell();
            JumpIndex();
        }
 
        private void DefaultSelect()
        {
            if (composeWinModel.secondType != 0)
            {
                curSecondType = composeWinModel.secondType;
                curThirdType = composeWinModel.thirdType;
                composeWinModel.ResetJumpToModel();
            }
 
            if (composeWinModel.CurComposeModel == null)
            {
                curComposeEquipIndex = -1;
            }
            List<ComposeWinModel.ComposeThirdTypeData> thirdTypeDatas = null;
            composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, curThirdType, out thirdTypeDatas);
            if (thirdTypeDatas != null)
            {
                for (int i = 0; i < thirdTypeDatas.Count; i++)
                {
                    var itemConfig = ItemConfig.Get(thirdTypeDatas[i].itemCompound.makeID[0]);
                    if (itemConfig.EquipPlace == selectEquipPlace)
                    {
                        curComposeEquipIndex = i;
                        break;
                    }
                }
            }
        }
 
        private void CreateTypeCell()
        {
            if (firstTypeData == null) return;
 
            cellCtrl.Refresh();
            foreach (var second in firstTypeData.secondTypeDict.Keys)
            {
                cellCtrl.AddCell(ScrollerDataType.Header, second);
                if (second == curSecondType)
                {
                    var thirdTypeDict = firstTypeData.secondTypeDict[second].thirdTypeDict;
                    foreach (var third in thirdTypeDict.Keys)
                    {
                        if (third != 0)
                        {
                            cellCtrl.AddCell(ScrollerDataType.Normal, third);
                        }
                    }
                }
            }
            cellCtrl.Restart();
 
            if (curThirdType != 0)
            {
                CreateEquipTypeLineCell();
                composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, curThirdType, out thirdTypeData);
                if (thirdTypeData != null)
                {
                    ItemConfig itemConfig = ItemConfig.Get(thirdTypeData.itemCompound.makeID[0]);
                    if (itemConfig != null && itemConfig.ItemColor == 6)
                    {
                        dismantleText.SetActive(true);
                    }
                    else
                    {
                        dismantleText.SetActive(false);
                    }
                }
            }
            else
            {
                RefreshUI(null);
                dismantleText.SetActive(false);
                ChangeUIState(true, false, false);
            }
        }
 
        private void RefreshTypeCell(ScrollerDataType type, CellView cell)
        {
            switch (type)
            {
                case ScrollerDataType.Header:
                    ComposeWinModel.ComposeSecondTypeData _secondTypeData = null;
                    ComposeFirstTypeCell firstTypeCell = cell.GetComponent<ComposeFirstTypeCell>();
                    composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Equip, cell.index, out _secondTypeData);
                    if (_secondTypeData != null)
                    {
                        var thirdTypeDict = _secondTypeData.thirdTypeDict;
                        foreach (var third in thirdTypeDict.Keys)
                        {
                            firstTypeCell.SetDisplay((int)ComposeFuncType.Equip, cell.index, third, curSecondType);
                            break;
                        }
                    }
                    break;
                case ScrollerDataType.Normal:
                    ComposeSecondTypeCell secondTypeCell = cell.GetComponent<ComposeSecondTypeCell>();
                    secondTypeCell.SetDisplay((int)ComposeFuncType.Equip, curSecondType, cell.index, curThirdType);
                    break;
            }
        }
 
        private void JumpIndex()
        {
            if (firstTypeData == null) return;
 
            var secondTypeDict = firstTypeData.secondTypeDict;
            if (secondTypeDict.Count >= 1 && curSecondType != 0
                && curThirdType >= 1)
            {
                cellCtrl.JumpIndex(GetCurIndex(curSecondType));
            }
        }
 
        private int GetCurIndex(int secondType)
        {
            if (firstTypeData == null) return 0;
            int curIndex = 0;
            var secondTypeDict = firstTypeData.secondTypeDict;
            List<int> secondlist = secondTypeDict.Keys.ToList();
            for (int i = 0; i < secondlist.Count; i++)
            {
                if (secondType == secondlist[i])
                {
                    curIndex = i;
                    break;
                }
            }
            if (curThirdType >= 4)
            {
                curIndex = curIndex + curThirdType - 2;
            }
            return curIndex;
        }
 
        private void UpdateSecondType(int secondType)
        {
            curThirdType = 0;
            curSecondType = secondType;
            composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Equip, secondType, out secondTypeData);
            OnClickSecondType();
            CreateTypeCell();
            JumpIndex();
        }
 
        private void OnClickSecondType()
        {
            if (secondTypeData == null) return;
 
            var thirdTypeDict = secondTypeData.thirdTypeDict;
            if (curThirdType == 0)
            {
                foreach (var thirdType in thirdTypeDict.Keys)
                {
                    if (thirdType != 0)
                    {
                        if (preSecondType == curSecondType)
                        {
                            curSecondType = 0;
                            preSecondType = 0;
                        }
                        else
                        {
                            curThirdType = thirdType;
                        }
                    }
                    break;
                }
            }
 
            if (preSecondType != curSecondType)
            {
                isIncreaseRate = false;
                preSecondType = curSecondType;
                curComposeEquipIndex = -1;
                selectModel.ClearSelectModel();
            }
        }
 
        private void UpdateThirdType(int thirdType)
        {
            composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, thirdType, out thirdTypeData);
            curThirdType = thirdType;
            OnClickThirdType();
            CreateTypeCell();
        }
 
        private void OnClickThirdType()
        {
            if (thirdTypeData == null) return;
 
            if (preThirdType != curThirdType)
            {
                isIncreaseRate = false;
                preThirdType = curThirdType;
            }
            curComposeEquipIndex = -1;
            selectModel.ClearSelectModel();
        }
 
        private void CreateEquipTypeLineCell()
        {
            List<ComposeWinModel.ComposeThirdTypeData> thirdTypeDatas = null;
            bool isthird = composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, curThirdType, out thirdTypeDatas);
            if (!isthird) return;
 
            if (thirdTypeDatas.Count > 1)
            {
                ChangeUIState(false, true, false);
                equipTypeLineCellCtrl.Refresh();
                int line = thirdTypeDatas.Count / 3;
                if (thirdTypeDatas.Count % 3 > 0)
                {
                    line += 1;
                }
                int i = 0;
                for (i = 0; i < line; i++)
                {
                    equipTypeLineCellCtrl.AddCell(ScrollerDataType.Header, i);
                }
                equipTypeLineCellCtrl.Restart();
            }
            else
            {
                if (thirdTypeDatas.Count > 0)
                {
                    ItemCompoundConfig tagItemCompound = thirdTypeDatas[0].itemCompound;
                    UpdateEquipType(tagItemCompound, 0);
                    RefreshUI(tagItemCompound);
                    ChangeUIState(false, false, true);
                }
            }
 
            if (curComposeEquipIndex != -1)
            {
                ItemCompoundConfig tagItemCompound = thirdTypeDatas[curComposeEquipIndex].itemCompound;
                UpdateEquipType(tagItemCompound, curComposeEquipIndex);
            }
 
        }
 
        private void ChangeUIState(params bool[] isShows)
        {
            notChooseBG.SetActive(isShows[0]);
            chooseComposeEquip.SetActive(isShows[1]);
            container_ComposeEquip.SetActive(isShows[2]);
        }
 
        private void UpdateComposeMat()
        {
            int[] makeIds = compoundModel.makeID;
            for (int i = 0; i < makeItems.Count; i++)
            {
                var matCell = makeItems[i];
                if (makeIds != null && i < makeIds.Length)
                {
                    matCell.SetDisplay(compoundModel, NeedMatType.MakeItem, false, "", makeIds[i]);
                }
                else
                {
                    matCell.SetDisplay(compoundModel, NeedMatType.MakeItem, true);
                }
            }
 
            int[] fixedIds = compoundModel.itemID;
            int[] fixedDisplays = compoundModel.itemDisplay;
            int[] unfixedDisplays = compoundModel.unfixedItemDisplay;
            if (compoundModel.unfixedItemCount <= 3)
            {
                three_ComposeEquip.SetActive(true);
                five_ComposeEquip.SetActive(false);
            }
            else
            {
                three_ComposeEquip.SetActive(false);
                five_ComposeEquip.SetActive(true);
            }
 
            var fixedAndUnfixeds = compoundModel.unfixedItemCount > 3 ? five_FixedAndUnfixeds : three_FixedAndUnfixeds;
            for (int i = 0; i < fixedAndUnfixeds.Count; i++)
            {
                var matCell = fixedAndUnfixeds[i];
                matCell.SetDisplay(compoundModel, NeedMatType.Nothing, true);
            }
 
            for (int i = 0; i < fixedDisplays.Length; i++)
            {
                var fixedDisplay = fixedDisplays[i];
                if (fixedDisplay != 0)
                {
                    var matCell = fixedAndUnfixeds[fixedDisplay - 1];
                    int fixedId = 0;
                    composeWinModel.TryGetIdByDisplay(NeedMatType.fixedItem, compoundModel, fixedDisplay, out fixedId);
                    matCell.SetDisplay(compoundModel, NeedMatType.fixedItem, false, "", fixedId);
                }
            }
 
            for (int i = 0; i < unfixedDisplays.Length; i++)
            {
                var unfixedDisplay = unfixedDisplays[i];
                if (unfixedDisplay != 0)
                {
                    var matCell = fixedAndUnfixeds[unfixedDisplay - 1];
                    matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false, UIHelper.ReplaceNewLine(Language.Get("ComposeWin_PutInText_2")));
                }
            }
 
 
            int[] increases = compoundModel.successRateIncrease;
            if (increases == null || increases.Length < 2)
            {
                isIncreaseRate = false;
                increaseRateMatCell.SetActive(isIncreaseRate);
            }
            else
            {
                int increaseId = increases[0];
                int increaseNeedNum = increases[1];
                int increaseRate = increases[2] / 100;
                increaseRateMatCell.SetActive(true);
                increaseRateMatCell.SetDisplay(compoundModel, NeedMatType.IncreaseItem, false, "", increaseId);
                increaseText.text = Language.Get("Compose109", StringUtility.Contact(increaseRate, "%"));
                int haveIncreaseNum = playerPack.GetItemCountByID(PackType.Item, increaseId);
                ItemConfig itemConfig = ItemConfig.Get(increaseId);
                isIncreaseRate = haveIncreaseNum >= increaseNeedNum ? isIncreaseRate : false;
                switchBtn.RefreshSwitchUI(isIncreaseRate);
                switchBtn.switchBtn.RemoveAllListeners();
                switchBtn.switchBtn.AddListener(() =>
                {
                    if (switchBtn.onObj.activeInHierarchy)
                    {
                        isIncreaseRate = false;
                        switchBtn.RefreshSwitchUI(false);
                    }
                    else
                    {
                        if (haveIncreaseNum >= increaseNeedNum)
                        {
                            isIncreaseRate = true;
                            switchBtn.RefreshSwitchUI(true);
                        }
                        else
                        {
                            isIncreaseRate = false;
                            ServerTipDetails.DisplayNormalTip(Language.Get("Compose110", increaseNeedNum, itemConfig.ItemName));
                        }
                    }
                    RefreshComposeSuccessRate();
                });
            }
        }
 
 
        private void UpdateSelect(ComposeMatCell matCell, int itemIndex, SelectItemType selectType)
        {
            switch (selectType)
            {
                case SelectItemType.unfixed:
                    matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false, "", 0, itemIndex);
                    break;
                case SelectItemType.addons:
                    matCell.SetDisplay(compoundModel, NeedMatType.addItem, false, "", 0, itemIndex);
                    break;
            }
        }
 
        private void UpdateReduce(ComposeMatCell matCell, NeedMatType matType)
        {
            switch (matType)
            {
                case NeedMatType.unfixedItem:
                    matCell.SetDisplay(compoundModel, matType, false, UIHelper.ReplaceNewLine(Language.Get("ComposeWin_PutInText_2")));
                    break;
                case NeedMatType.addItem:
                    matCell.SetDisplay(compoundModel, matType, false);
                    break;
            }
        }
 
 
        private void UpdateEquipType(ItemCompoundConfig itemCompound, int equipIndex)
        {
            curComposeEquipIndex = equipIndex;
            ChangeUIState(false, false, true);
            RefreshComposeSuccessRate();
            RefreshUI(itemCompound);
        }
 
        #endregion
 
        private void ResetModel()
        {
            curSecondType = 0;
            curThirdType = 0;
            compoundModel = null;
            if (!WindowJumpMgr.Instance.IsJumpState)
            {
                curComposeEquipIndex = -1;
                preSecondType = 0;
                preThirdType = 0;
            }
        }
 
        private void RefreshEquipTypeLineCell(ScrollerDataType type, CellView cell)
        {
            List<ComposeWinModel.ComposeThirdTypeData> thirdTypeDatas = null;
            composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, curThirdType, out thirdTypeDatas);
            EquipTypeLineCell typeLineCell = cell.GetComponent<EquipTypeLineCell>();
            typeLineCell.Refresh(cell, thirdTypeDatas);
        }
 
        private void RefreshUI(ItemCompoundConfig compoundModel)
        {
            this.compoundModel = compoundModel;
            if (compoundModel == null)
            {
                composeBtn.SetActive(false);
                onekeyPutBtn.SetActive(false);
            }
            else
            {
                composeWinModel.SetCurComposeModel(compoundModel);
                composeBtn.SetActive(true);
                onekeyPutBtn.SetActive(true);
                UpdateComposeMat();
                RefreshComposeSuccessRate();
            }
        }
 
        public void RefreshComposeSuccessRate()
        {
            if (compoundModel == null) return;
 
            successRate = 0;
            int increaseRate = 0;
            if (compoundModel != null)
            {
                successRate = compoundModel.successRate;
            }
            if (isIncreaseRate)
            {
                int[] increases = compoundModel.successRateIncrease;
                if (increases != null && increases.Length > 1)
                {
                    increaseRate = increases[2] / 100;
                }
            }
 
            if (increaseRate > 0)
            {
                string extraAddRate = UIHelper.AppendColor(TextColType.Green, StringUtility.Contact("+", increaseRate, "%"), true);
                successRateText.text = Language.Get("HallowsWin_Success", StringUtility.Contact(successRate / 100, "%", extraAddRate));
            }
            else
            {
                successRateText.text = Language.Get("HallowsWin_Success", StringUtility.Contact(successRate / 100, "%"));
            }
 
        }
 
        private void OnClickOnekeyPutBtn()
        {
            if (compoundModel == null)
                return;
 
            var unfixedSelectItemDict = selectModel.GetUnfixedItemModel();
            var unfixeAddDict = selectModel.GetHaveUnfixedSelectItem();
            int[] unfixedDisplays = compoundModel.unfixedItemDisplay;
            var fixedAndUnfixeds = compoundModel.unfixedItemCount > 3 ? five_FixedAndUnfixeds : three_FixedAndUnfixeds;
            List<ItemModel> unSelectItems = unfixedSelectItemDict.Values.ToList();
            unSelectItems.Sort(CompareByOverdueTime);
 
 
            for (int i = 0; i < unfixedDisplays.Length; i++)
            {
                var unfixedDisplay = unfixedDisplays[i];
                if (unfixedDisplay != 0)
                {
                    var matCell = fixedAndUnfixeds[unfixedDisplay - 1];
                    if (matCell.itemModel == null)
                    {
                        for (int j = 0; j < unSelectItems.Count; j++)
                        {
                            ItemModel _model = unSelectItems[j];
                            if (!unfixeAddDict.ContainsKey(_model.gridIndex))
                            {
                                selectModel.AddHaveUnfixedSelectItem(_model.gridIndex);
                                UpdateSelect(matCell, _model.gridIndex, SelectItemType.unfixed);
                                break;
                            }
                        }
                    }
                }
            }
        }
 
        private int CompareByOverdueTime(ItemModel start, ItemModel end)
        {
            int remainTime1 = 0;
            int remainTime2 = 0;
            bool isRemain1 = TryGetRemainTime(start, out remainTime1);
            bool isRemain2 = TryGetRemainTime(end, out remainTime2);
            if (isRemain1.CompareTo(isRemain2) != 0) return -isRemain1.CompareTo(isRemain2);
            if (remainTime1.CompareTo(remainTime2) != 0) return -remainTime1.CompareTo(remainTime2);
            return 0;
        }
 
        private bool TryGetRemainTime(ItemModel model, out int seconds)
        {
            seconds = 0;
            if (model.config.EquipPlace != (int)RoleEquipType.Guard
                || model.config.ExpireTime <= 0) return false;
 
            ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(model.guid);
            bool isShow = model.config.ExpireTime > 0;
            if (isShow)
            {
                List<int> itemEffectTime = model.GetUseData((int)ItemUseDataKey.createTime);
                seconds = model.config.ExpireTime;
                if (itemEffectTime != null && itemEffectTime[0] != 0 && model.guid != "")
                {
                    seconds = cool == null ? 0 : (int)cool.GetRemainTime();
                }
                return true;
            }
            return false;
        }
 
 
        private void UpdateSendCompose()
        {
            if (compoundModel == null) return;
 
            SetFixedItemIndexDic();
            composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, GetPlayUIEffct(), 1, 10000, isIncreaseRate);
        }
 
        private void OnClickComposeBtn()
        {
            if (compoundModel != null)
            {
                bool isTrailer = composeWinModel.IsTrailerByLevel(compoundModel);
                if (isTrailer)
                {
                    ServerTipDetails.DisplayNormalTip(Language.Get("FuncOpenLv", compoundModel.levelNeed));
                    return;
                }
            }
            if (compoundModel.makeID[0] == 5423)
            {
                ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose112"), (bool isOk) =>
                {
                    if (isOk)
                    {
                        SetFixedItemIndexDic();
                        composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, GetPlayUIEffct(), 1, 10000, isIncreaseRate);
                    }
                });
                return;
            }
 
 
            ItemConfig itemConfig = ItemConfig.Get(compoundModel.makeID[0]);
            switch ((RoleEquipType)itemConfig.EquipPlace)
            {
                case RoleEquipType.Guard:
                    if (!composeWinModel.IsEnoughUnfixedMat(compoundModel))
                    {
                        ServerTipDetails.DisplayNormalTip(Language.Get("Compose101"));
                    }
                    else
                    {
                        WindowCenter.Instance.Open<GuardComposeConfirmWin>();
                    }
                    break;
                default:
                    SetFixedItemIndexDic();
                    composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, GetPlayUIEffct(), 1, 10000, isIncreaseRate);
                    break;
            }
        }
 
        private void SetFixedItemIndexDic()
        {
            fixedItemIndexDict.Clear();
            if (compoundModel == null) return;
 
            var packType = composeWinModel.GetPackTypeByMakerId(compoundModel.makeID);
            SinglePack singlePack = playerPack.GetSinglePack(packType);
            if (singlePack == null) return;
 
            int[] fixedIds = compoundModel.itemID;
            int[] fixedCounts = compoundModel.itemCount;
            for (int i = 0; i < fixedIds.Length; i++)
            {
                var itemIndexlist = singlePack.GetItemIndexsAppointedCount(fixedIds[i], fixedCounts[i]);
                if (itemIndexlist != null)
                {
                    fixedItemIndexDict.Add(fixedIds[i], itemIndexlist);
                }
            }
 
        }
 
        private UIEffect GetPlayUIEffct()
        {
            if (compoundModel == null) return null;
 
            if (compoundModel.unfixedItemCount <= 3)
            {
                return composeEffect_Three;
            }
            return composeEffect_Five;
        }
 
        private void OnComposeAnswer(HA814_tagMCMakeItemAnswer answer)
        {
            if (answer.MakeType != (int)MakeType.ItemCompound)
                return;
 
            if (answer.Result == 1)
            {
                successEffect.Play();
            }
            else
            {
                failEffect.Play();
            }
 
            RefreshUI(compoundModel);
            selectModel.ClearSelectModel();
        }
 
        private void OnDownUp(GameObject go)
        {
            WindowCenter.Instance.Close<ComposeHelpWin>();
        }
 
        private void OnClickHelpBtn(GameObject go)
        {
            if (compoundModel != null)
            {
                WindowCenter.Instance.Open<ComposeHelpWin>();
            }
        }
 
    }
}