少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
 
namespace vnxbqy.UI
{
    public class YunShiXBProbabilityWin : Window
    {
        [SerializeField] ScrollerController scroller;
        [SerializeField] ButtonEx btnClose;
        HappyXBModel happyXBModel { get { return ModelCenter.Instance.GetModelEx<HappyXBModel>(); } }
 
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            btnClose.SetListener(CloseClick);
        }
 
        protected override void OnPreOpen()
        {
            scroller.OnRefreshCell += OnRefreshCell;
        }
 
        protected override void OnPreClose()
        {
            scroller.OnRefreshCell -= OnRefreshCell;
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            var _cell = cell as YunShiXBProbabilityCell;
            _cell.Display(_cell.index, cell);
        }
 
        protected override void OnAfterOpen()
        {
            OperationYunShi act;
            OperationTimeHepler.Instance.TryGetOperation(YunShiXBActModel.operaType, out act);
            if (act == null)
                return;
 
            int type = act.treasureType;
            var xbInfo = happyXBModel.GetXBInfoByType(type);
            if (xbInfo == null)
                return;
 
            XBGetItemConfig xbGetItemConfig = happyXBModel.GetXBItemConfigByType(type);
            if (xbGetItemConfig == null)
                return;
 
            int[][] GridItemRateList = xbGetItemConfig.GridItemRateList1;
            if (GridItemRateList.IsNullOrEmpty())
                return;
 
            Dictionary<int, int> rateDict = ConfigParse.GetRateDict(GridItemRateList);
            if (rateDict.IsNullOrEmpty())
                return;
 
            var dict = happyXBModel.GetXBGetItemByID(type);
            var list = dict.Keys.ToList();
            List<CellInfo> cellInfos = new List<CellInfo>();
            list.Sort();
            if (!list.IsNullOrEmpty())
            {
                for (int i = 0; i < list.Count; i++)
                {
                    int girdIndex = list[i];
                    var info = dict[girdIndex];
                    int rate;
                    if (!rateDict.TryGetValue(girdIndex, out rate))
                        continue;
 
                    CellInfo cellInfo = new CellInfo();
                    cellInfo.infoInt1 = info.itemId;
                    cellInfo.infoInt2 = info.count;
                    cellInfo.infoInt3 = rate;
                    cellInfos.Add(cellInfo);
                }
            }
            cellInfos.Sort(Cmp);
 
            scroller.Refresh();
            for (int i = 0; i < cellInfos.Count; i++)
            {
                CellInfo info = cellInfos[i];
                scroller.AddCell(ScrollerDataType.Header, i, info);
            }
            scroller.Restart();
        }
 
        private int Cmp(CellInfo x, CellInfo y)
        {
            // 首先比较 rate
            if (x.infoInt3 != y.infoInt3)
            {
                return x.infoInt3.CompareTo(y.infoInt3);
            }
 
            // 如果 rate 相同,则比较数量 (假设数量存储在 infoInt2 中)
            return x.infoInt2.CompareTo(y.infoInt2);
        }
 
        protected override void OnAfterClose()
        {
        }
    }
}