CTT/Unity/Assets/HotfixView/UI/RankingUI/RankingUI.cs

121 lines
4.4 KiB
C#

using ET;
using System;
using System.Collections.Generic;
using FairyGUI;
namespace ET
{
public class RankingUIAwakeSyatem : AwakeSystem<RankingUI>
{
public override void Awake(RankingUI self)
{
self.Awake();
}
}
public class RankingUIDestroySyatem : DestroySystem<RankingUI>
{
public override void Destroy(RankingUI self)
{
self.Destroy();
}
}
public class RankingUI : Entity
{
public FUI_RankUI ui;
private Scene zoneScene;
public void Awake()
{
zoneScene = this.ZoneScene();
ui = GetParent<FUI_RankUI>();
AwakeAsync().Coroutine();
}
private async ETVoid AwakeAsync()
{
//!临时变量
int selectIndex = 0;
ui.m_control.onChanged.Set(async () =>
{
selectIndex = ui.m_control.selectedIndex;
await GetRanking(selectIndex);
});
await GetRanking(selectIndex);
async ETTask GetRanking(int selectedIndex)
{
M2C_GetRanking ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetRanking>(new C2M_GetRanking { Index = selectedIndex });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
ShowUI((RankingInfo.RankingType)selectedIndex, ret.RankingInfoList);
}
void ShowUI(RankingInfo.RankingType rankingType, List<RankingInfo> rankingInfoList)
{
int index = -1;
ui.m_rankList.RemoveChildrenToPool();
foreach (RankingInfo rankingInfo in rankingInfoList)
{
GObject label = ui.m_rankList.AddItemFromPool();
FUI_LabelRankItem labelItem = FUI_LabelRankItem.GetFormPool(this.ui,label);
if (++index < 3)
{
labelItem.m_control.selectedIndex = index;
}
else
{
labelItem.m_control.selectedIndex = 3;
}
labelItem.m_rank.text = (index + 1).ToString();
labelItem.m_txtName.text = rankingInfo.Name;
labelItem.m_txtJob.text = null;
switch (rankingType)
{
case RankingInfo.RankingType.Level:
labelItem.m_txtJob.text = rankingInfo.Job;
labelItem.m_txtValue.text = (int)rankingInfo.Value + "";
break;
case RankingInfo.RankingType.Coin:
(long gold, int sliver, int coin) = TabHelper.GetCoinFormat((long)rankingInfo.Value);
labelItem.m_txtValue.text = $"{ gold} {TabHelper.Gold} {sliver} {TabHelper.Sliver} {coin} {TabHelper.Coin}";
break;
case RankingInfo.RankingType.Hp:
case RankingInfo.RankingType.Mp:
case RankingInfo.RankingType.PAtk:
case RankingInfo.RankingType.MAtk:
case RankingInfo.RankingType.PDef:
case RankingInfo.RankingType.MDef:
labelItem.m_txtValue.text = (int)rankingInfo.Value + "";
break;
case RankingInfo.RankingType.Pet:
break;
case RankingInfo.RankingType.Dvo:
case RankingInfo.RankingType.PCriR:
case RankingInfo.RankingType.PCri:
case RankingInfo.RankingType.MCriR:
case RankingInfo.RankingType.MCri:
case RankingInfo.RankingType.PRed:
case RankingInfo.RankingType.MRed:
labelItem.m_txtValue.text = $"{(float)rankingInfo.Value:p2}";
break;
default:
break;
}
}
}
await ETTask.CompletedTask;
}
public void Destroy()
{
}
}
}