From e1f5cd72c8e10f91b956516d0af9560022573ee4 Mon Sep 17 00:00:00 2001 From: yastreb Date: Wed, 8 Apr 2026 11:33:34 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=B0=D0=BD=D0=B5=D0=BB=D1=8C=20"?= =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=D0=BD=D1=81"=20=D0=B4=D0=BB=D1=8F=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=B4=D0=BE=D1=81=D1=82=D0=B0=D1=82=D0=BA=D0=B0=20=D1=81=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D1=81=D1=82=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/CreditSystem.cs | 8 ++++ Assets/Scripts/GameManager.cs | 27 +++++++++--- .../UI/Panels/InsufficientFundsPanel.cs | 43 +++++++++++++++++++ .../UI/Panels/InsufficientFundsPanel.cs.meta | 3 ++ .../UI/Panels/MainMenuButtonsUpdater.cs | 18 ++------ Assets/Scripts/UI/UIManager.cs | 14 +++++- 6 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs create mode 100644 Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs.meta diff --git a/Assets/Scripts/CreditSystem.cs b/Assets/Scripts/CreditSystem.cs index d828b297..5223cc11 100644 --- a/Assets/Scripts/CreditSystem.cs +++ b/Assets/Scripts/CreditSystem.cs @@ -23,6 +23,12 @@ public class CreditSystem : MonoBehaviour /// public static System.Action OnInitialize; + /// + /// Вызывается когда Pay() не прошёл из-за нехватки средств (playerId). + /// UIManager подписывается и показывает панель "Пополните баланс". + /// + public static event System.Action OnInsufficientFunds; + // ── Приватные данные ────────────────────────────────────────────────────── private static int _creditsPlayer1; private static int _creditsPlayer2; @@ -86,6 +92,8 @@ public static bool Pay(int coins = 1, int playerId = 1) return true; } + // Денег нет — сообщаем UIManager чтобы показал панель + OnInsufficientFunds?.Invoke(playerId); return false; } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 9ffe9dde..db9e536d 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -648,11 +648,26 @@ public void ArrangeGame() public void OnPlayVsPlayerClicked(int playerId) // мистр кастыль { + bool freeMode = SettingsManager.instance.GetSettingValue("Бесплатная игра") == "Вкл"; + if (!freeMode) + { + int opponentId = playerId == 1 ? 2 : 1; + int myCoins = CreditSystem.GetPlayerCredits(playerId); + int opponentCoins = CreditSystem.GetPlayerCredits(opponentId); - int opponentId = playerId == 1 ? 2 : 1; - - OnInviteSent?.Invoke(playerId, opponentId); + // Варианты оплаты: + // 1) у каждого по 1 монете — списываем с каждого по 1 + // 2) у меня 2 монеты — плачу за обоих сам + bool canStart = (myCoins >= 1 && opponentCoins >= 1) || myCoins >= 2; + if (!canStart) + { + uiManager?.ShowOverlay("InsufficientFunds", true, hideOtherOverlays: false); + return; + } + } + int oppId = playerId == 1 ? 2 : 1; + OnInviteSent?.Invoke(playerId, oppId); } public void AcceptInvite() @@ -706,8 +721,10 @@ public void StartBotGame() { opponentManager.DeclineInvite(); } - - CreditSystem.Pay(1, playerId); + + // Pay вернёт false если денег нет — и автоматически стрельнет OnInsufficientFunds + if (!CreditSystem.Pay(1, playerId)) return; + PrepareNewGame(); Debug.Log("Начинаем игру с ботом"); gameMode = GameMode.PlayerVsBot; diff --git a/Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs b/Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs new file mode 100644 index 00000000..2b94e625 --- /dev/null +++ b/Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs @@ -0,0 +1,43 @@ +using System.Collections; +using UnityEngine; + +/// +/// Панель "Пополните баланс" — показывается когда не хватает денег на игру. +/// Закрывается автоматически через autoHideDelay секунд. +/// +/// Настройка в сцене: +/// - Добавь UIPanelId на этот же GameObject, id = "InsufficientFunds", layer = Overlay +/// - Настрой визуал (фон + TMP_Text с нужным текстом) прямо в редакторе +/// +public class InsufficientFundsPanel : MonoBehaviour +{ + [SerializeField] private float autoHideDelay = 5f; + + private Coroutine _hideCoroutine; + + private void OnEnable() + { + // Каждый раз когда панель показывается — запускаем таймер автозакрытия + if (_hideCoroutine != null) + StopCoroutine(_hideCoroutine); + + _hideCoroutine = StartCoroutine(AutoHide()); + } + + private void OnDisable() + { + if (_hideCoroutine != null) + { + StopCoroutine(_hideCoroutine); + _hideCoroutine = null; + } + } + + private IEnumerator AutoHide() + { + yield return new WaitForSeconds(autoHideDelay); + gameObject.SetActive(false); + _hideCoroutine = null; + } +} + diff --git a/Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs.meta b/Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs.meta new file mode 100644 index 00000000..0462f132 --- /dev/null +++ b/Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 04ebda6e5b8a4de48e9a03fb4cc6088a +timeCreated: 1775224495 \ No newline at end of file diff --git a/Assets/Scripts/UI/Panels/MainMenuButtonsUpdater.cs b/Assets/Scripts/UI/Panels/MainMenuButtonsUpdater.cs index e2958a07..f37cd95f 100644 --- a/Assets/Scripts/UI/Panels/MainMenuButtonsUpdater.cs +++ b/Assets/Scripts/UI/Panels/MainMenuButtonsUpdater.cs @@ -2,7 +2,7 @@ using UnityEngine.UI; /// -/// �������� �� ���������� interactable ��������� ������ �������� ���� �� ������� +/// ���������� �� ���������� interactable ��������� ������ �������� ���� �� ������� /// public class MainMenuButtonsUpdater : MonoBehaviour { @@ -55,20 +55,8 @@ private void OnCoinsChanged(int playerID, int newAmount) public void UpdateButtons() { - int myCoins = CreditSystem.GetPlayerCredits(playerId); - int enemyId = playerId == 1 ? 2 : 1; - int enemyCoins = CreditSystem.GetPlayerCredits(enemyId); - - bool freePlay = SettingsManager.instance != null && - SettingsManager.instance.GetSettingValue("���������� ����") == "���"; - - if (playVsBotButton != null) - playVsBotButton.interactable = myCoins >= 1 || freePlay; - - bool bothHaveEnough = myCoins >= 2 || (myCoins >= 1 && enemyCoins >= 1) || freePlay; - - if (playVsPlayerButton != null) - playVsPlayerButton.interactable = bothHaveEnough; + // Визуальное состояние кнопок не меняется. + // При нехватке денег GameManager покажет панель "Пополните баланс". } } diff --git a/Assets/Scripts/UI/UIManager.cs b/Assets/Scripts/UI/UIManager.cs index dedb88dc..c9aae070 100644 --- a/Assets/Scripts/UI/UIManager.cs +++ b/Assets/Scripts/UI/UIManager.cs @@ -216,22 +216,32 @@ public void HideInvite() private void OnEnable() { GameManager.OnInviteSent += HandleInvite; + CreditSystem.OnInsufficientFunds += HandleInsufficientFunds; } private void OnDisable() { GameManager.OnInviteSent -= HandleInvite; + CreditSystem.OnInsufficientFunds -= HandleInsufficientFunds; } private void HandleInvite(int fromPlayerId, int toPlayerId) { if (toPlayerId != playerId) return; - if (!IsScreenActive("MainMenu")) return; - ShowInvite(fromPlayerId); } + /// + /// Ïîêàçûâàåò ïàíåëü "Ïîïîëíèòå áàëàíñ" íóæíîìó èãðîêó. + /// Ïàíåëü äîëæíà èìåòü UIPanelId.id = "InsufficientFunds" (Overlay). + /// + private void HandleInsufficientFunds(int forPlayerId) + { + if (forPlayerId != playerId) return; + ShowOverlay("InsufficientFunds", true, hideOtherOverlays: false); + } + // ================== UI HELPERS ================== private void ClearHighlights(GameObject panel)