2026-10-18 01:51:15 -05:00
|
|
|
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.
|
|
|
|
|
|
2026-10-18 20:21:27 -05:00
|
|
|
@onready var mainPanel = $CenterContainer
|
2026-10-18 01:51:15 -05:00
|
|
|
@onready var resumeButton = $CenterContainer/PanelContainer/VBoxContainer/ResumeButton
|
2026-10-18 20:21:27 -05:00
|
|
|
@onready var optionsButton = $CenterContainer/PanelContainer/VBoxContainer/OptionsButton
|
|
|
|
|
@onready var optionsMenu = $OptionsMenu
|
2026-10-18 01:51:15 -05:00
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
hide()
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
|
if event.is_action_pressed("pause"):
|
2026-10-18 20:21:27 -05:00
|
|
|
# From the options screen, Escape goes back a step instead of unpausing.
|
|
|
|
|
if optionsMenu.visible: optionsMenu.close()
|
|
|
|
|
elif visible: resume()
|
2026-10-18 01:51:15 -05:00
|
|
|
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:
|
2026-10-18 20:21:27 -05:00
|
|
|
mainPanel.hide()
|
|
|
|
|
optionsMenu.open()
|
|
|
|
|
|
|
|
|
|
func _on_options_menu_closed() -> void:
|
|
|
|
|
mainPanel.show()
|
|
|
|
|
optionsButton.grab_focus()
|
2026-10-18 01:51:15 -05:00
|
|
|
|
|
|
|
|
func _on_return_to_menu_button_pressed() -> void:
|
|
|
|
|
# TODO: Once there's a main menu scene, unpause and switch to it, e.g.
|
|
|
|
|
# get_tree().paused = false
|
|
|
|
|
# get_tree().change_scene_to_file("res://UI/main_menu.tscn")
|
|
|
|
|
# Unpausing first matters: the paused state carries over to the new scene.
|
|
|
|
|
print("Main menu not made yet!")
|
|
|
|
|
|
|
|
|
|
func _on_exit_button_pressed() -> void:
|
|
|
|
|
get_tree().quit()
|