2026-01-12 09:36:17 +03:00

384 lines
11 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 System.Collections;
using UnityEngine;
enum MenuSubStates {OpeningMenu, Choosing, Payment, ClosingMenu, SwitchState}
public class MenuState : IState
{
GameManager gm;
float timeToPromo = 180;
bool animationEnded = true;
public Transform
label,
buttonLeft,
buttonRight,
coinPanel,
label2,
board,
noPrizeLabel;
RectTransform SmallPrizesOut;
MenuSubStates subState;
#region начальные и конечные позиции для элементов меню
//s - startPosition, e - endPosition
Vector2
//надпись 4вряд
sLabel = new Vector2(0, 300),
eLabel = new Vector2(0, 1000),
//свечение
sGlow = new Vector2(490, 0),
eGlow = new Vector2(2000, 0),
//режимы
sButton = new Vector2(250, 180),
eButton = new Vector2(2000, 180),
//подсказка + лого + техподдержка
sLabel2 = new Vector2(0, -380),
eLabel2 = new Vector2(0, -1000),
//земля
sGround = new Vector2(0, -15),
eGround = new Vector2(0, -5.75f),
//Доска
sBoard = new Vector2(-40, -0.5f),
eBoard = new Vector2(0, -0.5f),
sNoPrize = new Vector2(-0, -50f),
eNoPrize = new Vector2(15, -409);
Vector3
sCoin = new Vector3(0, -1.93f, 0),
eCoin = new Vector3(-8.964f, 3.6f, 0);
Vector2 sSmallPrizesOutSize = new Vector2(560, 100);
Vector2 eSmallPrizesOutSize = new Vector2(660, 100);
#endregion
//bool leftPosition = true;
public MenuState()
{
gm = GameManager.instance;
label = gm.label;
buttonLeft = gm.buttonLeft;
buttonRight = gm.buttonRight;
coinPanel = gm.coinPanel;
label2 = gm.label2;
board = gm.board;
noPrizeLabel = gm.noPrizeLabel;
SmallPrizesOut = gm.smallPrizesOut;
subState = MenuSubStates.Choosing;
}
//если пришли из игры, то нужно начать с открытия меню
public MenuState(bool fromGameplay) : this()
{
subState = MenuSubStates.OpeningMenu;
}
public void enter()
{
gm.vsBotThinkTime = 0;
gm.vsBotMoves = 0;
CharacterController.HideCharacter();
CharacterController.I.SetAllCharactersPrizeAvailable(true);
DifficultyManager.instance.ResetDifficulty();
if (!gm.menuOpened)
{
subState = MenuSubStates.OpeningMenu;
}
else
{
subState = MenuSubStates.Choosing;
restTimeToPromo = timeToPromo;
}
gm.player1score = 0;
gm.player2score = 0;
gm.vsBotScore = 0;
LightUtility.Idle();
}
public void exit()
{
}
public void update()
{
switch (subState)
{
case MenuSubStates.OpeningMenu:
OpenMenu();
break;
case MenuSubStates.Choosing:
ChoosingMode();
break;
case MenuSubStates.Payment:
Payment();
break;
case MenuSubStates.ClosingMenu:
CloseMenu();
break;
case MenuSubStates.SwitchState:
SwitchState();
break;
}
}
float restTimeToPromo /*= timeToPromo*/;
//float timeToPromo = 180;
float timeToCheck = 2;
float timeToMenu;
private void ChoosingMode()
{
if (!animationEnded)
return;
//Заход в настройки
bool menuKeys = In.GetButton(ButtonPinMapping.secret) || Input.GetKey(KeyCode.F5);
if (menuKeys)
{
timeToMenu += Time.deltaTime;
if(timeToMenu >= 3f)
{
gm.stateMachine.ChangeState(new SettingsState());
timeToMenu = 0;
return;
}
}
else
{
timeToMenu -= Time.deltaTime;
}
timeToMenu = Mathf.Clamp(timeToMenu, 0, 3);
if (In.GetButtonDown(ButtonPinMapping.startOnePlayer))
{
gm.SetMode(GameMode.pve);
// тут проинициализировать шкалы для 1 или 2 игроков
gm.InitVictoryScales();
SoundManager.instance.playChoose();
subState = MenuSubStates.Payment;
}
if (In.GetButtonDown(ButtonPinMapping.startTwoPlayers))
{
gm.SetMode(GameMode.pvp);
// тут проинициализировать шкалы для 1 или 2 игроков
gm.InitVictoryScales();
SoundManager.instance.playChoose();
subState = MenuSubStates.Payment;
}
if (In.GetButtonDownAnyPlayer(PlayerAction.down))
{
gm.stateMachine.ChangeState(new RulesState());
}
restTimeToPromo -= Time.deltaTime;
if (restTimeToPromo < 0)
gm.stateMachine.ChangeState(new PromoState());
bool gotoLeaderboard = In.GetButtonDownAnyPlayer(PlayerAction.left) && In.GetButtonDownAnyPlayer(PlayerAction.right);
if (gotoLeaderboard)
gm.stateMachine.ChangeState(new CheckLeadersFromMenuState());
bool checkCountersCombination = In.GetButton(ButtonPinMapping.startOnePlayer) && In.GetButton(ButtonPinMapping.startTwoPlayers);
if (checkCountersCombination)
{
timeToCheck -= Time.deltaTime;
if (timeToCheck <= 0)
{
if (SettingsManager.GetBool("FastCheck", false))
{
gm.fastCheckCounters.SetActive(true);
timeToCheck = 2;
}
else
timeToCheck = 2;
}
}
else
timeToCheck = 2;
}
private void Payment()
{
int creditsPrice = gm.gameMode == GameMode.pve ? PlayerPrefs.GetInt("PricePVE", 10) : PlayerPrefs.GetInt("PricePVP", 10);
if (ComWrapper.Pay(creditsPrice))
{//оплата успешно - закрываем меню
subState = MenuSubStates.ClosingMenu;
}
else
{//не хватило монет - возвращаемся к выбору
gm.OnNoMoney?.Invoke();
subState = MenuSubStates.Choosing;
restTimeToPromo = timeToPromo;
}
}
void CloseMenu()
{
gm.timerManager.SetTimersActivity(gm.gameMode);
gm.menuOpened = true;
animationEnded = false;
gm.StartCoroutine(closeMenuAnimation());
subState = MenuSubStates.SwitchState;
}
void OpenMenu()
{
animationEnded = false;
gm.menuOpened = true;
gm.StartCoroutine(openMenuAnimation());
subState = MenuSubStates.Choosing;
restTimeToPromo = timeToPromo;
}
void SwitchState()
{
if (animationEnded)
{
if (subState == MenuSubStates.OpeningMenu)
{
subState = MenuSubStates.Choosing;
restTimeToPromo = timeToPromo;
return;
}
else
{//заход в игру
gm.menuOpened = false;
CharacterController.ResetState();
gm.stateMachine.ChangeState(new StartRoundState(CellState.Player1));//из меню по любому первым ходит игрок
}
}
}
IEnumerator closeMenuAnimation()
{
animationEnded = false;
float parametr;
//Мув кнопок, надписей, монетника
parametr = 0;
while (parametr < 1)
{
parametr += Time.deltaTime*2;
label.localPosition = Vector3.Lerp(sLabel, eLabel, parametr);
buttonLeft.localPosition = Vector3.Lerp(new Vector3(-sButton.x, sButton.y,0), new Vector3(-eButton.x, eButton.y, 0), parametr);
buttonRight.localPosition = Vector3.Lerp(sButton, eButton, parametr);
label2.localPosition = Vector3.Lerp(sLabel2, eLabel2, parametr);
noPrizeLabel.localPosition = Vector3.Lerp(sNoPrize, eNoPrize+Vector2.left*3500, parametr);
coinPanel.localPosition = Vector3.Lerp(sCoin, eCoin, parametr);
SmallPrizesOut.sizeDelta = Vector2.Lerp(sSmallPrizesOutSize, eSmallPrizesOutSize, parametr);
yield return null;
}
buttonLeft.localPosition = -eButton;
buttonRight.localPosition = eButton;
//мув доски
parametr = 0;
while (parametr < 1)
{
parametr += Time.deltaTime * 2;
board.localPosition = Vector3.Lerp(sBoard, eBoard, parametr);
noPrizeLabel.localPosition = Vector3.Lerp(sNoPrize + Vector2.left * 3500, eNoPrize, parametr);
yield return null;
}
animationEnded = true;
}
IEnumerator openMenuAnimation()
{
Vector3 coinStart = coinPanel.localPosition;
animationEnded = false;
float parametr = 1;
while (parametr >= 0)
{
board.localPosition = Vector3.Lerp(sBoard, eBoard, parametr);
noPrizeLabel.localPosition = Vector3.Lerp(eNoPrize + Vector2.left * 3500, eNoPrize , parametr);
parametr -= Time.deltaTime * 2;
yield return null;
}
parametr = 1;
while (parametr >= 0)
{
parametr -= Time.deltaTime * 2;
label.localPosition = Vector3.Lerp(sLabel, eLabel, parametr);
//перемещение кнопок
buttonLeft.localPosition = Vector3.Lerp(
-sButton + Vector2.up *sButton.y*2, //к точке старта (Y инвертируем)
-eButton, //от спрятанной позиции
parametr);
buttonRight.localPosition = Vector3.Lerp(
sButton /*+ Vector2.up * 10f*/,
eButton ,
parametr);
noPrizeLabel.localPosition = Vector3.Lerp(sNoPrize, eNoPrize + Vector2.left * 3500, parametr);
//монетка
float startDistance = Vector3.Distance(coinPanel.position, sCoin);
while (Vector3.Distance(coinPanel.position, sCoin) > 0.01f)
{
float coinspeed = startDistance * Time.deltaTime * 2;
coinPanel.localPosition = Vector3.MoveTowards(coinPanel.localPosition, sCoin, coinspeed);
yield return null;
}
coinPanel.localPosition = sCoin;
label2.localPosition = Vector3.Lerp(sLabel2, eLabel2, parametr);
SmallPrizesOut.sizeDelta = Vector2.Lerp(sSmallPrizesOutSize, eSmallPrizesOutSize, parametr);
yield return null;
}
animationEnded = true;
gm.botScale.gameObject.SetActive(false);
gm.Player1Scale.gameObject.SetActive(false);
gm.Player2Scale.gameObject.SetActive(false);
}
}