Add dynamic UI theme for server browser

Introduce runtime-driven UI theming for the server browser

- Expose PushUITheme() in F4TServerBrowserBridge and implement ColorToJson + PushUIThemeInternal to serialize HUD colors and invoke a JS hook.
- Call PushUITheme on UI initialization and when the browser is shown so the webview receives current HUD colors.
- Add frontend handler for "uiTheme" in app.js and a new components/theme.js that implements window.applyCoTheme to set CSS vars and tint the cursor SVG.
- Update styles.css to use RGB component CSS variables (--co-r/--co-g/--co-b and background equivalents) so colors can be overridden at runtime.
- Update index.html to include the new theme script and tweak cursor SVG stroke width; cursor asset updated as well.

This enables the plugin to synchronize the in-game HUD colors with the browser UI dynamically.
This commit is contained in:
2026-06-09 15:19:03 +12:00
parent 1f80b8ea49
commit fb4e238fcc
9 changed files with 131 additions and 17 deletions
+1
View File
@@ -178,6 +178,7 @@ namespace F4T::PrismaUI
});
F4T::ServerBrowser::ServerBrowserBridge::Initialize(g_api, a_view);
F4T::ServerBrowser::ServerBrowserBridge::PushUITheme();
g_api->BindUIEvent(a_view, "coAction", [](const char* a_json) {
if (!a_json) {
+39
View File
@@ -5,6 +5,7 @@
#include "F4TServerBrowserBridge.h"
#include "F4TServerBrowserData.h"
#include <algorithm>
#include <format>
#include <string_view>
@@ -58,6 +59,38 @@ namespace F4T::ServerBrowser
});
}
nlohmann::json ColorToJson(const RE::NiColor& a_color)
{
const auto toByte = [](float a_channel) {
return static_cast<int>(std::clamp(a_channel * 255.0f, 0.0f, 255.0f));
};
return nlohmann::json{
{ "r", toByte(a_color.r) },
{ "g", toByte(a_color.g) },
{ "b", toByte(a_color.b) }
};
}
void PushUIThemeInternal()
{
if (!g_api || g_view == 0 || !g_api->IsValid(g_view)) {
return;
}
const auto hudColor = RE::HUDMenuUtils::GetGameplayHUDColor();
const auto hudBgColor = RE::HUDMenuUtils::GetGameplayHUDBackgroundColor();
const auto themePayload = nlohmann::json{
{ "hud", ColorToJson(hudColor) },
{ "hudBackground", ColorToJson(hudBgColor) }
};
const auto script = std::format(
"if(window.applyCoTheme){{window.applyCoTheme({});}}",
themePayload.dump());
g_api->Invoke(g_view, script.c_str());
}
void PushConnectionStatusEvent()
{
const auto connected = F4T::Networking::IsConnectedToServer();
@@ -136,6 +169,7 @@ namespace F4T::ServerBrowser
void ServerBrowserBridge::OnBrowserShown()
{
PushUIThemeInternal();
DispatchEvent(nlohmann::json{ { "type", "menuOpened" } });
RefreshServerList();
}
@@ -289,4 +323,9 @@ namespace F4T::ServerBrowser
{
PushConnectionStatusEvent();
}
void ServerBrowserBridge::PushUITheme()
{
PushUIThemeInternal();
}
}