hch
2 天以前 1898a5f28dfffa7bbecf5d2bf024f20b8d0490e7
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
using System.Collections.Generic;
using UnityEngine;
 
public class HeroDebutCallRateWin : UIBase
{
    [SerializeField] ScrollerController scroller;
    public const int rowCountMax = 4;
    HeroDebutManager manager => HeroDebutManager.Instance;
 
    protected override void OnPreOpen()
    {
        scroller.OnRefreshCell += OnRefreshCell;
        CreateScroller();
    }
 
    protected override void OnPreClose()
    {
        scroller.OnRefreshCell -= OnRefreshCell;
    }
 
    void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell as HeroDebutCallRateCell;
        _cell.Display(cell.index, gridRateDict, gridList, xbConfig);
    }
 
    Dictionary<int, int> gridRateDict;
    List<int> gridList;
    XBGetItemConfig xbConfig;
    void CreateScroller()
    {
        var act = manager.GetOperationHeroAppearInfo();
        if (act == null) return;
 
        var config = ActHeroAppearConfig.Get(act.CfgID);
        if (config == null) return;
 
        xbConfig = HappyXBModel.Instance.GetXBItemConfigByType(config.ActTreasureType);
        if (xbConfig == null || xbConfig.GridItemRateList1 == null) return;
 
        gridRateDict = GetGridRateDict(xbConfig.GridItemRateList1);
        if (gridRateDict == null) return;
 
        gridList = GetSortedGridList();
        if (gridList == null) return;
 
        scroller.Refresh();
        int rowCount = (int)Mathf.Ceil((float)gridList.Count / rowCountMax);
        for (int i = 0; i < rowCount; i++)
        {
            scroller.AddCell(ScrollerDataType.Header, i);
        }
        scroller.Restart();
    }
 
    //<格子,万分率>
    public Dictionary<int, int> GetGridRateDict(int[][] gridItemRateList1)
    {
        Dictionary<int, int> res = new();
        for (int i = 0; i < gridItemRateList1.Length; i++)
        {
            res[gridItemRateList1[i][1]] = i == 0 ?
                gridItemRateList1[i][0] :
                gridItemRateList1[i][0] - gridItemRateList1[i - 1][0];
        }
        return res;
    }
 
    public List<int> GetSortedGridList()
    {
        if (gridRateDict == null || gridRateDict.Count == 0) return null;
        List<int> sortedGrids = new List<int>(gridRateDict.Keys);
        sortedGrids.Sort();
        // sortedGrids.Sort((a, b) =>
        // {
        //     int rateA = gridRateDict[a];
        //     int rateB = gridRateDict[b];
        //     return rateA.CompareTo(rateB);
        // });
 
        return sortedGrids;
    }
}