Pause Menu Display - UQcsse3200/2024-studio-3 GitHub Wiki
Introduction
This documentation describes the structure and functionality of the PauseMenuDisplay and PauseMenuActions classes. These two classes work together to manage the game's pause menu interface and handle the associated button actions such as resuming, restarting, accessing settings, and quitting the game. The pause menu is triggered when the player presses the "ESC" key, which pauses the game and brings up the menu.
Purpose
- PauseMenuDisplay: Displays the pause menu, allowing the player to interact with the game by using the buttons provided.
- PauseMenuActions: Handles the actions triggered by the buttons on the pause menu (e.g., resume, restart, quit).
Description
PauseMenuDisplay
Components of The PauseMenuDisplay class consists of several key components for rendering the pause menu:
- isVisible: Tracks whether the pause menu is currently visible.
- game: A reference to the
MainGameScreen
to control pausing and resuming of the game. - table: A Table object used for organising UI components.
- logger: Logs interactions with the pause menu.
- Textures: Background and koala images used in the pause menu, loaded from assets.
Visual Elements
createKoalaImage()
&createKoalaImage2()
: These methods create koala images that appear on the pause menu.createPauseMenuBackground()
: This method creates the background image for the pause menu.createButtonsTable()
: This method creates a table with buttons that trigger various actions like resuming, restarting, accessing settings, and quitting the game.toggleVisibility()
: This method is to stack all the images into the background of the pause manu display.
Input Handling
displayScreen()
: This method listens for a specific key input (the "ESC" key) to toggle the visibility of the pause menu. When "ESC" is pressed, the pause menu appears, pausing the game. Pressing "ESC" again hides the menu and resumes the game. toggleVisibility(): Manages the visibility of the pause menu and pauses/resumes the game accordingly.
PauseMenuActions
Components of The PauseMenuActions class is responsible for listening to events triggered by the buttons on the pause menu. These events trigger actions like restarting the game, accessing settings, or quitting.
Key Components
- game: A reference to the
GdxGame
instance, allowing for screen changes and game control. - logger: Logs button clicks and events for debugging.
Event Listeners
The PauseMenuActions
class listens for specific events, each tied to a button on the pause menu:
onRestart()
: Triggered when the "Restart" button is clicked. It restarts the game by setting the game screen to MAIN_GAME.onExit()
: Triggered when the "Exit to Main Menu" button is clicked. It returns the player to the MAIN_MENU screen.onQuit()
: Triggered when the "Quit" button is clicked. It exits the game entirely.
Pause Menu Button Actions
Each button in the pause menu triggers a specific action:
- Resume: Closes the pause menu and resumes gameplay.
- Restart: Restarts the game (onRestart()).
- Main Menu: Exits to the main menu (onExit()).
- Quit: Quits the game (onQuit()).
- Save/Load: Save and Load
PauseMenuDisplay
and PauseMenuActions
Integration Between - PauseMenuDisplay: Renders the pause menu and sets up buttons for interacting with the game.
- PauseMenuActions: Listens for button events and handles screen transitions and game actions. The two classes work together to provide both the visual interface and the event-driven logic for user interactions in the pause menu.
UML DIAGRAM
Summary
The PauseMenuDisplay and PauseMenuActions classes work together to manage the visual and functional aspects of the pause menu. While PauseMenuDisplay handles rendering and layout, PauseMenuActions is responsible for reacting to user interactions and triggering corresponding actions in the game. These two components ensure that the pause menu is interactive, responsive, and integrated seamlessly into the gameplay. The menu can be triggered by pressing the "ESC" key, pausing the game and bringing up the menu for the player to interact with.