fix: settings no longer stuck open until a tab was focused, and load game menu starts at the top item properly aligned

This commit is contained in:
tiger tiger tiger 2026-01-16 21:26:23 +01:00
parent cf057ec84f
commit c76f599e4b
3 changed files with 24 additions and 8 deletions

View File

@ -7,7 +7,12 @@ func _ready() -> void:
if "leave_stage" in child:
child.leave_stage.connect(_on_stage_left)
tab_changed.connect(_on_tab_changed)
pass_to_actor = get_child(current_tab)
# Initialize the first tab's focus state
var initial_child = get_child(current_tab)
if "focused" in initial_child:
initial_child.focused = true
pass_to_actor = initial_child
func _on_tab_changed(tab_id: int):
# Transfer focused to the new tab's child
@ -23,5 +28,4 @@ func _on_tab_changed(tab_id: int):
func _on_stage_left():
await get_tree().process_frame
if not pass_to_actor.focused:
get_parent().vanish()
get_parent().vanish()

View File

@ -9,6 +9,7 @@ var save_buttons: Array[SaveGameDisplay]
set(value):
_load_games()
@onready var scroll_container: ScrollContainer = %ScrollContainer
@onready var list_container: VBoxContainer = %ListContainer
@onready var back_button: Button = $MarginContainer/VBoxContainer/HBoxContainer/Button
@ -84,6 +85,9 @@ func _rebuild_buttons() -> void:
save_buttons.append(new_button)
new_button.pressed.connect(_on_game_picked.bind(i))
new_button.delete_requested.connect(_on_delete_requested.bind(i))
# Reset scroll position to top after rebuilding
scroll_container.scroll_vertical = 0
func _on_game_picked(id: int) -> void:
@ -139,7 +143,12 @@ func pick_save_slot() -> SaveGame:
# TODO: ugh, godot tweens are the wurst
func open() -> void:
show()
save_buttons[0].grab_focus()
await get_tree().process_frame
if save_buttons.size() > 0:
save_buttons[0].grab_focus()
# Reset scroll to top AFTER focus (which triggers auto-scroll)
await get_tree().process_frame
scroll_container.scroll_vertical = 0
modulate = Color.TRANSPARENT
if _tween != null:
_tween.kill()

View File

@ -28,10 +28,10 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 320
theme_override_constants/margin_top = 100
theme_override_constants/margin_right = 320
theme_override_constants/margin_bottom = 100
theme_override_constants/margin_left = 400
theme_override_constants/margin_top = 120
theme_override_constants/margin_right = 400
theme_override_constants/margin_bottom = 120
[node name="ColorRect" type="ColorRect" parent="MarginContainer"]
layout_mode = 2
@ -41,9 +41,12 @@ color = Color(0, 0, 0, 0.2509804)
layout_mode = 2
[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
follow_focus = true
horizontal_scroll_mode = 0
vertical_scroll_mode = 2
[node name="ListContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer"]
unique_name_in_owner = true