diff --git a/GFramework.Game.Abstractions/setting/AudioSettings.cs b/GFramework.Game.Abstractions/setting/data/AudioSettings.cs similarity index 80% rename from GFramework.Game.Abstractions/setting/AudioSettings.cs rename to GFramework.Game.Abstractions/setting/data/AudioSettings.cs index a70dce8..8af355a 100644 --- a/GFramework.Game.Abstractions/setting/AudioSettings.cs +++ b/GFramework.Game.Abstractions/setting/data/AudioSettings.cs @@ -1,9 +1,11 @@ +using GFramework.Core.Abstractions.versioning; + namespace GFramework.Game.Abstractions.setting; /// /// 音频设置类,用于管理游戏中的音频配置 /// -public class AudioSettings : ISettingsData +public class AudioSettings : ISettingsData, IVersioned { /// /// 获取或设置主音量,控制所有音频的总体音量 @@ -25,8 +27,11 @@ public class AudioSettings : ISettingsData /// public void Reset() { + // 重置所有音量设置为默认值 MasterVolume = 1.0f; BgmVolume = 0.8f; SfxVolume = 0.8f; } + + public int Version { get; set; } = 1; } \ No newline at end of file diff --git a/GFramework.Game.Abstractions/setting/GraphicsSettings.cs b/GFramework.Game.Abstractions/setting/data/GraphicsSettings.cs similarity index 83% rename from GFramework.Game.Abstractions/setting/GraphicsSettings.cs rename to GFramework.Game.Abstractions/setting/data/GraphicsSettings.cs index ed1af12..ad826a6 100644 --- a/GFramework.Game.Abstractions/setting/GraphicsSettings.cs +++ b/GFramework.Game.Abstractions/setting/data/GraphicsSettings.cs @@ -1,9 +1,11 @@ +using GFramework.Core.Abstractions.versioning; + namespace GFramework.Game.Abstractions.setting; /// /// 图形设置类,用于管理游戏的图形相关配置 /// -public class GraphicsSettings : ISettingsData +public class GraphicsSettings : ISettingsData, IVersioned { /// /// 获取或设置是否启用全屏模式 @@ -29,4 +31,6 @@ public class GraphicsSettings : ISettingsData ResolutionWidth = 1920; ResolutionHeight = 1080; } + + public int Version { get; set; } = 1; } \ No newline at end of file diff --git a/GFramework.Game.Abstractions/setting/data/LocalizationSettings.cs b/GFramework.Game.Abstractions/setting/data/LocalizationSettings.cs new file mode 100644 index 0000000..a998047 --- /dev/null +++ b/GFramework.Game.Abstractions/setting/data/LocalizationSettings.cs @@ -0,0 +1,44 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using GFramework.Core.Abstractions.versioning; + +namespace GFramework.Game.Abstractions.setting.data; + +/// +/// 本地化设置类,用于管理游戏的语言本地化配置 +/// 实现了ISettingsData接口提供设置数据功能,实现IVersioned接口提供版本控制功能 +/// +public class LocalizationSettings : ISettingsData, IVersioned +{ + /// + /// 获取或设置当前使用的语言 + /// + /// 默认值为"简体中文" + public string Language { get; set; } = "简体中文"; + + /// + /// 重置本地化设置到默认状态 + /// 将Language属性恢复为默认的"简体中文"值 + /// + public void Reset() + { + Language = "简体中文"; + } + + /// + /// 获取或设置设置数据的版本号 + /// + /// 默认版本号为1 + public int Version { get; set; } = 1; +} \ No newline at end of file diff --git a/GFramework.Godot/setting/GodotAudioSettings.cs b/GFramework.Godot/setting/GodotAudioSettings.cs index 7c1bbef..24a524d 100644 --- a/GFramework.Godot/setting/GodotAudioSettings.cs +++ b/GFramework.Godot/setting/GodotAudioSettings.cs @@ -7,8 +7,8 @@ namespace GFramework.Godot.setting; /// Godot音频设置实现类,用于应用音频配置到Godot音频系统 /// /// 音频设置对象,包含主音量、背景音乐音量和音效音量 -/// 音频总线映射对象,定义了不同音频类型的总线名称 -public class GodotAudioSettings(AudioSettings settings, AudioBusMapSettings audioBusMapSettings) +/// 音频总线映射对象,定义了不同音频类型的总线名称 +public class GodotAudioSettings(AudioSettings settings, AudioBusMap audioBusMap) : IPersistentApplyAbleSettings { /// @@ -17,15 +17,15 @@ public class GodotAudioSettings(AudioSettings settings, AudioBusMapSettings audi /// 表示异步操作的任务 public Task Apply() { - SetBus(audioBusMapSettings.Master, settings.MasterVolume); - SetBus(audioBusMapSettings.Bgm, settings.BgmVolume); - SetBus(audioBusMapSettings.Sfx, settings.SfxVolume); + SetBus(audioBusMap.Master, settings.MasterVolume); + SetBus(audioBusMap.Bgm, settings.BgmVolume); + SetBus(audioBusMap.Sfx, settings.SfxVolume); return Task.CompletedTask; } public void Reset() { - audioBusMapSettings.Reset(); + settings.Reset(); } /// diff --git a/GFramework.Godot/setting/GodotLocalizationSettings.cs b/GFramework.Godot/setting/GodotLocalizationSettings.cs new file mode 100644 index 0000000..6f2b48a --- /dev/null +++ b/GFramework.Godot/setting/GodotLocalizationSettings.cs @@ -0,0 +1,46 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using GFramework.Game.Abstractions.setting; +using GFramework.Game.Abstractions.setting.data; +using GFramework.Godot.setting.data; +using Godot; + +namespace GFramework.Godot.setting; + +/// +/// Godot本地化设置类,负责应用本地化配置到Godot引擎 +/// +/// 本地化设置对象 +/// 本地化映射表 +public class GodotLocalizationSettings(LocalizationSettings settings, LocalizationMap localizationMap) + : IPersistentApplyAbleSettings +{ + /// + /// 应用本地化设置到Godot引擎 + /// + /// 完成的任务 + public Task Apply() + { + // 尝试从映射表获取 Godot locale + var locale = localizationMap.LanguageMap.GetValueOrDefault(settings.Language, "en"); + // 默认值 + TranslationServer.SetLocale(locale); + return Task.CompletedTask; + } + + /// + /// 重置本地化设置 + /// + public void Reset() => settings.Reset(); +} \ No newline at end of file diff --git a/GFramework.Godot/setting/AudioBusMapSettings.cs b/GFramework.Godot/setting/data/AudioBusMap.cs similarity index 89% rename from GFramework.Godot/setting/AudioBusMapSettings.cs rename to GFramework.Godot/setting/data/AudioBusMap.cs index 6ba4bb2..941c67a 100644 --- a/GFramework.Godot/setting/AudioBusMapSettings.cs +++ b/GFramework.Godot/setting/data/AudioBusMap.cs @@ -1,12 +1,10 @@ -using GFramework.Game.Abstractions.setting; - namespace GFramework.Godot.setting; /// /// 音频总线映射设置 /// 定义了游戏中不同音频类型的总线名称配置 /// -public class AudioBusMapSettings : ISettingsData +public class AudioBusMap { /// /// 主音频总线名称 diff --git a/GFramework.Godot/setting/data/LocalizationMap.cs b/GFramework.Godot/setting/data/LocalizationMap.cs new file mode 100644 index 0000000..3501f5f --- /dev/null +++ b/GFramework.Godot/setting/data/LocalizationMap.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace GFramework.Godot.setting.data; + +/// +/// 本地化映射设置 +/// +public class LocalizationMap +{ + /// + /// 用户语言 -> Godot locale 映射表 + /// + public Dictionary LanguageMap { get; set; } = new() + { + { "简体中文", "zh_CN" }, + { "English", "en" } + }; +} \ No newline at end of file