139 lines
3.5 KiB
C#
139 lines
3.5 KiB
C#
public class MenuState : IState
|
|
{
|
|
private GameManager gm;
|
|
private UiManager ui;
|
|
private HoldTimer promoTimer;
|
|
private HoldTimer settingsTimer;
|
|
private MenuSubStates subState;
|
|
|
|
public void enter()
|
|
{
|
|
gm = GameManager.instance;
|
|
gm.ResetGameSession();
|
|
|
|
ui = gm.menuUi;
|
|
ui.OpenMenu();
|
|
subState = MenuSubStates.InputPolling;
|
|
|
|
promoTimer = new(180f);
|
|
settingsTimer = new(3f);
|
|
|
|
LightUtility.Idle();
|
|
}
|
|
|
|
public void exit()
|
|
{
|
|
promoTimer.Reset();
|
|
settingsTimer.Reset();
|
|
}
|
|
|
|
public void update()
|
|
{
|
|
if (subState == MenuSubStates.InputPolling)
|
|
InputPolling();
|
|
else if (subState == MenuSubStates.WaitAnimation)
|
|
WaitAnimation();
|
|
}
|
|
|
|
private void InputPolling()//основное состояние(выбор)
|
|
{
|
|
if (ui.AnimationInProcess) return;
|
|
|
|
if (HandleSettings()) return;
|
|
if (HandleGameStart()) return;
|
|
if (HandleRules()) return;
|
|
if (HandleLeaderboard()) return;
|
|
if (HandlePromo()) return;
|
|
}
|
|
|
|
private bool HandleSettings()
|
|
{
|
|
bool settingButtonPressed = In.GetButton(ButtonPinMapping.secret);
|
|
bool gotoSettings = UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.F5) || settingsTimer.Update(settingButtonPressed);
|
|
if (gotoSettings)
|
|
{
|
|
TransitionTo(new CheckSettingsPasswordState());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool HandleGameStart() => TrySelectGameMode(out var mode) && TryStartGame(mode);
|
|
|
|
private bool HandleRules()
|
|
{
|
|
if (In.GetButtonDownAnyPlayer(PlayerAction.down))
|
|
{
|
|
TransitionTo(new RulesState());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool HandleLeaderboard()
|
|
{
|
|
bool gotoLeaderboard = In.GetButtonDownAnyPlayer(PlayerAction.left) && In.GetButtonDownAnyPlayer(PlayerAction.right);
|
|
if (gotoLeaderboard)
|
|
{
|
|
TransitionTo(new CheckLeadersFromMenuState());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool HandlePromo()
|
|
{
|
|
if (promoTimer.Update(!In.AnyButton()))
|
|
{
|
|
TransitionTo(new PromoState(), playSound: false);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool TrySelectGameMode(out GameMode mode)
|
|
{
|
|
mode = GameMode.pve;
|
|
|
|
if (In.GetButtonDown(ButtonPinMapping.startOnePlayer))
|
|
mode = GameMode.pve;
|
|
else if (In.GetButtonDown(ButtonPinMapping.startTwoPlayers))
|
|
mode = GameMode.pvp;
|
|
else
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
private bool TryStartGame(GameMode mode)
|
|
{
|
|
if (!PaymentSystem.TryPayForMode(mode)) return false;
|
|
|
|
gm.SetMode(mode);
|
|
gm.timerManager.SetTimersActivity(gm.gameMode);
|
|
ui.CloseMenu();
|
|
gm.InitVictoryScales();
|
|
|
|
subState = MenuSubStates.WaitAnimation;
|
|
return true;
|
|
}
|
|
|
|
private void WaitAnimation()
|
|
{
|
|
if (ui.AnimationInProcess) return;
|
|
|
|
CharacterController.ResetState();
|
|
TransitionTo(new StartRoundState(CellState.Player1));
|
|
|
|
if (gm.gameMode == GameMode.pve)
|
|
gm.movesAndTimeCounter.SetVisibility(true);
|
|
}
|
|
|
|
private void TransitionTo(IState state, bool playSound = true)
|
|
{
|
|
if (playSound) SoundManager.instance.playChoose();
|
|
gm.stateMachine.ChangeState(state);
|
|
}
|
|
|
|
private enum MenuSubStates { InputPolling, WaitAnimation }
|
|
} |