193 lines
5.7 KiB
C#
193 lines
5.7 KiB
C#
using System;
|
|
using Steamworks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CreatorParticipantItem : MonoBehaviour
|
|
{
|
|
public enum Status
|
|
{
|
|
WAITING = 0,
|
|
JOINED = 1,
|
|
READY = 2
|
|
}
|
|
|
|
[HideInInspector]
|
|
public PlayerTournamentItem playerTournamentItem;
|
|
|
|
[HideInInspector]
|
|
public TournamentManager.CTournament tournament;
|
|
|
|
public int index;
|
|
|
|
public string playerID = "";
|
|
|
|
public bool isReadyPressed;
|
|
|
|
public Status status;
|
|
|
|
[SerializeField]
|
|
private Text playerNameText;
|
|
|
|
[SerializeField]
|
|
private RawImage playerAvatarImage;
|
|
|
|
[SerializeField]
|
|
private Text playerLevelText;
|
|
|
|
[SerializeField]
|
|
private Text playerTournamentsWonText;
|
|
|
|
[SerializeField]
|
|
private Text playerRankingsPointsText;
|
|
|
|
[SerializeField]
|
|
private Transform[] contentTypeTransform;
|
|
|
|
[SerializeField]
|
|
private Button addButton;
|
|
|
|
[SerializeField]
|
|
private Button readyButton;
|
|
|
|
[SerializeField]
|
|
private Button cancelInviteButton;
|
|
|
|
private Animator animator;
|
|
|
|
private void Start()
|
|
{
|
|
animator = GetComponent<Animator>();
|
|
contentTypeTransform[0].gameObject.SetActive(value: false);
|
|
contentTypeTransform[1].gameObject.SetActive(value: false);
|
|
readyButton.gameObject.SetActive(value: false);
|
|
UpdateParticipant();
|
|
InvokeRepeating("UpdateParticipant", 1f, 1f);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
private void UpdateParticipant()
|
|
{
|
|
if (tournament.tournamentParticipants.Count > index)
|
|
{
|
|
playerID = tournament.tournamentParticipants[index].playerId;
|
|
playerNameText.text = tournament.tournamentParticipants[index].playerName;
|
|
playerLevelText.text = LanguageManager.Instance.GetText("LEVEL") + " " + tournament.tournamentParticipants[index].player_level;
|
|
playerTournamentsWonText.text = LanguageManager.Instance.GetText("TOURNAMENTS_WON") + ": " + tournament.tournamentParticipants[index].tournaments_won;
|
|
playerRankingsPointsText.text = LanguageManager.Instance.GetText("RANKING_POINTS") + ": " + tournament.tournamentParticipants[index].rankings_points;
|
|
ulong.TryParse(playerID, out playerAvatarImage.GetComponent<SteamShowAvatarByUserId>().steamUserID);
|
|
status = (Status)Enum.Parse(typeof(Status), tournament.tournamentParticipants[index].status);
|
|
}
|
|
switch (status)
|
|
{
|
|
case Status.WAITING:
|
|
contentTypeTransform[0].gameObject.SetActive(value: true);
|
|
contentTypeTransform[1].gameObject.SetActive(value: false);
|
|
readyButton.gameObject.SetActive(value: true);
|
|
readyButton.image.enabled = false;
|
|
readyButton.interactable = false;
|
|
readyButton.GetComponentInChildren<Text>().text = LanguageManager.Instance.GetText("WAITING").ToUpper();
|
|
animator.SetBool("IsButtonReadyTextBlink", value: true);
|
|
break;
|
|
case Status.JOINED:
|
|
{
|
|
contentTypeTransform[0].gameObject.SetActive(value: false);
|
|
contentTypeTransform[1].gameObject.SetActive(value: true);
|
|
int num = 30 - Mathf.Clamp(Mathf.Abs(tournament.tournamentParticipants[index].joined_timeleft), 0, 30);
|
|
if (playerID == SteamUser.GetSteamID().m_SteamID.ToString())
|
|
{
|
|
readyButton.gameObject.SetActive(value: true);
|
|
readyButton.image.enabled = true;
|
|
if (!isReadyPressed)
|
|
{
|
|
readyButton.interactable = true;
|
|
}
|
|
readyButton.GetComponentInChildren<Text>().color = Color.white;
|
|
if (num > 0)
|
|
{
|
|
readyButton.GetComponentInChildren<Text>().text = LanguageManager.Instance.GetText("READY").ToUpper() + "\n" + num;
|
|
}
|
|
else
|
|
{
|
|
readyButton.GetComponentInChildren<Text>().text = LanguageManager.Instance.GetText("READY").ToUpper();
|
|
}
|
|
animator.SetBool("IsButtonReadyTextBlink", value: false);
|
|
if (tournament.tournamentParticipants[index].joined_timeleft < -30 && readyButton.interactable)
|
|
{
|
|
ReadyButton();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
readyButton.gameObject.SetActive(value: true);
|
|
readyButton.image.enabled = false;
|
|
readyButton.interactable = false;
|
|
readyButton.GetComponentInChildren<Text>().text = LanguageManager.Instance.GetText("WAITING").ToUpper();
|
|
animator.SetBool("IsButtonReadyTextBlink", value: true);
|
|
if (tournament.tournamentParticipants[index].joined_timeleft < -35 && !isReadyPressed)
|
|
{
|
|
ServerManager.Instance.AutoReadyTournament(tournament.tournamentParticipants[index], tournament.id);
|
|
isReadyPressed = true;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case Status.READY:
|
|
contentTypeTransform[0].gameObject.SetActive(value: false);
|
|
contentTypeTransform[1].gameObject.SetActive(value: true);
|
|
readyButton.gameObject.SetActive(value: true);
|
|
readyButton.image.enabled = false;
|
|
readyButton.interactable = false;
|
|
readyButton.GetComponentInChildren<Text>().text = LanguageManager.Instance.GetText("READY").ToUpper();
|
|
readyButton.GetComponentInChildren<Text>().color = Color.green;
|
|
animator.SetBool("IsButtonReadyTextBlink", value: false);
|
|
break;
|
|
}
|
|
CheckForAddButton();
|
|
}
|
|
|
|
private void CheckForAddButton()
|
|
{
|
|
if (status != Status.WAITING)
|
|
{
|
|
return;
|
|
}
|
|
if (TournamentManager.Instance.CheckIsTournamentJoined(tournament))
|
|
{
|
|
addButton.gameObject.SetActive(value: false);
|
|
}
|
|
else if (index > 0)
|
|
{
|
|
if (playerTournamentItem.creatorParticipantItems[index - 1].status != Status.WAITING)
|
|
{
|
|
addButton.gameObject.SetActive(value: true);
|
|
}
|
|
else
|
|
{
|
|
addButton.gameObject.SetActive(value: false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ReadyButton()
|
|
{
|
|
ServerManager.Instance.ReadyTournament(tournament);
|
|
readyButton.interactable = false;
|
|
isReadyPressed = true;
|
|
}
|
|
|
|
public void AddButton()
|
|
{
|
|
if (!GameManager.Instance._playerData.AddSubPlayerCashValue(-tournament.entryFee))
|
|
{
|
|
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("NOT_ENOUGH_MONEY_TO_JOIN"), UnityEngine.Object.FindObjectOfType<MainGameScene>().transform, deleteLast: true);
|
|
return;
|
|
}
|
|
ServerManager.Instance.JoinToTournament(tournament);
|
|
addButton.interactable = false;
|
|
}
|
|
}
|