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-15 16:57:26 +00:00
|
|
|
@onready var save_game_list: SaveGameList = %SaveGameList
|
2024-10-06 09:40:42 +00:00
|
|
|
|
2025-12-19 19:39:56 +00:00
|
|
|
signal success
|
2025-12-12 16:18:04 +00:00
|
|
|
|
2025-12-19 19:39:56 +00:00
|
|
|
func execute() -> void:
|
2025-12-13 10:06:15 +00:00
|
|
|
print_debug("main_menu.gd: execute()")
|
2025-12-19 19:39:56 +00:00
|
|
|
modulate.a = 0
|
2025-12-12 16:18:04 +00:00
|
|
|
assert(is_node_ready(), "MainMenu node not ready yet! (???)")
|
2025-12-19 19:39:56 +00:00
|
|
|
|
2025-12-12 23:22:21 +00:00
|
|
|
if State.save_game == null or State.save_game.current_room == 0:
|
2025-12-12 16:18:04 +00:00
|
|
|
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 = ""
|
|
|
|
|
|
|
|
|
|
_activate()
|
2025-12-19 19:39:56 +00:00
|
|
|
await _appear()
|
|
|
|
|
await success
|
|
|
|
|
await _vanish()
|
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-13 10:06:15 +00:00
|
|
|
print_debug("main_menu.gd: ready()")
|
2025-12-12 16:18:04 +00:00
|
|
|
_deactivate()
|
|
|
|
|
|
2025-12-12 23:22:21 +00:00
|
|
|
continue_button.pressed.connect(_start_game)
|
|
|
|
|
new_game_button.pressed.connect(_new_game)
|
2025-12-12 18:19:37 +00:00
|
|
|
load_game_button.pressed.connect(_load_save_game)
|
2025-10-07 22:33:15 +00:00
|
|
|
settings_button.pressed.connect(settings_popup.show_settings)
|
2025-12-19 19:39:56 +00:00
|
|
|
#credits_button.pressed.connect(_choose.bind("credits")) #FIXME: Needs some other encoding, like path
|
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 23:22:21 +00:00
|
|
|
func _new_game() -> void:
|
2025-12-13 10:06:15 +00:00
|
|
|
print_debug("main_menu.gd: start_new_game()")
|
2025-12-12 23:22:21 +00:00
|
|
|
State.save_game = SaveGame.new()
|
|
|
|
|
_start_game()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _start_game() -> void:
|
2025-12-13 10:06:15 +00:00
|
|
|
print_debug("main_menu.gd: _start_game()")
|
2025-12-19 19:39:56 +00:00
|
|
|
_deactivate()
|
|
|
|
|
success.emit()
|
|
|
|
|
await Main.start_game(State.save_game)
|
|
|
|
|
|
2025-12-12 18:19:37 +00:00
|
|
|
|
2025-12-13 10:06:15 +00:00
|
|
|
|
2025-12-12 18:19:37 +00:00
|
|
|
func _load_save_game() -> void:
|
2025-12-13 10:06:15 +00:00
|
|
|
print_debug("main_menu.gd: _load_save_game()")
|
2025-12-15 16:57:26 +00:00
|
|
|
var save: SaveGame = await save_game_list.pick_save_slot()
|
|
|
|
|
if (save != null):
|
|
|
|
|
State.save_game = save
|
2025-12-19 19:39:56 +00:00
|
|
|
_start_game()
|
|
|
|
|
_deactivate()
|
|
|
|
|
else:
|
|
|
|
|
_activate()
|
2025-12-12 16:18:04 +00:00
|
|
|
|
2025-12-13 10:06:15 +00:00
|
|
|
|
2025-12-12 16:18:04 +00:00
|
|
|
func _activate() -> void:
|
2025-12-15 16:57:26 +00:00
|
|
|
load_game_button.disabled = not save_game_list.has_more_saves()
|
|
|
|
|
continue_button.disabled = (State.save_game == null or State.save_game.is_empty)
|
|
|
|
|
|
|
|
|
|
load_game_button.disabled = not save_game_list.has_more_saves()
|
2025-12-13 23:53:48 +00:00
|
|
|
|
2025-12-12 16:18:04 +00:00
|
|
|
for child: Control in $PanelContainer.get_children():
|
|
|
|
|
child.focus_mode = Control.FOCUS_ALL
|
|
|
|
|
child.modulate = Color.WHITE
|
2025-12-13 19:11:51 +00:00
|
|
|
|
2025-12-13 10:06:15 +00:00
|
|
|
if continue_button.visible:
|
|
|
|
|
continue_button.grab_focus()
|
|
|
|
|
else:
|
|
|
|
|
new_game_button.grab_focus()
|
|
|
|
|
|
2025-12-12 16:18:04 +00:00
|
|
|
|
|
|
|
|
func _deactivate() -> void:
|
|
|
|
|
for child: Control in $PanelContainer.get_children():
|
|
|
|
|
child.focus_mode = FOCUS_NONE
|
|
|
|
|
child.modulate = Color.WEB_GRAY
|
2026-01-11 22:26:15 +00:00
|
|
|
|
2025-12-19 19:39:56 +00:00
|
|
|
|
|
|
|
|
func _appear() -> void:
|
|
|
|
|
modulate.a = 0
|
|
|
|
|
show()
|
|
|
|
|
var tween := create_tween()
|
|
|
|
|
tween.tween_property(self, "modulate:a", 1.0, 0.5)
|
|
|
|
|
await tween.finished
|
|
|
|
|
|
|
|
|
|
func _vanish() -> void:
|
|
|
|
|
var tween := create_tween()
|
|
|
|
|
tween.tween_property(self, "modulate:a", 0.0, 0.5)
|
|
|
|
|
await tween.finished
|
|
|
|
|
hide()
|