Skip to content

Commit

Permalink
Merge pull request #111 from FailSpy/scaling
Browse files Browse the repository at this point in the history
Scaling viewport appropriately
  • Loading branch information
Phazorknight authored Mar 12, 2024
2 parents 9f5fc70 + 0e30524 commit 6381b4d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
32 changes: 32 additions & 0 deletions COGITO/EasyMenus/Scenes/tab_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,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 @@ -460,6 +489,7 @@ main_menu_scene = "res://COGITO/DemoScenes/COGITO_MainMenu.tscn"
start_game_scene = "res://COGITO/DemoScenes/COGITO_01_Demo.tscn"

[connection signal="back_to_main_pressed" from="." to="MenuSceneSwitcher" method="_on_pause_menu_back_to_main_pressed"]
[connection signal="resume" from="." to="TabMenuOptions" method="_on_tab_menu_resume"]
[connection signal="pressed" from="Content/TabContainer/Game/VBoxContainer/ResumeGameButton" to="." method="_on_resume_game_button_pressed"]
[connection signal="pressed" from="Content/TabContainer/Game/VBoxContainer/SaveButton" to="." method="_on_save_button_pressed"]
[connection signal="pressed" from="Content/TabContainer/Game/VBoxContainer/HBoxContainer/LoadButton" to="." method="_on_load_button_pressed"]
Expand All @@ -469,6 +499,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
44 changes: 39 additions & 5 deletions COGITO/EasyMenus/Scripts/tab_menu_options.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extends Control
class_name TabMenuOptions
signal options_updated

const HSliderWLabel = preload("res://COGITO/EasyMenus/Scripts/slider_w_labels.gd")
Expand All @@ -7,6 +8,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 @@ -17,6 +20,8 @@ const HSliderWLabel = preload("res://COGITO/EasyMenus/Scripts/slider_w_labels.gd
var sfx_bus_index
var music_bus_index
var config = ConfigFile.new()
var render_resolution : Vector2i
var render_scale_val : float

# Array to set window modes.
const WINDOW_MODE_ARRAY : Array[String] = [
Expand All @@ -27,7 +32,7 @@ const WINDOW_MODE_ARRAY : Array[String] = [
]


const RESOUTION_DICTIONARY : Dictionary = {
const RESOLUTION_DICTIONARY : Dictionary = {
"1280x720 (16:9)" : Vector2i(1280,720),
"1280x800 (16:10)" : Vector2i(1280,800),
"1366x768 (16:9)" : Vector2i(1366,768),
Expand Down Expand Up @@ -62,7 +67,7 @@ func add_window_mode_items() -> void:

# Adding resolutions to the resolution button.
func add_resolution_items() -> void:
for resolution_text in RESOUTION_DICTIONARY:
for resolution_text in RESOLUTION_DICTIONARY:
resolution_option_button.add_item(resolution_text)


Expand All @@ -81,11 +86,15 @@ func on_window_mode_selected(index: int) -> void:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)

func refresh_render():
get_window().content_scale_size = render_resolution
get_window().scaling_3d_scale = render_scale_val

# Function to change resolution. Hooked up to the resolution_option_button.
func on_resolution_selected(index:int) -> void:
DisplayServer.window_set_size(RESOUTION_DICTIONARY.values()[index])

render_resolution = RESOLUTION_DICTIONARY.values()[index]
refresh_render()
get_window().size = render_resolution

func _on_sfx_volume_slider_value_changed(value):
set_volume(sfx_bus_index, value)
Expand All @@ -110,6 +119,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 @@ -128,6 +138,7 @@ func load_options():
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, 1)
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 +147,11 @@ func load_options():
sfx_volume_slider.hslider.value = sfx_volume
music_volume_slider.hslider.value = music_volume
render_scale_slider.value = render_scale
render_scale_val = render_scale

gui_scale_slider.value = gui_scale
gui_scale_current_value_label.text = str(gui_scale)
apply_gui_scale_value()

# Need to set it like that to guarantee signal to be triggered
vsync_check_button.set_pressed_no_signal(vsync)
Expand All @@ -156,8 +172,22 @@ func load_options():


func _on_render_scale_slider_value_changed(value):
get_viewport().scaling_3d_scale = value
render_scale_val = value
render_scale_current_value_label.text = str(value)
refresh_render()


func _on_gui_scale_slider_value_changed(value):
gui_scale_current_value_label.text = str(value)


func _on_gui_scale_slider_drag_ended(value_changed):
apply_gui_scale_value()

# TODO: Apply changes if the slider is clicked but not dragged
func apply_gui_scale_value():
get_viewport().content_scale_factor = gui_scale_slider.value
gui_scale_current_value_label.text = str(gui_scale_slider.value)


func _on_v_sync_check_button_toggled(button_pressed):
Expand Down Expand Up @@ -193,3 +223,7 @@ func set_msaa(mode, index):
func _on_apply_changes_pressed() -> void:
save_options()
options_updated.emit()

func _on_tab_menu_resume():
# reload options
load_options.call_deferred()
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

0 comments on commit 6381b4d

Please sign in to comment.