diff --git a/Changelog/2026-11-07-bar-menu.md b/Changelog/2026-11-07-bar-menu.md index 2e52936..34eb83a 100644 --- a/Changelog/2026-11-07-bar-menu.md +++ b/Changelog/2026-11-07-bar-menu.md @@ -17,9 +17,19 @@ Branch `up/bar-menu`, from `up/web-panel` (0ef12d7). Not deployed. The API numbe ## 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. +`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. +- `BarMenuHoverTiming`: the 0.15 s open delay, a quick sweep never opening, the 0.30 s close delay covering the gap + from icon to dropdown, switching to another icon at once, no reopen while still hovering after a click, and a + clock jump or a gap over 0.5 s resetting. +- `BarMenuReload`: a change to only `barMenu` leaves the panel signature alone (no re-registration) and changes the + menu signature (so the bar rebuilds). + +`tools/PluginManifestTests` pins the SDK and engine numbers together, and that `PluginContractVersion.BarMenu` is at or +below `Current`. Not yet tested in game. @@ -31,4 +41,6 @@ Not yet tested in game. chat command (the hotkey path) and closes the dropdown. The icon's own click still toggles the window. - A plugin reload that changes only `barMenu` reaches the bar: `PluginWindows.Sync` refreshes the hosted declaration (`WindowPlan.MenuSignature`) without re-registering the panel, and bumps the version so the bar rebuilds its buttons. +- The dropdown is brought to the display front every frame (cimgui `igBringWindowToDisplayFront`, no focus change), so a + panel focused since does not cover it; without those exports it keeps its normal order and logs once. - Timing is `ImGui/BarMenuHover.cs` (pure; `SectionsTests` `BarMenuHoverTiming`). Drawing is in-game only. diff --git a/src/RynthCore.Engine/ImGui/ImGuiBar.cs b/src/RynthCore.Engine/ImGui/ImGuiBar.cs index ed75aee..59d88bb 100644 --- a/src/RynthCore.Engine/ImGui/ImGuiBar.cs +++ b/src/RynthCore.Engine/ImGui/ImGuiBar.cs @@ -601,6 +601,9 @@ internal static class ImGuiBar { if (begun) { + // NoFocusOnAppearing leaves a re-shown menu behind a panel focused since: lift it + // every frame (no focus change, so another window's text edit stays active). + MenuToFront(); _overMenu = ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AllowWhenBlockedByActiveItem); foreach (UI.Sections.SectionBarMenuItem item in items) { @@ -608,7 +611,8 @@ internal static class ImGuiBar string glyph = letter ? FirstLetter(item.Tooltip) : item.Icon; if (IconButton(owner.Id + "_m_" + item.Id, letter ? letterFont : iconFont, glyph, square, RynthTheme.BarText)) { - AcMainThreadQueue.EnqueueChatCommand(item.Command.Trim(), ChatCommandOrigin.Player); + if (!AcMainThreadQueue.EnqueueChatCommand(item.Command, ChatCommandOrigin.Player)) + AcMainThreadQueue.EnqueueWriteToChat("[RynthCore] Bar menu: the chat command queue is full; try again.", 1); clicked = true; } SafeImGui.SetItemTooltip(item.Tooltip); @@ -624,6 +628,36 @@ internal static class ImGuiBar if (clicked) { _menuHover.Close(); _overMenu = false; } } + private static IntPtr _getCurrentWindow, _bringToFront; + private static int _frontState; // 0 = not resolved, 1 = available, -1 = off + + /// + /// Brings the current window (the bar menu) to the display front without focusing it, through + /// cimgui's igGetCurrentWindow and igBringWindowToDisplayFront (resolved once, as ImGuiStackGuard + /// does). Missing exports: logged once, and the menu keeps its normal order. Inside the menu's Begin. + /// + private static unsafe void MenuToFront() + { + if (_frontState == 0) + { + _frontState = -1; + IntPtr module = EntryPoint.ImGuiNativeHandle; + if (module != IntPtr.Zero + && System.Runtime.InteropServices.NativeLibrary.TryGetExport(module, "igGetCurrentWindow", out IntPtr get) + && System.Runtime.InteropServices.NativeLibrary.TryGetExport(module, "igBringWindowToDisplayFront", out IntPtr bring)) + { + _getCurrentWindow = get; + _bringToFront = bring; + _frontState = 1; + } + else + RynthLog.UI("ImGuiBar: this cimgui.dll has no igGetCurrentWindow / igBringWindowToDisplayFront exports; the bar menu can draw behind a panel focused since."); + } + if (_frontState < 0) return; + void* window = ((delegate* unmanaged[Cdecl])_getCurrentWindow)(); + if (window != null) ((delegate* unmanaged[Cdecl])_bringToFront)(window); + } + /// /// Places the next icon: beside the last one, or at the start of a new row (under the first /// icon) every icons. Leaving the first row, RL and pop out go at @@ -918,7 +952,7 @@ internal static class ImGuiBar string icon = IconFor(title, out bool letter); list.Add(new ButtonInfo(title, "##bar_" + title, icon, letter, title, BarOpenState.KeyFor(title, null))); } - // Windows plugins draw (their manifests' "windows" with "bar", docs/PLUGIN_WINDOWS.md): the + // Windows plugins draw (their manifests' "windows" with "bar", UI/Sections/SectionManifest.cs header): the // icon they name (a Phosphor glyph), else the title's letter; the button toggles the panel. foreach (UI.Sections.SectionWindowDecl w in UI.Sections.PluginWindows.BarWindows) { diff --git a/src/RynthCore.Engine/Plugins/PluginContractVersion.cs b/src/RynthCore.Engine/Plugins/PluginContractVersion.cs index aa071a9..0b1e3a2 100644 --- a/src/RynthCore.Engine/Plugins/PluginContractVersion.cs +++ b/src/RynthCore.Engine/Plugins/PluginContractVersion.cs @@ -55,5 +55,8 @@ internal static class PluginContractVersion // 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. + /// The API version that added the "barMenu" manifest key; a plugin declaring it pins its own copy against this. + public const uint BarMenu = 94; + public const uint Current = 94; } diff --git a/tools/PluginManifestTests/Program.cs b/tools/PluginManifestTests/Program.cs index 83dc114..9180535 100644 --- a/tools/PluginManifestTests/Program.cs +++ b/tools/PluginManifestTests/Program.cs @@ -569,6 +569,7 @@ internal static class Program { Eq(RynthCoreHost.CurrentApiVersion, PluginContractVersion.Current, "RynthCoreHost.CurrentApiVersion"); Check(RynthCoreHost.BaselineApiVersion <= RynthCoreHost.CurrentApiVersion, "baseline at or below current"); + Check(PluginContractVersion.BarMenu <= PluginContractVersion.Current, "BarMenu (the barMenu manifest key's version) is at or below current"); // The SDK's copy of the table must reach as far as the engine's (same field count, same size). int sdkFields = typeof(RynthCoreApiNative).GetFields().Length;