ServerPack: optional bar menu on the server's window (ServerBarMenu hook)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
865c3a3997
commit
4afb8f3ac3
3 changed files with 83 additions and 2 deletions
|
|
@ -21,6 +21,9 @@ namespace RynthCore.Plugin.ServerPack;
|
|||
/// <summary>RynthCore's verdict for this plugin's server.</summary>
|
||||
internal sealed record ServerVerdictView(string Name, bool Active, string Force, bool Detected, string Reason);
|
||||
|
||||
/// <summary>One entry of the server window's bar-icon dropdown: a click runs <paramref name="Command"/> as a chat command. <paramref name="Icon"/> is one Phosphor glyph.</summary>
|
||||
internal sealed record ServerBarMenuItem(string Id, string Tooltip, string Icon, string Command);
|
||||
|
||||
internal sealed class ServerPackModel
|
||||
{
|
||||
/// <summary>Payloads longer than this are not ours (a push is a few hundred bytes).</summary>
|
||||
|
|
@ -170,7 +173,7 @@ internal sealed class ServerPackModel
|
|||
/// shared "Server" section of the Mini Remote.
|
||||
/// </summary>
|
||||
public static string BuildSectionsJson(ServerPackInfo info, string pluginName, IReadOnlyList<ServerPage>? pages = null,
|
||||
IReadOnlyList<ServerWindow>? windows = null, bool frameless = false)
|
||||
IReadOnlyList<ServerWindow>? windows = null, bool frameless = false, IReadOnlyList<ServerBarMenuItem>? 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));
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
private readonly List<ServerPage> _pages;
|
||||
// The server's own windows (ServerWindows), validated the same way.
|
||||
private readonly List<ServerWindow> _windows;
|
||||
// The server window's bar-icon dropdown (ServerBarMenu), for the sections manifest.
|
||||
private readonly List<ServerBarMenuItem> _barMenu = new();
|
||||
private readonly List<string> _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
|
|||
/// <summary>Every frame while logged in (render thread, AC's main thread; the engine's ImGui context current).</summary>
|
||||
partial void ServerRender();
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
partial void ServerBarMenu(List<ServerBarMenuItem> items);
|
||||
/// <summary>
|
||||
/// Drawn at the top of the server card, under RynthCore's verdict; render thread; queue work with RunOnTick.
|
||||
/// </summary>
|
||||
partial void ServerCardActions();
|
||||
|
|
@ -301,7 +309,7 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
/// </summary>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// RynthPluginRenderEmbed "window:<id>": one of the server's own windows (ServerWindows), into the
|
||||
|
|
|
|||
Loading…
Reference in a new issue