diff --git a/Autoloads/GameSettings.cs b/Autoloads/GameSettings.cs index 9c5516a..09fced2 100644 --- a/Autoloads/GameSettings.cs +++ b/Autoloads/GameSettings.cs @@ -9,7 +9,7 @@ namespace CMSGame public record class VideoSettings : GameSettings { - public bool UseFullScreen = false; + public bool UseFullScreen { set; get; } = false; } public record class AudioSettings : GameSettings @@ -17,11 +17,11 @@ namespace CMSGame /// /// 音乐音量 /// - public double MusicVolume = 80; + public double MusicVolume { set; get; } = 80; /// /// 音效音量 /// - public double SoundEffectVolume = 80; + public double SoundEffectVolume { set; get; } = 80; } } diff --git a/Autoloads/GameSettingsNode.cs b/Autoloads/GameSettingsNode.cs index bc581e2..08e074d 100644 --- a/Autoloads/GameSettingsNode.cs +++ b/Autoloads/GameSettingsNode.cs @@ -11,7 +11,7 @@ namespace CMSGame { protected Dictionary CurrentSettings = new(); - protected Dictionary OriginalSettings = new(); + protected Dictionary PreviousSettings = new(); protected Dictionary SettingsPaths = new(); @@ -24,12 +24,9 @@ namespace CMSGame public GameSettingsNode() { RegisterAllSettings(); - } - - public override void _Ready() - { MakeDirectories(); LoadAllSettings(); + ApplyVideoSettings(); } protected void RegisterAllSettings() @@ -58,7 +55,7 @@ namespace CMSGame { foreach (var settingsType in SettingsPaths.Keys) { - if (!OriginalSettings.ContainsKey(settingsType) || OriginalSettings[settingsType] != CurrentSettings[settingsType]) + if (!PreviousSettings.ContainsKey(settingsType) || PreviousSettings[settingsType] != CurrentSettings[settingsType]) { SaveSettings(settingsType); } @@ -76,8 +73,8 @@ namespace CMSGame var settings = JsonConvert.DeserializeObject(settingsText, settingsType); if (settings != null) { - OriginalSettings[settingsType] = (GameSettings)settings; - CurrentSettings[settingsType] = (GameSettings)settings; + PreviousSettings[settingsType] = (GameSettings)settings; + CurrentSettings[settingsType] = (GameSettings)settings with { }; } } @@ -102,5 +99,17 @@ namespace CMSGame using var file = FileAccess.Open(SettingsPaths[settingsType], FileAccess.ModeFlags.Write); file.StoreString(settingsText); } + + public void ApplyVideoSettings() + { + if (VideoSettings.UseFullScreen) + { + DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen); + } + else + { + DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed); + } + } } } diff --git a/Components/Settings/SettingsMenu.tscn b/Components/Settings/SettingsMenu.tscn index a659f03..190518f 100644 --- a/Components/Settings/SettingsMenu.tscn +++ b/Components/Settings/SettingsMenu.tscn @@ -16,7 +16,6 @@ script = ExtResource("1_av57b") [node name="BattleSettingsMenu" type="Control" parent="."] unique_name_in_owner = true -visible = false layout_mode = 2 script = ExtResource("2_xtjo5") @@ -36,6 +35,7 @@ layout_mode = 2 [node name="VideoSettingsMenu" type="Control" parent="."] unique_name_in_owner = true +visible = false layout_mode = 2 script = ExtResource("3_68iki") diff --git a/Components/Settings/VideoSettingsMenu.cs b/Components/Settings/VideoSettingsMenu.cs index 8ff5219..1ab3569 100644 --- a/Components/Settings/VideoSettingsMenu.cs +++ b/Components/Settings/VideoSettingsMenu.cs @@ -12,9 +12,9 @@ namespace CMSGame this.GetUniqueNode(ref FullScreenCheckButton, nameof(FullScreenCheckButton)); - FullScreenCheckButton!.SetPressedNoSignal(Settings.UseFullScreen); + FullScreenCheckButton!.Toggled += FullScreenCheckButton_Toggled; - FullScreenCheckButton.Toggled += FullScreenCheckButton_Toggled; ; + FullScreenCheckButton.ButtonPressed = Settings.UseFullScreen; } private void FullScreenCheckButton_Toggled(bool buttonPressed) diff --git a/project.godot b/project.godot index c89751b..8375e93 100644 --- a/project.godot +++ b/project.godot @@ -17,6 +17,7 @@ config/name_localized={ "zh_Hant": "山與海的囯" } run/main_scene="res://Scenes/LandingScene/LandingScene.tscn" +config/project_settings_override="user://Engine.cfg" config/features=PackedStringArray("4.0", "C#", "Forward Plus") config/icon="res://icon.svg"