Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/TournamentPlayerWidget.cs
2026-02-21 16:45:37 +08:00

107 lines
2.6 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TournamentPlayerWidget : MonoBehaviour
{
public Text positionText;
public Text playerNameText;
public Text currentScoreText;
public Image background;
public Image trophy;
public Color defaultColor = Color.black;
public Color playerColor = Color.black;
public List<Color> trophyColors = new List<Color>();
public void Awake()
{
}
public void RefreshWidget(int position, TournamentPlayer tournamentPlayer, TournamentManager.TournamentDefinition.GoalType goalType)
{
if (tournamentPlayer == null || !tournamentPlayer.isLocalPlayer)
{
background.color = defaultColor;
}
else
{
background.color = playerColor;
}
if ((bool)trophy)
{
trophy.enabled = tournamentPlayer != null;
}
if (tournamentPlayer == null)
{
positionText.text = string.Empty;
playerNameText.text = string.Empty;
currentScoreText.text = string.Empty;
return;
}
playerNameText.text = tournamentPlayer.playerName;
if (tournamentPlayer.GetScore() == 0f)
{
positionText.text = "-";
}
else
{
positionText.text = string.Empty + tournamentPlayer.sortedPosition;
}
if (trophyColors.Count > 0)
{
if (tournamentPlayer.GetScore() == 0f)
{
if ((bool)trophy)
{
trophy.color = trophyColors[3];
trophy.transform.localScale = Vector3.one * 0.8f;
}
positionText.color = trophyColors[3];
}
else
{
if ((bool)trophy)
{
if (tournamentPlayer.sortedPosition == 1)
{
trophy.color = trophyColors[0];
trophy.transform.localScale = Vector3.one;
}
else if (tournamentPlayer.sortedPosition == 2)
{
trophy.color = trophyColors[1];
trophy.transform.localScale = Vector3.one * 0.92f;
}
else if (tournamentPlayer.sortedPosition == 3)
{
trophy.color = trophyColors[2];
trophy.transform.localScale = Vector3.one * 0.84f;
}
}
positionText.color = Color.white;
}
}
currentScoreText.enabled = GameController.Instance.tournamentManager.tournamentStarted;
currentScoreText.text = Utilities.GetTranslation("GUI/TOURNAMENTS_SCORE") + ": ";
switch (goalType)
{
case TournamentManager.TournamentDefinition.GoalType.AMOUNT:
currentScoreText.text += (int)tournamentPlayer.GetScore();
break;
case TournamentManager.TournamentDefinition.GoalType.WEIGHT_SUM:
currentScoreText.text += UtilitiesUnits.GetWeightString(tournamentPlayer.GetScore());
break;
case TournamentManager.TournamentDefinition.GoalType.WEIGHT_MAX:
currentScoreText.text += UtilitiesUnits.GetWeightString(tournamentPlayer.GetScore());
break;
}
}
}