diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-02-21 22:30:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-21 22:30:12 +0100 |
commit | f1c23555878ee4b0e40c6af5f89f05b666012309 (patch) | |
tree | 978dfdfd1ac6940414af5e19128060419076de76 /game/src/OptionMenu/OptionsMenu.gd | |
parent | fb9e316a18139ea6b6ffe3b237796b42d7114738 (diff) |
Add Keychain plugin for Controls tab (#15)
* Add modified Keychain plugin for future Controls tab
See https://github.com/Orama-Interactive/Keychain/tree/4.x
Added Events autoload singleton for global eventing namespace
Added Events.Options for global options functionality
* Add Controls tab via Keychain plugin
Use Events.Options for save, load, and reset of settings
Separate OptionMenu tabs into scene files
Add locale saving and loading
Refactor SettingNodes scripts for more generalized use
Remove random prints
Remove useless spinbox signal connection
Make Resolution consistently use Vector2i
* Implement Godot project overrides for resolution and window mode
Overrides are necessary as Godot does not load resolution or window mode on startup, so an override is necessary to ensure this happens.
Add null checks to SettingHSlider and SettingOptionButton
* Fix incorrect resolution value in ResolutionSelector
* Correct project settings override behavior in editor
Godot normally tries to overwrite the project settings in the editor, a template feature tag must be used to prevent the editor from overwriting the project.godot settings.
* Fix Orama-Interactive/Keychain#8
Diffstat (limited to 'game/src/OptionMenu/OptionsMenu.gd')
-rw-r--r-- | game/src/OptionMenu/OptionsMenu.gd | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/game/src/OptionMenu/OptionsMenu.gd b/game/src/OptionMenu/OptionsMenu.gd index e3c8433..5aba7f2 100644 --- a/game/src/OptionMenu/OptionsMenu.gd +++ b/game/src/OptionMenu/OptionsMenu.gd @@ -1,27 +1,9 @@ extends Control -@export -var user_settings_file_path : String = "settings.cfg" - signal back_button_pressed -signal save_settings(save_file: ConfigFile) -signal load_settings(load_file: ConfigFile) -signal reset_settings() - -@onready -var _settings_file_path := "user://" + user_settings_file_path -var _settings_file := ConfigFile.new() - func _ready(): # Prepare options menu before loading user settings - - print("TODO: Load user settings!") - - if FileAccess.file_exists(_settings_file_path): - _settings_file.load(_settings_file_path) - load_settings.emit(_settings_file) - var tab_bar : TabBar = $Margin/Tab.get_child(0, true) # This ends up easier to manage then trying to manually recreate the TabContainer's behavior @@ -33,7 +15,7 @@ func _ready(): var reset_button := Button.new() reset_button.text = "R" - reset_button.pressed.connect(func(): reset_settings.emit()) + reset_button.pressed.connect(Events.Options.try_reset_settings) button_list.add_child(reset_button) var back_button := Button.new() @@ -42,6 +24,8 @@ func _ready(): button_list.add_child(back_button) get_viewport().get_window().close_requested.connect(_on_window_close_requested) + _save_overrides.call_deferred() + Events.Options.save_settings.connect(func(_f): self._save_overrides.call_deferred()) func _notification(what): match what: @@ -51,22 +35,24 @@ func _notification(what): # Could pass the LocaleButton between the MainMenu and OptionsMenu # but that seems a bit excessive func toggle_locale_button_visibility(locale_visible : bool): - print("Toggling locale button: %s" % locale_visible) $LocaleVBox/LocaleHBox/LocaleButton.visible = locale_visible -func _on_ear_exploder_toggled(button_pressed): - print("KABOOM!!!" if button_pressed else "DEFUSED!!!") - - func _on_back_button_pressed(): - save_settings.emit(_settings_file) - _settings_file.save(_settings_file_path) + Events.Options.save_settings_from_file() back_button_pressed.emit() - -func _on_spin_box_value_changed(value): - print("Spinbox: %d" % value) - func _on_window_close_requested() -> void: if visible: - _on_back_button_pressed() + Events.Options.save_settings_from_file() + +func _save_overrides() -> void: + var override_path := ProjectSettings.get_setting("application/config/project_settings_override") as String + if override_path == null or override_path.is_empty(): + override_path = ProjectSettings.get_setting("openvic2/settings/settings_file_path") as String + var file := ConfigFile.new() + file.load(override_path) + file.set_value("display", "window/size/mode", get_viewport().get_window().mode) + var resolution : Vector2i = Resolution.get_current_resolution() + file.set_value("display", "window/size/viewport_width", resolution.x) + file.set_value("display", "window/size/viewport_height", resolution.y) + file.save(override_path) |