aboutsummaryrefslogtreecommitdiff
path: root/game/src/OptionMenu/GuiScaleSelector.gd
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-05-10 22:53:56 +0200
committer GitHub <noreply@github.com>2023-05-10 22:53:56 +0200
commitbd08b517ed8e3a42de981b7173a99fa362134021 (patch)
tree2a9a0816b571946c7d9fb00b49fc74203101c3ab /game/src/OptionMenu/GuiScaleSelector.gd
parent088a6ada0468f0bf73e8b9a5bb92e59ac2739fae (diff)
parent8a59cb15b58f512f27f01a71248feef4777e3a41 (diff)
Merge pull request #109 from Nemrav/gui-scaling
Add UI scaling through menu option
Diffstat (limited to 'game/src/OptionMenu/GuiScaleSelector.gd')
-rw-r--r--game/src/OptionMenu/GuiScaleSelector.gd64
1 files changed, 64 insertions, 0 deletions
diff --git a/game/src/OptionMenu/GuiScaleSelector.gd b/game/src/OptionMenu/GuiScaleSelector.gd
new file mode 100644
index 0000000..6593a07
--- /dev/null
+++ b/game/src/OptionMenu/GuiScaleSelector.gd
@@ -0,0 +1,64 @@
+extends SettingOptionButton
+
+# REQUIREMENTS
+# * UIFUN-24
+# * UIFUN-31
+
+@export
+var default_value : float = GuiScale.error_guiscale
+
+func _find_guiscale_index_by_value(value : float) -> int:
+ for item_index in item_count:
+ if get_item_metadata(item_index) == value:
+ return item_index
+ return -1
+
+func _sync_guiscales(to_select : float = GuiScale.get_current_guiscale()) -> void:
+ clear()
+ default_selected = -1
+ selected = -1
+ for guiscale_value in GuiScale.get_guiscale_value_list():
+ add_item(GuiScale.get_guiscale_display_name(guiscale_value))
+ set_item_metadata(item_count - 1, guiscale_value)
+
+ if guiscale_value == default_value:
+ default_selected = item_count - 1
+
+ if guiscale_value == to_select:
+ selected = item_count - 1
+
+ if default_selected == -1:
+ default_selected = item_count - 1
+
+ if selected == -1:
+ selected = default_selected
+
+func _setup_button():
+ if default_value <= 0:
+ default_value = ProjectSettings.get_setting("display/window/stretch/scale")
+ GuiScale.add_guiscale(default_value, &"default")
+ _sync_guiscales()
+
+func _get_value_for_file(select_value : int):
+ if _valid_index(select_value):
+ return get_item_metadata(select_value)
+ else:
+ return null
+
+func _set_value_from_file(load_value):
+ if typeof(load_value) == TYPE_FLOAT:
+ var target_guiscale : float = load_value
+ selected = _find_guiscale_index_by_value(target_guiscale)
+ if selected != -1: return
+ if GuiScale.add_guiscale(target_guiscale):
+ _sync_guiscales(target_guiscale)
+ return
+ push_error("Setting value '%s' invalid for setting [%s] %s" % [load_value, section_name, setting_name])
+ selected = default_selected
+
+func _on_item_selected(index:int):
+ if _valid_index(index):
+ GuiScale.set_guiscale(get_item_metadata(index))
+ else:
+ push_error("Invalid GuiScaleSelector index: %d" % index)
+ reset_setting()