Ludo-3D/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs

75 lines
1.8 KiB
C#
Raw Permalink Normal View History

2026-01-30 21:51:33 +05:30
using System.Collections;
using System.Collections.Generic;
using System.Linq;
2026-01-30 21:51:33 +05:30
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class GameOverPopup : PopupBase
{
[SerializeField] private Button playAgainBtn;
[SerializeField] private Button mainMenuBtn;
[SerializeField] private TextMeshProUGUI[] texts;
private GameModeHandler gameModeHandler;
public void InitData(List<PlayerData> playerData)
{
for (int idx = 0; idx < texts.Length; idx++)
{
if (idx >= playerData.Count)
{
texts[idx].gameObject.SetActive(false);
continue;
}
if (playerData[idx].ranking == 1)
{
texts[playerData[idx].ranking - 1].text = $"{playerData[idx].playerName} Wins";
continue;
}
texts[playerData[idx].ranking - 1].text = $"{playerData[idx].ranking}. {playerData[idx].playerName}";
}
}
2026-01-30 21:51:33 +05:30
private void OnEnable()
{
playAgainBtn.onClick.AddListener(OnPlayAgainClicked);
mainMenuBtn.onClick.AddListener(OnMainMenuClicked);
}
private void OnDisable()
{
playAgainBtn.onClick.RemoveAllListeners();
mainMenuBtn.onClick.RemoveAllListeners();
}
public void OnPlayAgainClicked()
{
HidePopup();
2026-02-02 17:30:03 +05:30
SetGameModeHandler();
2026-01-30 21:51:33 +05:30
gameModeHandler.OnGameRestarted();
}
private void HidePopup()
{
popupManager.HidePopup(popupType);
}
public void OnMainMenuClicked()
{
HidePopup();
2026-02-02 17:30:03 +05:30
SetGameModeHandler();
gameModeHandler.GameManager.OnGameStateChanged(GameState.InMenu);
}
private void SetGameModeHandler()
{
gameModeHandler = gameModeHandler == null ? InterfaceManager.Instance.GetInterfaceInstance<GameModeHandler>() : gameModeHandler;
2026-01-30 21:51:33 +05:30
}
}