feat: добавлена панель "Пополните баланс" для обработки недостатка средств
This commit is contained in:
parent
b084a59ff4
commit
e1f5cd72c8
@ -23,6 +23,12 @@ public class CreditSystem : MonoBehaviour
|
||||
/// </summary>
|
||||
public static System.Action OnInitialize;
|
||||
|
||||
/// <summary>
|
||||
/// Вызывается когда Pay() не прошёл из-за нехватки средств (playerId).
|
||||
/// UIManager подписывается и показывает панель "Пополните баланс".
|
||||
/// </summary>
|
||||
public static event System.Action<int> 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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
43
Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs
Normal file
43
Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Панель "Пополните баланс" — показывается когда не хватает денег на игру.
|
||||
/// Закрывается автоматически через autoHideDelay секунд.
|
||||
///
|
||||
/// Настройка в сцене:
|
||||
/// - Добавь UIPanelId на этот же GameObject, id = "InsufficientFunds", layer = Overlay
|
||||
/// - Настрой визуал (фон + TMP_Text с нужным текстом) прямо в редакторе
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs.meta
Normal file
3
Assets/Scripts/UI/Panels/InsufficientFundsPanel.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04ebda6e5b8a4de48e9a03fb4cc6088a
|
||||
timeCreated: 1775224495
|
||||
@ -2,7 +2,7 @@
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> interactable <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> interactable <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>") == "<22><><EFBFBD>";
|
||||
|
||||
if (playVsBotButton != null)
|
||||
playVsBotButton.interactable = myCoins >= 1 || freePlay;
|
||||
|
||||
bool bothHaveEnough = myCoins >= 2 || (myCoins >= 1 && enemyCoins >= 1) || freePlay;
|
||||
|
||||
if (playVsPlayerButton != null)
|
||||
playVsPlayerButton.interactable = bothHaveEnough;
|
||||
// Визуальное состояние кнопок не меняется.
|
||||
// При нехватке денег GameManager покажет панель "Пополните баланс".
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ïîêàçûâàåò ïàíåëü "Ïîïîëíèòå áàëàíñ" íóæíîìó èãðîêó.
|
||||
/// Ïàíåëü äîëæíà èìåòü UIPanelId.id = "InsufficientFunds" (Overlay).
|
||||
/// </summary>
|
||||
private void HandleInsufficientFunds(int forPlayerId)
|
||||
{
|
||||
if (forPlayerId != playerId) return;
|
||||
ShowOverlay("InsufficientFunds", true, hideOtherOverlays: false);
|
||||
}
|
||||
|
||||
// ================== UI HELPERS ==================
|
||||
|
||||
private void ClearHighlights(GameObject panel)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user