SFSE菜单框架

SFSE菜单框架

向游戏添加一个新的动态菜单,允许SFSE模组使用原有的Dear ImGui api添加自己的自定义页面

[size=4][b]描述[/b][/size]
模组作者可以使用此框架[在 [b]C++ SFSE 插件中直接[/b]编写用户界面。

这是 [url=https://www.nexusmods.com/skyrimspecialedition/mods/120352]SKSE Menu Framework[/url] 的移植版本。

[size=4][b]安装说明[/b][/size]
[b]对于用户:[/b]
需要 SFSE。如果其他模组需要此模组,只需用你的模组管理器安装即可。

按键盘上的 [b]F1[/b] 或游戏手柄上[b]双击 START[/b] 打开菜单。两种绑定方式均可通过菜单或 INI 自定义。

[b]对于作者:[/b]
下载 Miscellaneous Files 下的 SDK 包,并将其中的 SFSEMCP 文件夹复制到你项目的 include 目录。该文件夹包含独立头文件和许可证声明。

或者,使用 [url=https://github.com/QTR-Modding/SFSE-MCP#vcpkg]vcpkg 端口[/url]。按照链接的说明将其添加到你的项目。

选择一种方法即可;无需两者都采用。SDK 需要 C++23。

SDK 头文件采用 MIT 许可证。你的模组无需采用框架的 GPL 许可证。

[size=4][b]主要功能[/b][/size]
[b]对于用户:[/b]
打开 Mod Control Panel 即可访问已安装模组注册的菜单。使用鼠标、键盘或游戏手柄导航。

[b]对于作者:[/b]
[list]
[]在共享的 Mod Control Panel 中注册设置页面。[/]
[]使用 SDK 暴露的 ImGui 函数添加按钮、复选框、滑块、下拉菜单、选项卡、文本输入等。[/]
[]打开独立窗口。[/]
[]绘制持久 HUD 和叠加层,例如 [url=https://www.nexusmods.com/starfield/mods/18202]Performance Overlay[/url]。[/]
[]接收输入和菜单生命周期事件。[/]
[]使用框架的字体和 ImGui 绘制函数。[/]
[/list]框架负责渲染和输入集成,因此你可以专注于你的模组。

[b][size=4]兼容性
[/size][/b]兼容:
- Starfield Shader Injector
- Luma
- OSF UI
- Reshade
- DLSS 5 mods

[size=4][b]自定义[/b][/size]
通过设置选择主题、调整不透明度、更改字体、大小和粗细、选择光标,并配置可选音效。

你也可以创建并分享自己的自定义包。文件放在 [b]Data/SFSE/Plugins[/b] 下:
[list]
[][b]主题:[/b] SFSEMenuFrameworkThemes 中的 JSON 文件。[/]
[][b]壁纸:[/b] 主题引用的图像。参见自带的 Unity 主题作为示例。[/]
[][b]光标:[/b] SFSEMenuFrameworkCursors 中的 PNG 图像及匹配的 JSON 配置。附带一个圆环光标作为示例。[/]
[][b]字体:[/b] Fonts 中的 TTF 文件。[/]
[][b]音效:[/b] SFSEMenuFrameworkSounds 中的自定义 WAV 文件。添加文件后,在设置中选择 Reload sounds。[/]
[/list]这些自定义无需 C++ 代码或重新构建 DLL。

[size=4][b]不熟悉 ImGui?[/b][/size]
对于模组的设置菜单,你需要基础 C++ 和少量 ImGui。你的绘制函数描述要显示的控件。当你的页面可见时,框架每帧调用它。

复选框和滑块编辑你的变量。按钮在激活时返回 true。从下面的示例开始。

[spoiler]
此示例适用于使用 CommonLibSF 和 SFSE-MCP 的 C++23 SFSE 项目。你的项目仍需要其正常的构建配置和插件元数据。

[code]
#include <SFSE/SFSE.h>
#include <SFSEMCP/SFSEMenuFramework.hpp>

namespace
{
bool enabled = true;
float strength = 1.0f;

void __stdcall DrawSettings()
{
ImGuiMCP::TextUnformatted("My first settings page");

ImGuiMCP::Checkbox("Enabled", &enabled);
ImGuiMCP::SliderFloat("Strength", &strength, 0.0f, 2.0f);

if (ImGuiMCP::Button("Reset"))
{
enabled = true;
strength = 1.0f;
}
}

void RegisterSettings()
{
if (!SFSEMenuFramework::IsInstalled())
{
return;
}

SFSEMenuFramework::SetSection("My Mod");
SFSEMenuFramework::AddSectionItem("Settings", &DrawSettings);
}

void OnSFSEMessage(SFSE::MessagingInterface::Message* message)
{
if (message &&
message->type == SFSE::MessagingInterface::kPostLoad)
{
RegisterSettings();
}
}
}

SFSE_PLUGIN_LOAD(const SFSE::LoadInterface* sfse)
{
if (!sfse)
{
return false;
}

SFSE::Init(sfse);

const auto* messaging = SFSE::GetMessagingInterface();
return messaging && messaging->RegisterListener(OnSFSEMessage);
}[/code]
当 SFSE 加载你的插件时,入口点会注册一个消息监听器。在 kPostLoad 时,该监听器会在 My Mod 下添加 Settings。随后,当页面可见时,框架会调用 DrawSettings。

[b]已经有 SFSE 插件?[/b]
保留你现有的入口点和初始化。添加绘制和注册函数,然后从你现有的 kPostLoad 处理程序中调用 RegisterSettings()。如果你还没有消息监听器,请在 SFSE::Init 之后注册一个。

示例变量会在会话期间保留其值。将它们保存到配置文件并应用到游戏玩法是你模组的责任。[/spoiler]

[b]示例与参考:[/b]
[list]
[][url=https://github.com/QTR-Modding/SFSE-MCP/blob/main/README.md]SDK 设置和 API 指南[/url][/]
[][url=https://github.com/QTR-Modding/SFSE-Menu-Framework-Example/blob/main/src/plugin.cpp]SFSE 入口点和监听器注册[/url][/]
[][url=https://github.com/QTR-Modding/SFSE-Menu-Framework-Example/blob/main/src/Menu.cpp]菜单注册、设置页面和独立窗口[/url][/]
[][url=https://github.com/QTR-Modding/SFSE-Menu-Framework-Example/blob/main/src/InputHudDemo.cpp]输入监听器和 HUD 元素[/url][/]
[][url=https://github.com/QTR-Modding/SFSE-Menu-Framework-Example/blob/main/src/FontDemo.cpp]字体示例[/url][/]
[][url=https://github.com/QTR-Modding/SFSE-Menu-Framework/blob/main/README.md#custom-themes]主题自定义[/url][/]
[][url=https://github.com/QTR-Modding/SFSE-Menu-Framework/blob/main/README.md#custom-cursors]光标自定义[/url][/]
[/list]
[size=4][b]致谢[/b][/size]
非常感谢我的挚友 Thiago 在 2024 年实现我的愿望,制作了 SKSE Menu Framework,并允许将其移植到 Starfield。

查看[url=https://www.patreon.com/QTRModding]我们的 Patreon[/url],与 [url=https://www.nexusmods.com/skyrimspecialedition/users/12458883]SkyrimThiago[/url]、[url=https://www.nexusmods.com/skyrimspecialedition/users/14258439]RavenKZP[/url] 和我一起!

[url=https://discord.gg/9cbZ5KPqQb]加入我们的 Discord![/url]

[url=https://discord.gg/9cbZ5KPqQb][img]https://img.icons8.com/?size=100&amp;id=dMsFK9i6IaZq&amp;format=png&amp;color=000000[/img][/url]
[url=https://www.patreon.com/QTRModding][img]https://i.imgur.com/PMbnf6v.png[/img][/url]