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;
|
}
|
}
|