Browse Source

Comments and formatting

pull/21/head
Ryan Reed 1 month ago
parent
commit
67a34d6611
4 changed files with 29 additions and 22 deletions
  1. +3
    -4
      scenes/ui/pause_menu/base_menu.gd
  2. +3
    -3
      scenes/ui/pause_menu/main_menu.gd
  3. +21
    -13
      scenes/ui/pause_menu/pause_menu.gd
  4. +2
    -2
      scenes/ui/pause_menu/saves_menu.gd

+ 3
- 4
scenes/ui/pause_menu/base_menu.gd View File

@ -20,12 +20,11 @@ func open_menu() -> void:
func reset_menu() -> void: func reset_menu() -> void:
animation_player.play("RESET") 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] ## Requires:[br]
## Track 1 - Must be for the content_container[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: func update_animation_tracks() -> void:
var hide_animation: Animation = animation_player.get_animation("hide") var hide_animation: Animation = animation_player.get_animation("hide")
var show_animation: Animation = animation_player.get_animation("show") var show_animation: Animation = animation_player.get_animation("show")


+ 3
- 3
scenes/ui/pause_menu/main_menu.gd View File

@ -9,8 +9,8 @@ func _on_exit_game_button_pressed() -> void:
func _on_resume_button_pressed() -> void: func _on_resume_button_pressed() -> void:
close_menu() close_menu()
func _on_settings_button_pressed() -> void:
pause_menu.open_menu.emit("SettingsMenu")
func _on_saves_button_pressed() -> void: func _on_saves_button_pressed() -> void:
pause_menu.open_menu.emit("SavesMenu") pause_menu.open_menu.emit("SavesMenu")
func _on_settings_button_pressed() -> void:
pause_menu.open_menu.emit("SettingsMenu")

+ 21
- 13
scenes/ui/pause_menu/pause_menu.gd View File

@ -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 class_name PauseMenu
extends Panel extends Panel
@ -24,19 +25,20 @@ func _ready() -> void:
menu.pause_menu = self menu.pause_menu = self
menu.init() menu.init()
SaveGameManager.load_save.connect(_on_load_save)
SaveGameManager.create_save.connect(_on_create_save) SaveGameManager.create_save.connect(_on_create_save)
SaveGameManager.load_save.connect(_on_load_save)
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and !visible: if event.is_action_pressed("ui_cancel") and !visible:
_open_pause_menu() _open_pause_menu()
elif event.is_action_pressed("ui_cancel") and visible and _active_menu == "MainMenu": elif event.is_action_pressed("ui_cancel") and visible and _active_menu == "MainMenu":
menu_mapping["MainMenu"].animation_player.play("hide") 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") 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: func _change_menu(menu_name: String) -> void:
visible = true visible = true
_next_menu = menu_name _next_menu = menu_name
@ -47,25 +49,31 @@ func _change_menu(menu_name: String) -> void:
func _close_pause_menu() -> void: func _close_pause_menu() -> void:
visible = false visible = false
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
_next_menu = "" _next_menu = ""
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
SignalManager.resume_game.emit() 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: func _open_pause_menu() -> void:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
SignalManager.pause_game.emit() SignalManager.pause_game.emit()
menu_mapping["MainMenu"].animation_player.play("show") 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: 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: func _on_change_menu(menu_name: String) -> void:
_change_menu(menu_name) _change_menu(menu_name)


+ 2
- 2
scenes/ui/pause_menu/saves_menu.gd View File

@ -17,10 +17,10 @@ signal open_save_list
func init() -> void: func init() -> void:
super.init() 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_button.pressed.connect(_on_create_save_button_pressed)
create_save_cancel_button.pressed.connect(_on_create_save_cancel_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) pause_menu.open_menu.connect(_on_open_menu)


Loading…
Cancel
Save