using vnxbqy.UI;
|
using UnityEngine;
|
using System.Linq;
|
using System.Collections.Generic;
|
|
|
public class TreasurePavilionUpgradeChooseWin : Window
|
{
|
[SerializeField] ScrollerController scroller;
|
[SerializeField] TreasureCustomizedItemCell itemCell;
|
[SerializeField] TextEx txtCount;
|
[SerializeField] ButtonEx btnAutoAdd;
|
[SerializeField] ButtonEx btnOk;
|
Dictionary<int, int> dict;
|
TreasurePavilionUpgradeChooseModel model { get { return ModelCenter.Instance.GetModelEx<TreasurePavilionUpgradeChooseModel>(); } }
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
btnOk.SetListener(CloseClick);
|
|
btnAutoAdd.SetListener(() =>
|
{
|
model.AutoChoose();
|
model.UpdateInfoAction?.Invoke();
|
});
|
}
|
|
protected override void OnPreOpen()
|
{
|
model.UpdateInfoAction += OnUpdateInfoAction;
|
scroller.OnRefreshCell += OnRefreshCell;
|
Display();
|
}
|
|
protected override void OnPreClose()
|
{
|
model.UpdateInfoAction -= OnUpdateInfoAction;
|
scroller.OnRefreshCell -= OnRefreshCell;
|
model.UpdateInfoAction?.Invoke();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CreateScroller();
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
void Display()
|
{
|
int totalCount = ILGubaoStarConfig.GetNeedGubaPieceCountByQuality(model.nowGubaoId, model.nowStar, model.nowQuality);
|
int allUseCount = model.GetAllGuBaoPieceCountByQuality(GubaoPieceInfoType.Choose, model.nowGubaoId, model.nowStar, model.nowQuality);
|
txtCount.text = StringUtility.Contact(allUseCount, "/", totalCount);
|
txtCount.color = UIHelper.GetUIColor(allUseCount >= totalCount ? TextColType.Green : TextColType.Red);
|
itemCell.Init(null);
|
itemCell.itemIcon.SetActive(true);
|
itemCell.bgIcon.SetItemBackGround(model.nowQuality, 0);
|
itemCell.itemIcon.SetSprite("TreasureClooseQualityType_" + model.nowQuality);
|
}
|
|
void CreateScroller()
|
{
|
scroller.Refresh();
|
model.UpdateGubaoPieceInfo();
|
if (!model.TryGetPieceDictInfo(GubaoPieceInfoType.Have, model.nowGubaoId, model.nowStar, model.nowQuality, out dict))
|
{
|
dict = new Dictionary<int, int>();
|
}
|
var list = dict.Keys.ToList();
|
list.Sort(ShowCmp);
|
for (int i = 0; i < list.Count; i++)
|
{
|
scroller.AddCell(ScrollerDataType.Header, list[i]);
|
}
|
scroller.Restart();
|
}
|
|
private void OnUpdateInfoAction()
|
{
|
Display();
|
scroller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as TreasurePavilionUpgradeChooseCell;
|
_cell.Display(_cell.index);
|
}
|
|
//展示排序规则 数量多 > 数量少
|
public int ShowCmp(int a, int b)
|
{
|
int count1 = dict[a];
|
int count2 = dict[b];
|
if (count1 > count2)
|
{
|
return -1;
|
}
|
else if (count1 < count2)
|
{
|
return 1;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
}
|