using UnityEngine; using UnityEngine.UI; using TMPro; /// /// Отвечает за отображение экрана GameOver и обновление кнопок /// public class GameOverUI : MonoBehaviour { [SerializeField] private int playerId; [SerializeField] private GameManager gameManager; [Header("UI Elements")] [SerializeField] private Button replayButton; [SerializeField] private Button continueButton; [SerializeField] private TextMeshProUGUI resultText; [SerializeField] private GameObject uiParticle; [SerializeField] private GameOver gameOverStatusImage; public void Show(bool isWin, bool isBotGame) { if (uiParticle != null) uiParticle.SetActive(isWin); if (resultText != null) { resultText.text = isWin ? "Хорош!" : "Увы..."; resultText.color = isWin ? new Color(1f, 0.84f, 0f) : Color.white; if (gameOverStatusImage != null) gameOverStatusImage.GameOverSwitch(isWin); } int credits = ComWrapper.GetPlayerCredits(playerId); if (continueButton != null) continueButton.gameObject.SetActive(false); if (replayButton != null) replayButton.gameObject.SetActive(false); if (isBotGame) { ShowBotGameButtons(isWin, credits); } else { ShowPvPGameButtons(credits); } } private void ShowBotGameButtons(bool isWin, int credits) { if (isWin) { if (continueButton != null) { continueButton.gameObject.SetActive(true); continueButton.interactable = true; } } else { if (replayButton != null) { replayButton.gameObject.SetActive(true); replayButton.interactable = credits >= 1; var txt = replayButton.GetComponentInChildren(); if (txt != null) txt.text = "Переиграть"; } } } private void ShowPvPGameButtons(int credits) { if (replayButton != null) { int oponentId = playerId == 1 ? 2 : 1; int oponentCredits = ComWrapper.GetPlayerCredits(oponentId); replayButton.gameObject.SetActive(true); replayButton.interactable = credits >= 2 || (credits >= 1 && oponentCredits >= 1); var txt = replayButton.GetComponentInChildren(); if (txt != null) txt.text = "Ещё раз!"; } } public void UpdateButtons() { int credits = ComWrapper.GetPlayerCredits(playerId); int oponentId = playerId == 1 ? 2 : 1; int oponentCredits = ComWrapper.GetPlayerCredits(oponentId); if (continueButton != null && continueButton.gameObject.activeSelf) continueButton.interactable = credits >= 1; if (replayButton != null && replayButton.gameObject.activeSelf) { if (gameManager != null && gameManager.gameMode == GameMode.PlayerVsBot) replayButton.interactable = credits >= 1; else replayButton.interactable = credits >= 2 || (credits >= 1 && oponentCredits >= 1); } } }