GFramework/GFramework.Godot/Setting/GodotGraphicsSettings.cs
GeWuYou 23489570bf fix(analyzers): 降低 Core、Cqrs、Godot 与生成器的构建警告
- 清理 GFramework.Core 与 GFramework.Cqrs 中的大量低风险 Meziantou 警告

- 修复 GFramework.Godot 运行时中的 ConfigureAwait、StringComparison 与参数校验告警

- 调整 Core SourceGenerators 中的字符串比较、文件命名与局部长方法问题

- 拆分部分配置与缓存辅助类型文件以消除 file/type mismatch 告警

- 更新 warning reduction 跟踪与执行记录,保留下一批结构性告警的恢复点
2026-04-18 16:47:44 +08:00

66 lines
2.0 KiB
C#

using GFramework.Game.Abstractions.Setting;
using GFramework.Game.Abstractions.Setting.Data;
using Godot;
namespace GFramework.Godot.Setting;
/// <summary>
/// Godot图形设置应用器
/// </summary>
/// <param name="model">设置模型接口</param>
public class GodotGraphicsSettings(ISettingsModel model) : IResetApplyAbleSettings
{
/// <summary>
/// 应用图形设置到Godot引擎
/// </summary>
/// <returns>异步任务</returns>
public Task Apply()
{
var settings = model.GetData<GraphicsSettings>();
// 创建分辨率向量
var size = new Vector2I(settings.ResolutionWidth, settings.ResolutionHeight);
// 设置窗口边框状态
DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.Borderless, settings.Fullscreen);
// 设置窗口模式(全屏或窗口化)
DisplayServer.WindowSetMode(
settings.Fullscreen
? DisplayServer.WindowMode.ExclusiveFullscreen
: DisplayServer.WindowMode.Windowed
);
// 非全屏模式下设置窗口大小和居中位置
if (!settings.Fullscreen)
{
DisplayServer.WindowSetSize(size);
var screen = DisplayServer.GetPrimaryScreen();
var screenSize = DisplayServer.ScreenGetSize(screen);
var pos = (screenSize - size) / 2;
DisplayServer.WindowSetPosition(pos);
}
return Task.CompletedTask;
}
/// <summary>
/// 重置图形设置
/// </summary>
public void Reset()
{
model.GetData<GraphicsSettings>().Reset();
}
/// <summary>
/// 获取图形设置的数据对象。
/// 该属性提供对图形设置数据的只读访问。
/// </summary>
public ISettingsData Data { get; } = model.GetData<GraphicsSettings>();
/// <summary>
/// 获取图形设置数据的类型。
/// 该属性返回图形设置数据的具体类型信息。
/// </summary>
public Type DataType { get; } = typeof(GraphicsSettings);
}