From 67a34d6611a5f46477ae53b8a3dd5fd6ff9101ae Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sun, 30 Mar 2025 08:54:30 -0400 Subject: [PATCH] Comments and formatting --- scenes/ui/pause_menu/base_menu.gd | 7 +++--- scenes/ui/pause_menu/main_menu.gd | 6 +++--- scenes/ui/pause_menu/pause_menu.gd | 34 ++++++++++++++++++------------ scenes/ui/pause_menu/saves_menu.gd | 4 ++-- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/scenes/ui/pause_menu/base_menu.gd b/scenes/ui/pause_menu/base_menu.gd index c8d8494..4a8178f 100644 --- a/scenes/ui/pause_menu/base_menu.gd +++ b/scenes/ui/pause_menu/base_menu.gd @@ -20,12 +20,11 @@ func open_menu() -> void: func reset_menu() -> void: animation_player.play("RESET") -## Update the animation tracks to account for the size of the different container sizes[br] -## Only the x position is modified.[br][br] +## Update the animation tracks to account for the varying sizes of the menu container[br] ## Requires:[br] ## Track 1 - Must be for the content_container[br] -## First Property - Must be position[br] -## Keys - Must only have 2 keys, the start and end position keys +## First Property - Must be position[br] +## Second Property - Visibility func update_animation_tracks() -> void: var hide_animation: Animation = animation_player.get_animation("hide") var show_animation: Animation = animation_player.get_animation("show") diff --git a/scenes/ui/pause_menu/main_menu.gd b/scenes/ui/pause_menu/main_menu.gd index 2ca069e..bc2574f 100644 --- a/scenes/ui/pause_menu/main_menu.gd +++ b/scenes/ui/pause_menu/main_menu.gd @@ -9,8 +9,8 @@ func _on_exit_game_button_pressed() -> void: func _on_resume_button_pressed() -> void: close_menu() -func _on_settings_button_pressed() -> void: - pause_menu.open_menu.emit("SettingsMenu") - func _on_saves_button_pressed() -> void: pause_menu.open_menu.emit("SavesMenu") + +func _on_settings_button_pressed() -> void: + pause_menu.open_menu.emit("SettingsMenu") diff --git a/scenes/ui/pause_menu/pause_menu.gd b/scenes/ui/pause_menu/pause_menu.gd index c9b49db..f3dfc21 100644 --- a/scenes/ui/pause_menu/pause_menu.gd +++ b/scenes/ui/pause_menu/pause_menu.gd @@ -1,4 +1,5 @@ -## Handle changing of pause menus +## Handle changing changing menus and running the show/hide animations for each menu. +## Each menu should extend BaseMenu class_name PauseMenu extends Panel @@ -24,19 +25,20 @@ func _ready() -> void: menu.pause_menu = self menu.init() - SaveGameManager.load_save.connect(_on_load_save) SaveGameManager.create_save.connect(_on_create_save) + SaveGameManager.load_save.connect(_on_load_save) func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("ui_cancel") and !visible: _open_pause_menu() elif event.is_action_pressed("ui_cancel") and visible and _active_menu == "MainMenu": menu_mapping["MainMenu"].animation_player.play("hide") - elif event.is_action_pressed("ui_cancel"): + elif event.is_action_pressed("ui_cancel"): ## Always back out to the MainMenu - Future, maybe add _previous_menu to allow backing out to any menu open_menu.emit("MainMenu") -## The animation to show the next menu will take place in _on_animation_finished() +## Start the `hide` animation for the current menu. +## The `show` animation will play after the `hide` has completed, from `_on_animation_finished()`. func _change_menu(menu_name: String) -> void: visible = true _next_menu = menu_name @@ -47,25 +49,31 @@ func _change_menu(menu_name: String) -> void: func _close_pause_menu() -> void: visible = false - Input.mouse_mode = Input.MOUSE_MODE_CAPTURED _next_menu = "" + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED SignalManager.resume_game.emit() +## Run the `show` animation for the next menu +## If there is no next menu, close the pause menu +func _handle_next_menu() -> void: + if _next_menu == "": + _active_menu = "MainMenu" + _close_pause_menu() + else: + _active_menu = _next_menu + _next_menu = "" + menu_mapping[_active_menu].animation_player.play("show") + func _open_pause_menu() -> void: Input.mouse_mode = Input.MOUSE_MODE_VISIBLE SignalManager.pause_game.emit() menu_mapping["MainMenu"].animation_player.play("show") -## When the hide animation finished, we can move on to opening the next menu +## When the hide animation finished, start show `show` animation for the next menu func _on_animation_finished(animation_name: String) -> void: - if animation_name == "hide" and _next_menu == "": - _active_menu = "MainMenu" - _close_pause_menu() - elif animation_name == "hide": - _active_menu = _next_menu - _next_menu = "" - menu_mapping[_active_menu].animation_player.play("show") + if animation_name == "hide": + _handle_next_menu() func _on_change_menu(menu_name: String) -> void: _change_menu(menu_name) diff --git a/scenes/ui/pause_menu/saves_menu.gd b/scenes/ui/pause_menu/saves_menu.gd index d1bb7f2..9a7ae9e 100644 --- a/scenes/ui/pause_menu/saves_menu.gd +++ b/scenes/ui/pause_menu/saves_menu.gd @@ -17,10 +17,10 @@ signal open_save_list func init() -> void: super.init() - show_save_ui_button.pressed.connect(_on_show_save_ui_button_pressed) + create_save_button.pressed.connect(_on_create_save_button_pressed) create_save_cancel_button.pressed.connect(_on_create_save_cancel_button_pressed) - + show_save_ui_button.pressed.connect(_on_show_save_ui_button_pressed) pause_menu.open_menu.connect(_on_open_menu)