diff --git a/Autoloads/GameSettingsNode.cs b/Autoloads/GameSettingsNode.cs index 88f024b..3f5f1d1 100644 --- a/Autoloads/GameSettingsNode.cs +++ b/Autoloads/GameSettingsNode.cs @@ -1,7 +1,6 @@ -using CMSGame.Models; using Newtonsoft.Json; -namespace CMSGame.Autoloads +namespace CMSGame { /// /// 游戏设置持久化节点 @@ -27,6 +26,7 @@ namespace CMSGame.Autoloads RegisterAllSettings(); MakeDirectories(); LoadAllSettings(); + ApplyVideoSettings(); } protected void RegisterAllSettings() @@ -62,12 +62,12 @@ namespace CMSGame.Autoloads } } - private static void MakeDirectories() + protected static void MakeDirectories() { DirAccess.MakeDirRecursiveAbsolute("user://Settings/"); } - private void LoadSettings(Type settingsType) + protected void LoadSettings(Type settingsType) { string settingsText = ReadFileAsString(SettingsPaths[settingsType]); var settings = JsonConvert.DeserializeObject(settingsText, settingsType); @@ -83,7 +83,7 @@ namespace CMSGame.Autoloads return (TSettings)CurrentSettings[typeof(TSettings)]; } - private static string ReadFileAsString(string path) + protected static string ReadFileAsString(string path) { if (FileAccess.FileExists(path)) { @@ -93,11 +93,16 @@ namespace CMSGame.Autoloads return "null"; } - private void SaveSettings(Type settingsType) + protected void SaveSettings(Type settingsType) { string settingsText = JsonConvert.SerializeObject(CurrentSettings[settingsType]); using var file = FileAccess.Open(SettingsPaths[settingsType], FileAccess.ModeFlags.Write); file.StoreString(settingsText); } + + protected void ApplyVideoSettings() + { + DisplayServerHelper.ApplyResolutionSettings(VideoSettings.UseFullScreen); + } } } diff --git a/Components/Settings/DeveloperOptionsMenu.cs b/Components/Settings/DeveloperOptionsMenu.cs index 5338d59..d031f73 100644 --- a/Components/Settings/DeveloperOptionsMenu.cs +++ b/Components/Settings/DeveloperOptionsMenu.cs @@ -6,7 +6,7 @@ namespace CMSGame { } - public void On_OpenUserDataDirButton_Pressed() + public static void On_OpenUserDataDirButton_Pressed() { OS.ShellOpen(new GodotPath("user://")); } diff --git a/Components/Settings/SettingsMenu.cs b/Components/Settings/SettingsMenu.cs index 24ee483..bf980aa 100644 --- a/Components/Settings/SettingsMenu.cs +++ b/Components/Settings/SettingsMenu.cs @@ -1,5 +1,3 @@ -using CMSGame.Autoloads; - namespace CMSGame { public partial class SettingsMenu : TabContainer diff --git a/Components/Settings/VideoSettingsMenu.cs b/Components/Settings/VideoSettingsMenu.cs index 64e8590..1de25d6 100644 --- a/Components/Settings/VideoSettingsMenu.cs +++ b/Components/Settings/VideoSettingsMenu.cs @@ -1,5 +1,3 @@ -using CMSGame.Models; - namespace CMSGame { public partial class VideoSettingsMenu : Control @@ -16,20 +14,13 @@ namespace CMSGame FullScreenCheckButton!.Toggled += FullScreenCheckButton_Toggled; - FullScreenCheckButton.ButtonPressed = Settings.UseFullScreen; + FullScreenCheckButton.SetPressedNoSignal(Settings.UseFullScreen); } private void FullScreenCheckButton_Toggled(bool buttonPressed) { Settings!.UseFullScreen = buttonPressed; - if (buttonPressed) - { - DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen); - } - else - { - DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed); - } + DisplayServerHelper.ApplyResolutionSettings(buttonPressed); } } } diff --git a/GlobalUsings.cs b/GlobalUsings.cs index b454275..79da1f8 100644 --- a/GlobalUsings.cs +++ b/GlobalUsings.cs @@ -1,5 +1,4 @@ global using System; -global using System.Collections; global using System.Collections.Generic; global using System.Linq; global using Godot; diff --git a/Helpers/DisplayServerHelper.cs b/Helpers/DisplayServerHelper.cs index 57bf58f..378c8ed 100644 --- a/Helpers/DisplayServerHelper.cs +++ b/Helpers/DisplayServerHelper.cs @@ -1,8 +1,8 @@ -namespace CMSGame.Helpers +namespace CMSGame { internal static class DisplayServerHelper { - public static void ApplyAndPersistResolutionSettings(bool useFullScreen) + public static void ApplyResolutionSettings(bool useFullScreen) { if (useFullScreen) { diff --git a/Models/Changelog.cs b/Models/Changelog.cs index a5edc05..03e146d 100644 --- a/Models/Changelog.cs +++ b/Models/Changelog.cs @@ -1,6 +1,6 @@ using System.Text; -namespace CMSGame.Models +namespace CMSGame { internal record class Changelog { diff --git a/Models/GameSettings.cs b/Models/GameSettings.cs index 7eb3bf0..09fced2 100644 --- a/Models/GameSettings.cs +++ b/Models/GameSettings.cs @@ -1,4 +1,4 @@ -namespace CMSGame.Models +namespace CMSGame { public record class GameSettings { diff --git a/Scenes/LandingScene/ChangelogContainer.cs b/Scenes/LandingScene/ChangelogContainer.cs index bcb60cd..f0087f9 100644 --- a/Scenes/LandingScene/ChangelogContainer.cs +++ b/Scenes/LandingScene/ChangelogContainer.cs @@ -1,4 +1,3 @@ -using CMSGame.Models; using System.Text; namespace CMSGame