// ServerPackWindows.cs - Windows of its own a server plugin adds to RynthCore's bar, beside the server's // window (2026-11-07: RynthDreamWeave's Skills panel, the retail Character panel drawn by the plugin). // // The ServerPackPlugin.ServerWindows hook lists them once, at construction. Each is declared in the // sections manifest's "windows" (plugin windows, API v89; "chrome": "none" for one that draws its own // frame, v90), only while the server is active, and drawn through RynthPluginRenderEmbed "window:" // on the render thread. A frameless window is declared only on engines with frameless windows (an older // engine would wrap it in its own frame), so it simply isn't there on those. // Pure (no ImGui, no host calls): RynthServerPack.Tests covers it. using System; using System.Collections.Generic; using System.Text; namespace RynthCore.Plugin.ServerPack; /// /// One window a server plugin adds. is 1-16 of a-z, 0-9 and '-' (its surface is /// "window:<id>"); is its panel key (bar tooltip, saved place, /rc commands). /// draws the body (popped out or not) and returns the size it wants: the height it used and, for a window that sizes its width too, that width (0: the width it was given). Render thread. /// internal sealed record ServerWindow(string Id, string Title, string Icon, int Width, int Height, int MinWidth, int MinHeight, bool Frameless, Func Draw, bool FitHeight = false, bool UnderUi = false, bool DrawScale = false); internal static class ServerPackWindows { /// At most this many windows besides the server's own. public const int MaxWindows = 3; public static string SurfaceFor(string id) => "window:" + id; /// The window id a surface names ("window:skills" -> "skills"), or null. ":popout" is the caller's to strip. public static string? IdOf(string? surface) { if (surface == null || !surface.StartsWith("window:", StringComparison.Ordinal)) return null; string id = surface["window:".Length..]; return ServerPackPages.IsValidId(id) && id != ServerPackModel.WindowId ? id : null; } /// The windows that can be declared: a valid id that isn't the server window's, a title, each id once. public static List Validate(List windows, Action note) { var ok = new List(); var ids = new HashSet(StringComparer.Ordinal); foreach (ServerWindow w in windows) { if (w == null) continue; if (!ServerPackPages.IsValidId(w.Id) || w.Id == ServerPackModel.WindowId) { note($"Window \"{w.Id}\" left out: its id must be 1-16 of a-z, 0-9 and '-', not \"server\"."); continue; } if (string.IsNullOrWhiteSpace(w.Title)) { note($"Window \"{w.Id}\" left out: it has no title."); continue; } if (!ids.Add(w.Id)) { note($"Window \"{w.Id}\" left out: the id is used twice."); continue; } if (ok.Count >= MaxWindows) { note($"Window \"{w.Id}\" left out: at most {MaxWindows} windows."); continue; } ok.Add(w); } return ok; } /// The manifest entries (",{...}" each) for ; frameless ones only when . public static string Json(IReadOnlyList windows, string serverId, bool frameless) { var sb = new StringBuilder(); foreach (ServerWindow w in windows) { if (w.Frameless && !frameless) continue; sb.Append(",{\"id\":").Append(ServerPackModel.Q(w.Id)); sb.Append(",\"title\":").Append(ServerPackModel.Q(w.Title.Trim())); sb.Append(",\"surface\":").Append(ServerPackModel.Q(SurfaceFor(w.Id))); sb.Append(",\"icon\":").Append(ServerPackModel.Q(w.Icon)); sb.Append(",\"width\":").Append(w.Width).Append(",\"height\":").Append(w.Height); sb.Append(",\"minWidth\":").Append(w.MinWidth).Append(",\"minHeight\":").Append(w.MinHeight); sb.Append(",\"bar\":true,\"server\":").Append(ServerPackModel.Q(serverId)); if (w.Frameless) sb.Append(",\"chrome\":\"none\""); // The window is as tall as the height the draw reports (the plugin sizes it itself, v90). if (w.FitHeight && w.Frameless) sb.Append(",\"fitHeight\":true"); // Drawn under AC's own UI, like a native AC window (engines from 2026-11-07; older ones ignore it). if (w.UnderUi && w.Frameless) sb.Append(",\"layer\":\"underUi\""); // It draws itself at any size: Ctrl+wheel steps its own draw size (PanelScale, 30-250%), not its text. if (w.DrawScale && w.Frameless) sb.Append(",\"scale\":\"draw\""); sb.Append('}'); } return sb.ToString(); } }