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()
|
{
|
}
|
}
|
}
|