|
|
游戏界面大小
.\Resources\ClientDefinitions.ini -> [Settings] -> SettingsFile= (filename with .ini extension)
该文件(例如 RA2MD.ini)中存储游戏分辨率等设置,其节名和键名由游戏类型(ClientType)硬编码决定:
- 对于 YR / TS:使用 [Video] 节,键名为 ScreenWidth 和 ScreenHeight
- 对于 RA / RA2:使用 [Options] 节,键名为 Width 和 Height
SettingsFile 的文件名由 ClientDefinitions.ini 定义,文件路径由 GamePath(游戏根目录)决定。相关代码见 ClientCore\Settings\UserINISettings.cs#L49
var userIni = new IniFile(SafePath.CombineFilePath(ProgramConstants.GamePath, userIniFileName)); 以及 ClientCore\ProgramConstants.cs
public static readonly string StartupExecutable = Assembly.GetEntryAssembly().Location; public static readonly string StartupPath = SafePath.CombineDirectoryPath(new FileInfo(StartupExecutable).Directory.FullName); public static readonly string GamePath = SafePath.CombineDirectoryPath(GetGamePath(StartupPath)); 游戏是否窗口化
默认设置(渲染器配置)
.\Resources\Renderers.ini 中定义各个渲染器(DirectDraw Wrapper)的配置。在渲染配置节下可包含以下键:
- ResConfigFileName = 源文件名(位于 Resources 目录,默认等于 ConfigFileName)
- ConfigFileName = 目标文件名(位于游戏根目录)
- WindowedModeSection = 窗口化设置所在的节名(例如 ddraw)
- WindowedModeKey = 窗口化设置的键名(例如 windowed)
- BorderlessWindowedModeKey = 无边框窗口化设置的键名(可选)
- IsBorderlessWindowedModeKeyReversed = 是否反转无边框键的布尔值(可选)
例如:
- cnc-ddraw 渲染器:WindowedModeSection=ddraw,WindowedModeKey=windowed
- DxWnd 渲染器:WindowedModeSection=DxWnd,WindowedModeKey=RunInWindow
客户端启动时,会根据当前选中的渲染器,将默认配置文件从 Resources 目录复制到游戏根目录(仅当目标文件不存在时)。复制逻辑见 DXMainClient\Domain\DirectDrawWrapper.cs:
if (!string.IsNullOrEmpty(ConfigFileName) && !string.IsNullOrEmpty(resConfigFileName) && !SafePath.GetFile(ProgramConstants.GamePath, ConfigFileName).Exists) { File.Copy( SafePath.CombineFilePath(ProgramConstants.GetBaseResourcePath(), resConfigFileName), SafePath.CombineFilePath(ProgramConstants.GamePath, Path.GetFileName(ConfigFileName)) ); } 其中 GetBaseResourcePath() 返回 .\Resources 目录(见 ClientCore\ProgramConstants.cs):
public static string BASE_RESOURCE_PATH = "Resources"; public static string GetBaseResourcePath() { return SafePath.CombineDirectoryPath(GamePath, BASE_RESOURCE_PATH); } 注意:ConfigFileName 中的目录部分会被 Path.GetFileName 剥离,最终文件始终直接放在游戏根目录。
客户端设置(窗口化选项的读写)
客户端通过 DXMainClient\DXGUI\Generic\OptionPanels\DisplayOptionsPanel.cs 中的 Load() 和 Save() 方法处理窗口化选项。
读取规则:
- 若渲染器的 WindowedModeSection 和 WindowedModeKey 均非空(即支持自定义窗口化选项),则从 GamePath\ConfigFileName 中读取窗口化状态。
- 否则,从 GamePath\SettingsFile(例如 RA2MD.ini)中读取窗口化设置。此时固定使用 [Video] 节,窗口化键名为 Video.Windowed(由
ClientConfiguration.WindowedModeKey 定义,默认值为 "Video.Windowed"),无边框键名为 NoWindowFrame(硬编码)。
写入规则:
- 若渲染器支持自定义窗口化选项,则用户修改窗口化状态后,会写入到 GamePath\ConfigFileName 中由 WindowedModeSection 和 WindowedModeKey 指定的位置。
- 否则,写入到 GamePath\SettingsFile 的 [Video] 节下,窗口化键名固定为 Video.Windowed(可自定义),无边框键名固定为 NoWindowFrame。
切换渲染器时的行为:
- DirectDrawWrapperManager.Save() 会删除旧渲染器的配置文件(调用 Clean()),并确保新渲染器的默认配置文件已就位(若不存在则从 Resources 复制)。
- 窗口化设置的写入并不由该函数直接完成,而是由 DisplayOptionsPanel.Save() 在用户点击“保存”时根据上述规则执行。
执行方式总结
- 切换渲染器时:将 Resources 目录下名为 ResConfigFileName 的文件复制到游戏根目录并重命名为 ConfigFileName(若目标已存在则跳过)。
- 更改窗口化选项并保存时:
若渲染器支持自定义(WindowedModeSection 和 WindowedModeKey 均非空),写入 GamePath\ConfigFileName。 否则,写入 GamePath\SettingsFile 的 [Video] 节下的 Video.Windowed 和 NoWindowFrame 键。
- 重要提示:渲染器的默认模板文件(位于 Resources 目录)永远不会被用户修改;所有用户更改都保存在游戏根目录下的实际配置文件中。
以上具体文件及行号地址和源码片段以 CnCNet/xna-cncnet-client 仓库 develop 分支最新提交 d56011f223f6a2cec4256f0c6c5b4f62d5f486ec 为准,许多 Mod 可能一直在用 2021 年某个提交开出去的 Fork,需要自行对照和重新定位。文案由人工编写全篇后 AI 洗稿并标记重点,若有与源码实际执行方式冲突处以源码为准。
|
|