Skip to content

Commit

Permalink
Merge pull request #5 from Maaack/video-settings
Browse files Browse the repository at this point in the history
Video settings
  • Loading branch information
Maaack authored Dec 1, 2023
2 parents 05a78bc + 471a706 commit a6c7468
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 15 deletions.
6 changes: 3 additions & 3 deletions App/Scenes/Credits/Credits.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ layout_mode = 2
size_flags_horizontal = 3

[node name="HeaderSpace" type="Control" parent="ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 648)
custom_minimum_size = Vector2(0, 720)
layout_mode = 2

[node name="RichTextLabel" type="RichTextLabel" parent="ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(1152, 0)
custom_minimum_size = Vector2(1280, 0)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 5
Expand All @@ -60,7 +60,7 @@ fit_content = true
scroll_active = false

[node name="FooterSpace" type="Control" parent="ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 648)
custom_minimum_size = Vector2(0, 720)
layout_mode = 2

[node name="ScrollResetTimer" type="Timer" parent="."]
Expand Down
64 changes: 56 additions & 8 deletions App/Scenes/Menus/OptionsMenu/Video/VideoOptionsMenu.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
extends Control

const FULLSCREEN_ENABLED = 'FullscreenEnabled'
const VIDEO_SECTION = 'VideoSettings'
@export var resolutions_array : Array[Vector2i] = [
Vector2i(640, 360),
Vector2i(960, 540),
Vector2i(1024, 576),
Vector2i(1280, 720),
Vector2i(1600, 900),
Vector2i(1920, 1080),
Vector2i(2048, 1152),
Vector2i(2560, 1440),
Vector2i(3200, 1800),
]

@onready var fullscreen_button = $VBoxContainer/FullscreenControl/FullscreenButton
@onready var fullscreen_button = %FullscreenButton
@onready var resolution_options = %ResolutionOptions
@onready var user_resolutions_array : Array[Vector2i] = resolutions_array.duplicate()

func _update_ui():
fullscreen_button.button_pressed = ((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN))
func _preselect_resolution(window : Window):
var current_resolution : Vector2i = window.size
if not current_resolution in user_resolutions_array:
user_resolutions_array.append(current_resolution)
user_resolutions_array.sort()
resolution_options.clear()
for resolution in user_resolutions_array:
var resolution_string : String = "%d x %d" % [resolution.x, resolution.y]
resolution_options.add_item(resolution_string)
if not resolution in resolutions_array:
var last_index : int = resolution_options.item_count - 1
resolution_options.set_item_disabled(last_index, true)
var current_resolution_index : int = user_resolutions_array.find(current_resolution)
resolution_options.select(current_resolution_index)

func _update_resolution_options_enabled(window : Window):
if OS.has_feature("web"):
resolution_options.disabled = true
resolution_options.tooltip_text = "Disabled for web"
elif AppSettings.is_fullscreen(window):
resolution_options.disabled = true
resolution_options.tooltip_text = "Disabled for fullscreen"
else:
resolution_options.disabled = false
resolution_options.tooltip_text = "Select a screen size"

func _update_ui(window : Window):
var current_resolution : Vector2i = window.size
fullscreen_button.button_pressed = AppSettings.is_fullscreen(window)
_preselect_resolution(window)
_update_resolution_options_enabled(window)

func _ready():
_update_ui()
var window : Window = get_window()
_update_ui(window)
window.connect("size_changed", _preselect_resolution.bind(window))

func _on_FullscreenButton_toggled(button_pressed):
AppSettings.set_fullscreen_enabled(button_pressed, get_window())
func _on_fullscreen_button_toggled(toggled_on):
var window : Window = get_window()
AppSettings.set_fullscreen_enabled(toggled_on, window)
_update_resolution_options_enabled(window)

func _on_resolution_options_item_selected(index):
if index < 0 or index >= user_resolutions_array.size():
return
AppSettings.set_resolution(user_resolutions_array[index], get_window())
17 changes: 16 additions & 1 deletion App/Scenes/Menus/OptionsMenu/Video/VideoOptionsMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ size_flags_horizontal = 3
text = "Fullscreen :"

[node name="FullscreenButton" type="CheckButton" parent="VBoxContainer/FullscreenControl"]
unique_name_in_owner = true
layout_mode = 2

[connection signal="toggled" from="VBoxContainer/FullscreenControl/FullscreenButton" to="." method="_on_FullscreenButton_toggled"]
[node name="ResolutionControl" type="HBoxContainer" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 40)
layout_mode = 2

[node name="ResolutionLabel" type="Label" parent="VBoxContainer/ResolutionControl"]
layout_mode = 2
size_flags_horizontal = 3
text = "Resolution :"

[node name="ResolutionOptions" type="OptionButton" parent="VBoxContainer/ResolutionControl"]
unique_name_in_owner = true
layout_mode = 2

[connection signal="toggled" from="VBoxContainer/FullscreenControl/FullscreenButton" to="." method="_on_fullscreen_button_toggled"]
[connection signal="item_selected" from="VBoxContainer/ResolutionControl/ResolutionOptions" to="." method="_on_resolution_options_item_selected"]
21 changes: 18 additions & 3 deletions App/Scripts/AppSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const AUDIO_SECTION = 'AudioSettings'
const VIDEO_SECTION = 'VideoSettings'

const FULLSCREEN_ENABLED = 'FullscreenEnabled'
const SCREEN_RESOLUTION = 'ScreenResolution'
const MUTE_SETTING = 'Mute'
const MASTER_BUS_INDEX = 0

Expand Down Expand Up @@ -114,17 +115,31 @@ static func set_fullscreen_enabled(value : bool, window : Window) -> void:
window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN if (value) else Window.MODE_WINDOWED
Config.set_config(VIDEO_SECTION, FULLSCREEN_ENABLED, value)

static func set_resolution(value : Vector2i, window : Window) -> void:
if value.x == 0 or value.y == 0:
return
window.size = value
Config.set_config(VIDEO_SECTION, SCREEN_RESOLUTION, value)

static func reset_video_config(window : Window) -> void:
Config.set_config(VIDEO_SECTION, FULLSCREEN_ENABLED, ((window.mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (window.mode == Window.MODE_FULLSCREEN)))

static func is_fullscreen(window : Window) -> bool:
return (window.mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (window.mode == Window.MODE_FULLSCREEN)

static func get_resolution(window : Window) -> Vector2i:
var current_resolution : Vector2i = window.size
current_resolution = Config.get_config(VIDEO_SECTION, SCREEN_RESOLUTION, current_resolution)
return current_resolution

static func set_video_from_config(window : Window) -> void:
var fullscreen_enabled : bool = (window.mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (window.mode == Window.MODE_FULLSCREEN)
var fullscreen_enabled : bool = is_fullscreen(window)
fullscreen_enabled = Config.get_config(VIDEO_SECTION, FULLSCREEN_ENABLED, fullscreen_enabled)
window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN if (fullscreen_enabled) else Window.MODE_WINDOWED

set_fullscreen_enabled(fullscreen_enabled, window)
if not (fullscreen_enabled or OS.has_feature("web")):
var current_resolution : Vector2i = get_resolution(window)
set_resolution(current_resolution, window)

# All

static func set_from_config() -> void:
Expand Down
6 changes: 6 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ config/icon="res://icon.png"
InGameMenuController="*res://App/Scripts/InGameMenuController.gd"
SceneLoader="*res://App/Scripts/SceneLoader.gd"

[display]

window/size/viewport_width=1280
window/size/viewport_height=720
window/size/mode=3

[gui]

theme/custom="res://App/Themes/BaseTheme.tres"
Expand Down

0 comments on commit a6c7468

Please sign in to comment.