Snapshot for release 2026.10.23.1 (internal 4204305)

This commit is contained in:
Tom Bohar 2026-10-23 16:34:00 -04:00
commit 539a7a3e64
69 changed files with 5385 additions and 107 deletions

View file

@ -789,6 +789,8 @@ internal static class EngineFrameController
if (ImGuiBar.Visible)
ImGuiBar.Draw(_uiScale);
ImGuiPanelHost.DrawAll(_uiScale);
// Settings drawer bodies RynthAi's window didn't draw this frame let their sources go.
Panels.SettingsDrawerBodies.EndFrame();
ImGuiBar.SyncPopOut(_uiScale);
}
if (ImGuiFontTest.Enabled)

View file

@ -16,6 +16,11 @@
// of the atlas's input data for three glyphs (2026-10-15). DX9Backend frees the
// input data once the texture is uploaded (ClearInputData).
//
// Narrow labels (2026-10-21): Barlow Semi Condensed SemiBold and Bold (OFL,
// Assets/Fonts, embedded like Phosphor) at 9/10/11 and bold 11/13, for plugin
// windows (GetUiFont Narrow*: the instrument dashboard's caps labels). They
// get the icons but never Segoe UI Symbol (nothing draws those three with them).
//
// Icons: the Phosphor icon font (MIT, Assets/Fonts/Phosphor.ttf, embedded in
// this assembly) is merged into every baked font, the scaled sets included,
// at the web font's code points (U+E000 up), so an icon is text
@ -54,6 +59,8 @@ internal enum UiFont
// Scaled-up nameplate text and big combat numbers: picked by Sharp() so text is
// shrunk from a bigger bake, never stretched from a smaller one.
Ui18, NumBold48,
// Narrow labels for plugin windows (Barlow Semi Condensed SemiBold, then Bold).
Narrow9, Narrow10, Narrow11, NarrowBold11, NarrowBold13,
Count,
}
@ -75,9 +82,11 @@ internal static unsafe class ImGuiFonts
0x25CF, // ● (Meta source: unapplied edits)
};
private static byte[]? _segoe, _segoeBold, _consolas, _cascadia, _symbol, _phosphor;
private static byte[]? _segoe, _segoeBold, _consolas, _cascadia, _symbol, _phosphor, _narrow, _narrowBold;
private const string PhosphorResource = "RynthCore.Engine.Assets.Fonts.Phosphor.ttf";
private const string NarrowResource = "RynthCore.Engine.Assets.Fonts.BarlowSemiCondensed-SemiBold.ttf";
private const string NarrowBoldResource = "RynthCore.Engine.Assets.Fonts.BarlowSemiCondensed-Bold.ttf";
// Icon size relative to the text's em, capped at the line height (x0.95) for
// fonts whose em fills the line (Consolas): bigger icons climb out of the line.
private const float IconScale = 1.2f, IconMaxOfLine = 0.95f;
@ -140,7 +149,7 @@ internal static unsafe class ImGuiFonts
}
// Native copies of the font files and glyph ranges, made once: rebuilds reuse them.
private static IntPtr _nSegoe, _nSegoeBold, _nMono, _nCode, _nSymbol, _nPhosphor;
private static IntPtr _nSegoe, _nSegoeBold, _nMono, _nCode, _nSymbol, _nPhosphor, _nNarrow, _nNarrowBold;
private static ushort* _mainRanges, _symbolRanges, _iconRanges;
/// <summary>Reads the font files. Engine init worker thread; safe to skip (Build reads them itself).</summary>
@ -152,7 +161,9 @@ internal static unsafe class ImGuiFonts
_consolas = TryRead("consola.ttf");
_cascadia = TryRead("CascadiaMono.ttf");
_symbol = TryRead("seguisym.ttf");
_phosphor = TryReadResource(PhosphorResource);
_phosphor = TryReadResource(PhosphorResource, "icons will not draw");
_narrow = TryReadResource(NarrowResource, "plugin windows' narrow labels use their fallback");
_narrowBold = TryReadResource(NarrowBoldResource, "plugin windows' narrow labels use their fallback");
_preloaded = true;
}
@ -217,7 +228,9 @@ internal static unsafe class ImGuiFonts
double ms = (Stopwatch.GetTimestamp() - t0) * 1000.0 / Stopwatch.Frequency;
RynthLog.UI($"ImGuiFonts: {CountBaked()} fonts queued at scale {scale:0.##} in {ms:0.0} ms " +
$"(Cascadia Mono {(_cascadia != null ? "found" : "missing, using Consolas")}, symbols from the main fonts{(_symbolMerges > 0 ? $" (Segoe UI Symbol merged into {_symbolMerges})" : "")}, " +
$"(Cascadia Mono {(_cascadia != null ? "found" : "missing, using Consolas")}, " +
$"Barlow {(_narrow != null && _narrowBold != null ? "embedded" : "missing")}, " +
$"symbols from the main fonts{(_symbolMerges > 0 ? $" (Segoe UI Symbol merged into {_symbolMerges})" : "")}, " +
$"icons {(_phosphor != null ? $"{IconCount()} merged" : "missing")}).");
Compatibility.MemoryUse.Mark("ImGui fonts queued");
}
@ -234,6 +247,7 @@ internal static unsafe class ImGuiFonts
_iconRanges = PinRanges(IconRanges());
_nSegoe = ToNative(_segoe); _nSegoeBold = ToNative(_segoeBold); _nMono = ToNative(mono);
_nCode = ToNative(code); _nSymbol = ToNative(_symbol); _nPhosphor = ToNative(_phosphor);
_nNarrow = ToNative(_narrow); _nNarrowBold = ToNative(_narrowBold);
}
/// <summary>
@ -251,11 +265,12 @@ internal static unsafe class ImGuiFonts
ushort* symbolRanges = _symbolRanges;
ushort* iconRanges = _iconRanges;
IntPtr segoe = _nSegoe, segoeBold = _nSegoeBold, consolas = _nMono, codeFont = _nCode, symbol = _nSymbol,
phosphor = _nPhosphor;
phosphor = _nPhosphor, narrow = _nNarrow, narrowBold = _nNarrowBold;
// Each base font's em and cap height, to size and place the icons merged into it.
FaceMetrics mSegoe = FaceMetrics.Read(_segoe), mSegoeBold = FaceMetrics.Read(_segoeBold),
mMono = FaceMetrics.Read(mono), mCode = FaceMetrics.Read(code);
mMono = FaceMetrics.Read(mono), mCode = FaceMetrics.Read(code),
mNarrow = FaceMetrics.Read(_narrow), mNarrowBold = FaceMetrics.Read(_narrowBold);
ImFontPtr[] target = baseSet;
float factor = 1f;
@ -270,7 +285,8 @@ internal static unsafe class ImGuiFonts
return need;
}
void Add(UiFont id, IntPtr data, byte[]? bytes, FaceMetrics metrics, float px)
// symbols: false for the narrow label faces (no ≤ ≥ ● drawn with them; Segoe UI Symbol is 2.4 MB per merge).
void Add(UiFont id, IntPtr data, byte[]? bytes, FaceMetrics metrics, float px, bool symbols = true)
{
if (data == IntPtr.Zero || bytes == null) return;
float size = MathF.Round(px * scale * factor);
@ -279,7 +295,7 @@ internal static unsafe class ImGuiFonts
{
cfg.FontDataOwnedByAtlas = false;
target[(int)id] = atlas.AddFontFromMemoryTTF(data, bytes.Length, size, cfg, (IntPtr)mainRanges);
if (symbol != IntPtr.Zero && _symbol != null && NeedsSymbol(bytes))
if (symbols && symbol != IntPtr.Zero && _symbol != null && NeedsSymbol(bytes))
{
_symbolMerges++;
cfg.MergeMode = true;
@ -327,6 +343,17 @@ internal static unsafe class ImGuiFonts
Add(UiFont.NumBold48, segoeBold, _segoeBold, mSegoeBold, 48);
for (int i = 0; i < 6; i++)
Add(UiFont.Chat8 + i, consolas, mono, mMono, 8 + i * 2);
AddNarrow();
// The narrow label faces (plugin windows), in the base set and in each scaled one.
void AddNarrow()
{
Add(UiFont.Narrow9, narrow, _narrow, mNarrow, 9, symbols: false);
Add(UiFont.Narrow10, narrow, _narrow, mNarrow, 10, symbols: false);
Add(UiFont.Narrow11, narrow, _narrow, mNarrow, 11, symbols: false);
Add(UiFont.NarrowBold11, narrowBold, _narrowBold, mNarrowBold, 11, symbols: false);
Add(UiFont.NarrowBold13, narrowBold, _narrowBold, mNarrowBold, 13, symbols: false);
}
// Bigger copies for each panel text size in use (chat keeps its own size setting).
foreach (int step in steps)
@ -347,6 +374,10 @@ internal static unsafe class ImGuiFonts
Add(UiFont.Dash10, codeFont, code, mCode, 10);
Add(UiFont.Dash11, codeFont, code, mCode, 11);
Add(UiFont.Dash14, codeFont, code, mCode, 14);
// Plugin windows draw their icons from Ui18's (GetUiFont Ui18: about 16 px icons at
// normal size), so it grows with the panel's text size too, and stays sharp.
Add(UiFont.Ui18, segoe, _segoe, mSegoe, 18);
AddNarrow();
scaled[step] = target;
}
}
@ -514,7 +545,7 @@ internal static unsafe class ImGuiFonts
Array.Clear(Fonts);
ScaledFonts.Clear();
_mainRanges = _symbolRanges = _iconRanges = null;
_nSegoe = _nSegoeBold = _nMono = _nCode = _nSymbol = _nPhosphor = IntPtr.Zero;
_nSegoe = _nSegoeBold = _nMono = _nCode = _nSymbol = _nPhosphor = _nNarrow = _nNarrowBold = IntPtr.Zero;
}
private static int CountBaked()
@ -668,15 +699,15 @@ internal static unsafe class ImGuiFonts
return (IntPtr)p;
}
/// <summary>A font embedded in this assembly (the Phosphor icons); null when missing.</summary>
private static byte[]? TryReadResource(string name)
/// <summary>A font embedded in this assembly (the Phosphor icons, the narrow labels); null when missing.</summary>
private static byte[]? TryReadResource(string name, string whenMissing)
{
try
{
using Stream? stream = typeof(ImGuiFonts).Assembly.GetManifestResourceStream(name);
if (stream == null)
{
RynthLog.UI($"ImGuiFonts: embedded font {name} missing; icons will not draw.");
RynthLog.UI($"ImGuiFonts: embedded font {name} missing; {whenMissing}.");
return null;
}
var bytes = new byte[stream.Length];

View file

@ -36,6 +36,9 @@ using RynthCore.Engine.UI;
namespace RynthCore.Engine.ImGuiBackend;
/// <summary>Where a panel first opens when nothing is saved for it (v90 plugin windows' "corner").</summary>
internal enum PanelCorner { None, TopLeft, TopRight, BottomLeft, BottomRight, Top, Bottom }
internal enum PanelChrome
{
/// <summary>DRAG + title + pop-out + close header, resize grip.</summary>
@ -77,7 +80,15 @@ internal sealed record PanelSpec(
bool OpenCentered = false,
// No resize grip, docked or popped out: the face sizes itself (the RynthNav arrow
// fits its height to what it shows). Chromeless and GripInBody panels only.
bool NoResize = false);
bool NoResize = false,
// The grip over the body's corner shows only while the mouse is near it (or resizing):
// a frameless plugin window's corner is its own content (RynthAi's footer clock).
bool GripOnHover = false,
// With nothing saved: open in this corner of the game view (a plugin window's "corner", v90).
PanelCorner OpenCorner = PanelCorner.None,
// The panel draws its own content at any size (a plugin window's "scale": "draw", v90): Ctrl+wheel
// steps its draw size (PanelDrawScale, 30-250%) instead of its text size.
bool DrawScale = false);
/// <summary>An ImGui panel face. One instance per open; dropped on close.</summary>
internal interface IImGuiPanel
@ -590,6 +601,51 @@ internal static class ImGuiPanelHost
}
DrawPanel(entry, uiScale, placeScale, null);
}
DrawSizeNote();
}
// ── One way to resize every panel (Tom 2026-10-23) ───────────────────
//
// Ctrl+wheel anywhere over a panel - engine panel, plugin window, framed or frameless, docked
// or popped out - makes that panel one step bigger or smaller; each panel keeps its own size.
// A panel that draws its own content at any size (a plugin window with "scale": "draw") steps
// its draw size 10% (30-250%, PanelDrawScale); the others their text size (100-250%,
// PanelTextScale). The wheel is used up, so the panel doesn't also scroll. A face that has its
// own Ctrl+wheel inside it (the Mini Remote's boxes) clears the wheel first and keeps it.
// A note by the cursor says the new size for a moment.
private static string _sizeNote = string.Empty;
private static long _sizeNoteUntilMs;
private static void StepSizeWithWheel(Entry entry)
{
ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();
if (!io.KeyCtrl || io.MouseWheel == 0f) return;
if (!ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.RootAndChildWindows | ImGuiHoveredFlags.AllowWhenBlockedByActiveItem)) return;
int dir = io.MouseWheel > 0f ? 1 : -1;
io.MouseWheel = 0f;
int pct;
if (entry.Spec.DrawScale)
{
int now = PanelDrawScale.Get(entry.Title);
if (now == 0) now = (int)MathF.Round(PanelTextScale.Factor(PanelTextScale.Get(entry.Title)) * 10f) * 10;
pct = Math.Clamp(now + dir * PanelDrawScale.Step, PanelDrawScale.Min, PanelDrawScale.Max);
PanelDrawScale.Set(entry.Title, pct);
}
else
{
int step = Math.Clamp(PanelTextScale.Get(entry.Title) + dir, 0, PanelTextScale.SizeNames.Length - 1);
PanelTextScale.SetForWindow(entry.Title, step);
pct = (int)MathF.Round(PanelTextScale.Factor(step) * 100f);
}
_sizeNote = $"{entry.Title}: {pct.ToString(System.Globalization.CultureInfo.InvariantCulture)}%";
_sizeNoteUntilMs = Environment.TickCount64 + 1200;
}
private static void DrawSizeNote()
{
if (_sizeNote.Length == 0 || Environment.TickCount64 > _sizeNoteUntilMs) return;
ImGuiNET.ImGui.SetTooltip(_sizeNote + " (Ctrl+wheel)");
}
private static bool HiddenWhileDocked(Entry entry)
@ -781,6 +837,10 @@ internal static class ImGuiPanelHost
{
pos = defaultPos; // the face's own first spot (a script window's FirstUseEver position)
}
else if (entry.Spec.OpenCorner != PanelCorner.None && CornerLogicalPos(entry.Spec.OpenCorner, size, placeScale) is Vector2 corner)
{
pos = corner;
}
else if (entry.Spec.OpenCentered && CenteredLogicalPos(size, placeScale) is Vector2 centered)
{
pos = centered;
@ -904,6 +964,19 @@ internal static class ImGuiPanelHost
return Vector2.Max(Vector2.Zero, (display / placeScale - size) * 0.5f);
}
/// <summary>A corner of the game view, 8 units in from its edges (logical units).</summary>
private static Vector2? CornerLogicalPos(PanelCorner corner, Vector2 size, float placeScale)
{
Vector2 display = ImGuiNET.ImGui.GetIO().DisplaySize;
if (display.X <= 1 || display.Y <= 1 || placeScale <= 0) return null;
Vector2 view = display / placeScale;
const float m = 8f;
float x = corner is PanelCorner.TopRight or PanelCorner.BottomRight ? view.X - size.X - m
: corner is PanelCorner.Top or PanelCorner.Bottom ? (view.X - size.X) * 0.5f : m;
float y = corner is PanelCorner.BottomLeft or PanelCorner.BottomRight or PanelCorner.Bottom ? view.Y - size.Y - m : m;
return Vector2.Max(Vector2.Zero, new Vector2(x, y));
}
private static Vector2 ClampToDisplay(Vector2 pos, Vector2 size)
{
Vector2 display = ImGuiNET.ImGui.GetIO().DisplaySize;
@ -1098,7 +1171,8 @@ internal static class ImGuiPanelHost
}
// Grip painted on top of the face when the body covers the corner
// (a GripInBody face's even while it lets clicks through: its slot stays).
if ((manualGrip || inlineGrip || (popped && !standard)) && gripRoom == 0f)
if ((manualGrip || inlineGrip || (popped && !standard)) && gripRoom == 0f
&& (!spec.GripOnHover || gHot || NearGrip(gMin, gSize)))
GripPaint(entry, uiScale, gMin, gHot, ImGuiNET.ImGui.GetWindowDrawList());
entry.BodyScrolls = ImGuiNET.ImGui.GetScrollMaxY() > 0f;
}
@ -1115,6 +1189,8 @@ internal static class ImGuiPanelHost
DrawGrip(entry, uiScale, minSize);
if (resizing) _pendingDragDelta = Vector2.Zero; // the face's window-drag doesn't also move it
StepSizeWithWheel(entry);
// A drag started from the panel's own surface (DragWindowWithLastItem).
if (popped) _pendingDragDelta = Vector2.Zero;
if (_pendingDragDelta != Vector2.Zero)
@ -1405,17 +1481,7 @@ internal static class ImGuiPanelHost
}
ImGuiNET.ImGui.PopStyleVar();
// Ctrl+wheel anywhere on the title bar steps this window's size. Only the
// header: the body's wheel belongs to the face (lists, chat, radar zoom).
// Popped out, the drag band is the window's own caption and never reaches
// ImGui, so there it works over the buttons.
ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();
if (!gone && io.KeyCtrl && io.MouseWheel != 0f
&& ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AllowWhenBlockedByActiveItem)
&& ImGuiNET.ImGui.IsMouseHoveringRect(winPos, winPos + new Vector2(width, h), false))
{
PanelTextScale.SetForWindow(entry.Title, step + (io.MouseWheel > 0f ? 1 : -1));
}
// Ctrl+wheel anywhere over the panel steps its size (StepSizeWithWheel, for every panel).
// Under the header, right-aligned to the button: never over a pop-out's drag band.
ImGuiNET.ImGui.SetNextWindowPos(winPos + new Vector2(tsX + btn, h), ImGuiCond.Appearing, new Vector2(1, 0));
@ -1537,6 +1603,10 @@ internal static class ImGuiPanelHost
/// <summary>The resize grip at the bottom-right (16 px, teal, rounded outer corner).</summary>
private static float GripSize(Entry entry, float s) => (entry.Spec.GoldGrip ? 14f : 16f) * s;
/// <summary>The mouse within a grip's width of the grip (PanelSpec.GripOnHover shows it then).</summary>
private static bool NearGrip(Vector2 gMin, float gSize) =>
ImGuiNET.ImGui.IsMouseHoveringRect(gMin - new Vector2(gSize, gSize), gMin + new Vector2(2 * gSize, 2 * gSize), false);
/// <summary>Top-left of the grip for a corner (bottom-right point).</summary>
private static Vector2 GripMin(Entry entry, float s, Vector2 corner)
{

View file

@ -58,6 +58,9 @@ internal sealed class ChatFace : IImGuiPanel
private readonly DashboardDrawers _drawers;
private bool _openTabsPopup;
/// <summary>/rc ui channels: the channels drawer opens or closes on the next draw, as its button does.</summary>
public static volatile bool ToggleChannelsRequested;
public ChatFace()
{
_channels = new ChannelsDrawer(this);
@ -1101,6 +1104,12 @@ internal sealed class ChatFace : IImGuiPanel
private void DrawPopups()
{
if (ToggleChannelsRequested)
{
ToggleChannelsRequested = false;
if (ImGuiPopOuts.InPopOutFrame) _openTabsPopup = true;
else _drawers.Toggle(_channels);
}
if (_openSettings)
{
_openSettings = false;

View file

@ -201,12 +201,7 @@ internal sealed class ClassicDashboard
ImGuiPanelHost.DragWindowWithLastItem();
SafeImGui.SetItemTooltip("Drag to move. Right-click: size. Ctrl+wheel: bigger or smaller.");
if (ImGuiNET.ImGui.IsItemClicked(ImGuiMouseButton.Right)) ImGuiNET.ImGui.OpenPopup(SizePopupId);
if (ImGuiNET.ImGui.IsItemHovered())
{
ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();
if (io.KeyCtrl && io.MouseWheel != 0f)
PanelTextScale.SetForWindow(RynthAiFace.Title, PanelTextScale.Get(RynthAiFace.Title) + (io.MouseWheel > 0f ? 1 : -1));
}
// Ctrl+wheel: the panel host steps its size (over any panel).
// "RynthAi" in gold, then the profile and what the bot is doing.
float tx = o.X + Px(10);

View file

@ -204,7 +204,7 @@ internal sealed class ClassicTuningTab : IClassicTab
case SettingKind.Int:
case SettingKind.Float:
case SettingKind.Double: return NumberRow(row, w);
case SettingKind.Combo when row.Items is { Length: > 0 }: ComboRow(ctx, row, w); return false;
case SettingKind.Combo when row.CurrentItems.Length > 0: ComboRow(ctx, row, w); return false;
default:
// The special rows (buttons, hotkeys, colours, server picker, status): the Settings panel's drawing.
_rows.DrawRow(row, w);
@ -296,7 +296,7 @@ internal sealed class ClassicTuningTab : IClassicTab
private void ComboRow(ClassicContext ctx, SettingRow row, float w)
{
RynthAiSettings data = _rows.Data;
string[] items = row.Items!;
string[] items = row.CurrentItems;
int cur = row.Get != null ? Math.Clamp((int)Math.Round(row.Get(data)), 0, items.Length - 1) : 0;
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
float rh = Px(22), ddW = Math.Min(Px(170), w * 0.55f);

View file

@ -373,7 +373,10 @@ internal sealed partial class MiniRemoteFace : IImGuiPanel
if (ready && io.KeyCtrl && io.MouseWheel != 0
&& ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.ChildWindows)
&& ImGuiNET.ImGui.IsMouseHoveringRect(start, start + new Vector2(w, shownH)))
{
ResizeSlots(io.MouseWheel > 0 ? SlotSizeStep : -SlotSizeStep);
io.MouseWheel = 0f; // the boxes took it: not the panel's size too
}
if (clicked >= 0 && ready) Click(data, items, clicked);
else if (clicked >= 0) ShowMessage(ItemHudStore.Loaded ? "Waiting for your character..." : "Loading...", Amber);

View file

@ -11,6 +11,10 @@
// (ImGuiStackGuard): whatever the plugin left open (colours, style vars, fonts,
// IDs, groups, child windows, tables...) is ended and popped there, so the
// panels drawn after it start clean; logged once per window, then counted.
// A "fitHeight" window (v90) takes the height the plugin's draw asks for
// (wantHeight) as its minimum and is fitted to it whenever it changes and the
// mouse is up (a frameless window's empty rows would still catch clicks meant
// for the game); a text size change scales its width along with its fonts.
// docs/PLUGIN_WINDOWS.md. AC's render thread.
// ============================================================================
@ -18,6 +22,7 @@ using System;
using System.Numerics;
using System.Text;
using RynthCore.Engine.Plugins;
using RynthCore.Engine.UI;
using static RynthCore.Engine.ImGuiBackend.Panels.FaceKit;
namespace RynthCore.Engine.ImGuiBackend.Panels;
@ -32,20 +37,37 @@ internal sealed class PluginWindowFace : IImGuiPanel
private long _failedAtMs = -1;
private const long RetryMs = 5000;
public PluginWindowFace(string plugin, string surface, string title)
// "fitHeight" (v90): the content height the plugin asked for (logical units; 0 = not known
// yet), and the text size factor and width (logical) the window was last fitted at.
private readonly bool _fitHeight;
private readonly float _minWidth;
private float _contentHeight, _fitK, _fitWidth;
public PluginWindowFace(string plugin, string surface, string title, bool fitHeight = false, float minWidth = 0f)
{
_plugin = plugin;
_title = title;
_surface = Encoding.UTF8.GetBytes(surface + "\0");
_idScope = "##pw_" + surface;
_fitHeight = fitHeight;
_minWidth = minWidth;
}
/// <summary>A fitHeight window's minimum: its minimum width at its text size, and the content's height.</summary>
public Vector2? MinSize => _fitHeight && _contentHeight > 0f
? new Vector2(_minWidth * TextFactor(), _contentHeight)
: null;
/// <summary>The panel's text size factor at the size its fonts are baked for.</summary>
private float TextFactor() => PanelTextScale.Factor(ImGuiFonts.BakedStepNear(PanelTextScale.Get(_title)));
public void Draw()
{
Vector2 start = ImGuiNET.ImGui.GetCursorScreenPos();
Vector2 avail = ImGuiNET.ImGui.GetContentRegionAvail();
long now = Environment.TickCount64;
int result = PluginManager.EmbedFailed;
Vector2 want = Vector2.Zero;
if (_failedAtMs < 0 || now - _failedAtMs >= RetryMs)
{
// Two stack records: the body's base (where a recovery goes back to: the panel host
@ -57,7 +79,7 @@ internal sealed class PluginWindowFace : IImGuiPanel
ImGuiNET.ImGui.PushID(_idScope);
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui11));
ImGuiStackGuard.Mark given = guarded ? ImGuiStackGuard.Take() : default;
try { result = PluginManager.RenderEmbed(_plugin, _surface, avail, out _); }
try { result = PluginManager.RenderEmbed(_plugin, _surface, avail, out want); }
finally
{
ImGuiStackGuard.Mark after = default;
@ -78,7 +100,11 @@ internal sealed class PluginWindowFace : IImGuiPanel
else if (result == PluginManager.EmbedDrawn) _failedAtMs = -1;
else if (_failedAtMs >= 0) { _failedAtMs = now; result = PluginManager.EmbedFailed; } // still off since the throw
}
if (result == PluginManager.EmbedDrawn) return;
if (result == PluginManager.EmbedDrawn)
{
if (_fitHeight) Fit(want.Y, avail.X);
return;
}
ImGuiNET.ImGui.SetCursorScreenPos(start + new Vector2(6, 6));
Label(result switch
@ -89,6 +115,39 @@ internal sealed class PluginWindowFace : IImGuiPanel
}, Mute);
}
/// <summary>
/// fitHeight: keeps the window as tall as the content the plugin drew (<paramref name="wantPx"/>,
/// client px) and scales its width with a text size change. Docked only (popped out, the OS window
/// is the player's to size); never while the mouse is down, so a drag or a resize isn't fought.
/// </summary>
private void Fit(float wantPx, float widthPx)
{
if (wantPx <= 0f || ImGuiPopOuts.InPopOutFrame) return;
float place = Math.Max(0.01f, ImGuiPanelHost.PlacementScale());
float height = MathF.Ceiling(wantPx / place);
float width = widthPx / place;
float k = PanelTextScale.Factor(ImGuiFonts.CurrentStep);
float shownHeight = ImGuiNET.ImGui.GetWindowHeight() / place;
bool mouseUp = !ImGuiNET.ImGui.IsMouseDown(ImGuiNET.ImGuiMouseButton.Left);
_contentHeight = height;
if (_fitK > 0f && MathF.Abs(k - _fitK) > 0.001f)
{
// A text size change: the width from the one it had at the old size.
width = MathF.Max(_fitWidth * (k / _fitK), _minWidth * k);
float screenW = ImGuiNET.ImGui.GetIO().DisplaySize.X / place;
if (screenW > 1f) width = MathF.Min(width, screenW);
ImGuiPanelHost.RequestSize(_title, new Vector2(width, height));
// Clamped to the screen at the new size: near the right or bottom edge it moves in.
ImGuiPanelHost.RequestPos(_title, ImGuiNET.ImGui.GetWindowPos() / place);
}
else if (mouseUp && MathF.Abs(shownHeight - height) > 0.5f)
{
ImGuiPanelHost.RequestSize(_title, new Vector2(width, height));
}
_fitK = k;
_fitWidth = width;
}
// Unbalanced draws by plugin + surface: logged the first time, then every RepeatEvery-th.
private static readonly System.Collections.Generic.Dictionary<string, int> Unbalanced = new(StringComparer.Ordinal);
private const int RepeatEvery = 1000;

View file

@ -78,16 +78,34 @@ internal sealed class QuickSettingsDrawer : RynthAiDrawer
ImGuiNET.ImGui.OpenPopup(AddPopupId);
}
ImGuiNET.ImGui.SetItemTooltip("Pin or unpin settings");
DrawBody(x, y, w, MathF.Max(1, origin.Y + panelH - Pad * k - y), k, openPicker: false);
}
/// <summary>
/// The pinned rows at (<paramref name="x"/>, <paramref name="y"/>) in a <paramref name="w"/> x
/// <paramref name="h"/> child that scrolls (RynthAi's own dashboard window draws the frame and the
/// + button: <paramref name="openPicker"/> opens the pin list at the mouse, SettingsDrawerBodies).
/// Returns the rows' height (pixels).
/// </summary>
public float DrawBody(float x, float y, float w, float h, float k, bool openPicker)
{
if (openPicker)
{
_filter = string.Empty;
ImGuiNET.ImGui.SetNextWindowPos(ImGuiNET.ImGui.GetMousePos() + new Vector2(0, 8 * k), ImGuiCond.Always, new Vector2(1, 0));
ImGuiNET.ImGui.OpenPopup(AddPopupId);
}
AddPopup(k);
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(x, y));
Vector2 size = new(w, MathF.Max(1, origin.Y + panelH - Pad * k - y));
Vector2 size = new(w, MathF.Max(1, h));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
bool open = ImGuiNET.ImGui.BeginChild("##quick_body", size, ImGuiChildFlags.None, ImGuiWindowFlags.NoBackground);
ImGuiNET.ImGui.PopStyleVar();
float contentH = EmptyH * k;
try
{
if (!open) return;
if (!open) return contentH;
_rows.Sync();
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui11));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 0));
@ -116,6 +134,8 @@ internal sealed class QuickSettingsDrawer : RynthAiDrawer
ImGuiNET.ImGui.PopTextWrapPos();
ImGuiNET.ImGui.PopStyleColor();
}
// What the rows took (unscrolled), for a host that fits its height to them.
contentH = ImGuiNET.ImGui.GetCursorPosY() + 2 * k; // content space: the scroll is in it
}
finally
{
@ -124,6 +144,7 @@ internal sealed class QuickSettingsDrawer : RynthAiDrawer
}
}
finally { ImGuiNET.ImGui.EndChild(); }
return contentH;
}
/// <summary>A pinned row's right-click, after Remove: Move up / Move down.</summary>

