From 4afb8f3ac362dd7768de223bc83b52a64d6398e5 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Sat, 7 Nov 2026 20:07:53 -0800 Subject: [PATCH] ServerPack: optional bar menu on the server's window (ServerBarMenu hook) Co-Authored-By: Claude Opus 5.5 --- Plugins/Shared/ServerPack/ServerPackModel.cs | 19 ++++++- Plugins/Shared/ServerPack/ServerPackPlugin.cs | 10 +++- .../ServerPackModelTests.cs | 56 +++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/Plugins/Shared/ServerPack/ServerPackModel.cs b/Plugins/Shared/ServerPack/ServerPackModel.cs index da1e059..016e24e 100644 --- a/Plugins/Shared/ServerPack/ServerPackModel.cs +++ b/Plugins/Shared/ServerPack/ServerPackModel.cs @@ -21,6 +21,9 @@ namespace RynthCore.Plugin.ServerPack; /// RynthCore's verdict for this plugin's server. internal sealed record ServerVerdictView(string Name, bool Active, string Force, bool Detected, string Reason); +/// One entry of the server window's bar-icon dropdown: a click runs as a chat command. is one Phosphor glyph. +internal sealed record ServerBarMenuItem(string Id, string Tooltip, string Icon, string Command); + internal sealed class ServerPackModel { /// Payloads longer than this are not ours (a push is a few hundred bytes). @@ -170,7 +173,7 @@ internal sealed class ServerPackModel /// shared "Server" section of the Mini Remote. /// public static string BuildSectionsJson(ServerPackInfo info, string pluginName, IReadOnlyList? pages = null, - IReadOnlyList? windows = null, bool frameless = false) + IReadOnlyList? windows = null, bool frameless = false, IReadOnlyList? barMenu = null) { var sb = new StringBuilder(512); sb.Append("{\"version\":1,\"servers\":[{\"id\":").Append(Q(info.Id)).Append(",\"name\":").Append(Q(info.Name)); @@ -185,6 +188,20 @@ internal sealed class ServerPackModel sb.Append(",\"icon\":").Append(Q(WindowIcon)); sb.Append(",\"width\":").Append(tabs ? ServerPackPages.Width : 460).Append(",\"height\":").Append(ServerPackPages.Height); sb.Append(",\"minWidth\":320,\"minHeight\":200,\"bar\":true,\"server\":").Append(Q(info.Id)); + // The bar icon's hover dropdown (RynthCore API 94); an older engine ignores the key. + if (barMenu != null && barMenu.Count > 0) + { + sb.Append(",\"barMenu\":["); + for (int i = 0; i < barMenu.Count; i++) + { + ServerBarMenuItem item = barMenu[i]; + sb.Append(i == 0 ? "" : ",").Append("{\"id\":").Append(Q(item.Id)); + sb.Append(",\"tooltip\":").Append(Q(item.Tooltip)); + sb.Append(",\"icon\":").Append(Q(item.Icon)); + sb.Append(",\"command\":").Append(Q(item.Command)).Append('}'); + } + sb.Append(']'); + } sb.Append('}'); // The server's own windows (ServerWindows, ServerPackWindows.cs, 2026-11-07). if (windows != null) sb.Append(ServerPackWindows.Json(windows, info.Id, frameless)); diff --git a/Plugins/Shared/ServerPack/ServerPackPlugin.cs b/Plugins/Shared/ServerPack/ServerPackPlugin.cs index 71e8046..16a00ee 100644 --- a/Plugins/Shared/ServerPack/ServerPackPlugin.cs +++ b/Plugins/Shared/ServerPack/ServerPackPlugin.cs @@ -77,6 +77,8 @@ public sealed partial class ServerPackPlugin : RynthPluginBase private readonly List _pages; // The server's own windows (ServerWindows), validated the same way. private readonly List _windows; + // The server window's bar-icon dropdown (ServerBarMenu), for the sections manifest. + private readonly List _barMenu = new(); private readonly List _pageNotes = new(); private readonly ServerPackSettings _settings = new(ServerPackSettings.DefaultPath(RynthPluginInfo.Name)); private readonly ServerProfileValues _profileValues = new(); @@ -109,6 +111,7 @@ public sealed partial class ServerPackPlugin : RynthPluginBase foreach (string v in verbs) if (!string.IsNullOrWhiteSpace(v)) _serverVerbs.Add(v.Trim()); ServerUsageLines(_usageLines.Add); _ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world, _pages, DrawCardActions); + ServerBarMenu(_barMenu); } internal ServerPackInfo Info => _model.Info; @@ -158,6 +161,11 @@ public sealed partial class ServerPackPlugin : RynthPluginBase /// Every frame while logged in (render thread, AC's main thread; the engine's ImGui context current). partial void ServerRender(); /// + /// Items for a hover dropdown on the server window's bar icon (RynthCore API 94; an older engine + /// ignores it). Called once, from the constructor (no Host yet). + /// + partial void ServerBarMenu(List items); + /// /// Drawn at the top of the server card, under RynthCore's verdict; render thread; queue work with RunOnTick. /// partial void ServerCardActions(); @@ -301,7 +309,7 @@ public sealed partial class ServerPackPlugin : RynthPluginBase /// internal string? BuildSectionsJson() => _sectionsJson ??= ServerPackModel.BuildSectionsJson(Info, RynthPluginInfo.Name, _pages, _windows, - frameless: _windows.Count > 0 && Host.HasFramelessWindows); + frameless: _windows.Count > 0 && Host.HasFramelessWindows, barMenu: _barMenu); /// /// RynthPluginRenderEmbed "window:<id>": one of the server's own windows (ServerWindows), into the diff --git a/Tools/RynthServerPack.Tests/ServerPackModelTests.cs b/Tools/RynthServerPack.Tests/ServerPackModelTests.cs index ccea702..ef241ca 100644 --- a/Tools/RynthServerPack.Tests/ServerPackModelTests.cs +++ b/Tools/RynthServerPack.Tests/ServerPackModelTests.cs @@ -1,6 +1,8 @@ using System; using System.Linq; +using System.Collections.Generic; using System.Text.Json; +using RynthCore.Engine.UI.Sections; using RynthCore.Plugin.ServerPack; using RynthCore.RynthAiTests.Harness; @@ -18,6 +20,9 @@ internal static class ServerPackModelTests r.Add("server pack: before any push the world name decides", WorldFallback); r.Add("server pack: override commands are checked before sending", ForceCommands); r.Add("server pack: the sections manifest declares the server and a server-only card", SectionsJson); + r.Add("server pack: no bar menu writes no barMenu key", NoBarMenuKey); + r.Add("server pack: the bar menu items reach the engine parser as given", BarMenuRoundTrip); + r.Add("server pack: a bar menu tooltip with quotes and backslashes round-trips", BarMenuEscapes); r.Add("server pack: logout clears the verdict", ClearOnLogout); r.Add("server pack: the card's botting line and address", InfoText); r.Add("server pack: the RynthServer.Profile JSON carries the server's settings", ProfileJson); @@ -217,6 +222,57 @@ internal static class ServerPackModelTests Check.Eq(odd.RootElement.GetProperty("servers")[0].GetProperty("hosts")[0].GetString(), "a\\b", "escaped"); } + private static ServerBarMenuItem[] MenuItems() => new[] + { + new ServerBarMenuItem("market", "Market", ((char)0xE470).ToString(), "/rserver market"), + new ServerBarMenuItem("suit", "Suit Builder", ((char)0xE40A).ToString(), "/rserver suit"), + new ServerBarMenuItem("abilities", "Ability Planner", ((char)0xE6A2).ToString(), "/rserver abilities"), + }; + + private static void NoBarMenuKey() + { + string plain = ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve"); + Check.Eq(ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve", null, barMenu: null), plain, "null pages and null menu are the default"); + Check.Eq(ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve", null, barMenu: new List()), plain, "an empty menu is the default"); + Check.False(plain.Contains("barMenu"), "no barMenu key"); + } + + private static void BarMenuRoundTrip() + { + ServerBarMenuItem[] items = MenuItems(); + string json = ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve", null, barMenu: items); + SectionManifest m = SectionManifestParser.Parse("RynthColdeve", json, out string error); + Check.Eq(error, string.Empty, "parses clean: " + error); + SectionBarMenuItem[] menu = m.Windows.Single().Menu; + Check.Eq(menu.Length, 3, "three items"); + for (int i = 0; i < items.Length; i++) + { + Check.Eq(menu[i].Id, items[i].Id, "id " + i); + Check.Eq(menu[i].Tooltip, items[i].Tooltip, "tooltip " + i); + Check.Eq(menu[i].Icon, items[i].Icon, "icon " + i); + Check.Eq(menu[i].Command, items[i].Command, "command " + i); + } + + // With windows of the server's own (ServerWindows), the menu stays on the server's window only. + var own = new[] { new ServerWindow("skills", "Skills", "x", 300, 400, 200, 200, false, _ => default) }; + SectionManifest both = SectionManifestParser.Parse("RynthColdeve", + ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve", null, own, barMenu: items), out error); + Check.Eq(error, string.Empty, "with a window of its own: parses clean: " + error); + Check.Eq(both.Windows.Length, 2, "with a window of its own: two windows"); + Check.Eq(both.Windows[0].Menu.Length, 3, "with a window of its own: the server window has the menu"); + Check.Eq(both.Windows[1].Menu.Length, 0, "with a window of its own: that window has none"); + } + + private static void BarMenuEscapes() + { + const string tip = "Say \"hi\" \\ there"; + var items = new[] { new ServerBarMenuItem("odd", tip, ((char)0xE470).ToString(), "/rserver market") }; + string json = ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve", null, barMenu: items); + SectionManifest m = SectionManifestParser.Parse("RynthColdeve", json, out string error); + Check.Eq(error, string.Empty, "parses clean: " + error); + Check.Eq(m.Windows.Single().Menu.Single().Tooltip, tip, "tooltip survives escaping"); + } + private static void ClearOnLogout() { var model = new ServerPackModel(Coldeve());