diff --git a/Resources/MenuTheme.tres b/Resources/MenuTheme.tres index f2f306b..7ce5911 100644 --- a/Resources/MenuTheme.tres +++ b/Resources/MenuTheme.tres @@ -3,9 +3,11 @@ [ext_resource type="FontFile" uid="uid://dq8ojwul8884x" path="res://Fonts/AtkinsonHyperlegible-Regular.ttf" id="1_aadm8"] [resource] +default_font = ExtResource("1_aadm8") Button/font_sizes/font_size = 32 Button/fonts/font = ExtResource("1_aadm8") Label/font_sizes/font_size = 32 Label/fonts/font = ExtResource("1_aadm8") LineEdit/font_sizes/font_size = 32 LineEdit/fonts/font = ExtResource("1_aadm8") +PopupMenu/font_sizes/font_size = 32 diff --git a/Scenes/UI/Menus/Settings.tscn b/Scenes/UI/Menus/Settings.tscn index ba54748..ddde7fa 100644 --- a/Scenes/UI/Menus/Settings.tscn +++ b/Scenes/UI/Menus/Settings.tscn @@ -34,8 +34,7 @@ size_flags_horizontal = 4 [node name="Label" type="Label" parent="ScrollContainer/InternalMainContainer/ScaleContainer"] layout_mode = 2 size_flags_horizontal = 4 -text = "Scale -" +text = "Scale" [node name="Scale" type="SpinBox" parent="ScrollContainer/InternalMainContainer/ScaleContainer"] layout_mode = 2 @@ -45,6 +44,30 @@ step = 0.01 value = 1.0 alignment = 1 +[node name="VSyncContainer" type="VBoxContainer" parent="ScrollContainer/InternalMainContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +alignment = 1 + +[node name="Label" type="Label" parent="ScrollContainer/InternalMainContainer/VSyncContainer"] +layout_mode = 2 +text = "VSync" +horizontal_alignment = 1 + +[node name="VSyncOptions" type="OptionButton" parent="ScrollContainer/InternalMainContainer/VSyncContainer"] +layout_mode = 2 +item_count = 4 +selected = 1 +fit_to_longest_item = false +popup/item_0/text = "Disabled" +popup/item_0/id = 0 +popup/item_1/text = "Enabled" +popup/item_1/id = 1 +popup/item_2/text = "Adaptive" +popup/item_2/id = 2 +popup/item_3/text = "Mailbox" +popup/item_3/id = 3 + [node name="SaveButton" type="Button" parent="."] layout_mode = 2 disabled = true @@ -59,5 +82,7 @@ theme_override_font_sizes/font_size = 32 text = "Back " +[connection signal="value_changed" from="ScrollContainer/InternalMainContainer/ScaleContainer/Scale" to="." method="ScaleChanged"] +[connection signal="item_selected" from="ScrollContainer/InternalMainContainer/VSyncContainer/VSyncOptions" to="." method="VSyncChanged"] [connection signal="pressed" from="SaveButton" to="." method="OnSaveButtonPressed"] [connection signal="pressed" from="BackButton" to="." method="OnBackButtonPressed"] diff --git a/Scripts/Data/GameArea.cs b/Scripts/Data/GameArea.cs index 3713b0d..8a338a3 100644 --- a/Scripts/Data/GameArea.cs +++ b/Scripts/Data/GameArea.cs @@ -3,7 +3,7 @@ namespace Pong.Scripts.Data; /// /// a record class that represents the game area. /// -public record class GameArea +public record GameArea { /// /// the X coordinate of the GameArea wrapped in a struct that makes operating on it easier. this is divided @@ -28,7 +28,6 @@ public record class GameArea return new Vector2(normalizedX, normalizedY); } - /// /// take a normalized position and convert it back into a globalized position. /// diff --git a/Scripts/Data/Settings.cs b/Scripts/Data/Settings.cs index 0dafce7..4422f91 100644 --- a/Scripts/Data/Settings.cs +++ b/Scripts/Data/Settings.cs @@ -8,10 +8,16 @@ public struct Settings /// /// the scale of the game. this can be from 1.0 to 2.0 /// - public double Scale; + public double Scale; + + /// + /// options for VSync. 0 is Disabled, 1 is Enabled, 2 is Adaptive, 3 is Mailbox. These match the enum on + /// the . + /// + public long VSync; /// /// the default values of settings. /// - public static Settings Default => new() { Scale = 1.0 }; + public static Settings Default => new() { Scale = 1.0, VSync = (long)DisplayServer.VSyncMode.Enabled }; } diff --git a/Scripts/Managers/UI/BaseMenu.cs b/Scripts/Managers/UI/BaseMenu.cs index 292d1df..e16f62c 100644 --- a/Scripts/Managers/UI/BaseMenu.cs +++ b/Scripts/Managers/UI/BaseMenu.cs @@ -3,36 +3,34 @@ namespace Pong.Scripts.Managers.UI; public partial class BaseMenu : VBoxContainer { private SettingsManager _settingsManager; - + public override void _EnterTree() { _settingsManager = GetNode("/root/SettingsManager"); - _settingsManager.SettingsChanged += AdaptUiToGameResolution; + _settingsManager.SettingsChanged += SettingsChanged; GetTree().Root.SizeChanged += AdaptUiToGameResolution; AdaptUiToGameResolution(); - - EnterTree(); } public override void _ExitTree() { GetTree().Root.SizeChanged -= AdaptUiToGameResolution; - _settingsManager.SettingsChanged -= AdaptUiToGameResolution; - ExitTree(); - } - - protected virtual void EnterTree() - { - } - - protected virtual void ExitTree() - { + _settingsManager.SettingsChanged -= SettingsChanged; } + /// + /// method that fires when the settings get changed. + /// + private void SettingsChanged() + { + AdaptUiToGameResolution(); + DisplayServer.WindowSetVsyncMode((DisplayServer.VSyncMode)_settingsManager.SettingsData.VSync); + } + /// /// change the size of the UI container to the current resolution of the game. /// - protected void AdaptUiToGameResolution() + private void AdaptUiToGameResolution() { var scale = _settingsManager.SettingsData.Scale; Size = (Vector2)DisplayServer.WindowGetSize() / scale; diff --git a/Scripts/Managers/UI/Menus/Settings.cs b/Scripts/Managers/UI/Menus/Settings.cs index 6077487..8c961a9 100644 --- a/Scripts/Managers/UI/Menus/Settings.cs +++ b/Scripts/Managers/UI/Menus/Settings.cs @@ -4,15 +4,19 @@ public partial class Settings : BaseMenu { private SettingsManager _settings; private SpinBox _scale; + private OptionButton _vSync; private Button _saveButton; private bool _scaleModified; + private bool _vSyncModified; - protected override void EnterTree() + public override void _EnterTree() { + base._EnterTree(); GetNodes(); _scale.Value = _settings.SettingsData.Scale; + _vSync.Selected = (int)_settings.SettingsData.VSync; } private void OnBackButtonPressed() @@ -20,31 +24,57 @@ public partial class Settings : BaseMenu GetTree().ChangeSceneToFile("res://Scenes/UI/Menus/MainMenu.tscn"); } + /// + /// get references to the nodes required for the settings menu to function and bind to events. + /// private void GetNodes() { - _settings = GetNode("/root/SettingsManager"); - _scale = GetNode("ScrollContainer/InternalMainContainer/ScaleContainer/Scale"); - _saveButton = GetNode