2024-10-18 16:04:50 +00:00
|
|
|
class_name MainMenu extends Panel
|
2024-10-01 23:32:59 +00:00
|
|
|
|
|
|
|
|
@onready var new_game_button: Button = $PanelContainer/NewGameButton
|
|
|
|
|
@onready var continue_button: Button = $PanelContainer/ContinueGameButton
|
|
|
|
|
@onready var load_game_button: Button = $PanelContainer/LoadGameButton
|
2025-10-07 22:33:15 +00:00
|
|
|
@onready var settings_button: Button = $PanelContainer/SettingsButton
|
2024-10-07 09:21:36 +00:00
|
|
|
@onready var settings_popup: SettingsPopup = %SettingsPopup
|
|
|
|
|
@onready var credits_button: Button = $PanelContainer/CreditsButton
|
2024-10-01 23:32:59 +00:00
|
|
|
@onready var quit_button: Button = $PanelContainer/QuitButton
|
2025-12-12 15:35:07 +00:00
|
|
|
@onready var save_game_handle: SaveGameList = %SaveGameList
|
2024-10-06 09:40:42 +00:00
|
|
|
|
2025-12-12 16:18:04 +00:00
|
|
|
# Internal Signals
|
|
|
|
|
signal _user_choice(result: String)
|
|
|
|
|
|
|
|
|
|
func execute() -> String:
|
|
|
|
|
print("main_menu.gd: execute()")
|
|
|
|
|
assert(is_node_ready(), "MainMenu node not ready yet! (???)")
|
|
|
|
|
|
|
|
|
|
if State.active_save_game == null or State.active_save_game.current_room == 0:
|
|
|
|
|
continue_button.visible = false
|
|
|
|
|
continue_button.disabled = true
|
|
|
|
|
new_game_button.theme_type_variation = "H1Button"
|
|
|
|
|
else:
|
|
|
|
|
continue_button.visible = true
|
|
|
|
|
continue_button.disabled = false
|
|
|
|
|
new_game_button.theme_type_variation = ""
|
|
|
|
|
|
|
|
|
|
load_game_button.disabled = not save_game_handle.has_existing_saves()
|
|
|
|
|
|
|
|
|
|
save_game_handle.visible = save_game_handle.has_existing_saves()
|
|
|
|
|
|
|
|
|
|
if continue_button.visible:
|
|
|
|
|
continue_button.grab_focus()
|
|
|
|
|
else:
|
|
|
|
|
new_game_button.grab_focus()
|
|
|
|
|
|
|
|
|
|
_activate()
|
|
|
|
|
var result = await _user_choice
|
|
|
|
|
_deactivate()
|
|
|
|
|
|
|
|
|
|
return str(result)
|
2024-10-06 09:40:42 +00:00
|
|
|
|
2024-10-01 23:32:59 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2025-12-12 15:33:06 +00:00
|
|
|
print("main_menu.gd: ready()")
|
2025-12-12 16:18:04 +00:00
|
|
|
_deactivate()
|
|
|
|
|
|
|
|
|
|
continue_button.pressed.connect(_choose.bind("continue"))
|
2025-12-12 18:19:37 +00:00
|
|
|
new_game_button.pressed.connect(_start_new_game)
|
|
|
|
|
load_game_button.pressed.connect(_load_save_game)
|
2025-03-25 21:34:13 +00:00
|
|
|
load_game_button.disabled = not save_game_handle.has_existing_saves()
|
2025-10-07 22:33:15 +00:00
|
|
|
settings_button.pressed.connect(settings_popup.show_settings)
|
2025-12-12 16:18:04 +00:00
|
|
|
credits_button.pressed.connect(_choose.bind("credits"))
|
2024-10-07 09:21:36 +00:00
|
|
|
quit_button.pressed.connect(get_tree().quit)
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2025-12-12 18:19:37 +00:00
|
|
|
func _start_new_game() -> void:
|
|
|
|
|
print("main_menu.gd: start_new_game()")
|
|
|
|
|
State.active_save_game = SaveGame.new()
|
|
|
|
|
_user_choice.emit("start_game")
|
|
|
|
|
|
|
|
|
|
func _load_save_game() -> void:
|
|
|
|
|
print("main_menu.gd: _load_save_game()")
|
|
|
|
|
var save: SaveGame = await save_game_handle.pick_save_slot()
|
|
|
|
|
_on_save_picked(save)
|
|
|
|
|
|
2025-12-12 16:18:04 +00:00
|
|
|
func _choose(choice: String) -> void:
|
|
|
|
|
print("main_menu.gd: _choose(", choice, ")")
|
|
|
|
|
_user_choice.emit(choice)
|
|
|
|
|
|
|
|
|
|
func _activate() -> void:
|
|
|
|
|
save_game_handle.visible = false
|
|
|
|
|
|
|
|
|
|
for child: Control in $PanelContainer.get_children():
|
|
|
|
|
child.focus_mode = Control.FOCUS_ALL
|
|
|
|
|
child.modulate = Color.WHITE
|
|
|
|
|
child.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
|
|
|
|
|
|
|
|
func _deactivate() -> void:
|
|
|
|
|
save_game_handle.visible = false
|
|
|
|
|
|
|
|
|
|
for child: Control in $PanelContainer.get_children():
|
|
|
|
|
child.focus_mode = FOCUS_NONE
|
|
|
|
|
child.modulate = Color.WEB_GRAY
|
|
|
|
|
child.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
2024-10-01 23:32:59 +00:00
|
|
|
|
2024-10-06 09:40:42 +00:00
|
|
|
func _on_save_picked(save: SaveGame):
|
2025-12-12 16:18:04 +00:00
|
|
|
print("main_menu.gd: _on_save_picked(", save, ")")
|
2025-12-12 18:19:37 +00:00
|
|
|
if (save != null):
|
|
|
|
|
State.active_save_game = save
|
|
|
|
|
_user_choice.emit("start_game")
|