aboutsummaryrefslogtreecommitdiff
path: root/game/src/OptionMenu/ResolutionSelector.gd
diff options
context:
space:
mode:
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
commitf1c23555878ee4b0e40c6af5f89f05b666012309 (patch)
tree978dfdfd1ac6940414af5e19128060419076de76 /game/src/OptionMenu/ResolutionSelector.gd
parentfb9e316a18139ea6b6ffe3b237796b42d7114738 (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/ResolutionSelector.gd')
-rw-r--r--game/src/OptionMenu/ResolutionSelector.gd62
1 files changed, 48 insertions, 14 deletions
diff --git a/game/src/OptionMenu/ResolutionSelector.gd b/game/src/OptionMenu/ResolutionSelector.gd
index ef1a0ff..e602bab 100644
--- a/game/src/OptionMenu/ResolutionSelector.gd
+++ b/game/src/OptionMenu/ResolutionSelector.gd
@@ -1,24 +1,58 @@
extends SettingOptionButton
-func _ready():
- print("Resolution selector ready")
+@export
+var default_value : Vector2i = Vector2i(-1, -1)
+
+func add_resolution(value : Vector2i, selection_name : String = "") -> void:
+ if selection_name.is_empty():
+ selection_name = "%sx%s" % [value.x, value.y]
+ add_item(selection_name)
+ set_item_metadata(item_count - 1, value)
+
+func find_resolution_value(value : Vector2i) -> int:
+ for item_index in range(item_count):
+ if get_item_metadata(item_index) == value:
+ return item_index
+ return -1
+
+func _setup_button():
+ if default_value.x < 0:
+ default_value.x = ProjectSettings.get_setting("display/window/size/viewport_width")
+
+ if default_value.y < 0:
+ default_value.y = ProjectSettings.get_setting("display/window/size/viewport_height")
clear()
- var resolution_index := 0
+ default_selected = -1
+ selected = -1
for resolution in Resolution.get_resolution_name_list():
- add_item(resolution)
+ var resolution_value := Resolution.get_resolution(resolution)
+ add_resolution(resolution_value, resolution)
- if Vector2(Resolution.get_resolution(resolution)) == Resolution.get_current_resolution():
- if default_value == -1:
- default_value = resolution_index
- _select_int(resolution_index)
- print(resolution)
+ if resolution_value == default_value:
+ default_selected = item_count - 1
- resolution_index += 1
+ if resolution_value == Resolution.get_current_resolution():
+ selected = item_count - 1
+ if default_selected == -1:
+ add_resolution(default_value)
+ default_selected = item_count - 1
-func _on_item_selected(index):
- print("Selected index: %d" % index)
+ if selected == -1:
+ selected = default_selected
+
+func _get_value_for_file(select_value : int):
+ return get_item_metadata(select_value)
- var resolution_size : Vector2i = Resolution.get_resolution(get_item_text(index))
- Resolution.set_resolution(resolution_size)
+func _set_value_from_file(load_value):
+ var resolution_value := load_value as Vector2i
+ selected = find_resolution_value(resolution_value)
+ if selected == -1:
+ if add_nonstandard_value:
+ add_resolution(resolution_value)
+ selected = item_count - 1
+ else: push_error("Setting value '%s' invalid for setting [%s] %s" % [load_value, section_name, setting_name])
+
+func _on_item_selected(index):
+ Resolution.set_resolution(get_item_metadata(index))