From 1426c43bd7f68bbed938776e851e40cf9bfa7977 Mon Sep 17 00:00:00 2001 From: nc5432 Date: Wed, 1 Jan 2025 12:48:07 -0500 Subject: [PATCH] Settings now save between rounds --- Scenes/UI/MainMenu.tscn | 4 +++- Scripts/Settings.gd | 27 +++++++++++++++++++++++++++ Scripts/UI/MainMenuUIHandler.gd | 5 ++++- project.godot | 1 - 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 Scripts/Settings.gd diff --git a/Scenes/UI/MainMenu.tscn b/Scenes/UI/MainMenu.tscn index 93001fe..de37fe7 100644 --- a/Scenes/UI/MainMenu.tscn +++ b/Scenes/UI/MainMenu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=90 format=3 uid="uid://078w2ydk8xqb"] +[gd_scene load_steps=91 format=3 uid="uid://078w2ydk8xqb"] [ext_resource type="Script" path="res://Scripts/UI/MainMenu.gd" id="1_apwjj"] [ext_resource type="Theme" uid="uid://kp44uy5twt4a" path="res://Theme/title.tres" id="2_3f6ag"] @@ -8,6 +8,7 @@ [ext_resource type="Texture2D" uid="uid://c15w40e16g78s" path="res://Sprites/gift.png" id="6_dis66"] [ext_resource type="PackedScene" uid="uid://dsncoyuq0i02q" path="res://Models/kenney_city-kit-roads/Models/GLTF format/road_crossroad.glb" id="7_hlv1s"] [ext_resource type="Script" path="res://Scripts/UI/CreditsMenu.gd" id="7_muosy"] +[ext_resource type="Script" path="res://Scripts/Settings.gd" id="7_npksp"] [ext_resource type="PackedScene" uid="uid://ckhtfnuf3aoi5" path="res://Models/kenney_city-kit-roads/Models/GLTF format/road_straight.glb" id="8_4tpst"] [ext_resource type="AudioStream" uid="uid://dhem5ct3h665f" path="res://Sounds/Effects/Christmas Sound Effects #1 (by MrSnooze)/038 magic twinkle.wav" id="8_dgt8v"] [ext_resource type="Script" path="res://Scripts/Resources/Credit.gd" id="8_qsm6r"] @@ -449,6 +450,7 @@ offset_right = 577.0 offset_bottom = 293.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("7_npksp") [node name="VBoxContainer" type="VBoxContainer" parent="UI/Settings"] layout_mode = 2 diff --git a/Scripts/Settings.gd b/Scripts/Settings.gd new file mode 100644 index 0000000..df8ae3f --- /dev/null +++ b/Scripts/Settings.gd @@ -0,0 +1,27 @@ +class_name Settings extends MarginContainer + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + $VBoxContainer/TabContainer/Audio/VBoxContainer/Master/MasterSlider.value = db_to_linear(AudioServer.get_bus_volume_db(0)) + $VBoxContainer/TabContainer/Audio/VBoxContainer/Music/MusicSlider.value = db_to_linear(AudioServer.get_bus_volume_db(1)) + $VBoxContainer/TabContainer/Audio/VBoxContainer/Effects/EffectsSlider.value = db_to_linear(AudioServer.get_bus_volume_db(2)) + $VBoxContainer/TabContainer/Audio/VBoxContainer/Ambiance/AmbianceSlider.value = db_to_linear(AudioServer.get_bus_volume_db(3)) + + $VBoxContainer/TabContainer/Video/VBoxContainer/MSAA/AntiAliasing.selected = get_window().msaa_3d as int + $VBoxContainer/TabContainer/Video/VBoxContainer/VSync/VSyncMode.selected = MainMenuUIHandler.vsyncSetting + + match Engine.max_fps: + 0: + $VBoxContainer/TabContainer/Video/VBoxContainer/FPSCap/FPSCap.selected = 0 + 30: + $VBoxContainer/TabContainer/Video/VBoxContainer/FPSCap/FPSCap.selected = 1 + 60: + $VBoxContainer/TabContainer/Video/VBoxContainer/FPSCap/FPSCap.selected = 2 + 90: + $VBoxContainer/TabContainer/Video/VBoxContainer/FPSCap/FPSCap.selected = 3 + 120: + $VBoxContainer/TabContainer/Video/VBoxContainer/FPSCap/FPSCap.selected = 4 + 144: + $VBoxContainer/TabContainer/Video/VBoxContainer/FPSCap/FPSCap.selected = 5 + if (is_instance_valid(FPSCounter.instance)): + $VBoxContainer/TabContainer/Video/VBoxContainer/FPSCounter/CheckBox.button_pressed = FPSCounter.instance.visible diff --git a/Scripts/UI/MainMenuUIHandler.gd b/Scripts/UI/MainMenuUIHandler.gd index fae1090..b40a7d6 100644 --- a/Scripts/UI/MainMenuUIHandler.gd +++ b/Scripts/UI/MainMenuUIHandler.gd @@ -1,5 +1,7 @@ class_name MainMenuUIHandler extends Control +static var vsyncSetting: int = 1 + @export var animator: AnimationPlayer func _on_settings_pressed() -> void: @@ -47,9 +49,10 @@ func _on_ambiance_slider_value_changed(value: float) -> void: func _on_anti_aliasing_item_selected(index: int) -> void: - RenderingServer.viewport_set_msaa_3d(get_window().get_viewport_rid(), index as RenderingServer.ViewportMSAA) + get_window().msaa_3d = index as Viewport.MSAA func _on_v_sync_mode_item_selected(index: int) -> void: + vsyncSetting = index DisplayServer.window_set_vsync_mode(index as DisplayServer.VSyncMode) func _on_fps_cap_item_selected(index: int) -> void: diff --git a/project.godot b/project.godot index f53f9cc..7e4023d 100644 --- a/project.godot +++ b/project.godot @@ -13,7 +13,6 @@ config_version=5 config/name="Speedin' Santa" run/main_scene="res://Scenes/UI/MainMenu.tscn" config/features=PackedStringArray("4.3", "GL Compatibility") -run/max_fps=60 config/icon="res://icon.svg" [display]