View file

@ -158,10 +158,18 @@ internal sealed class RangesSlideOut : RynthAiDrawer
public override void DrawPanel(Vector2 origin, float panelW, float panelH, float k)
{
var dl = ImGuiNET.ImGui.GetWindowDrawList();
// Title row: ruler + RANGES (yards) | close.
float y = PanelFrame(origin, panelW, panelH, k, PhosphorIcons.Ruler, "RANGES", "yards", "Hide the ranges");
float x = origin.X + Pad * k, w = panelW - 2 * Pad * k;
DrawBody(origin.X + Pad * k, y, panelW - 2 * Pad * k, k);
}
/// <summary>The body's height under the title row (pixels): RynthAi's own dashboard window draws the frame (SettingsDrawerBodies).</summary>
public static float BodyHeight(float k) => (3 * LineH + 6 + 3 + Math.Max(1, Rows.Length) * (RowH + RowGap)) * k;
/// <summary>The selected monster and the range rows at (<paramref name="x"/>, <paramref name="y"/>), <paramref name="w"/> wide.</summary>
public void DrawBody(float x, float y, float w, float k)
{
var dl = ImGuiNET.ImGui.GetWindowDrawList();
ImFontPtr f10 = ImGuiFonts.Get(UiFont.Dash10);
MonsterBlock(dl, x, y, w, k);

View file

@ -100,8 +100,14 @@ internal sealed partial class RynthAiFace
}
}
/// <summary>The Dungeon Patrol settings, hazard cells and saved routes (the Patrol launcher's right-click).</summary>
private sealed class PatrolDrawer : RynthAiDrawer
/// <summary>The size factor the static helpers (Px) draw at, for a drawer body drawn outside the face (SettingsDrawerBodies).</summary>
internal static void UseScale(float k) => _k = k;
/// <summary>
/// The Dungeon Patrol settings, hazard cells and saved routes (the Patrol launcher's right-click).
/// Internal: RynthAi's own dashboard window shows its body too (SettingsDrawerBodies).
/// </summary>
internal sealed class PatrolDrawer : RynthAiDrawer
{
private bool _sub;
// Settings > Navigation > Dungeon Patrol, drawn here too (2026-10-14).
@ -147,13 +153,24 @@ internal sealed partial class RynthAiFace
{
float y = PanelFrame(origin, panelW, panelH, k, PhosphorIcons.Footprints, "PATROL & ROUTES", null, "Hide the patrol drawer");
float x = origin.X + Pad * k;
DrawBody(x, y, panelW - 2 * Pad * k, MathF.Max(1, origin.Y + panelH - Pad * k - y), k);
}
/// <summary>
/// Start patrol, the settings and the lists in a <paramref name="w"/> x <paramref name="h"/> child at
/// (<paramref name="x"/>, <paramref name="y"/>) that scrolls. Returns what they took (pixels), for a
/// host that fits its height to them (RynthAi's own dashboard window, SettingsDrawerBodies).
/// </summary>
public float DrawBody(float x, float y, float w, float h, float k)
{
// A scrolling child for the lists. A child window is clipped to its parent's clip rect,
// so the host's slide clip covers it too.
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(x, y));
Vector2 size = new(panelW - 2 * Pad * k, MathF.Max(1, origin.Y + panelH - Pad * k - y));
Vector2 size = new(w, MathF.Max(1, h));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
bool open = ImGuiNET.ImGui.BeginChild("##patrol_body", size, ImGuiChildFlags.None, ImGuiWindowFlags.NoBackground);
ImGuiNET.ImGui.PopStyleVar();
float contentH = 200 * k;
try
{
if (open)
@ -165,7 +182,7 @@ internal sealed partial class RynthAiFace
// The settings, with the Settings panel's rows (right-click one to pin it to My settings).
Section("SETTINGS");
_rows.Sync();
float w = ImGuiNET.ImGui.GetContentRegionAvail().X - 2 * k;
float rw = ImGuiNET.ImGui.GetContentRegionAvail().X - 2 * k;
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui11));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 0));
SettingRow[] rows = SettingRows;
@ -173,7 +190,7 @@ internal sealed partial class RynthAiFace
{
if (!rows[i].IsVisible(_rows.Data)) continue;
ImGuiNET.ImGui.PushID(i);
_rows.DrawRow(rows[i], w);
_rows.DrawRow(rows[i], rw);
ImGuiNET.ImGui.PopID();
}
ImGuiNET.ImGui.PopStyleVar();
@ -181,9 +198,11 @@ internal sealed partial class RynthAiFace
PatrolInfo info = UiSources.Patrol.Current?.Value ?? new PatrolInfo();
PatrolBody(info, withTitle: false);
contentH = ImGuiNET.ImGui.GetCursorPosY() + 2 * k; // content space: the scroll is in it
}
}
finally { ImGuiNET.ImGui.EndChild(); }
return contentH;
}
}

