diff --git a/Assets/Scripts/Gameplay/Panels/PveLossPanel.cs b/Assets/Scripts/Gameplay/Panels/PveLossPanel.cs index 8c5d06f..efae7a4 100644 --- a/Assets/Scripts/Gameplay/Panels/PveLossPanel.cs +++ b/Assets/Scripts/Gameplay/Panels/PveLossPanel.cs @@ -63,11 +63,14 @@ public class PveLossPanel : MonoBehaviour, IControlable public void Close() { + int selectedButtonIndex = buttonIndex; + if (selectedButtonIndex == 0 && revengeButton is RevengeButton paidRestartButton && + !paidRestartButton.TryPay(GameMode.pve)) + return; + ControlsEnabled = false; ControlsPerformer.Instance.SetControlable(null); - int selectedButtonIndex = buttonIndex; - if (_animation != null) { diff --git a/Assets/Scripts/Gameplay/Panels/PvpWinPanel.cs b/Assets/Scripts/Gameplay/Panels/PvpWinPanel.cs index b18499b..d960c40 100644 --- a/Assets/Scripts/Gameplay/Panels/PvpWinPanel.cs +++ b/Assets/Scripts/Gameplay/Panels/PvpWinPanel.cs @@ -67,10 +67,13 @@ public class PvpWinPanel : MonoBehaviour, IControlable public void Close() { + int selectedButtonIndex = _buttonIndex; + if (selectedButtonIndex == 0 && !_restartButton.TryPay(GameMode.pvp)) + return; + ControlsEnabled = false; ControlsPerformer.Instance.SetControlable(null); - int selectedButtonIndex = _buttonIndex; _animation?.Kill(); _animation = GetCloseSequence(); _animation.OnComplete(() => CompleteClose(selectedButtonIndex)); @@ -88,7 +91,7 @@ public class PvpWinPanel : MonoBehaviour, IControlable _description.localRotation = Quaternion.identity; _description.GetComponent().text = GetDescription(winner, isMatchWin, player1Score, player2Score); - _restartButton.InitializeForFreeRestart(); + _restartButton.Initialize(GameMode.pvp); _restartButton.transform.localScale = Vector3.zero; _menuButton.transform.localScale = Vector3.zero; _background.color = _backgroundDisabledColor; diff --git a/Assets/Scripts/Gameplay/Panels/RevengeButton.cs b/Assets/Scripts/Gameplay/Panels/RevengeButton.cs index 8f9d740..b964a50 100644 --- a/Assets/Scripts/Gameplay/Panels/RevengeButton.cs +++ b/Assets/Scripts/Gameplay/Panels/RevengeButton.cs @@ -1,50 +1,48 @@ -using System; using TMPro; using UnityEngine; +using UnityEngine.Serialization; using UnityEngine.UI; public class RevengeButton : PveLossButton { [Header("Layout ссылки")] - [SerializeField] private TextMeshProUGUI oldPrice; - [SerializeField] private TextMeshProUGUI actualPrice; - [SerializeField] private Image saleImage; - + [SerializeField, FormerlySerializedAs("oldPrice")] private TextMeshProUGUI _oldPrice; + [SerializeField, FormerlySerializedAs("actualPrice")] private TextMeshProUGUI _actualPrice; + [SerializeField, FormerlySerializedAs("saleImage")] private Image _saleImage; + public override void Initialize() + => Initialize(GameMode.pve); + + public void Initialize(GameMode gameMode) { if (PaymentSystem.Freeplay) { - oldPrice.gameObject.SetActive(false); - actualPrice.gameObject.SetActive(false); - saleImage.gameObject.SetActive(false); + _oldPrice.gameObject.SetActive(false); + _actualPrice.gameObject.SetActive(false); + _saleImage.gameObject.SetActive(false); return; } - int revengePrice = PaymentSystem.PriceRevengePve; - int normalPrice = PaymentSystem.PricePve; + int revengePrice = PaymentSystem.GetRevengePrice(gameMode); + int normalPrice = PaymentSystem.GetModePrice(gameMode); - actualPrice.gameObject.SetActive(true); - actualPrice.text = $"{revengePrice} {PaymentSystem.ValutaName}"; + _actualPrice.gameObject.SetActive(true); + _actualPrice.text = PaymentSystem.GetPluralizedMoney(revengePrice); bool revengeCheaper = revengePrice < normalPrice; - oldPrice.gameObject.SetActive(revengeCheaper); - oldPrice.text = $"{normalPrice} {PaymentSystem.ValutaName}"; - - saleImage.gameObject.SetActive(revengeCheaper); + _oldPrice.gameObject.SetActive(revengeCheaper); + _oldPrice.text = PaymentSystem.GetPluralizedMoney(normalPrice); + _saleImage.gameObject.SetActive(revengeCheaper); } - public void InitializeForFreeRestart() - { - oldPrice.gameObject.SetActive(false); - actualPrice.gameObject.SetActive(false); - saleImage.gameObject.SetActive(false); - } + public bool TryPay(GameMode gameMode) + => PaymentSystem.TryPay(PaymentSystem.GetRevengePrice(gameMode)); public override void Interact() { - if (!interactable) return; + if (!interactable) + return; base.Interact(); - } }