defensive get_locale + focus tab strip when options menu becomes visible

get_locale() now falls back to TranslationServer.get_locale() if the
locale key is missing from _state, avoiding a crash when the options
autoload hasn't run _ready yet (e.g. another autoload triggers it
during its own _ready).

When the options menu becomes visible, focus moves to the TabContainer
so keyboard/gamepad navigation between tabs works without a click.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Samson 2026-04-29 23:54:16 +01:00
parent 058bb91383
commit 845e155719
No known key found for this signature in database
GPG Key ID: A9EB2589C60F7268
2 changed files with 7 additions and 2 deletions

View File

@ -17,7 +17,7 @@ func _ready():
TranslationServer.set_locale(_state[_KEY_LOCALE]) TranslationServer.set_locale(_state[_KEY_LOCALE])
func get_locale() -> String: func get_locale() -> String:
return _state[_KEY_LOCALE] return _state.get(_KEY_LOCALE, TranslationServer.get_locale())
func set_locale(locale: String) -> void: func set_locale(locale: String) -> void:
_state[_KEY_LOCALE] = locale _state[_KEY_LOCALE] = locale

View File

@ -17,4 +17,9 @@ func _on_back_button_pressed() -> void:
func _on_visibility_changed() -> void: func _on_visibility_changed() -> void:
if visible: if visible:
grab_focus() # Defer one frame so the TabContainer is laid out and focusable before
# we call grab_focus on it.
await get_tree().process_frame
var tabs := find_child("TabContainer")
if tabs is Control:
(tabs as Control).grab_focus()