sea-battle-vr/Assets/Scripts/Menu/MenuControllerOneRegime.cs
2026-06-02 17:04:29 +03:00

122 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Periscope;
using TMPro;
using UnityEngine;
public class MenuControllerOneRegime : MonoBehaviour
{
[SerializeField] private string GameplaySceneName = "Gameplay";
[SerializeField] private TextMeshProUGUI BalanceLabel;
[SerializeField] private TextMeshProUGUI GamesPayedLabel;
[SerializeField] private TextMeshProUGUI FreeplayLabel;
[SerializeField] private string BalancePrefix = "Баланс: ";
[SerializeField] private string GamesPayedPrefix = "Оплачено игр: ";
[SerializeField] private GameObject _instructionCommon;
[SerializeField] private GameObject _instructionPeriscope;
private int gamePrice;
private bool initialized = false;
private string valuta;
private bool _freeplay;
private bool EnoughMoney => _freeplay || WalletManager.Balance >= gamePrice;
private int ActualPrice => _freeplay ? 0 : gamePrice;
public void Initialize()
{
gamePrice = SettingsManager.GetInt(SettingKey.GamePrice, 100);
valuta = SettingsManager.GetString(SettingKey.Valuta, "руб.");
_freeplay = SettingsManager.GetBool(SettingKey.Freeplay, false);
InitLayout();
WalletManager.OnBalanceChanged += UpdateUI;
UpdateUI(WalletManager.Balance);
WalletManager.OnBalanceAdd += WalletManager_OnBalanceAdd;
initialized = true;
}
//перископ
private void WalletManager_OnBalanceAdd(int obj)
{
if (EnoughMoney)
{
WalletManager.OnBalanceAdd -= WalletManager_OnBalanceAdd;
PeriscopeManager.MoveCenter();
}
}
private void Update()
{
if (!initialized) return;
if (EnoughMoney && In.GetButtonDown(InSignal.DownRight))
{
WalletManager.TakeMoney(ActualPrice);
CountersSystem.Increment(CountersSystem.CounterType.TotalStarts);
CountersSystem.Increment(CountersSystem.CounterType.StartsFromMenu);
SceneLoader.LoadScene(GameplaySceneName);
}
if (In.GetButtonDown(InSignal.Service))
SceneLoader.LoadScene("Settings");
PeriscopeProcess();
}
private void OnDestroy()
{
WalletManager.OnBalanceChanged -= UpdateUI;
WalletManager.OnBalanceAdd -= WalletManager_OnBalanceAdd;
PeriscopeManager.StopAllForce();
}
public void UpdateUI(int balance)
{
if (_freeplay)
{
_instructionCommon.SetActive(false);
_instructionPeriscope.SetActive(true);
return;
}
string valutaPluralized = valuta == "руб." ? PluralizeUtil.Rubles(balance) : PluralizeUtil.Tokens(balance);
BalanceLabel.text = $"{BalancePrefix}{balance}/{ActualPrice} {valutaPluralized}";
GamesPayedLabel.text = $"{GamesPayedPrefix}{balance / gamePrice}";
bool enoughMoney = balance >= gamePrice;
_instructionCommon.SetActive(!enoughMoney);
_instructionPeriscope.SetActive(enoughMoney);
}
private void InitLayout()
{
bool needPay = !_freeplay;
BalanceLabel.gameObject.SetActive(needPay);
GamesPayedLabel.gameObject.SetActive(needPay);
FreeplayLabel.gameObject.SetActive(_freeplay);
}
private void PeriscopeProcess()
{
if(PeriscopeManager.AutoRegime) return;
if(!EnoughMoney) return;
bool up = In.GetButton(InSignal.UpLeft) || Input.GetKey(KeyCode.UpArrow);
bool down = In.GetButton(InSignal.DownLeft) || Input.GetKey(KeyCode.DownArrow);
bool stop = (up == down);
if(stop)
PeriscopeManager.StopManually();
else if (up)
PeriscopeManager.UpManually();
else if (down)
PeriscopeManager.DownManually();
}
}