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);
|
}
|
}
|