fix state management issues with settings

This commit is contained in:
betalars 2025-03-25 22:35:01 +01:00
parent 022053a078
commit 076c7a3315
7 changed files with 26 additions and 4 deletions

View File

@ -129,8 +129,6 @@ func _ready():
get_viewport().gui_focus_changed.connect(reclaim_lost_focus) get_viewport().gui_focus_changed.connect(reclaim_lost_focus)
print(get_save_dict())
func reclaim_lost_focus(): func reclaim_lost_focus():
if has_stage: if has_stage:

View File

@ -19,14 +19,16 @@ var has_stage:bool = false:
@onready var font_picker: OptionButton = %FontSeettings @onready var font_picker: OptionButton = %FontSeettings
@onready var subtitle_picker: OptionButton = %SubtitleSettings @onready var subtitle_picker: OptionButton = %SubtitleSettings
@onready var scale_slider: HSlider = %UIScaleSlider @onready var scale_slider: HSlider = %UIScaleSlider
@onready var accept_or_continue: Button = %SaveButton @onready var save_button: Button = %SaveButton
@onready var back_button: Button = %BackButton @onready var back_button: Button = %BackButton
func _ready() -> void: func _ready() -> void:
if is_in_beginning: if is_in_beginning:
%SaveButton.text = "save and continue" %SaveButton.text = "save and continue"
back_button.show()
else: else:
%SaveButton.text = "save and exit" %SaveButton.text = "save and exit"
back_button.hide()
update_ui_from_state() update_ui_from_state()
@ -38,6 +40,7 @@ func _ready() -> void:
font_picker.item_selected.connect(func(value): State.font_style = value) font_picker.item_selected.connect(func(value): State.font_style = value)
subtitle_picker.item_selected.connect(func(value): State.subtitles = value) subtitle_picker.item_selected.connect(func(value): State.subtitles = value)
scale_slider.drag_ended.connect(_on_scale_slider_dragged) scale_slider.drag_ended.connect(_on_scale_slider_dragged)
save_button.pressed.connect(_on_save_button_pressed)
func _on_scale_slider_dragged(update:bool): func _on_scale_slider_dragged(update:bool):
@ -54,7 +57,11 @@ func update_ui_from_state():
subtitle_picker.selected = State.subtitles subtitle_picker.selected = State.subtitles
scale_slider.value = State.ui_scaling scale_slider.value = State.ui_scaling
func _on_exit_button_pressed() -> void: func _on_save_button_pressed() -> void:
leave_stage.emit() leave_stage.emit()
State.save_settings() State.save_settings()
State.leave_stage(self) State.leave_stage(self)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and has_stage:
State.leave_stage(self)

View File

@ -111,6 +111,7 @@ disabled = true
selected = 1 selected = 1
item_count = 3 item_count = 3
popup/item_0/text = "none" popup/item_0/text = "none"
popup/item_0/id = 0
popup/item_1/text = "spoken text" popup/item_1/text = "spoken text"
popup/item_1/id = 1 popup/item_1/id = 1
popup/item_2/text = "closed captions" popup/item_2/text = "closed captions"

View File

@ -78,3 +78,7 @@ func _on_exit_button_pressed() -> void:
leave_stage.emit() leave_stage.emit()
State.save_settings() State.save_settings()
State.leave_stage(self) State.leave_stage(self)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and has_stage:
State.leave_stage(self)

View File

@ -42,3 +42,7 @@ func _on_exit_button_pressed() -> void:
leave_stage.emit() leave_stage.emit()
State.save_settings() State.save_settings()
State.leave_stage(self) State.leave_stage(self)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and has_stage:
State.leave_stage(self)

View File

@ -33,3 +33,7 @@ func _on_exit_button_pressed() -> void:
leave_stage.emit() leave_stage.emit()
State.save_settings() State.save_settings()
State.leave_stage(self) State.leave_stage(self)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and has_stage:
State.leave_stage(self)

View File

@ -274,3 +274,7 @@ func window_mode_to_select_id(mode: DisplayServer.WindowMode) -> int:
func select_id_to_window_mode(item_id) -> DisplayServer.WindowMode: func select_id_to_window_mode(item_id) -> DisplayServer.WindowMode:
return item_id + 2 if item_id != 0 else 0 return item_id + 2 if item_id != 0 else 0
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and has_stage:
_on_exit_button_pressed()