extends CanvasLayer # (menu was quickily generated with Claude. a great placehold but adjust as needed) # The menu's process_mode is set to "Always" in the scene, so this script keeps # running while the rest of the game is paused. Without that, the menu would # freeze along with everything else and you could never unpause. @onready var mainPanel = $CenterContainer @onready var resumeButton = $CenterContainer/PanelContainer/VBoxContainer/ResumeButton @onready var optionsButton = $CenterContainer/PanelContainer/VBoxContainer/OptionsButton @onready var optionsMenu = $OptionsMenu func _ready() -> void: hide() func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("pause"): # From the options screen, Escape goes back a step instead of unpausing. if optionsMenu.visible: optionsMenu.close() elif visible: resume() else: pause() # Stop anything else from also reacting to this key press. get_viewport().set_input_as_handled() func pause() -> void: show() get_tree().paused = true # Give the first button keyboard focus so the menu works with arrow keys + Enter. resumeButton.grab_focus() func resume() -> void: hide() get_tree().paused = false func _on_resume_button_pressed() -> void: resume() func _on_options_button_pressed() -> void: mainPanel.hide() optionsMenu.open() func _on_options_menu_closed() -> void: mainPanel.show() optionsButton.grab_focus() func _on_return_to_menu_button_pressed() -> void: # Unpausing first matters: the paused state carries over to the new scene. get_tree().paused = false Transition.change_scene("res://UI/main_menu.tscn") func _on_exit_button_pressed() -> void: get_tree().quit()