16. INTERACTIVE MENUS
interactive dialogs, standard menus




More about dialogs

You have started these practical chapters, with one about displaying messages. As you have seen, these messages are simple bordered dialog boxes. Their single interaction is to wait for the player to press the action key, so they can return from their latent loop and be closed.

Now, we'll look into more interactive dialogs, like the main menu, game menu, or inventory menu. They are also dialogs. In fact, they are not much different from the simple message dialogs. What makes them special is the latent loop that does a little more than just waiting for the action key.

Their latent loop also tests for arrow keys, managing a selection index that represents the option selected by the player. So, when the player presses the up key, the selection index is decremented, and when he presses the down key, it is incremented. Of course the selection index is limited by the number of options specific for the menu in cause.

The dialog content is refreshed when this selection changes, to reflect the focused option, that is usually painted in a different or flashing color.

Start from the default template data and add the following functions in the game.gs file. Then call the OpenMyMenu function at the end of the BeginNewGame callback, instead of the "Hello World!" message.

See how the menu is opened when you start the game, allowing you to choose one of the presented options. Then, the option is displayed in a simple message dialog.



The text set for dialogs supports a few special commands.
They are interpreted by the HudDrawText function when displaying the text.
Example:
{a:l}, {a:c}, {a:r} to change the align mode to left, center or right
{c:ff0080} to change the text color
{f:0}, {f:1} to set the flashing color off or on
{t:10 16 18} to draw a tile with the id=10 at the 16,18 coordinates in the text area.



Standard menus

In the DizzyAGE games, there are a few standard menus. Of course, users can change them, or add more. They are implemented in the same way as presented above using the RunDialogSelect function for the menu loop. This funcion receives the id of the function that is supposed to create the dialog and it returns the selected option.
Main Menu
This is the menu opened when the game application starts. It allows the player to begin a new game or to load a previous saved one, to adjust game's options, see the credits and exit the application. The main menu is opened from the GameStartLoad function, that is requested by the HandlerGameStart handler. It is implemented in the OpenDialogMainMenu function, from the menus.gs file.

Game Menu
This is the menu opened during the gameplay, when the player presses the menu key. It allows him to save or load the game, to adjust game's options and to quit or resume the game. The game menu is requested by the HandlerMenu handler. It is implemented in the OpenDialogGameMenu function, from the menus.gs file.

Inventory Menu
This is the menu opened when the player wants to choose an item from his inventory, like when pressing the action key. It shows the owned items, let the player select one and it returns the object index of the selected item, or -1 if no item was selected. The inventory menu is usually requested through the HandlerAction handler, but it can also be opened from a callback, as a result of a puzzle, or a collision, etc. It is implemented in the OpenDialogInventory function, from the menus.gs file.

Finish Menu
The finish menu can be opened by the user from a callback function, when the game is over, as a result of solving the last puzzle. It allows the player to restart or exit the game and to visit the author's or the official DizzyAGE website, by opening it's address in the default internet browser. It is implemented in the OpenDialogFinish function, from the menus.gs file.


There are also other menus, like the save or open game menu, or like the credits menu. These are called as the result of selecting their options, in the menus noted above. Users should adjust the OpenDialogCredits menu, according to their needs.


Homework

Change the content of the credits menu and try to make it available in the game menu too. You will have to edit both the OpenDialogGameMenu and the DialogGameMenu functions.

To learn more about dialogs and menus see the reference chapters:
Default Template menus functions
Engine exported dialog functions