Game menus are implemented using normal Godot scenes and GDScript code, outside of Escoria. Menus are placed on a specific canvas layer on top of the main scene, and they act as a top stack. The menu at the top of the stack receives all the input from the _input callback, but you need to make sure to block the UI so that mouse clicks and such can't go to the menus below the current one. When a menu is opened, the game is paused.
The current game configuration is only aware of 3 menus, the "Main Menu", the "In Game Menu" and the "Credits" menu.
The Main Menu is opened at the start of the game, from the script globals/scene_main.gd. It's also opened during the main game, when the user presses the Escape key (or any other key bound to the "menu_request" input action), when the game is outside of a cutscene (i.e. when no Esc script running).
The In Game Menu is opened when the user requests the menu while a cutscene is running during the game. Keep in mind that while cutscenes are running, you can't save the game, so your in-game menu works as a pause menu, but it can't provide the full functionality of a main menu. Alternatively you could simply not open any menu while a cutscene is in progress.
The Credits Menu is opened after issuing a "game_over" command from your Esc scripts (if the parameter for credits is supplied).
The path to each menu scene is configured in the Project Settings > Ui of your game, also found in the file "engine.cfg", in the "ui" section:
[ui] main_menu="res://ui/main_menu.tscn" in_game_menu="" credits="" savegames=""
It's a good idea to provide paths for other menus of your game here, because they can be customized for specific platforms. From gdscript, use Globals to access the configuration values:
Globals.get("ui/main_menu")
Menus have no predefined structure or functionality, but in order to work inside the stack system, they have certain API requirements.
To add your menu to the stack, call the "menu_open" parameter on the "/root/main" node:
get_node("/root/main").menu_open(self)
Similarly, to remove your menu, call menu_close:
get_node("/root/main").menu_close(self)
Your node is in charge of deleting itself and removing itself from the tree, etc. Generally this is done by calling queue_free().
The Buttons and other Controls on your menu will receive input from the mouse normally, but other types or input (like joystick events) are sent via the main scene. You menu needs to implement a method called "input" to receive them:
func input(event): if event.is_action("menu_request") && event.is_pressed() && !event.is_echo(): close()
Your menu is in charge of handling the "menu_request" event, usually bound to the Escape key, to close the current menu.
Some events might cause the entire menu stack to close, so the user can go back to the game. This usually happens when a new game is started. When this happens, your menu will receive a call to the method "menu_collapsed":
func menu_collapsed(): close()
When the language of the game is changed, you can get a notification on your menu to handle it. Remember your menu is on a stack, so the language could be changed by some menu on top of yours. To get the notification, add your menu to the "ui" group, and implement a "language_changed" method:
func _ready(): add_to_group("ui") func language_changed(): # do whatever here pass
If you make a Settings menu, there is a settings structure in the node found in /root/vm with the following parameters:
varsettings_default = { "text_lang": "en", "voice_lang": "en", "music_volume": 1, "sfx_volume": 1, "voice_volume": 1, "fullscreen": false, "skip_dialog": true, }
You can change these values directly on the node, but some will need an extra call to apply the settings. When changing the text language, also change the current locale in the TranslationServer singleton, and notify the "ui" group that the language has changed:
TranslationServer.set_locale(vm.settings.text_lang) get_tree().call_group(0, "ui", "language_changed")
When changing the sound effects volume, also change it in the AudioServer singleton:
AudioServer.set_fx_global_volume_scale(val)
When changing the music volume, also notify the vm node:
vm.settings.music_volume = vol vm.music_volume_changed()
The "skip_dialog" flags is used to toggle the skip dialog functionality. When true, while showing a speech text, the text will disappear when the speech sound file is done playing (if any). If false, it will wait for the user to click the screen to continue.
When changing the fullscreen mode, also notify the vm node:
vm.settings.fullscreen = p_fs vm.update_window_fullscreen()
When you're finished changing the settings, use the "save_settings" method to save them to disk:
vm.save_settings()
Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.
Vous devriez rafraîchir la page.