View file

@ -410,9 +410,7 @@ internal sealed partial class RynthAiFace : IImGuiPanel
if (ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AllowWhenBlockedByActiveItem)
&& ImGuiNET.ImGui.IsMouseHoveringRect(new Vector2(x0, y), new Vector2(x0 + width, y + rowH), false))
{
ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();
if (io.KeyCtrl && io.MouseWheel != 0f)
PanelTextScale.SetForWindow(Title, PanelTextScale.Get(Title) + (io.MouseWheel > 0f ? 1 : -1));
// Ctrl+wheel: the panel host steps its size (over any panel).
if (ImGuiNET.ImGui.IsMouseClicked(ImGuiMouseButton.Right))
ImGuiNET.ImGui.OpenPopup(SizePopupId);
}

View file

@ -0,0 +1,112 @@
// ============================================================================
// RynthCore.Engine - ImGui/Panels/SettingsDrawerBodies.cs
// The dashboard drawers that show Settings rows, drawn into RynthAi's own
// dashboard window (2026-10-21, plugin API v90 RenderSettingsDrawer). RynthAi
// draws its dashboard itself now, its drawers' tabs and frames included, but
// three drawers show the Settings panel's rows, and the Settings panel is still
// RynthCore's: until it moves to RynthAi, RynthAi's drawer windows ask for
// these bodies here (the frame and the title row are RynthAi's):
// ranges the selected monster and the key ranges (RangesSlideOut.cs)
// patrol Start patrol, the Dungeon Patrol settings, this dungeon's hazard
// cells, the recorded hazards and the saved routes (the Patrol
// drawer, RynthAiFace.Drawers.cs)
// pinned My settings, the rows the player pinned (QuickSettingsDrawer.cs)
// Each is the same drawer the engine's own dashboard shows, so a value changed
// here is saved the same way and a pin made here is the same pin. A drawer
// that wasn't drawn in a frame drops its hub subscriptions (EndFrame).
//
// AC thread only (inside RynthAi's window, and EndFrame after the panels).
// ============================================================================
using System;
using System.Numerics;
using RynthCore.Engine.UI;
namespace RynthCore.Engine.ImGuiBackend.Panels;
internal static class SettingsDrawerBodies
{
private static RangesSlideOut? _ranges;
private static RynthAiFace.PatrolDrawer? _patrol;
private static QuickSettingsDrawer? _pinned;
// The frame each was last drawn in (EndFrame counts frames).
private static long _frame, _rangesDrawn = -1, _patrolDrawn = -1, _pinnedDrawn = -1;
/// <summary>
/// Draws <paramref name="key"/>'s body at the cursor, <paramref name="width"/> pixels wide, in at most
/// <paramref name="room"/> pixels of height (0: as tall as it wants); <paramref name="openPicker"/>:
/// open My settings' list of settings to pin. Returns the height it wants (pixels), or -1 for a key
/// that isn't one of these.
/// </summary>
public static float Draw(string key, float width, float room, bool openPicker)
{
Vector2 at = ImGuiNET.ImGui.GetCursorScreenPos();
float w = MathF.Max(1, width);
float k = MathF.Max(1f, ImGuiFonts.Get(UiFont.Dash11).FontSize / 11f);
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Dash10));
try
{
switch (key)
{
case "ranges":
{
_ranges ??= new RangesSlideOut();
_rangesDrawn = _frame;
_ranges.Update(true);
float h = RangesSlideOut.BodyHeight(k);
ImGuiNET.ImGui.PushID("##sdb_ranges");
try { _ranges.DrawBody(at.X, at.Y, w, k); }
finally { ImGuiNET.ImGui.PopID(); }
ImGuiNET.ImGui.SetCursorScreenPos(at);
ImGuiNET.ImGui.Dummy(new Vector2(w, h));
return h;
}
case "patrol":
{
_patrol ??= new RynthAiFace.PatrolDrawer();
_patrolDrawn = _frame;
_patrol.Update(true);
RynthAiFace.UseScale(k);
float h = room > 0 ? room : 400 * k;
float want;
ImGuiNET.ImGui.PushID("##sdb_patrol");
try { want = _patrol.DrawBody(at.X, at.Y, w, h, k); }
finally { ImGuiNET.ImGui.PopID(); }
ImGuiNET.ImGui.SetCursorScreenPos(at);
ImGuiNET.ImGui.Dummy(new Vector2(w, h));
return want;
}
case "pinned":
{
_pinned ??= new QuickSettingsDrawer();
_pinnedDrawn = _frame;
_pinned.Update(true);
float h = room > 0 ? room : 120 * k;
float want;
ImGuiNET.ImGui.PushID("##sdb_pinned");
try { want = _pinned.DrawBody(at.X, at.Y, w, h, k, openPicker); }
finally { ImGuiNET.ImGui.PopID(); }
ImGuiNET.ImGui.SetCursorScreenPos(at);
ImGuiNET.ImGui.Dummy(new Vector2(w, h));
return want;
}
default:
return -1f;
}
}
finally
{
ImGuiNET.ImGui.PopFont();
}
}
/// <summary>After the panels each frame: a body that wasn't drawn this frame lets its hub sources go.</summary>
public static void EndFrame()
{
if (_ranges != null && _rangesDrawn != _frame) _ranges.Update(false);
if (_patrol != null && _patrolDrawn != _frame) _patrol.Update(false);
if (_pinned != null && _pinnedDrawn != _frame) _pinned.Update(false);
_frame++;
}
}

