diff options
Diffstat (limited to 'game/src/OptionMenu/ResolutionSelector.gd')
-rw-r--r-- | game/src/OptionMenu/ResolutionSelector.gd | 62 |
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)) |