lcy
昨天 247c64258e0102a1028199f14866a1fd1c1a205f
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
101
102
103
104
105
106
107
108
109
110
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using LitJson;
using UnityEngine;
 
//战场结算界面,存在多个的情况
public class ArenaBattleFailWin : UIBase
{
    [SerializeField] AvatarCell myAvatarCell;
    [SerializeField] AvatarCell enemyAvatarCell;
    [SerializeField] TextEx txtMyName;
    [SerializeField] TextEx txtEnemyName;
    [SerializeField] TextEx txtMyScore;
    [SerializeField] TextEx txtEnemyScore;
    [SerializeField] ScrollerController scroller;
    JsonData jsonData;
    string guid;
 
    protected override void InitComponent()
    {
 
    }
 
    protected override void OnPreOpen()
    {
        scroller.OnRefreshCell += OnRefreshCell;
        guid = BattleSettlementManager.Instance.notifyGuid;
        jsonData = BattleSettlementManager.Instance.GetBattleSettlement(guid);
        if (jsonData == null)
        {
            DelayCloseWindow().Forget();
            return;
        }
        Display();
        CreateScroller();
    }
 
    protected override void OnPreClose()
    {
        scroller.OnRefreshCell -= OnRefreshCell;
        BattleSettlementManager.Instance.WinShowOver(guid);
    }
 
    // B4 20 回合制战斗状态 #tagMCTurnFightState  通用的结算状态 State 4-结算奖励
    // Msg 中额外信息
    // "tagPlayerID":对战的目标ID,
    // "atkAddScore":发起方增加的积分,可能为0,
    // "defDecScore":被击方减少的积分,可能为0,
    // itemInfo:奖励物品列表,可能为空
    void Display()
    {
        if (!jsonData.ContainsKey("tagPlayerID") || !jsonData.ContainsKey("atkAddScore") || !jsonData.ContainsKey("defDecScore"))
            return;
        uint tagPlayerID = (uint)jsonData["tagPlayerID"];
        int atkAddScore = (int)jsonData["atkAddScore"];
        int defDecScore = (int)jsonData["defDecScore"];
        if (!ArenaManager.Instance.TryGetPlayerInfo(tagPlayerID, out ArenaMatchInfo info))
            return;
        uint enemyFace = info.Face;
        uint enemyFacePic = info.FacePic;
 
        myAvatarCell.InitUI(AvatarHelper.GetAvatarModel((int)PlayerDatas.Instance.baseData.PlayerID,
                                                PlayerDatas.Instance.baseData.face,
                                                PlayerDatas.Instance.baseData.facePic));
        enemyAvatarCell.InitUI(AvatarHelper.GetAvatarModel((int)tagPlayerID, (int)enemyFace, (int)enemyFacePic));
        txtMyName.text = PlayerDatas.Instance.baseData.PlayerName;
        txtEnemyName.text = UIHelper.ServerStringTrim(info.PlayerName);
        txtMyScore.text = Language.Get("Arena17", atkAddScore);
        txtEnemyScore.text = Language.Get("Arena21", defDecScore);
    }
    List<Item> showItems = new List<Item>();
    void CreateScroller()
    {
 
        showItems.Clear();
        scroller.Refresh();
 
        if (!jsonData.ContainsKey("itemInfo"))
        {
            return;
        }
 
        var resultStr = jsonData["itemInfo"];
        for (int i = 0; i < resultStr.Count; i++)
        {
            showItems.Add(new Item((int)resultStr[i]["ItemID"], (long)resultStr[i]["Count"]));
        }
 
        showItems.Sort(SortItem);
        for (int i = 0; i < showItems.Count; i++)
        {
            scroller.AddCell(ScrollerDataType.Header, i);
        }
        scroller.Restart();
    }
 
    int SortItem(Item itemA, Item itemB)
    {
        var itemConfigA = ItemConfig.Get(itemA.id);
        var itemConfigB = ItemConfig.Get(itemB.id);
        return itemConfigB.ItemColor - itemConfigA.ItemColor;
    }
 
    void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell as SettlementAwardCell;
        var item = showItems[cell.index];
        _cell?.Display(item.id, item.countEx);
    }
}