55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System.Net.Mime;
|
|
using Code.App.StateMachine;
|
|
using Code.Input;
|
|
using Code.Scenes;
|
|
using Code.StateMachine;
|
|
using Code.UI;
|
|
using UnityEngine;
|
|
|
|
namespace Code.App.AppStates
|
|
{
|
|
public class MainMenuState : BaseState<AppStateMachineContext>
|
|
{
|
|
public MainMenuState(AppStateMachineContext context) : base(context)
|
|
{ }
|
|
|
|
public override void EnterState()
|
|
{
|
|
Context.SceneLoaderService.LoadScene((int)SceneIds.MainMenu, SceneLoaded);
|
|
Context.InputService.EnableMap(ActionMappings.MainMenu);
|
|
|
|
Context.UIService.LoadingScreen.Show();
|
|
Context.UIService.SwitchPanelTo(UIPanel.MainMenu);
|
|
((MainMenuPanel)Context.UIService.CurrentPanel).startButton.onClick.AddListener(StartGame);
|
|
((MainMenuPanel)Context.UIService.CurrentPanel).exitButton.onClick.AddListener(ExitGame);
|
|
}
|
|
|
|
private void SceneLoaded()
|
|
{
|
|
Context.UIService.LoadingScreen.Hide();
|
|
|
|
base.EnterState();
|
|
}
|
|
public override void Tick()
|
|
{ }
|
|
|
|
private void StartGame()
|
|
{
|
|
Context.StateMachine.SwitchState(AppState.Gameplay)
|
|
.AllowStateTransition(AppState.MainMenu)
|
|
.AllowStateTransition(AppState.GameOver);
|
|
}
|
|
|
|
private void ExitGame()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
|
|
public override void ExitState()
|
|
{
|
|
Context.InputService.DisableMap(ActionMappings.MainMenu);
|
|
|
|
base.ExitState();
|
|
}
|
|
}
|
|
} |