View file

@ -416,7 +416,8 @@ internal sealed class SettingsRows
private void ComboRow(SettingRow row, float w)
{
var dl = ImGuiNET.ImGui.GetWindowDrawList();
string[] items = row.Items!;
string[] items = row.CurrentItems;
if (items.Length == 0) return;
int current = Math.Clamp((int)row.Get!(_data), 0, items.Length - 1);
ImGuiNET.ImGui.Dummy(new Vector2(0, 2));
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();

View file

@ -172,7 +172,8 @@ internal static unsafe class PhosphorIcons
+ Binoculars + Crown + Sun
+ CastleTurret + ClockCounterClockwise + GlobeHemisphereWest + Path + Star + Target + User
+ TextAa + Leaf + Keyboard
+ PushPin + SlidersHorizontal + Wrench;
+ PushPin + SlidersHorizontal + Wrench
+ Scroll;
/// <summary>
/// Draws <paramref name="glyph"/> (one icon) centred in the box at

View file

@ -7,7 +7,8 @@
//
// Colour themes (Tom 2026-10-14): the structural colours come from a palette
// the player can change in Settings > Display: a preset (RynthCore, Ember,
// Verdant, Amethyst, Crimson, Slate) or their own eight colours (accent,
// Verdant, Amethyst, Crimson, Slate, and since 2026-10-21 Brass, Volt and
// Ivory, the instrument dashboard's three) or their own eight colours (accent,
// highlight, background, title bars, buttons, borders, text, muted text).
// The other shades (selected rows, fields, hover, the dashboard's border...)
// are worked out from those eight; the RynthCore preset keeps every original
@ -15,8 +16,9 @@
// toggles, radar gold) don't follow the theme. The faces read the tokens
// (properties) every frame, so a change shows at once; the base ImGui style
// is re-coloured before the next frame (RefreshStyle, each ImGui context).
// Saved to %AppData%\RynthCore\theme.txt (preset=, then name=AARRGGBB for a
// custom palette's eight colours).
// Saved to %AppData%\RynthCore\theme.txt (preset=, then name=AARRGGBB for the
// player's own eight colours, kept whichever theme is in use since 2026-10-22);
// the schemes a player saved are in ThemeSchemes.cs.
//
// Apply() sets the base style once at context creation; per-window colours
// (bar, RynthAi, Radar) are pushed around Begin by the panel host.
@ -45,6 +47,10 @@ internal sealed class ThemePalette
public uint AccentFill, AccentAlt, BoxBg, Field, Selected, WindowBorder, DashBorder, PanelGlass, BarBg, FrameBg,
FrameHover, FrameActive, BarButtonBorder, RowAlt, MuteAlt, StyleText, PopupBg, FrameBgHover, FrameBgActive, SliderGrab;
// The instrument look's shades (2026-10-21, plugin windows: UiColorToken KeyFace..Faint), worked
// out from the eight for every palette, Default included (DeriveInstrument).
public uint KeyFace, Hairline, Inset, Faint;
/// <summary>A copy (its own array of the eight).</summary>
public ThemePalette Clone()
{
@ -55,6 +61,7 @@ internal sealed class ThemePalette
FrameHover = FrameHover, FrameActive = FrameActive, BarButtonBorder = BarButtonBorder, RowAlt = RowAlt,
MuteAlt = MuteAlt, StyleText = StyleText, PopupBg = PopupBg, FrameBgHover = FrameBgHover,
FrameBgActive = FrameBgActive, SliderGrab = SliderGrab,
KeyFace = KeyFace, Hairline = Hairline, Inset = Inset, Faint = Faint,
};
Array.Copy(P, c.P, Primaries);
return c;
@ -71,6 +78,7 @@ internal sealed class ThemePalette
t.BarBg = 0xFF0A0A14; t.FrameBg = 0xFF1A2230; t.FrameHover = 0xFF2A3850; t.FrameActive = 0xFF34466A;
t.BarButtonBorder = 0xFF3A4A5A; t.RowAlt = 0xFF101822; t.MuteAlt = 0xFFC8D6E4; t.StyleText = 0xFFE6E6E6;
t.PopupBg = 0xFF14141E; t.FrameBgHover = 0xFF243044; t.FrameBgActive = 0xFF2C3A52; t.SliderGrab = 0xFF26A18C;
t.DeriveInstrument();
return t;
}
@ -107,6 +115,20 @@ internal sealed class ThemePalette
FrameBgHover = Mix(FrameBg, FrameHover, 0.50f);
FrameBgActive = Mix(FrameHover, FrameActive, 0.50f);
SliderGrab = Mix(AccentAlt, bg, 0.17f);
DeriveInstrument();
}
/// <summary>
/// The instrument look's shades from the eight: a key's face (a step up from the background),
/// the hairlines, the inset wells (the activity line, bar tracks) and the faint text.
/// </summary>
public void DeriveInstrument()
{
uint bg = P[2], button = P[4], border = P[5], muted = P[7];
KeyFace = Mix(bg, button, 0.60f);
Hairline = Mix(bg, border, 0.45f);
Inset = Mix(bg, 0xFF000000, 0.45f);
Faint = Mix(muted, bg, 0.28f);
}
/// <summary>#AARRGGBB mix: <paramref name="t"/> of the way from <paramref name="a"/> to <paramref name="b"/>, opaque.</summary>
@ -120,7 +142,10 @@ internal sealed class ThemePalette
}
// ── Presets ─────────────────────────────────────────────────────────
public static readonly string[] PresetNames = { "RynthCore", "Ember", "Verdant", "Amethyst", "Crimson", "Slate" };
// Brass, Volt and Ivory (2026-10-21): the instrument dashboard's three, from its Claude Design
// canvas. Their Buttons and Borders are chosen so DeriveInstrument lands on the canvas's key
// face and hairline; appended, so the older presets keep their places in the picker.
public static readonly string[] PresetNames = { "RynthCore", "Ember", "Verdant", "Amethyst", "Crimson", "Slate", "Brass", "Volt", "Ivory" };
public static ThemePalette Preset(int index) => index switch
{
@ -129,6 +154,9 @@ internal sealed class ThemePalette
3 => From(0xB98CFF, 0xFFC857, 0x0F0A16, 0x1C1428, 0x2A1C40, 0x5A4A8A, 0xF6F2FC, 0xCBBEDC),
4 => From(0xFF5C6C, 0xFFC857, 0x140A0C, 0x241216, 0x3A161E, 0x7A3442, 0xFCF2F3, 0xD8B8BE),
5 => From(0xD0D8E0, 0xF0C060, 0x0E0F11, 0x1A1C20, 0x24282E, 0x4A5260, 0xF4F5F7, 0xB4BAC2),
6 => From(0xE3B662, 0x85C7B2, 0x12100D, 0x1C1915, 0x26221E, 0x595349, 0xEEE9DC, 0xB0A89B),
7 => From(0xCBF559, 0xF7B245, 0x0E1115, 0x161A1F, 0x1F2329, 0x4C5661, 0xEDF0F4, 0xA7ADB5),
8 => From(0xFCF7E7, 0xF7B245, 0x100F0E, 0x191918, 0x222322, 0x535451, 0xF1EEE6, 0xABA9A5),
_ => Default(),
};
@ -157,7 +185,8 @@ internal static class RynthTheme
{
public uint Accent, Highlight, Background, TitleBar, Button, Border, Text, TextMuted,
AccentFill, AccentAlt, BoxBg, Field, Selected, WindowBorder, DashBorder, PanelGlass, BarBg, FrameBg,
FrameHover, FrameActive, BarButtonBorder, RowAlt, MuteAlt, StyleText, PopupBg, FrameBgHover, FrameBgActive, SliderGrab;
FrameHover, FrameActive, BarButtonBorder, RowAlt, MuteAlt, StyleText, PopupBg, FrameBgHover, FrameBgActive, SliderGrab,
KeyFace, Hairline, Inset, Faint;
public Tokens(ThemePalette p)
{
@ -169,6 +198,7 @@ internal static class RynthTheme
FrameActive = Argb(p.FrameActive); BarButtonBorder = Argb(p.BarButtonBorder); RowAlt = Argb(p.RowAlt);
MuteAlt = Argb(p.MuteAlt); StyleText = Argb(p.StyleText); PopupBg = Argb(p.PopupBg);
FrameBgHover = Argb(p.FrameBgHover); FrameBgActive = Argb(p.FrameBgActive); SliderGrab = Argb(p.SliderGrab);
KeyFace = Argb(p.KeyFace); Hairline = Argb(p.Hairline); Inset = Argb(p.Inset); Faint = Argb(p.Faint);
}
}
@ -206,6 +236,11 @@ internal static class RynthTheme
public static uint BarButtonBorder => _t.BarButtonBorder;
public static uint RowAlt => _t.RowAlt;
public static uint MuteAlt => _t.MuteAlt;
// ...and the instrument look's (plugin windows, UiColorToken KeyFace..Faint):
public static uint KeyFace => _t.KeyFace;
public static uint Hairline => _t.Hairline;
public static uint Inset => _t.Inset;
public static uint Faint => _t.Faint;
// ── Bar (AvaloniaOverlay.cs BuildRoot) ─────────────────────────────
public static uint BarBackground => WithAlpha(_t.BarBg, 0xE6);
@ -243,30 +278,74 @@ internal static class RynthTheme
public static readonly uint RadarGripHover = Argb(0xA00A121A);
// ── Choosing a theme (Settings > Display) ───────────────────────────
//
// Three kinds of theme (Tom 2026-10-22: a new preset must never cost a player the colours they
// made, and players can keep their own schemes):
// a preset RynthCore, Ember ... Brass, Volt, Ivory (ThemePalette.PresetNames)
// a saved scheme a named set of the eight the player saved (ThemeSchemes, themes\*.theme)
// Custom the player's own eight colours. Kept whichever theme is in use and always
// written to theme.txt, so picking Custom again brings them back.
// Changing a colour makes the theme Custom with that change; when the player's own colours would
// be replaced that way (the change was made on a preset or a scheme) and aren't kept anywhere
// else, they are saved as a scheme first ("My colours"), so no click loses them.
/// <summary>The preset in use (ThemePalette.PresetNames index), or Custom.</summary>
public const int Scheme = -2;
private static ThemePalette _custom = ThemePalette.Default(); // the player's own eight (Custom)
private static bool _customSet; // theme.txt had them, or the player made them
private static string _scheme = string.Empty; // the saved scheme in use (Scheme)
/// <summary>The preset in use (ThemePalette.PresetNames index), Scheme, or Custom.</summary>
public static int Preset { get { EnsureLoaded(); return _preset; } }
/// <summary>Settings' Theme picker: the presets, then "Custom" while the player's own colours are in use.</summary>
public static readonly string[] PickerNames = BuildPickerNames();
public static int PickerIndex => Preset == Custom ? PickerNames.Length - 1 : Preset;
/// <summary>The saved scheme in use ("" unless <see cref="Preset"/> is Scheme).</summary>
public static string SchemeName { get { EnsureLoaded(); lock (Sync) return _preset == Scheme ? _scheme : string.Empty; } }
private static string[] BuildPickerNames()
public static bool SchemeInUse => Preset == Scheme;
/// <summary>Settings' Theme picker now: the presets, the saved schemes, then Custom.</summary>
public static string[] PickerNames()
{
var names = new string[ThemePalette.PresetNames.Length + 1];
string[] schemes = ThemeSchemes.Names;
var names = new string[ThemePalette.PresetNames.Length + schemes.Length + 1];
Array.Copy(ThemePalette.PresetNames, names, ThemePalette.PresetNames.Length);
Array.Copy(schemes, 0, names, ThemePalette.PresetNames.Length, schemes.Length);
names[^1] = "Custom";
return names;
}
/// <summary>Uses preset <paramref name="index"/> (the picker's last item, Custom, keeps the colours as they are).</summary>
public static int PickerIndex
{
get
{
int p = Preset;
string[] schemes = ThemeSchemes.Names;
if (p >= 0) return p;
if (p == Scheme)
{
int i = Array.FindIndex(schemes, n => n.Equals(SchemeName, StringComparison.OrdinalIgnoreCase));
if (i >= 0) return ThemePalette.PresetNames.Length + i;
}
return ThemePalette.PresetNames.Length + schemes.Length;
}
}
/// <summary>The picker's item <paramref name="index"/>: a preset, a saved scheme, or Custom (the player's own colours).</summary>
public static void SetPicker(int index)
{
if (index >= 0 && index < ThemePalette.PresetNames.Length) { SetPreset(index); return; }
string[] schemes = ThemeSchemes.Names;
int s = index - ThemePalette.PresetNames.Length;
if (s >= 0 && s < schemes.Length) { UseScheme(schemes[s]); return; }
UseCustom();
}
/// <summary>Uses preset <paramref name="index"/>; out of range means Custom (the player's own colours).</summary>
public static void SetPreset(int index)
{
EnsureLoaded();
if (index < 0 || index >= ThemePalette.PresetNames.Length)
{
lock (Sync) _preset = Custom;
Changed();
UseCustom();
return;
}
lock (Sync)
@ -277,6 +356,72 @@ internal static class RynthTheme
Changed();
}
/// <summary>The player's own colours (Custom), as they last left them.</summary>
public static void UseCustom()
{
EnsureLoaded();
lock (Sync)
{
_preset = Custom;
_palette = _custom.Clone();
}
Changed();
}
/// <summary>A saved scheme by name; false when there is none by that name (or it can't be read).</summary>
public static bool UseScheme(string name)
{
EnsureLoaded();
ThemePalette? p = ThemeSchemes.Load(name);
if (p == null) return false;
lock (Sync)
{
_preset = Scheme;
_scheme = ThemeSchemes.DisplayName(name);
_palette = p;
}
Changed();
return true;
}
/// <summary>
/// Saves the colours in use as scheme <paramref name="name"/> (replacing one of that name) and
/// switches to it. Returns the name saved, or "" for an empty or unusable name.
/// </summary>
public static string SaveScheme(string name)
{
EnsureLoaded();
name = ThemeSchemes.CleanName(name);
if (name.Length == 0) return string.Empty;
ThemePalette p;
lock (Sync) p = _palette.Clone();
if (!ThemeSchemes.Save(name, p)) return string.Empty;
lock (Sync)
{
_preset = Scheme;
_scheme = name;
}
Changed();
return name;
}
/// <summary>Deletes the scheme in use; its colours stay on screen as the player's own (Custom).</summary>
public static bool DeleteCurrentScheme()
{
EnsureLoaded();
string name = SchemeName;
if (name.Length == 0 || !ThemeSchemes.Delete(name)) return false;
lock (Sync)
{
_custom = _palette.Clone();
_customSet = true;
_preset = Custom;
_scheme = string.Empty;
}
Changed();
return true;
}
/// <summary>One of the eight colours (#AARRGGBB).</summary>
public static uint GetPrimary(int i)
{
@ -284,20 +429,33 @@ internal static class RynthTheme
lock (Sync) return _palette.P[Math.Clamp(i, 0, ThemePalette.Primaries - 1)];
}
/// <summary>Changes one of the eight colours (#RRGGBB, opaque): the theme becomes Custom and its shades follow.</summary>
/// <summary>
/// Changes one of the eight colours (#RRGGBB, opaque): the theme becomes Custom with the change and
/// its shades follow. Made on a preset or a scheme, it replaces the player's own colours, which are
/// saved as a scheme first when they aren't kept anywhere yet.
/// </summary>
public static void SetPrimary(int i, uint argb)
{
EnsureLoaded();
if (i < 0 || i >= ThemePalette.Primaries) return;
argb |= 0xFF000000;
ThemePalette? keep = null;
lock (Sync)
{
if (_palette.P[i] == argb) return;
if (_preset != Custom && _customSet) keep = _custom.Clone();
}
if (keep != null) ThemeSchemes.KeepIfNew("My colours", keep);
lock (Sync)
{
var p = _palette.Clone();
p.P[i] = argb;
p.Derive();
_palette = p;
_custom = p.Clone();
_customSet = true;
_preset = Custom;
_scheme = string.Empty;
}
Changed();
}
@ -321,7 +479,12 @@ internal static class RynthTheme
ApplyColors(ImGuiNET.ImGui.GetStyle());
}
/// <summary>Reads theme.txt if it hasn't been read yet. Engine init calls this so AC's thread never does.</summary>
/// <summary>
/// Reads theme.txt if it hasn't been read yet. Engine init calls this so AC's thread never does.
/// "preset=" names a preset, "scheme:Name" a saved scheme, or Custom; the eight colour lines are the
/// player's own colours whatever the preset (before 2026-10-22 they were written only for Custom).
/// A scheme that is gone falls back to the player's own colours.
/// </summary>
public static void EnsureLoaded()
{
if (_loaded) return;
@ -333,7 +496,9 @@ internal static class RynthTheme
if (File.Exists(FilePath))
{
int preset = 0;
string scheme = string.Empty;
var custom = ThemePalette.Default();
bool anyColour = false;
foreach (string raw in File.ReadAllLines(FilePath))
{
string line = raw.Trim();
@ -342,6 +507,12 @@ internal static class RynthTheme
string key = line[..eq].Trim(), value = line[(eq + 1)..].Trim();
if (key.Equals("preset", StringComparison.OrdinalIgnoreCase))
{
if (value.StartsWith("scheme:", StringComparison.OrdinalIgnoreCase))
{
scheme = value["scheme:".Length..].Trim();
preset = Scheme;
continue;
}
int idx = Array.FindIndex(ThemePalette.PresetNames, n => n.Equals(value, StringComparison.OrdinalIgnoreCase));
preset = idx >= 0 ? idx : Custom;
continue;
@ -349,11 +520,19 @@ internal static class RynthTheme
for (int i = 0; i < ThemePalette.Primaries; i++)
if (key.Equals(ThemePalette.Key(i), StringComparison.OrdinalIgnoreCase)
&& uint.TryParse(value, System.Globalization.NumberStyles.HexNumber, null, out uint c))
{
custom.P[i] = 0xFF000000 | c;
anyColour = true;
}
}
custom.Derive();
_custom = custom;
_customSet = anyColour;
ThemePalette? fromScheme = preset == Scheme ? ThemeSchemes.Load(scheme) : null;
if (preset == Scheme && fromScheme == null) preset = Custom;
_preset = preset;
if (preset == Custom) { custom.Derive(); _palette = custom; }
else _palette = ThemePalette.Preset(preset);
_scheme = preset == Scheme ? ThemeSchemes.DisplayName(scheme) : string.Empty;
_palette = preset == Custom ? custom.Clone() : preset == Scheme ? fromScheme! : ThemePalette.Preset(preset);
_t = new Tokens(_palette);
_version++;
}
@ -363,8 +542,13 @@ internal static class RynthTheme
}
}
private static string FilePath =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore", "theme.txt");
/// <summary>%AppData%\RynthCore, or RYNTHCORE_THEME_DIR when set (tools\ThemeTests' temp folder).</summary>
internal static string Folder =>
Environment.GetEnvironmentVariable("RYNTHCORE_THEME_DIR") is { Length: > 0 } dir
? dir
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore");
private static string FilePath => Path.Combine(Folder, "theme.txt");
private static void Save()
{
@ -373,10 +557,13 @@ internal static class RynthTheme
var sb = new System.Text.StringBuilder();
lock (Sync)
{
sb.Append("preset=").Append(_preset == Custom ? "Custom" : ThemePalette.PresetNames[_preset]).Append('\n');
if (_preset == Custom)
sb.Append("preset=")
.Append(_preset == Custom ? "Custom" : _preset == Scheme ? "scheme:" + _scheme : ThemePalette.PresetNames[_preset])
.Append('\n');
// The player's own colours, whatever is in use (an older engine reads them only for Custom).
if (_customSet || _preset == Custom)
for (int i = 0; i < ThemePalette.Primaries; i++)
sb.Append(ThemePalette.Key(i)).Append('=').Append((_palette.P[i] & 0xFFFFFF).ToString("X6")).Append('\n');
sb.Append(ThemePalette.Key(i)).Append('=').Append((_custom.P[i] & 0xFFFFFF).ToString("X6")).Append('\n');
}
Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!);
File.WriteAllText(FilePath, sb.ToString());

