少年修仙传客户端代码仓库
hch
2025-07-24 50e53441950268933694eeb5aad36147bbe1014d
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
        }
    }
}