diff --git a/Changelog/2026-11-07-bar-menu.md b/Changelog/2026-11-07-bar-menu.md new file mode 100644 index 0000000..394b5f2 --- /dev/null +++ b/Changelog/2026-11-07-bar-menu.md @@ -0,0 +1,24 @@ +# Bar icon dropdown: plugin API v94 + +Branch `up/bar-menu`, from `up/web-panel` (0ef12d7). Not deployed. The API number 94 is provisional, as 93 is +(upstream may take it first; it renumbers on merge). This change is the manifest only; a later change draws it. + +## What changed + +- A plugin window in the sections manifest (`windows`, with `"bar": true`) may declare `"barMenu"`: up to 6 items of + `{ "id", "tooltip", "icon", "command" }`. `SectionManifest.cs` parses it into `SectionWindowDecl.BarMenu` + (`SectionBarMenuItem` records; `Menu` is the never-null view). +- Validation, with the window always kept: the id is a short lower-case word and unique in the menu, the tooltip is + non-empty and capped at 48 characters, the command is a single `/...` chat command (the same rule as a contribution's), + the icon is one Phosphor glyph or empty (an empty icon is kept). An item failing any of these is dropped; items past + `MaxBarMenuItems` (6) are ignored; a `barMenu` that is not an array is ignored. +- `PluginContractVersion.Current` and the SDK's `RynthCoreSdkApiVersion` (`RynthCore.PluginSdk.targets`) go to 94. + No function table change. Engines before v94 ignore the key, so a plugin can declare it unconditionally. + +## Tests + +`tools/SectionsTests` `ManifestBarMenu`: valid items in order with exact fields, rejected commands (no slash, a line +break, over-long), empty id, duplicate id, empty tooltip, empty icon kept, 20 items capped to 6, a non-array +`barMenu`, no key, and the 48-character tooltip cap. `tools/PluginManifestTests` pins the SDK and engine numbers together. + +Not yet tested in game. \ No newline at end of file diff --git a/src/RynthCore.Engine/Plugins/PluginContractVersion.cs b/src/RynthCore.Engine/Plugins/PluginContractVersion.cs index e89f2d8..aa071a9 100644 --- a/src/RynthCore.Engine/Plugins/PluginContractVersion.cs +++ b/src/RynthCore.Engine/Plugins/PluginContractVersion.cs @@ -51,5 +51,9 @@ internal static class PluginContractVersion // game window (WebPanel\WebPanelApi.cs; DreamWeave's in-game market and tools), appended after v93's // GetMonsterHealth (was v93 on up/web-panel; renumbered after upstream's v93). The number is // PROVISIONAL: the unmerged branches named under v93 also use 94; whichever merges second renumbers. + // v94: no table change. SectionManifest.cs reads a plugin window's "barMenu" (a hover dropdown on its + // bar icon: up to 6 items of id, tooltip, icon and a /command the engine runs on click). Engines + // before v94 ignore the key. The number is PROVISIONAL, as 93 is: upstream may take 94 first, + // in which case this renumbers on merge. public const uint Current = 94; } diff --git a/src/RynthCore.Engine/UI/Sections/SectionManifest.cs b/src/RynthCore.Engine/UI/Sections/SectionManifest.cs index 20b8c27..438df06 100644 --- a/src/RynthCore.Engine/UI/Sections/SectionManifest.cs +++ b/src/RynthCore.Engine/UI/Sections/SectionManifest.cs @@ -51,6 +51,16 @@ // opens when nothing is saved for it (v90, 2026-10-22). "scale": "draw" = // the window draws its content at any size (PanelScale): Ctrl+wheel over // it steps that size, 30-250%, not its text size (v90, 2026-10-23). +// "barMenu" (v94, 2026-11-07): a hover dropdown on the window's bar icon, for a +// window with "bar": true. An array of { "id": "market", "tooltip": "Market", +// "icon": "", "command": "/rserver market" }: +// "id" a short lower-case word (unique in the menu), "tooltip" the item's +// label (capped like any label), "icon" as the window's icon (one glyph or +// ""), "command" a single "/..." chat command the engine runs as a player +// chat command when the item is clicked. An item missing its id, tooltip or +// command, or with a duplicate id, is dropped; at most MaxBarMenuItems (6) +// are kept, and a "barMenu" that is not an array is ignored (the window is +// kept). Engines before v94 ignore the key. // // Everything from a plugin is checked here: ids are short lower-case words, // text is capped, a command must be a single "/..." chat command, and the lists @@ -92,6 +102,9 @@ internal sealed record SectionContribution( public bool IsUniversal => Server.Length == 0; } +/// One entry of a window's bar-icon dropdown ("barMenu", v94): a click runs as a player chat command. +internal sealed record SectionBarMenuItem(string Id, string Tooltip, string Icon, string Command); + /// /// A window a plugin draws, hosted by the engine (docs/PLUGIN_WINDOWS.md): its panel key and header /// are , its body the plugin's through RynthPluginRenderEmbed. @@ -121,10 +134,15 @@ internal sealed record SectionWindowDecl( bool DrawScale = false, // 2026-11-07 (no version bump: older engines ignore the key): drawn under AC's own UI, like a native // AC window ("layer": "underUi"; frameless windows only). AC's windows cover it and take the clicks there. - bool UnderUi = false) + bool UnderUi = false, + // v94: the bar icon's hover dropdown ("barMenu"); null when the window declares none. + SectionBarMenuItem[]? BarMenu = null) { /// For every world, not one server. public bool IsUniversal => Server.Length == 0; + + /// The bar icon's dropdown items (empty when none). + public SectionBarMenuItem[] Menu => BarMenu ?? System.Array.Empty(); } /// One plugin's parsed manifest. @@ -158,6 +176,8 @@ internal static class SectionManifestParser public const int MaxJsonLength = 256 * 1024; public const int MaxWindows = 8; public const int MaxWindowTitleLength = 32; + /// Most items kept in one window's bar-icon dropdown (v94). + public const int MaxBarMenuItems = 6; public const float DefaultWindowWidth = 420f, DefaultWindowHeight = 300f, MinWindowSize = 120f, MaxWindowSize = 2000f; /// @@ -237,6 +257,16 @@ internal static class SectionManifestParser float height = WindowSize(Size(e, "height"), DefaultWindowHeight); float minWidth = Math.Min(WindowSize(Size(e, "minWidth"), MinWindowSize), width); float minHeight = Math.Min(WindowSize(Size(e, "minHeight"), MinWindowSize), height); + var barMenu = new List(); + foreach (JsonElement item in Array(e, "barMenu")) + { + if (barMenu.Count >= MaxBarMenuItems) break; + string itemId = Id(Str(item, "id")); + string tooltip = Text(Str(item, "tooltip"), MaxLabelLength); + string itemCommand = Command(Str(item, "command")); + if (itemId.Length == 0 || tooltip.Length == 0 || itemCommand.Length == 0 || barMenu.Exists(b => b.Id == itemId)) continue; + barMenu.Add(new SectionBarMenuItem(itemId, tooltip, Icon(Str(item, "icon")), itemCommand)); + } windows.Add(new SectionWindowDecl(plugin, id, title, surface, Icon(Str(e, "icon")), width, height, minWidth, minHeight, Bool(e, "bar", false), Bool(e, "edgeToEdge", false), server, Bool(e, "takeOver", false), @@ -244,7 +274,8 @@ internal static class SectionManifestParser FitHeight: Bool(e, "fitHeight", false), Corner: Str(e, "corner").Trim() is "topLeft" or "topRight" or "bottomLeft" or "bottomRight" or "top" or "bottom" ? Str(e, "corner").Trim() : "", DrawScale: Str(e, "scale").Trim().Equals("draw", StringComparison.OrdinalIgnoreCase), - UnderUi: Str(e, "layer").Trim().Equals("underUi", StringComparison.OrdinalIgnoreCase))); + UnderUi: Str(e, "layer").Trim().Equals("underUi", StringComparison.OrdinalIgnoreCase), + BarMenu: barMenu.Count > 0 ? barMenu.ToArray() : null)); } return new SectionManifest(plugin, servers.ToArray(), sections.ToArray(), contributions.ToArray()) diff --git a/tools/SectionsTests/Program.cs b/tools/SectionsTests/Program.cs index 13807e4..f767210 100644 --- a/tools/SectionsTests/Program.cs +++ b/tools/SectionsTests/Program.cs @@ -33,6 +33,7 @@ internal static class Program WindowPlanChoices(); WindowTakeOver(); WindowFrameless(); + ManifestBarMenu(); StackCheckAfterPluginDraw(); Console.WriteLine(); @@ -585,6 +586,66 @@ internal static class Program "chrome and fitHeight are in the signature (a change re-registers)"); } + // -- Bar icon dropdown (v94) --────── + + private static string BarMenuManifest(string windowExtra) => + "{ \"version\": 1, \"windows\": [ { \"id\": \"server\", \"title\": \"DreamWeave\", \"surface\": \"window:server\", \"bar\": true" + + windowExtra + " } ] }"; + + private static void ManifestBarMenu() + { + Case("plugin windows: barMenu (v94)"); + string storefront = ((char)0xE470).ToString(), shield = ((char)0xE40A).ToString(), sparkle = ((char)0xE6A2).ToString(); + string longTip = new string('T', 60); + string longCommand = "/" + new string('c', 250); + string items = """ + [ + { "id": "market", "tooltip": "Market", "icon": "@STORE@", "command": "/rserver market" }, + { "id": "nocmdslash", "tooltip": "No slash", "icon": "@STORE@", "command": "rserver x" }, + { "id": "multiline", "tooltip": "Two lines", "icon": "@STORE@", "command": "/rserver a\n/rserver b" }, + { "id": "toolong", "tooltip": "Too long", "icon": "@STORE@", "command": "@LONGCMD@" }, + { "id": "", "tooltip": "No id", "icon": "@STORE@", "command": "/rserver x" }, + { "id": "market", "tooltip": "Duplicate", "icon": "@STORE@", "command": "/rserver market" }, + { "id": "notip", "tooltip": "", "icon": "@STORE@", "command": "/rserver x" }, + { "id": "suit", "tooltip": "Suit Builder", "icon": "@SHIELD@", "command": "/rserver suit" }, + { "id": "noicon", "tooltip": "No icon", "icon": "", "command": "/rserver x" }, + { "id": "abilities", "tooltip": "Ability Planner", "icon": "@SPARKLE@", "command": "/rserver abilities" }, + { "id": "longtip", "tooltip": "@LONGTIP@", "icon": "@STORE@", "command": "/rserver x" } + ] + """ + .Replace("@STORE@", storefront).Replace("@SHIELD@", shield).Replace("@SPARKLE@", sparkle) + .Replace("@LONGCMD@", longCommand).Replace("@LONGTIP@", longTip); + + SectionManifest m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": " + items), out string err); + Check(err.Length == 0 && m.Windows.Length == 1, "parses and the window is kept: " + err); + SectionBarMenuItem[] menu = m.Windows[0].Menu; + string[] ids = menu.Select(i => i.Id).ToArray(); + Check(ids.SequenceEqual(new[] { "market", "suit", "noicon", "abilities", "longtip" }), + "bad items dropped, order kept: " + string.Join(",", ids)); + Check(menu[0] == new SectionBarMenuItem("market", "Market", storefront, "/rserver market"), "market: fields exactly equal"); + Check(menu[1] == new SectionBarMenuItem("suit", "Suit Builder", shield, "/rserver suit"), "suit: fields exactly equal"); + Check(menu[3] == new SectionBarMenuItem("abilities", "Ability Planner", sparkle, "/rserver abilities"), "abilities: fields exactly equal"); + Check(menu[2].Icon == "" && menu[2].Tooltip == "No icon", "an empty icon is kept as \"\""); + Check(menu[4].Tooltip.Length == SectionManifestParser.MaxLabelLength && menu[4].Tooltip == longTip[..48], + "an over-long tooltip is cut to 48: " + menu[4].Tooltip.Length); + Check(SectionManifestParser.Command("/rserver a\n/rserver b").Length == 0 && SectionManifestParser.Command("rserver x").Length == 0 + && SectionManifestParser.Command(longCommand).Length == 0, "(the rejected commands are ones Command() rejects)"); + + var many = new System.Text.StringBuilder("["); + for (int i = 0; i < 20; i++) + many.Append(i > 0 ? "," : "").Append($"{{ \"id\": \"item{i}\", \"tooltip\": \"Item {i}\", \"icon\": \"\", \"command\": \"/rserver x{i}\" }}"); + many.Append(']'); + m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": " + many), out err); + Check(SectionManifestParser.MaxBarMenuItems == 6 && m.Windows[0].Menu.Length == SectionManifestParser.MaxBarMenuItems, + "twenty valid items give exactly MaxBarMenuItems: " + m.Windows[0].Menu.Length); + Check(m.Windows[0].Menu[0].Id == "item0" && m.Windows[0].Menu[5].Id == "item5", "the first six are the ones kept"); + + m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": \"nope\""), out err); + Check(err.Length == 0 && m.Windows.Length == 1 && m.Windows[0].Menu.Length == 0, "barMenu not an array: window kept, no menu"); + m = SectionManifestParser.Parse("DW", BarMenuManifest(""), out err); + Check(err.Length == 0 && m.Windows.Length == 1 && m.Windows[0].Menu.Length == 0, "no barMenu key: no menu"); + } + // ImGui 1.91.6's ImGuiErrorRecoveryState, in field order: windows, IDs, tree nodes, colours, // style vars, fonts, focus scopes, groups, item flags, popups, disabled. The base values are // the ones a 32-bit probe of our cimgui.dll read inside a panel's body child (2026-10-21).