Menu System - EasterEggProductions/adventure-mode-godot GitHub Wiki

The menu system uses the Control node system to create a sequence of menu panels. The system automatically fades between the menus, or plays their animations for opening or closing. It can also specify a back button that can close the game, and a button to apply focus to, allowing use by controllers.

Table of Contents

Basic Functionality

Menus are created as a linear hierarchy. One menu has the function "open_submenu(submenu : PackedScene)" that opens a new menu. The PackedScene needs to be a control type that extends menu. When this function is called, the transition animations play, and the parent menu pauses and hides itself. The new submenu is not actually a child to the previous menu, but rather a sibling. See the image for this relationship. In the menus, the properties "parent_menu" and "child_menu" are the actual menu relationship and not the scene tree one.

In this way, a sequence of menus may be created, and also allow for certain menus to be easily reused, for example an options menu, or a shop menu.

The Menu class can be extended by other control nodes. This was done with Game_HUD_Master.gd, which operates the main player display during play. As it extends menu, new menus can be given to it, which naturally hides this menu for things like the start menu or the rest menu.

Buttons

Two variables are exported for buttons; close_button and focus_button.

close_button specifies a button that goes back to the previous menu. This button automatically changes it's name to 'quit' if it is present on the root menu, and does close the game. Otherwise it simply closes the current menu and returns to the previous one.

focus_button simply sets focus when the menu opens, making this button a default starting position and allowing navigation with the arrow keys or joysticks.

Animations

By default, a tweener is used to both close and open a menu. However if the "anim" of the menu is set, it will instead play the "open" and "close" animations of that animator, and wait for them to finish before moving on to the other menu.

Currently there is no provision to easily animate the opening or closing of the menus programmatically. For example having each dynamically created button slide in or out. Though the system could probably be extended to allow for that.

Utilities and Tools

menu_goto.gd can be placed on a button so that when the button is pressed, it will open it's referenced packed scene as the next menu in the sequence. It needs a reference to the parent menu it is a part of to be able to do this properly, but otherwise connects the appropriate signals automatically.

⚠️ **GitHub.com Fallback** ⚠️