|  | @ -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) | 
														
													
												
													
														
															
																|  | 
 |