146 lines
4.5 KiB
C#
146 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HUDTournament : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public TournamentManager tournamentManager;
|
|
|
|
public GameObject headerParent;
|
|
|
|
public GameObject playersParent;
|
|
|
|
public GameObject startInfoParent;
|
|
|
|
public Text startInfoMaster;
|
|
|
|
public Text startInfoGuest;
|
|
|
|
public Text timerText;
|
|
|
|
public Text goalText;
|
|
|
|
[Space(10f)]
|
|
public TournamentPlayerWidget playerWidgetPrefab;
|
|
|
|
public Transform playerWidgetsParent;
|
|
|
|
public List<TournamentPlayerWidget> playerWidgets = new List<TournamentPlayerWidget>();
|
|
|
|
[Space(10f)]
|
|
public TournamentPlayerWidget playerWidgetFinishPrefab;
|
|
|
|
public Transform playerWidgetsFinishParent;
|
|
|
|
public List<TournamentPlayerWidget> playerWidgetsFinish = new List<TournamentPlayerWidget>();
|
|
|
|
public void Initialize()
|
|
{
|
|
tournamentManager = GameController.Instance.tournamentManager;
|
|
timerText.gameObject.SetActive(tournamentManager.tournamentDefinition.finishCondition == TournamentManager.TournamentDefinition.FinishCondition.TIME);
|
|
goalText.gameObject.SetActive(tournamentManager.tournamentDefinition.finishCondition == TournamentManager.TournamentDefinition.FinishCondition.GOAL_FIRST);
|
|
LeanTween.alphaText(startInfoMaster.rectTransform, 0.12f, 1.5f).setLoopPingPong().setEaseInOutQuad();
|
|
LeanTween.alphaText(startInfoGuest.rectTransform, 0.12f, 1.5f).setLoopPingPong().setEaseInOutQuad();
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
TournamentPlayerWidget tournamentPlayerWidget = Object.Instantiate(playerWidgetPrefab, Vector3.zero, Quaternion.identity);
|
|
tournamentPlayerWidget.transform.SetParent(playerWidgetsParent);
|
|
tournamentPlayerWidget.transform.localScale = Vector3.one;
|
|
playerWidgets.Add(tournamentPlayerWidget);
|
|
if (i >= tournamentManager.tournamentDefinition.nrOfPlayers)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (!(tournamentManager == null))
|
|
{
|
|
UpdateGoal((int)tournamentManager.tournamentDefinition.goalAmount);
|
|
UpdatePlayerWidgets();
|
|
}
|
|
}
|
|
|
|
public void ShowPlayersParent(bool show)
|
|
{
|
|
playersParent.SetActive(show);
|
|
}
|
|
|
|
public void UpdateStartInfo()
|
|
{
|
|
if (tournamentManager.tournamentStarted)
|
|
{
|
|
startInfoParent.SetActive(false);
|
|
return;
|
|
}
|
|
startInfoParent.SetActive(true);
|
|
startInfoMaster.enabled = PhotonNetwork.isMasterClient;
|
|
startInfoGuest.enabled = !PhotonNetwork.isMasterClient;
|
|
if (VRManager.Instance.IsControllersInput() && PhotonNetwork.isMasterClient)
|
|
{
|
|
startInfoMaster.text = string.Format(Utilities.GetTranslation("TOURNAMENT/PRESS_TO_START_VR"), Utilities.GetTranslation("VR/QUICK_MENU"));
|
|
}
|
|
}
|
|
|
|
public void UpdateMultiplayerSettings()
|
|
{
|
|
timerText.gameObject.SetActive(tournamentManager.tournamentDefinition.finishCondition == TournamentManager.TournamentDefinition.FinishCondition.TIME);
|
|
goalText.gameObject.SetActive(tournamentManager.tournamentDefinition.finishCondition == TournamentManager.TournamentDefinition.FinishCondition.GOAL_FIRST);
|
|
}
|
|
|
|
public void UpdateTime(float time)
|
|
{
|
|
if (timerText.gameObject.activeSelf)
|
|
{
|
|
timerText.text = Utilities.FormatTime(time, false, 0f);
|
|
}
|
|
}
|
|
|
|
public void UpdateGoal(int goal)
|
|
{
|
|
goalText.text = Utilities.GetTranslation("GUI/TOURNAMENTS_GOAL") + ": ";
|
|
if (tournamentManager.tournamentDefinition.goalType == TournamentManager.TournamentDefinition.GoalType.WEIGHT_MAX || tournamentManager.tournamentDefinition.goalType == TournamentManager.TournamentDefinition.GoalType.WEIGHT_SUM)
|
|
{
|
|
goalText.text += UtilitiesUnits.GetWeightString(goal);
|
|
}
|
|
else
|
|
{
|
|
goalText.text += goal;
|
|
}
|
|
}
|
|
|
|
public void UpdatePlayerWidgets()
|
|
{
|
|
UpdateWidgets(playerWidgets);
|
|
}
|
|
|
|
public void UpdateFinishWidgets()
|
|
{
|
|
UpdateWidgets(playerWidgetsFinish);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
if (i >= tournamentManager.tournamentDefinition.nrOfPlayers)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateWidgets(List<TournamentPlayerWidget> widgets)
|
|
{
|
|
for (int i = 0; i < tournamentManager.sortedPlayers.Count && i < widgets.Count; i++)
|
|
{
|
|
widgets[i].RefreshWidget(i + 1, tournamentManager.sortedPlayers[i], tournamentManager.tournamentDefinition.goalType);
|
|
}
|
|
for (int j = tournamentManager.sortedPlayers.Count; j < widgets.Count; j++)
|
|
{
|
|
widgets[j].RefreshWidget(0, null, tournamentManager.tournamentDefinition.goalType);
|
|
}
|
|
if (tournamentManager.currentPlayerPosition >= widgets.Count)
|
|
{
|
|
widgets[widgets.Count - 1].RefreshWidget(tournamentManager.currentPlayerPosition + 1, tournamentManager.sortedPlayers[tournamentManager.currentPlayerPosition], tournamentManager.tournamentDefinition.goalType);
|
|
}
|
|
}
|
|
}
|