2024-08-11 07:20:58 +08:00
|
|
|
/*
|
|
|
|
* author: mark joshwel
|
|
|
|
* date: 11/8/2024
|
|
|
|
* description: 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 ScreenMainMenu : CommonMenu
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// button to quit game
|
|
|
|
/// </summary>
|
2024-08-11 15:51:21 +08:00
|
|
|
private Button _buttonExit;
|
2024-08-11 07:20:58 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// button to show the options menu
|
|
|
|
/// </summary>
|
2024-08-11 15:51:21 +08:00
|
|
|
private Button _buttonOptions;
|
2024-08-11 07:20:58 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// button to play game
|
|
|
|
/// </summary>
|
2024-08-11 15:51:21 +08:00
|
|
|
private Button _buttonPlay;
|
2024-08-11 07:20:58 +08:00
|
|
|
|
|
|
|
/// <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
|
2024-08-11 15:51:21 +08:00
|
|
|
_buttonPlay = UI.Q<Button>("ButtonPlay");
|
|
|
|
_buttonPlay.clicked += PlayClick;
|
|
|
|
_buttonPlay.clicked += OptionStartGame;
|
2024-08-11 07:20:58 +08:00
|
|
|
|
|
|
|
// get the options button from the ui root and subscribe appropriate functions
|
2024-08-11 15:51:21 +08:00
|
|
|
_buttonOptions = UI.Q<Button>("ButtonOptions");
|
|
|
|
_buttonOptions.clicked += PlayClick;
|
|
|
|
_buttonOptions.clicked += OptionShowOptions;
|
2024-08-11 07:20:58 +08:00
|
|
|
|
|
|
|
// get the quit button from the ui root and subscribe appropriate functions
|
2024-08-11 15:51:21 +08:00
|
|
|
_buttonExit = UI.Q<Button>("ButtonExit");
|
|
|
|
_buttonExit.clicked += PlayClick;
|
|
|
|
_buttonExit.clicked += OptionQuitGame;
|
2024-08-11 07:20:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// handles start button press,
|
|
|
|
/// signals the game manager appropriately
|
|
|
|
/// </summary>
|
|
|
|
private void OptionStartGame()
|
|
|
|
{
|
2024-08-11 13:05:00 +08:00
|
|
|
Debug.Log("ScreenMainMenu.OptionStartGame: clicked, starting game");
|
2024-08-11 07:20:58 +08:00
|
|
|
Game.NewGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// handles options button press,
|
|
|
|
/// signals the game manager appropriately
|
|
|
|
/// </summary>
|
|
|
|
private void OptionShowOptions()
|
|
|
|
{
|
2024-08-11 13:05:00 +08:00
|
|
|
Debug.Log("ScreenMainMenu.OptionShowOptions: clicked, showing options menu");
|
2024-08-11 07:20:58 +08:00
|
|
|
Game.SetDisplayState(GameManager.DisplayState.ScreenOptionsMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// handles quit button press,
|
|
|
|
/// signals the game manager appropriately
|
|
|
|
/// </summary>
|
|
|
|
private void OptionQuitGame()
|
|
|
|
{
|
2024-08-11 13:05:00 +08:00
|
|
|
Debug.Log("ScreenMainMenu.OptionQuitGame: clicked, quitting game");
|
2024-08-11 07:20:58 +08:00
|
|
|
Game.Quit();
|
|
|
|
}
|
|
|
|
}
|