View file

@ -0,0 +1,230 @@
// ============================================================================
// RynthCore.Engine - ImGui/ThemeSchemes.cs
// The colour schemes a player saved (Tom 2026-10-22: "a profile people can
// save their color schemes"): named sets of the theme's eight colours, one
// file each in %AppData%\RynthCore\themes\ ("name=", then the eight colours
// as theme.txt writes them), for the PC, so every client lists the same ones.
// RynthTheme puts them in Settings > Display's Theme picker between the
// presets and Custom; "Save colours as" adds one, Delete removes the one in
// use.
//
// The list is read from the folder at most every 3 s (a scheme saved in one
// client shows in the others' pickers without a restart) and at once after
// this client saves or deletes one. Any thread; the files are small.
// ============================================================================
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace RynthCore.Engine.ImGuiBackend;
internal static class ThemeSchemes
{
private const int MaxNameLength = 40;
private const long RescanMs = 3000;
private static readonly object Sync = new();
private static string[] _names = Array.Empty<string>();
private static Dictionary<string, string> _files = new(StringComparer.OrdinalIgnoreCase); // display name -> file
private static long _scannedAt = long.MinValue / 2;
private static string Folder => Path.Combine(RynthTheme.Folder, "themes");
/// <summary>The saved schemes' names, A-Z (read again from the folder at most every 3 s).</summary>
public static string[] Names
{
get
{
long now = Environment.TickCount64;
lock (Sync)
{
if (now - _scannedAt < RescanMs) return _names;
_scannedAt = now;
}
Rescan();
lock (Sync) return _names;
}
}
private static void Rescan()
{
var files = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
try
{
if (Directory.Exists(Folder))
foreach (string file in Directory.GetFiles(Folder, "*.theme"))
{
string name = ReadName(file);
if (name.Length > 0 && !files.ContainsKey(name)) files[name] = file;
}
}
catch { /* unreadable folder: no schemes */ }
string[] names = files.Keys.OrderBy(n => n, StringComparer.OrdinalIgnoreCase).ToArray();
lock (Sync)
{
_files = files;
_names = names;
}
}
private static void Invalidate()
{
lock (Sync) _scannedAt = long.MinValue / 2;
}
/// <summary>The name as saved (its own capitals), or <paramref name="name"/> when there's none by it.</summary>
public static string DisplayName(string name)
{
_ = Names;
lock (Sync)
return _names.FirstOrDefault(n => n.Equals(name, StringComparison.OrdinalIgnoreCase)) ?? name;
}
/// <summary>
/// A name a scheme can have: trimmed, at most 40 characters, not a preset's or "Custom"
/// (those get "My " in front, so the picker never shows two alike). "" when nothing is left.
/// </summary>
public static string CleanName(string name)
{
name = new string((name ?? string.Empty).Where(c => !char.IsControl(c)).ToArray()).Trim();
if (name.Length > MaxNameLength) name = name[..MaxNameLength].TrimEnd();
if (name.Length == 0) return string.Empty;
if (name.Equals("Custom", StringComparison.OrdinalIgnoreCase)
|| ThemePalette.PresetNames.Any(p => p.Equals(name, StringComparison.OrdinalIgnoreCase)))
name = "My " + name;
return name;
}
/// <summary>The scheme's eight colours (and its shades), or null when there's none by that name.</summary>
public static ThemePalette? Load(string name)
{
string? file;
_ = Names;
lock (Sync) _files.TryGetValue(name, out file);
if (file == null) return null;
try
{
var p = ThemePalette.Default();
int found = 0;
foreach (string raw in File.ReadAllLines(file))
{
string line = raw.Trim();
int eq = line.IndexOf('=');
if (eq <= 0) continue;
string key = line[..eq].Trim(), value = line[(eq + 1)..].Trim();
for (int i = 0; i < ThemePalette.Primaries; i++)
if (key.Equals(ThemePalette.Key(i), StringComparison.OrdinalIgnoreCase)
&& uint.TryParse(value, System.Globalization.NumberStyles.HexNumber, null, out uint c))
{
p.P[i] = 0xFF000000 | c;
found++;
}
}
if (found == 0) return null;
p.Derive();
return p;
}
catch { return null; }
}
/// <summary>Saves (or replaces) scheme <paramref name="name"/> (already cleaned). False when the file can't be written.</summary>
public static bool Save(string name, ThemePalette palette)
{
try
{
Directory.CreateDirectory(Folder);
string? existing;
lock (Sync) _files.TryGetValue(name, out existing);
string file = existing ?? Path.Combine(Folder, FileStem(name) + ".theme");
var sb = new StringBuilder();
sb.Append("name=").Append(name).Append('\n');
for (int i = 0; i < ThemePalette.Primaries; i++)
sb.Append(ThemePalette.Key(i)).Append('=').Append((palette.P[i] & 0xFFFFFF).ToString("X6")).Append('\n');
File.WriteAllText(file, sb.ToString());
Invalidate();
RynthLog.UI($"ThemeSchemes: saved \"{name}\" ({file}).");
return true;
}
catch (Exception ex)
{
RynthLog.UI($"ThemeSchemes: could not save \"{name}\": {ex.GetType().Name}: {ex.Message}");
return false;
}
}
public static bool Delete(string name)
{
string? file;
_ = Names;
lock (Sync) _files.TryGetValue(name, out file);
if (file == null) return false;
try
{
File.Delete(file);
Invalidate();
RynthLog.UI($"ThemeSchemes: deleted \"{name}\".");
return true;
}
catch { return false; }
}
/// <summary>
/// Keeps <paramref name="palette"/> as a scheme unless it's already kept: the same eight colours as
/// a preset or a saved scheme. Saved as <paramref name="baseName"/>, or "baseName 2", 3... when taken.
/// </summary>
public static void KeepIfNew(string baseName, ThemePalette palette)
{
for (int i = 0; i < ThemePalette.PresetNames.Length; i++)
if (SameColours(ThemePalette.Preset(i), palette)) return;
foreach (string n in Names)
{
ThemePalette? s = Load(n);
if (s != null && SameColours(s, palette)) return;
}
string name = baseName;
for (int k = 2; Names.Any(n => n.Equals(name, StringComparison.OrdinalIgnoreCase)) && k < 100; k++)
name = baseName + " " + k;
Save(name, palette);
}
private static bool SameColours(ThemePalette a, ThemePalette b)
{
for (int i = 0; i < ThemePalette.Primaries; i++)
if ((a.P[i] & 0xFFFFFF) != (b.P[i] & 0xFFFFFF)) return false;
return true;
}
private static string ReadName(string file)
{
try
{
foreach (string raw in File.ReadLines(file))
{
string line = raw.Trim();
if (line.StartsWith("name=", StringComparison.OrdinalIgnoreCase))
return CleanStored(line[5..]);
}
}
catch { return string.Empty; }
return CleanStored(Path.GetFileNameWithoutExtension(file));
}
private static string CleanStored(string name)
{
name = name.Trim();
return name.Length > MaxNameLength ? name[..MaxNameLength].TrimEnd() : name;
}
/// <summary>A file name for the scheme: its letters and digits, the rest as '_'.</summary>
private static string FileStem(string name)
{
var sb = new StringBuilder(name.Length);
foreach (char c in name)
sb.Append(char.IsLetterOrDigit(c) || c is ' ' or '-' ? c : '_');
string stem = sb.ToString().Trim();
return stem.Length == 0 ? "scheme" : stem;
}
}