167 lines
5.7 KiB
C#
167 lines
5.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Logic;
|
|
using RuntimeData;
|
|
using Animancer;
|
|
using ET;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using Logic.Multilingual;
|
|
using TH1Resource;
|
|
using UI;
|
|
|
|
public class RankingUI
|
|
{
|
|
public GameObject RORankingUI;
|
|
|
|
public bool NeedShow = false;
|
|
|
|
private bool _isShowing = false;
|
|
private bool _isAnimating = false;
|
|
private float _fadeDuration = 0.2f;
|
|
|
|
public RankingUI()
|
|
{
|
|
RORankingUI = UIManager.Instance.ROUIManager.transform.Find("RankingPanel").gameObject;
|
|
GameStartInit();
|
|
}
|
|
|
|
public void GameStartInit()
|
|
{
|
|
RORankingUI.SetActive(false);
|
|
NeedShow = false;
|
|
_isShowing = false;
|
|
_isAnimating = false;
|
|
}
|
|
public void UpdateRankingList()
|
|
{
|
|
var playerList = new List<PlayerData>(Main.MapData.PlayerMap.PlayerDataList);
|
|
playerList.Sort((a, b) => b.PlayerScore.CompareTo(a.PlayerScore));
|
|
|
|
var selfPlayer = Main.MapData.PlayerMap.SelfPlayerData;
|
|
var content = RORankingUI.transform.Find("MsgList/Scroll View/Viewport/Content");
|
|
for (int i = 0; i < 16; i++)
|
|
{
|
|
var row = content.Find("Row (" + i + ")");
|
|
if (i < playerList.Count)
|
|
{
|
|
var player = playerList[i];
|
|
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out var playerInfo))
|
|
continue;
|
|
//row.gameObject.SetActive(true);
|
|
row.Find("Rank").GetComponent<TextMeshProUGUI>().text = (i + 1).ToString();
|
|
string name = playerInfo.ForceName;
|
|
Sprite sprite = playerInfo.LeaderIllustration;
|
|
row.Find("AvatarMask/AvatarImage").GetComponent<Image>().color = Color.white;
|
|
row.Find("CityCount").GetComponent<TextMeshProUGUI>().text = Main.MapData.GetCityCount(player.Id).ToString();
|
|
row.Find("Score").GetComponent<TextMeshProUGUI>().text = player.PlayerScore.ToString();
|
|
row.Find("Name").GetComponent<TextMeshProUGUI>().color = Color.black;
|
|
|
|
if (!selfPlayer.MeetPlayers.Contains(player.Id))
|
|
{
|
|
name = "???";
|
|
sprite = null;
|
|
}
|
|
|
|
if (!player.Alive)
|
|
{
|
|
row.Find("Name").GetComponent<TextMeshProUGUI>().color = Color.gray;
|
|
row.Find("AvatarMask/AvatarImage").GetComponent<Image>().color = new Color(128,128,128 ,1);;
|
|
}
|
|
|
|
if (player == selfPlayer)
|
|
{
|
|
row.Find("Name").GetComponent<TextMeshProUGUI>().color = Color.blue;
|
|
}
|
|
|
|
if (name != "???")
|
|
MultilingualManager.Instance.SetUIText(row.Find("Name").GetComponent<TextMeshProUGUI>(), name);
|
|
else
|
|
row.Find("Name").GetComponent<TextMeshProUGUI>().text = name;
|
|
row.Find("AvatarMask/AvatarImage").GetComponent<Image>().sprite = sprite;
|
|
}
|
|
else
|
|
{
|
|
row.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
public void Update()
|
|
{
|
|
if (_isAnimating) return;
|
|
if (NeedShow && !RORankingUI.activeSelf)
|
|
{
|
|
UpdateRankingList();
|
|
Show();
|
|
}
|
|
else if (!NeedShow && RORankingUI.activeSelf)
|
|
{
|
|
Hide();
|
|
}
|
|
else if(NeedShow && RORankingUI.activeSelf)
|
|
{
|
|
UpdateRankingList();
|
|
}
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
if (_isShowing || _isAnimating) return;
|
|
|
|
_isShowing = true;
|
|
_isAnimating = true;
|
|
RORankingUI.SetActive(true);
|
|
|
|
AnimancerComponent animancer = RORankingUI.GetComponent<AnimancerComponent>();
|
|
AnimationClip fadeInClip = Resources.Load<AnimationClip>("Animations/UI/RankingPanelFadeIn");
|
|
if (fadeInClip != null)
|
|
animancer.Play(fadeInClip);
|
|
|
|
|
|
var playerList = new List<PlayerData>(Main.MapData.PlayerMap.PlayerDataList);
|
|
var content = RORankingUI.transform.Find("MsgList/Scroll View/Viewport/Content");
|
|
for (int i = 0; i < 16; i++)
|
|
{
|
|
var row = content.Find("Row (" + i + ")");
|
|
if (i < playerList.Count)
|
|
{
|
|
var player = playerList[i];
|
|
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out var playerInfo))
|
|
continue;
|
|
row.gameObject.SetActive(false);
|
|
var anim = row.GetComponent<AnimancerComponent>();
|
|
if (anim != null)
|
|
Timer.Instance.TimerRegister(anim,
|
|
() =>
|
|
{
|
|
row.gameObject.SetActive(true);
|
|
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
|
}, 0.1f * i);
|
|
}
|
|
}
|
|
|
|
Timer.Instance.TimerRegister(RORankingUI, () => { _isAnimating = false; }, _fadeDuration);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (!_isShowing || _isAnimating) return;
|
|
|
|
_isShowing = false;
|
|
_isAnimating = true;
|
|
|
|
AnimancerComponent animancer = RORankingUI.GetComponent<AnimancerComponent>();
|
|
AnimationClip fadeOutClip = Resources.Load<AnimationClip>("Animations/UI/RankingPanelFadeOut");
|
|
if (fadeOutClip != null)
|
|
animancer.Play(fadeOutClip);
|
|
var content = RORankingUI.transform.Find("MsgList/Scroll View/Viewport/Content");
|
|
foreach (Transform child in content)
|
|
child.gameObject.SetActive(false);
|
|
|
|
Timer.Instance.TimerRegister(RORankingUI, () =>
|
|
{
|
|
RORankingUI.SetActive(false);
|
|
_isAnimating = false;
|
|
}, _fadeDuration);
|
|
}
|
|
} |