fix: settings no longer race condition.

This commit is contained in:
tiger tiger tiger 2025-12-12 17:18:04 +01:00
parent 3e030e2b85
commit 21bb98db8d
4 changed files with 85 additions and 59 deletions

View File

@ -1,11 +1,18 @@
class_name SettingsPopup extends PanelContainer
func _ready() -> void:
get_parent_control().visible = false
func show_settings(id: int = -1):
get_parent_control().visible = true
$AnimationPlayer.play("reveal")
await $AnimationPlayer.animation_finished
if not id == -1:
$TabContainer.current_tab = id
State.pass_stage_to($TabContainer)
func vanish():
$AnimationPlayer.play("vanish")
State.save_settings()
$AnimationPlayer.play("vanish")
await $AnimationPlayer.animation_finished
get_parent_control().visible = false

View File

@ -19,12 +19,10 @@ var has_stage: bool = false
@onready var focus_forward = %MainMenu
func _ready() -> void:
await get_tree().create_timer(1.0).timeout
print("main.gd: ready()")
main_menu.has_stage = true
# TODO: Only do this if we're not in a debug scene.
await main_menu.execute()
# TODO: Find out if we want this.
signal room_loaded
#
#var in_game = false

View File

@ -1,32 +1,5 @@
class_name MainMenu extends Panel
var has_stage: bool = false:
set(value):
has_stage = value
assert(is_node_ready(), "MainMenu node not ready yet!")
if save_game_handle.get_most_recent_save().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 = not has_stage
new_game_button.theme_type_variation = ""
load_game_button.disabled = not save_game_handle.has_existing_saves()
for child: Control in $PanelContainer.get_children():
child.focus_mode = FOCUS_ALL if has_stage else FOCUS_NONE
child.modulate = Color.WHITE if has_stage else Color.WEB_GRAY
child.mouse_filter = Control.MOUSE_FILTER_STOP if has_stage else Control.MOUSE_FILTER_IGNORE
if has_stage:
if continue_button.visible:
continue_button.grab_focus()
else:
new_game_button.grab_focus()
signal start_game(savegame: SaveGame)
signal open_settings(new_game: bool)
signal roll_credits
@onready var new_game_button: Button = $PanelContainer/NewGameButton
@onready var continue_button: Button = $PanelContainer/ContinueGameButton
@onready var load_game_button: Button = $PanelContainer/LoadGameButton
@ -35,29 +8,74 @@ signal roll_credits
@onready var credits_button: Button = $PanelContainer/CreditsButton
@onready var quit_button: Button = $PanelContainer/QuitButton
@onready var save_game_handle: SaveGameList = %SaveGameList
@export var save_game_exists: bool = false:
set(value):
save_game_exists = value
var await_new_game: bool = false
# 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)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print("main_menu.gd: ready()")
_deactivate()
save_game_handle.picked.connect(_on_save_picked)
if save_game_handle.get_most_recent_save().current_room == 0:
continue_button.disabled = true
continue_button.visible = false
new_game_button.theme_type_variation = "H1Button"
continue_button.pressed.connect(func(): start_game.emit(save_game_handle.get_most_recent_save()))
continue_button.pressed.connect(_choose.bind("continue"))
new_game_button.pressed.connect(func(): save_game_handle.pick_save_slot(true))
load_game_button.pressed.connect(func(): save_game_handle.pick_save_slot(false))
load_game_button.disabled = not save_game_handle.has_existing_saves()
settings_button.pressed.connect(settings_popup.show_settings)
credits_button.pressed.connect(_choose.bind("credits"))
quit_button.pressed.connect(get_tree().quit)
credits_button.pressed.connect(roll_credits.emit)
#State.take_stage(self)
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
func _on_save_picked(save: SaveGame):
start_game.emit(save)
print("main_menu.gd: _on_save_picked(", save, ")")
State.active_save_game = save
_user_choice.emit("start_game")

View File

