Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add GUI scale setting to options #90

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions COGITO/EasyMenus/Scenes/tab_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,35 @@ theme_override_font_sizes/font_size = 20
text = "1"
horizontal_alignment = 1

[node name="HBoxContainer_GUIScale" type="HBoxContainer" parent="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(400, 40)
layout_mode = 2

[node name="GUIScaleLabel" type="Label" parent="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_GUIScale"]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2
size_flags_horizontal = 0
text = "UI Scale"

[node name="GUIScaleSlider" type="HSlider" parent="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_GUIScale"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
mouse_force_pass_scroll_events = false
min_value = 0.25
max_value = 1.5
step = 0.05
value = 1.0

[node name="GUIScaleCurrentValueLabel" type="Label" parent="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_GUIScale"]
unique_name_in_owner = true
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
theme_override_font_sizes/font_size = 20
text = "1"
horizontal_alignment = 1

[node name="VSyncCheckButton" type="CheckButton" parent="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(200, 0)
Expand Down Expand Up @@ -433,6 +462,8 @@ start_game_scene = "res://COGITO/DemoScenes/COGITO_01_Demo.tscn"
[connection signal="item_selected" from="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_AA2D/AntiAliasing2DOptionButton" to="TabMenuOptions" method="_on_anti_aliasing_2d_option_button_item_selected"]
[connection signal="item_selected" from="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_AA3D/AntiAliasing3DOptionButton" to="TabMenuOptions" method="_on_anti_aliasing_3d_option_button_item_selected"]
[connection signal="value_changed" from="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_RenderScale/RenderScaleSlider" to="TabMenuOptions" method="_on_render_scale_slider_value_changed"]
[connection signal="drag_ended" from="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_GUIScale/GUIScaleSlider" to="TabMenuOptions" method="_on_gui_scale_slider_drag_ended"]
[connection signal="value_changed" from="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/HBoxContainer_GUIScale/GUIScaleSlider" to="TabMenuOptions" method="_on_gui_scale_slider_value_changed"]
[connection signal="toggled" from="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/VSyncCheckButton" to="TabMenuOptions" method="_on_v_sync_check_button_toggled"]
[connection signal="pressed" from="Content/TabContainer/Graphics/ScrollContainer/VBoxContainer/ApplyChanges" to="TabMenuOptions" method="_on_apply_changes_pressed"]
[connection signal="value_changed" from="Content/TabContainer/Audio/ScrollContainer/VBoxContainer/MarginContainer/VBoxContainer/SFXVolumeSlider" to="TabMenuOptions" method="_on_sfx_volume_slider_value_changed"]
Expand Down
1 change: 1 addition & 0 deletions COGITO/EasyMenus/Scripts/options_constants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const music_volume_key_name = "music_volume"
const windowmode_key_name = "window_mode"
const resolution_index_key_name = "resolution_index"
const render_scale_key = "render_scale"
const gui_scale_key = "gui_scale"
const vsync_key = "vsync"
const msaa_2d_key = "msaa_2d"
const msaa_3d_key = "msaa_3d"
Expand Down
32 changes: 32 additions & 0 deletions COGITO/EasyMenus/Scripts/tab_menu_options.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const HSliderWLabel = preload("res://COGITO/EasyMenus/Scripts/slider_w_labels.gd
@onready var music_volume_slider: HSliderWLabel = $%MusicVolumeSlider
@onready var render_scale_current_value_label: Label = %RenderScaleCurrentValueLabel
@onready var render_scale_slider: HSlider = %RenderScaleSlider
@onready var gui_scale_current_value_label: Label = %GUIScaleCurrentValueLabel
@onready var gui_scale_slider: HSlider = %GUIScaleSlider
@onready var vsync_check_button: CheckButton = %VSyncCheckButton
@onready var invert_y_check_button: CheckButton = %InvertYAxisCheckButton
@onready var anti_aliasing_2d_option_button: OptionButton = $%AntiAliasing2DOptionButton
Expand All @@ -18,6 +20,9 @@ var sfx_bus_index
var music_bus_index
var config = ConfigFile.new()

# Need to store this while player drags the slider
var temp_gui_scale_value = null

# Array to set window modes.
const WINDOW_MODE_ARRAY : Array[String] = [
"Full screen",
Expand Down Expand Up @@ -110,6 +115,7 @@ func save_options():
config.set_value(OptionsConstants.section_name, OptionsConstants.windowmode_key_name, window_mode_option_button.selected)
config.set_value(OptionsConstants.section_name, OptionsConstants.resolution_index_key_name, resolution_option_button.selected)
config.set_value(OptionsConstants.section_name, OptionsConstants.render_scale_key, render_scale_slider.value);
config.set_value(OptionsConstants.section_name, OptionsConstants.gui_scale_key, gui_scale_slider.value);
config.set_value(OptionsConstants.section_name, OptionsConstants.vsync_key, vsync_check_button.button_pressed)
config.set_value(OptionsConstants.section_name, OptionsConstants.invert_vertical_axis_key, invert_y_check_button.button_pressed)
config.set_value(OptionsConstants.section_name, OptionsConstants.msaa_2d_key, anti_aliasing_2d_option_button.get_selected_id())
Expand All @@ -123,11 +129,15 @@ func load_options():
if err != 0:
print("Loading options config failed. Using defaults.")

# Set in Project Settings
var default_gui_scale = get_viewport().scaling_3d_scale

var sfx_volume = config.get_value(OptionsConstants.section_name, OptionsConstants.sfx_volume_key_name, 1)
var music_volume = config.get_value(OptionsConstants.section_name, OptionsConstants.music_volume_key_name, 1)
var window_mode = config.get_value(OptionsConstants.section_name, OptionsConstants.windowmode_key_name, 0)
var resolution_index = config.get_value(OptionsConstants.section_name, OptionsConstants.resolution_index_key_name, 0)
var render_scale = config.get_value(OptionsConstants.section_name, OptionsConstants.render_scale_key, 1)
var gui_scale = config.get_value(OptionsConstants.section_name, OptionsConstants.gui_scale_key, default_gui_scale)
var vsync = config.get_value(OptionsConstants.section_name, OptionsConstants.vsync_key, true)
var invert_y = config.get_value(OptionsConstants.section_name, OptionsConstants.invert_vertical_axis_key, true)
var msaa_2d = config.get_value(OptionsConstants.section_name, OptionsConstants.msaa_2d_key, 0)
Expand All @@ -136,6 +146,9 @@ func load_options():
sfx_volume_slider.hslider.value = sfx_volume
music_volume_slider.hslider.value = music_volume
render_scale_slider.value = render_scale

gui_scale_slider.value = gui_scale
render_scale_current_value_label.text = str(gui_scale)

# Need to set it like that to guarantee signal to be triggered
vsync_check_button.set_pressed_no_signal(vsync)
Expand All @@ -160,6 +173,22 @@ func _on_render_scale_slider_value_changed(value):
render_scale_current_value_label.text = str(value)


func _on_gui_scale_slider_value_changed(value):
temp_gui_scale_value = value


func _on_gui_scale_slider_drag_ended(value_changed):
apply_temp_gui_scale_value()

# TODO: Apply changes if the slider is clicked but not dragged

func apply_temp_gui_scale_value():
if temp_gui_scale_value != null:
get_viewport().content_scale_factor = temp_gui_scale_value
gui_scale_current_value_label.text = str(temp_gui_scale_value)
temp_gui_scale_value = null


func _on_v_sync_check_button_toggled(button_pressed):
# There are multiple V-Sync Methods supported by Godot
# For now we just use the simple ones could be worth a consideration to add the others
Expand Down Expand Up @@ -193,3 +222,6 @@ func set_msaa(mode, index):
func _on_apply_changes_pressed() -> void:
save_options()
options_updated.emit()



2 changes: 2 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ CogitoQuestManager="*res://COGITO/QuestSystemPD/CogitoQuestManager.gd"
window/size/viewport_width=1280
window/size/viewport_height=720
window/size/initial_position_type=3
window/stretch/mode="viewport"
window/stretch/aspect="expand"

[editor_plugins]

Expand Down