using LitJson;
|
using UnityEngine;
|
|
namespace vnxbqy.UI
|
{
|
public class FairySiegeRankInfoWin : Window
|
{
|
[SerializeField] ButtonEx btnClose;
|
[SerializeField] ScrollerController scroller;
|
[SerializeField] TextEx txtAllScore;
|
RankModel rankModel { get { return ModelCenter.Instance.GetModel<RankModel>(); } }
|
FairySiegeActModel model { get { return ModelCenter.Instance.GetModel<FairySiegeActModel>(); } }
|
|
#region Build-in
|
|
protected override void AddListeners()
|
{
|
btnClose.SetListener(CloseClick);
|
}
|
|
protected override void BindController()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
scroller.OnRefreshCell += OnRefreshCell;
|
var rankInfo = rankModel.GetRankPageDatas(FairySiegeActModel.crossFamilyRankType);
|
if (rankInfo == null || model.chooseRankIndex < 0 || model.chooseRankIndex >= rankInfo.Count)
|
return;
|
var info = rankInfo[model.chooseRankIndex];
|
ParseJson(info.userData);
|
txtAllScore.text = UIHelper.ReplaceLargeNum(GetAllScore());
|
}
|
|
protected override void OnPreClose()
|
{
|
scroller.OnRefreshCell -= OnRefreshCell;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CreateScroller();
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
#endregion
|
|
public void ParseJson(string jsonStr)
|
{
|
// 使用LitJson解析JSON
|
JsonData jsonData = JsonMapper.ToObject(jsonStr);
|
|
// 遍历所有轮次
|
foreach (string roundKey in jsonData.Keys)
|
{
|
JsonData roundJson = jsonData[roundKey];
|
|
FairySiegeAllRoundData roundData = new FairySiegeAllRoundData
|
{
|
batType = (int)roundJson["batType"],
|
groupNum = (int)roundJson["groupNum"],
|
rank = (int)roundJson["rank"],
|
score = (int)roundJson["score"]
|
};
|
// 添加到字典
|
model.roundsData[int.Parse(roundKey)] = roundData;
|
}
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell.GetComponent<FairySiegeRankInfoCell>();
|
_cell?.Display(cell.index);
|
}
|
|
private void CreateScroller()
|
{
|
scroller.Refresh();
|
for (int i = 1; i <= model.matchRoundMax; i++)
|
{
|
scroller.AddCell(ScrollerDataType.Header, i);
|
}
|
scroller.Restart();
|
}
|
|
private int GetAllScore()
|
{
|
int score = 0;
|
foreach (var item in model.roundsData.Keys)
|
{
|
score += model.roundsData[item].score;
|
}
|
return score;
|
}
|
}
|
}
|