@ -360,35 +360,35 @@ alignment = 0
script = ExtResource("4_iotk1")
metadata/_custom_type_script = "uid://cxton1pffwxk4"
[node name="CenterContainer2" type="CenterContainer" parent="."]
[node name="SettingsContainer" type="CenterContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
mouse_filter = 0
[node name="SettingsPopup" type="PanelContainer" parent="CenterContainer2"]
[node name="SettingsPopup" type="PanelContainer" parent="SettingsContainer"]
unique_name_in_owner = true
visible = false
self_modulate = Color(1, 1, 1, 0)
layout_mode = 2
script = ExtResource("4_k8jo0")
[node name="AnimationPlayer" type="AnimationPlayer" parent="CenterContainer2/SettingsPopup"]
[node name="AnimationPlayer" type="AnimationPlayer" parent="SettingsContainer/SettingsPopup"]
root_node = NodePath("../TabContainer/Video Settings")
libraries = {
&"": SubResource("AnimationLibrary_lmxul")
}
autoplay = "RESET"
[node name="Decoration" type="Control" parent="CenterContainer2/SettingsPopup"]
[node name="Decoration" type="Control" parent="SettingsContainer/SettingsPopup"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="decoration" type="PanelContainer" parent="CenterContainer2/SettingsPopup/Decoration"]
[node name="decoration" type="PanelContainer" parent="SettingsContainer/SettingsPopup/Decoration"]
modulate = Color(1, 1, 1, 0)
layout_mode = 0
offset_left = -374.0
@ -400,36 +400,36 @@ grow_vertical = 2
rotation = 1.26885
pivot_offset = Vector2(374, 378.5)
[node name="TabContainer" type="TabContainer" parent="CenterContainer2/SettingsPopup"]
[node name="TabContainer" type="TabContainer" parent="SettingsContainer/SettingsPopup"]
modulate = Color(1, 1, 1, 0)
layout_mode = 2
current_tab = 3
current_tab = 0
use_hidden_tabs_for_min_size = true
script = ExtResource("5_lhfti")
[node name="Accessibility" parent="CenterContainer2/SettingsPopup/TabContainer" instance=ExtResource("6_875a3")]
[node name="Accessibility" parent="SettingsContainer/SettingsPopup/TabContainer" instance=ExtResource("6_875a3")]
unique_name_in_owner = true
visible = false
layout_mode = 2
[node name="Video Settings" parent="CenterContainer2/SettingsPopup/TabContainer" instance=ExtResource("3_f0dcd")]
[node name="Video Settings" parent="SettingsContainer/SettingsPopup/TabContainer" instance=ExtResource("3_f0dcd")]
unique_name_in_owner = true
visible = false
layout_mode = 2
metadata/_tab_index = 1
[node name="Audio Settings" parent="CenterContainer2/SettingsPopup/TabContainer" instance=ExtResource("4_o07mg")]
[node name="Audio Settings" parent="SettingsContainer/SettingsPopup/TabContainer" instance=ExtResource("4_o07mg")]
unique_name_in_owner = true
visible = false
layout_mode = 2
metadata/_tab_index = 2
[node name="Gameplay Settings" parent="CenterContainer2/SettingsPopup/TabContainer" instance=ExtResource("6_p7ypt")]
[node name="Gameplay Settings" parent="SettingsContainer/SettingsPopup/TabContainer" instance=ExtResource("6_p7ypt")]
unique_name_in_owner = true
visible = false
layout_mode = 2
metadata/_tab_index = 3
[node name="Content Notes" parent="CenterContainer2/SettingsPopup/TabContainer" instance=ExtResource("7_pnd48")]
[node name="Content Notes" parent="SettingsContainer/SettingsPopup/TabContainer" instance=ExtResource("7_pnd48")]
unique_name_in_owner = true
visible = false
layout_mode = 2
@ -437,11 +437,14 @@ metadata/_tab_index = 4
[node name="SaveGameList" type="CenterContainer" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 40.0
offset_top = -45.0
offset_right = 40.0
offset_bottom = -45.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2