This repository has been archived on 2024-07-09. You can view files and clone it, but cannot push or open issues or pull requests.
everellia/SheKnowsWhatYouAreToHerGame/Assets/Scripts/MainMenu.cs

106 lines
3 KiB
C#

/*
* author: mark joshwel
* date: 29/5/2024
* description: main menu script for handling main menu button functions
*/
using UnityEngine;
using UnityEngine.UIElements;
/// <summary>
/// class managing the main menu and button function invocations
/// </summary>
public class MainMenu : CommonMenu
{
/// <summary>
/// button to show the credits menu
/// </summary>
public Button ButtonCredits;
/// <summary>
/// button to quit game
/// </summary>
public Button ButtonExit;
/// <summary>
/// button to show the options menu
/// </summary>
public Button ButtonOptions;
/// <summary>
/// button to play game
/// </summary>
public Button ButtonPlay;
/// <summary>
/// function to associate a display state with the menu,
/// and subscribe button events to their respective functions
/// </summary>
public override void OnEnable()
{
// set the associated state and call the base OnEnable
associatedState = GameManager.DisplayState.ScreenMainMenu;
base.OnEnable();
// get the start button from the ui root and subscribe appropriate functions
ButtonPlay = UI.Q<Button>("ButtonPlay");
ButtonPlay.clicked += PlayClick;
ButtonPlay.clicked += OptionStartGame;
// get the options button from the ui root and subscribe appropriate functions
ButtonOptions = UI.Q<Button>("ButtonOptions");
ButtonOptions.clicked += PlayClick;
ButtonOptions.clicked += OptionShowOptions;
// get the credits button from the ui root and subscribe appropriate functions
ButtonCredits = UI.Q<Button>("ButtonCredits");
ButtonCredits.clicked += PlayClick;
ButtonCredits.clicked += OptionShowCredits;
// get the quit button from the ui root and subscribe appropriate functions
ButtonExit = UI.Q<Button>("ButtonExit");
ButtonExit.clicked += PlayClick;
ButtonExit.clicked += OptionQuitGame;
}
/// <summary>
/// handles start button press,
/// signals the game manager appropriately
/// </summary>
private void OptionStartGame()
{
// start game
Game.NewGame();
}
/// <summary>
/// handles credits button press,
/// signals the game manager appropriately
/// </summary>
private void OptionShowCredits()
{
// show the credits menu
Game.SetDisplayState(GameManager.DisplayState.ScreenCreditsMenu);
}
/// <summary>
/// handles options button press,
/// signals the game manager appropriately
/// </summary>
private void OptionShowOptions()
{
// show the option menu
Game.SetDisplayState(GameManager.DisplayState.ScreenOptionsMenu);
}
/// <summary>
/// handles quit button press,
/// signals the game manager appropriately
/// </summary>
private void OptionQuitGame()
{
// quit game
Debug.Log("MainMenu.OptionQuitGame: exiting");
Game.Quit();
}
}