diff options
Diffstat (limited to 'game/src/OptionMenu')
-rw-r--r-- | game/src/OptionMenu/GuiScaleSelector.gd | 65 | ||||
-rw-r--r-- | game/src/OptionMenu/VideoTab.tscn | 18 |
2 files changed, 82 insertions, 1 deletions
diff --git a/game/src/OptionMenu/GuiScaleSelector.gd b/game/src/OptionMenu/GuiScaleSelector.gd new file mode 100644 index 0000000..ec94269 --- /dev/null +++ b/game/src/OptionMenu/GuiScaleSelector.gd @@ -0,0 +1,65 @@ +extends SettingOptionButton + +@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(): + print("Setup Gui scales Button") + if default_value <= 0: + #TODO: verify this project setting is what we actually want + #print("get default from project settings, default was %f",default_value) + 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): + #no need to match types like resolution does since we don't + #intend on supporting strings + var target_guiscale = 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): + print("Change GUI scale on selector index: %d" % index) + GuiScale.set_guiscale(get_item_metadata(index)) + else: + push_error("Invalid GuiScaleSelector index: %d" % index) + reset_setting() diff --git a/game/src/OptionMenu/VideoTab.tscn b/game/src/OptionMenu/VideoTab.tscn index c92f7f7..8fc8747 100644 --- a/game/src/OptionMenu/VideoTab.tscn +++ b/game/src/OptionMenu/VideoTab.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://bq3awxxjn1tuw"] +[gd_scene load_steps=8 format=3 uid="uid://bq3awxxjn1tuw"] [ext_resource type="Script" path="res://src/OptionMenu/ResolutionSelector.gd" id="1_i8nro"] [ext_resource type="Script" path="res://src/OptionMenu/VideoTab.gd" id="1_jvv62"] [ext_resource type="Script" path="res://src/OptionMenu/ScreenModeSelector.gd" id="2_wa7vw"] +[ext_resource type="Script" path="res://src/OptionMenu/GuiScaleSelector.gd" id="3_pgc5d"] [ext_resource type="Script" path="res://src/OptionMenu/MonitorDisplaySelector.gd" id="3_y6lyb"] [ext_resource type="Script" path="res://src/OptionMenu/RefreshRateSelector.gd" id="4_381mg"] [ext_resource type="Script" path="res://src/OptionMenu/QualityPresetSelector.gd" id="5_srg4v"] @@ -42,6 +43,20 @@ script = ExtResource("1_i8nro") section_name = "video" setting_name = "resolution" +[node name="GuiScaleLabel" type="Label" parent="VBoxContainer/GridContainer"] +layout_mode = 2 +text = "OPTIONS_VIDEO_GUI_SCALE" + +[node name="GuiScaleSelector" type="OptionButton" parent="VBoxContainer/GridContainer"] +editor_description = "UI-19" +layout_mode = 2 +focus_neighbor_bottom = NodePath("../ScreenModeSelector") +item_count = 1 +selected = 0 +popup/item_0/text = "MISSING" +popup/item_0/id = 0 +script = ExtResource("3_pgc5d") + [node name="ScreenModeLabel" type="Label" parent="VBoxContainer/GridContainer"] editor_description = "UI-44" layout_mode = 2 @@ -138,5 +153,6 @@ setting_name = "quality_preset" default_selected = 1 [connection signal="item_selected" from="VBoxContainer/GridContainer/ResolutionSelector" to="VBoxContainer/GridContainer/ResolutionSelector" method="_on_item_selected"] +[connection signal="item_selected" from="VBoxContainer/GridContainer/GuiScaleSelector" to="VBoxContainer/GridContainer/GuiScaleSelector" method="_on_item_selected"] [connection signal="item_selected" from="VBoxContainer/GridContainer/ScreenModeSelector" to="VBoxContainer/GridContainer/ScreenModeSelector" method="_on_item_selected"] [connection signal="item_selected" from="VBoxContainer/GridContainer/MonitorDisplaySelector" to="VBoxContainer/GridContainer/MonitorDisplaySelector" method="_on_item_selected"] |