RynthCore as of 2026-11-10 (internal b7e3008): release 2026.11.10.1

This commit is contained in:
Tom Bohar 2026-11-10 15:28:10 -05:00
commit 55e15c0ac4
59 changed files with 6963 additions and 1030 deletions

View file

@ -0,0 +1,79 @@
// ============================================================================
// RynthCore.Engine - ImGui/BarMenuHover.cs
// The timing of the bar icon dropdown (a plugin window's "barMenu", plugin API
// v95): pure, so tools/SectionsTests compiles it as is. ImGuiBar feeds it once
// a frame.
//
// An icon must be hovered OpenDelay before its dropdown opens (a sweep of the
// mouse across the bar opens nothing). Once open, the dropdown stays while the
// mouse is over the icon or the dropdown, and for CloseDelay after it leaves
// both (the gap between them is crossed within that). Hovering another icon
// while one is open switches at once. After a click (Close) the same icon does
// not reopen until the mouse has left it and hovered it again.
// ============================================================================
namespace RynthCore.Engine.ImGuiBackend;
internal sealed class BarMenuHover
{
public const double OpenDelay = 0.15, CloseDelay = 0.30;
/// <summary>Frames further apart than this (or a clock that runs backwards) reset the state.</summary>
public const double ResetGap = 0.5;
private string? _hovered; // the icon being hovered, and since when (_hoverStart)
private double _hoverStart;
private double? _leftAt; // when the mouse left both the icon and the dropdown (open only)
private string? _closedByClick; // the icon hovered when Close() ran: ignored until it is left
private double _lastNow = double.NegativeInfinity;
/// <summary>The bar button id whose dropdown is open, else null.</summary>
public string? OpenFor { get; private set; }
/// <summary>
/// Once per frame. <paramref name="hoveredButton"/>: id of the menu-bearing bar button under the mouse, else null.
/// <paramref name="overMenu"/>: the mouse is over the open dropdown. <paramref name="now"/>: seconds.
/// </summary>
public void Update(string? hoveredButton, bool overMenu, double now)
{
// The clock is one ImGui context's (the popped-out bar has its own, starting near 0), and a bar that
// wasn't drawn for a while sends no frames: either way, start from a closed dropdown.
if (now < _lastNow || now - _lastNow > ResetGap)
{
OpenFor = null;
_hovered = null;
_hoverStart = now;
_leftAt = null;
_closedByClick = null;
}
_lastNow = now;
if (_closedByClick != null && hoveredButton != _closedByClick) _closedByClick = null;
string? hovered = hoveredButton != null && hoveredButton == _closedByClick ? null : hoveredButton;
if (hovered != _hovered) { _hovered = hovered; _hoverStart = now; }
if (OpenFor != null)
{
if (hovered != null) { OpenFor = hovered; _leftAt = null; }
else if (overMenu) _leftAt = null;
else
{
_leftAt ??= now;
if (now - _leftAt.Value >= CloseDelay) { OpenFor = null; _leftAt = null; }
}
}
else if (hovered != null && now - _hoverStart >= OpenDelay)
{
OpenFor = hovered;
_leftAt = null;
}
}
/// <summary>An item was clicked, or the bar went away.</summary>
public void Close()
{
OpenFor = null;
_leftAt = null;
_closedByClick = _hovered;
}
}

View file

@ -894,6 +894,7 @@ internal static class EngineFrameController
ImGuiNET.ImGui.NewFrame();
UiCost.Stop(UiCost.ImGuiNewFrame, cNew);
frameStarted = true;
ImGuiPopOuts.NoteMainFrame(); // _context is current: the frame number pop-out frames share
// Before any window: a drag from a popped-out Inventory or AC's inventory becomes
// a payload the client's drop targets (Mini Remote slots) see this frame.
ItemDragBridge.SubmitMainFrame(io);

View file

@ -11,6 +11,9 @@
// draws that asked for one (its manifest's "windows" with "bar", UI/Sections/
// PluginWindows.cs; an engine panel such a window has taken over loses its own
// button), reload (RL) and pop out.
// A plugin window with a "barMenu" (plugin API v95) drops a column of icon buttons below its
// bar icon after the mouse rests on it (BarMenuHover: open and close delays); a click runs that
// item's chat command. The icon's own click still toggles the window.
// A button whose window is open, docked or popped out, draws highlighted in the
// theme's accent (RynthTheme.BarButtonOpen*); the ILT and Scripts buttons while
// any window in their menu is (UI/BarOpenState.cs; one IsOpen lookup a key).
@ -71,7 +74,17 @@ internal static class ImGuiBar
// the button toggles it through ScriptWindowRegistry, like the Scripts menu does.
// OpenKey: the panel whose open state lights the button (BarOpenState.KeyFor).
private sealed record ButtonInfo(string Title, string Id, string Icon, bool Letter, string Tooltip,
string OpenKey, ScriptWindow? Window = null);
string OpenKey, ScriptWindow? Window = null, UI.Sections.SectionBarMenuItem[]? Menu = null);
// The bar icon dropdown (a plugin window's "barMenu"): the timer, last frame's "mouse is over the
// dropdown", the menu-bearing buttons' rects this frame, and when the timer was last fed (a gap
// means the bar wasn't drawn: start from a closed dropdown).
private static readonly BarMenuHover _menuHover = new();
private static bool _overMenu;
private static readonly List<(ButtonInfo Button, Vector2 Min, Vector2 Max)> _menuRects = new();
private const ImGuiWindowFlags MenuFlags = ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.AlwaysAutoResize
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoDocking
| ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNav;
// The open check every highlight uses (one set lookup a key), as one delegate: no allocation a frame.
private static readonly Func<string, bool> IsOpenCheck = ImGuiPanelHost.IsOpen;
@ -133,7 +146,13 @@ internal static class ImGuiBar
{
letter = !PanelIcons.TryGetValue(title, out string? icon);
if (!letter) return icon!;
foreach (char c in title)
return FirstLetter(title);
}
/// <summary>The bar's letter fallback: the first letter or digit of <paramref name="text"/>, upper-cased, else "?".</summary>
private static string FirstLetter(string text)
{
foreach (char c in text)
if (char.IsLetterOrDigit(c)) return char.ToUpperInvariant(c).ToString();
return "?";
}
@ -468,7 +487,9 @@ internal static class ImGuiBar
SafeImGui.SetItemTooltip(collapsed ? "Show the bar" : "Fold the bar to this button");
PhosphorIcons.DrawCentered(dl, iconFont, collapsed ? PhosphorIcons.CaretRight : PhosphorIcons.CaretLeft, cPos, caretSize,
caretHot ? RynthTheme.RcLabel : 0xFF9A9A9Au);
if (collapsed) return;
double menuNow = ImGuiNET.ImGui.GetTime();
_menuRects.Clear();
if (collapsed) { _menuHover.Update(null, false, menuNow); _overMenu = false; return; }
// Rows (header): perRow icons a row, each row from iconsX (under the first icon);
// RL and pop out go at the end of the first row (NextSlot, or after the icons when
@ -487,6 +508,7 @@ internal static class ImGuiBar
ImFontPtr letterFont = ImGuiFonts.Get(UiFont.UiBold11);
// A button whose window is open (docked or popped out) draws in the theme's accent
// (BarOpenState); a menu button (ILT, Scripts) while any window it lists is open.
string? menuHovered = null;
foreach (ButtonInfo b in _buttons!)
{
NextSlot(ref slot, perRow, iconsX, s, iconFont, popped);
@ -496,7 +518,12 @@ internal static class ImGuiBar
if (b.Window != null) ScriptWindowRegistry.PlayerSetVisible(b.Window, !open);
else PanelRouter.Toggle(b.Title);
}
SafeImGui.SetItemTooltip(b.Tooltip);
if (b.Menu != null)
{
if (ImGuiNET.ImGui.IsItemHovered()) menuHovered = b.Id;
_menuRects.Add((b, ImGuiNET.ImGui.GetItemRectMin(), ImGuiNET.ImGui.GetItemRectMax()));
}
if (_menuHover.OpenFor != b.Id) SafeImGui.SetItemTooltip(b.Tooltip); // the dropdown sits where it would show
}
// The ILT section: one button, only on Infinite Leaftide with ILT panels registered
@ -533,6 +560,109 @@ internal static class ImGuiBar
// Drawn after the bar buttons' style is popped, so the menu has the normal look.
ScriptsMenu(scripts);
IltMenu();
_menuHover.Update(menuHovered, _overMenu, menuNow);
DrawBarMenu(s, square, iconFont, letterFont);
}
/// <summary>
/// The bar icon dropdown of the button <see cref="BarMenuHover.OpenFor"/> names: a column of square icon
/// buttons flush under the icon (flush above it when that would cross the bottom of the screen), clamped
/// to the screen sideways. Its own window, not a popup, so the bar keeps its hover. A click runs the
/// item's chat command as the player's. AC thread, inside the bar window.
/// </summary>
private static void DrawBarMenu(float s, Vector2 square, ImFontPtr iconFont, ImFontPtr letterFont)
{
_overMenu = false;
string? openFor = _menuHover.OpenFor;
if (openFor == null) return;
ButtonInfo? owner = null;
Vector2 min = default, max = default;
foreach (var r in _menuRects)
if (r.Button.Id == openFor) { owner = r.Button; min = r.Min; max = r.Max; break; }
if (owner?.Menu == null || owner.Menu.Length == 0) { _menuHover.Close(); return; }
UI.Sections.SectionBarMenuItem[] items = owner.Menu;
Vector2 display = ImGuiNET.ImGui.GetIO().DisplaySize;
float inset = 4f * s; // WindowPadding (4, 3)
float width = square.X + 2f * inset;
float height = items.Length * square.Y + (items.Length - 1) * ButtonGap * s + 6f * s;
float x = min.X - inset, y = max.Y; // icons straight under the parent
if (display.X > 1 && display.Y > 1)
{
if (y + height > display.Y && min.Y - height >= 0f) y = min.Y - height; // flush above instead
x = Math.Max(0f, Math.Min(x, display.X - width));
}
ImGuiNET.ImGui.SetNextWindowPos(new Vector2(x, y), ImGuiCond.Always);
PushBarWindowStyle(s);
PushBarButtonStyle(s);
bool begun = ImGuiNET.ImGui.Begin("##rc_bar_menu", MenuFlags);
bool clicked = false;
try
{
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);
// ImGui truncates the window's position, which can leave the icons up to a pixel left of
// the parent; put each one exactly where the placement meant (the parent's left edge
// unless the viewport clamp moved the window). Each new line starts back at the window's
// own content edge, so this is set per icon.
float iconX = x + inset;
foreach (UI.Sections.SectionBarMenuItem item in items)
{
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(iconX, ImGuiNET.ImGui.GetCursorScreenPos().Y));
bool letter = item.Icon.Length == 0;
string glyph = letter ? FirstLetter(item.Tooltip) : item.Icon;
if (IconButton(owner.Id + "_m_" + item.Id, letter ? letterFont : iconFont, glyph, square, RynthTheme.BarText))
{
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);
}
}
}
finally
{
ImGuiNET.ImGui.End();
PopBarButtonStyle();
PopBarWindowStyle();
}
if (clicked) { _menuHover.Close(); _overMenu = false; }
}
private static IntPtr _getCurrentWindow, _bringToFront;
private static int _frontState; // 0 = not resolved, 1 = available, -1 = off
/// <summary>
/// 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.
/// </summary>
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]<void*>)_getCurrentWindow)();
if (window != null) ((delegate* unmanaged[Cdecl]<void*, void>)_bringToFront)(window);
}
/// <summary>
@ -836,7 +966,7 @@ internal static class ImGuiBar
bool letter = false;
string icon = w.Icon.Length > 0 ? w.Icon : IconFor(w.Title, out letter);
list.Add(new ButtonInfo(w.Title, "##bar_pw_" + w.Plugin + "_" + w.Id, icon, letter, w.Title,
BarOpenState.KeyFor(w.Title, null)));
BarOpenState.KeyFor(w.Title, null), Menu: w.Menu.Length > 0 ? w.Menu : null));
}
// Plugin script windows that asked for a button (RynthSort, Oracle, ...): after the
// engine's own. Only while the plugin is loaded and has submitted the window.

View file

@ -256,11 +256,14 @@ internal static class ImGuiPanelHost
}
}
/// <summary>Changes a dynamic face's header text. Any thread.</summary>
/// <summary>
/// Changes a face's header text: a dynamic face's, or an engine panel's that names what it
/// shows (an extra chat window's tab). Not while a plugin window has the panel's place. Any thread.
/// </summary>
public static void SetDisplayTitle(string key, string displayTitle)
{
lock (Sync)
if (Entries.TryGetValue(key, out Entry? e) && e.Dynamic) e.DisplayTitle = displayTitle;
if (Entries.TryGetValue(key, out Entry? e) && !e.TakenOver) e.DisplayTitle = displayTitle;
}
/// <summary>

View file

@ -109,6 +109,23 @@ internal static unsafe class ImGuiPopOuts
/// <summary>True while a pop-out's ImGui frame is being built (inside a face's Draw). AC thread.</summary>
public static bool InPopOutFrame => _current != null;
private static int _mainFrame;
/// <summary>
/// The main context's ImGui frame number, the same inside a pop-out's frame (whose own
/// context counts its frames from 0): for frame-numbered state shared across contexts
/// (a script window's local values and its replay budget, ScriptWindowReplay). AC thread.
/// </summary>
public static int FrameNumber =>
_current != null || ImGuiNET.ImGui.GetCurrentContext() == IntPtr.Zero ? _mainFrame : ImGuiNET.ImGui.GetFrameCount();
/// <summary>
/// Records the main context's frame number for <see cref="FrameNumber"/>. Call right after
/// the main context's NewFrame, with it current (EngineFrameController.BuildImGuiFrame):
/// the main context is not current when the pop-outs render. AC thread.
/// </summary>
public static void NoteMainFrame() => _mainFrame = ImGuiNET.ImGui.GetFrameCount();
/// <summary>
/// Where a popped-out face puts its window (its top-left in the pop-out's ImGui
/// coordinates): the panel's place on the work area. (0,0) outside a pop-out frame.
@ -422,6 +439,10 @@ internal static unsafe class ImGuiPopOuts
return;
}
// No ImGui call before a pop-out's own context is current: the main context is NOT current
// here (EngineFrameController restores the previous one, normally none, after each frame), and
// igGetFrameCount with no context is an access violation that ends the client (11-10). The main
// frame number comes from NoteMainFrame instead.
IntPtr previous = ImGuiNET.ImGui.GetCurrentContext();
long now = Stopwatch.GetTimestamp();
try
@ -720,7 +741,10 @@ internal static unsafe class ImGuiPopOuts
public static string? RequestSnapshot(string title)
{
if (!Pops.TryGetValue(title, out PopOut? pop)) return null;
string path = System.IO.Path.Combine(LogPaths.LogDirectory, $"popout_{title.Replace(' ', '_')}.bmp");
// A script window's key ("script:RynthLua/loot-inbox/Loot") isn't a file name as it is.
var name = new System.Text.StringBuilder(title.Length);
foreach (char c in title) name.Append(c == ' ' || Array.IndexOf(System.IO.Path.GetInvalidFileNameChars(), c) >= 0 ? '_' : c);
string path = System.IO.Path.Combine(LogPaths.LogDirectory, $"popout_{name}.bmp");
pop.Surface.SnapshotPath = path;
pop.HotFrames = Math.Max(pop.HotFrames, 2);
return path;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,265 @@
// ============================================================================
// RynthCore.Engine - ImGui/Panels/ChatWindowFace.cs
// Extra chat windows (2026-11-09; retail AC has them): "Chat 2" to "Chat 7"
// (UI/Data/ChatWindows.cs), each showing one tab of RynthChat beside the main
// chat, with its own scroll (following the newest line until you scroll up),
// search, unread counts and right-click menus - a ChatView of its own, drawn
// by the same code as the main chat's.
//
// Opening: the main chat's New chat window button (a list of tabs), "Open in
// new window" in any tab's right-click menu (main chat or an extra window), or
// /rc chatwindow open [tab]. Each window opens in the first free slot. Its
// header row: the tab button (click: the tabs, to switch this window's tab;
// right-click: the tab's menu), search, New chat window and Filters. The
// window's own header has pop-out and close, as every panel's.
//
// Each window is an ordinary engine panel to the host (registered once, by
// key), so it opens, closes, moves, resizes, pops out of the client into its
// own window and docks back like the main chat, independently of the others,
// and where it is, its size, docked or popped out and whether it is open are
// saved in the panel layout (panel_state.txt, per character) and come back
// after a hot reload or a restart (ImGuiPanelHost.RestoreOnce). The tab it
// shows is saved in that layout too (PanelStateStore value chatwin.<n>.tab),
// written only when the player opens a window on a tab, picks another tab
// for it, or renames that tab; a tab that is deleted shows as All without
// changing what is saved.
//
// No input line: there is one chat entry (Enter, the typed line, Tell), the
// main chat's. These windows don't count as the chat being shown
// (ChatModel.SetShown), so Enter never types into a window without a box.
// AC's thread (the panel host), except the static Open/Close/Describe calls
// (any thread: they only queue panel requests and read the store).
// ============================================================================
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Threading;
using ImGuiNET;
using RynthCore.Engine.UI;
using RynthCore.Engine.UI.Data;
using static RynthCore.Engine.ImGuiBackend.Panels.FaceKit;
namespace RynthCore.Engine.ImGuiBackend.Panels;
internal sealed class ChatWindowFace : IImGuiPanel
{
private readonly int _number;
private readonly string _key;
private readonly ChatView _view;
/// <summary>The tab saved for this window ("" when none).</summary>
private string _savedTab = "";
private int _readGeneration = -1, _readVersion = -1;
private string _shownHeader = "";
/// <summary>Goes up when any window's saved tab changes: the open ones read theirs again.</summary>
private static int s_tabsVersion;
private ChatWindowFace(int number)
{
_number = number;
_key = ChatWindows.Key(number);
_view = new ChatView(_key, isMain: false, () => CurrentTab, tab => SaveTab(_number, tab));
}
/// <summary>The extra windows' panels: once, at engine init, beside the main chat.</summary>
public static void RegisterAll()
{
for (int n = ChatWindows.FirstNumber; n <= ChatWindows.LastNumber; n++)
{
int number = n;
ImGuiPanelHost.Register(ChatWindows.Key(number), ChatFace.Spec, () => new ChatWindowFace(number));
}
}
private string CurrentTab => ChatWindows.EffectiveTab(_savedTab, ChatModel.AllTabs());
public bool ClickThrough => ChatModel.CtrlGatedClickThrough && !ImGuiNET.ImGui.GetIO().KeyCtrl;
public int PopOutIdleHz => 5;
public void OnShown()
{
ChatModel.EnsureSettingsLoaded();
UiSources.Chat.Subscribe();
UiSources.Chat.RequestRefresh();
ReadTab();
UpdateHeader();
_view.OnShown();
}
public void OnHidden()
{
UiSources.Chat.Unsubscribe();
_view.OnHidden();
}
/// <summary>Reads this window's saved tab (on open, after a layout switch, after a tab was saved).</summary>
private void ReadTab()
{
_readGeneration = PanelStateStore.Generation;
_readVersion = Volatile.Read(ref s_tabsVersion);
_savedTab = PanelStateStore.TryGetValue(ChatWindows.TabValueKey(_number), out string t) ? t : "";
}
private void UpdateHeader()
{
string header = ChatWindows.HeaderText(_number, CurrentTab);
if (string.Equals(header, _shownHeader, StringComparison.Ordinal)) return;
_shownHeader = header;
ImGuiPanelHost.SetDisplayTitle(_key, header);
}
public void Draw()
{
if (PanelStateStore.Generation != _readGeneration || Volatile.Read(ref s_tabsVersion) != _readVersion)
ReadTab();
UpdateHeader();
Vector2 origin = ImGuiNET.ImGui.GetCursorScreenPos();
Vector2 size = ImGuiNET.ImGui.GetContentRegionAvail();
var dl = ImGuiNET.ImGui.GetWindowDrawList();
uint bg = RynthTheme.Argb(((uint)Math.Clamp(ChatModel.BackgroundAlpha, 0, 255) << 24) | 0x0A121A);
dl.AddRectFilled(origin, origin + size, bg, 4);
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui10));
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 4));
float x0 = origin.X + 4, w = size.X - 8;
var snap = UiSources.Chat.Current;
ChatLine[] lines = snap?.Value ?? Array.Empty<ChatLine>();
string tab = _view.BeginFrame(lines, snap?.Version ?? -1);
// Top row: the tab button, search, New chat window, Filters.
const float h = 22;
var start = new Vector2(x0, origin.Y + 4);
float right = x0 + w, btnW = 22;
if (IconButton("##chatwin_filters", PhosphorIcons.Funnel, new Vector2(right - btnW, start.Y), new Vector2(btnW, h), Text, BtnFill))
PanelRouter.Toggle("ChatFilters");
ImGuiNET.ImGui.SetItemTooltip("Filters: move, copy or hide lines by regex, and colour them");
float winX = right - btnW - 3 - btnW;
_view.DrawNewWindowButton("##chatwin_newwin", new Vector2(winX, start.Y), new Vector2(btnW, h));
if (_view.DrawTabButton("##chatwin_tab", start, w * 0.45f, h, highlight: false))
_view.OpenTabsPopup();
if (ImGuiNET.ImGui.IsItemClicked(ImGuiMouseButton.Right)) _view.OpenTabMenu(tab);
float sx = start.X + _view.LastTabButtonWidth + 4, sw = winX - 4 - sx;
if (sw > 40) _view.DrawSearch(new Vector2(sx, start.Y), sw);
float y = start.Y + h + 4;
_view.SyncLines(snap, lines, tab);
// The scrollback fills the rest, ending above the resize grip in the bottom-right corner.
float reserve = ImGuiPanelHost.BodyGripReserve;
float bottom = origin.Y + size.Y - Math.Max(2f, reserve);
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(x0, y));
_view.DrawLines(new Vector2(w, Math.Max(20, bottom - y)));
ImGuiNET.ImGui.PopStyleVar();
ChatView.PushPopupStyle();
_view.DrawPopups();
ChatView.PopPopupStyle();
ImGuiNET.ImGui.PopFont();
}
// ── Opening, closing and the saved tabs (any thread) ────────────────────
private static string SavedTab(int number) =>
PanelStateStore.TryGetValue(ChatWindows.TabValueKey(number), out string t) ? t : "";
/// <summary>Saves the tab window <paramref name="number"/> shows: the player picked it.</summary>
private static void SaveTab(int number, string tab)
{
PanelStateStore.SetValue(ChatWindows.TabValueKey(number), tab);
Interlocked.Increment(ref s_tabsVersion);
}
/// <summary>The extra windows are registered (RynthChat is installed and the ImGui layer is on). Any thread.</summary>
internal static bool Available =>ImGuiPanelHost.HasFace(ChatWindows.Key(ChatWindows.FirstNumber));
private const string NotAvailable = "Chat windows aren't available (the ImGui layer is off?).";
/// <summary>
/// Opens <paramref name="tab"/> (null or blank: the main chat's tab) in the first free extra
/// window; one that already shows it stays the only one. The player asked for it (a button,
/// a menu or a command). Returns whether a window shows it now, and what to tell the player.
/// </summary>
public static (bool Ok, string Message) OpenNew(string? tab)
{
if (!Available) return (false, NotAvailable);
string[] all = ChatModel.AllTabs();
string? resolved = string.IsNullOrWhiteSpace(tab) ? ChatModel.CurrentTab() : ChatWindows.Resolve(tab, all);
if (resolved == null) return (false, $"No tab called '{tab!.Trim()}'. Tabs: {string.Join(", ", all)}.");
for (int n = ChatWindows.FirstNumber; n <= ChatWindows.LastNumber; n++)
if (ImGuiPanelHost.IsOpen(ChatWindows.Key(n))
&& string.Equals(ChatWindows.EffectiveTab(SavedTab(n), all), resolved, StringComparison.OrdinalIgnoreCase))
return (true, $"Chat {n} already shows {resolved}.");
int free = ChatWindows.FirstFree(ImGuiPanelHost.IsOpen);
if (free == 0) return (false, $"All {ChatWindows.MaxWindows} extra chat windows are open: close one first.");
SaveTab(free, resolved);
ImGuiPanelHost.Open(ChatWindows.Key(free));
return (true, $"Chat {free} opened on {resolved}.");
}
/// <summary>Shows <paramref name="tab"/> in window <paramref name="number"/> (opening it if closed).</summary>
public static (bool Ok, string Message) ShowTab(int number, string tab)
{
if (!Available) return (false, NotAvailable);
string[] all = ChatModel.AllTabs();
string? resolved = ChatWindows.Resolve(tab, all);
if (resolved == null) return (false, $"No tab called '{tab.Trim()}'. Tabs: {string.Join(", ", all)}.");
SaveTab(number, resolved);
bool wasOpen = ImGuiPanelHost.IsOpen(ChatWindows.Key(number));
if (!wasOpen) ImGuiPanelHost.Open(ChatWindows.Key(number));
return (true, wasOpen ? $"Chat {number} now shows {resolved}." : $"Chat {number} opened on {resolved}.");
}
public static (bool Ok, string Message) Close(int number)
{
if (!Available) return (false, NotAvailable);
string key = ChatWindows.Key(number);
if (!ImGuiPanelHost.IsOpen(key)) return (false, $"Chat {number} isn't open.");
ImGuiPanelHost.Close(key);
return (true, $"Chat {number} closed.");
}
public static (bool Ok, string Message) CloseAll()
{
if (!Available) return (false, NotAvailable);
int closed = 0;
foreach (string key in ChatWindows.Keys())
if (ImGuiPanelHost.IsOpen(key)) { ImGuiPanelHost.Close(key); closed++; }
return (true, closed == 0 ? "No extra chat window is open." : $"Closed {closed} chat window{(closed == 1 ? "" : "s")}.");
}
/// <summary>One line per extra window: open or closed, its tab, docked or popped out.</summary>
public static List<string> Describe()
{
var lines = new List<string>();
if (!Available) { lines.Add(NotAvailable); return lines; }
string[] all = ChatModel.AllTabs();
int open = 0;
for (int n = ChatWindows.FirstNumber; n <= ChatWindows.LastNumber; n++)
{
string key = ChatWindows.Key(n);
if (!ImGuiPanelHost.IsOpen(key)) continue;
open++;
string saved = SavedTab(n);
string tab = ChatWindows.EffectiveTab(saved, all);
string gone = saved.Length > 0 && !string.Equals(saved, tab, StringComparison.OrdinalIgnoreCase) ? $" ({saved} is gone)" : "";
lines.Add($"Chat {n}: {tab}{gone}, {(ImGuiPanelHost.IsPopped(key) ? "popped out" : "in the client")}.");
}
lines.Insert(0, open == 0
? "No extra chat window is open (the main chat's window button, or right-click a tab: Open in new window). " + ChatWindows.Usage
: $"{open} of {ChatWindows.MaxWindows} extra chat windows open:");
return lines;
}
/// <summary>
/// The player renamed a tab (ChatModel.RenameCustomTab): the windows that show it follow. Any thread.
/// </summary>
public static void OnTabRenamed(string from, string to)
{
for (int n = ChatWindows.FirstNumber; n <= ChatWindows.LastNumber; n++)
if (ChatWindows.FollowRename(SavedTab(n), from, to) is string next)
SaveTab(n, next);
}
}

View file

@ -70,7 +70,9 @@ internal static unsafe class ScriptWindowReplay
/// <summary>Draws <paramref name="w"/>'s latest list into the current window. AC thread.</summary>
public static void Draw(ScriptWindow w)
{
int frame = ImGuiNative.igGetFrameCount();
// The main context's frame number, also in a pop-out (whose context counts from 0):
// the locals' ages, the budget and the latency stay in one count when a window moves.
int frame = ImGuiPopOuts.FrameNumber;
if (frame != _frame)
{
_frame = frame;
@ -466,6 +468,10 @@ internal static unsafe class ScriptWindowReplay
}
case ScriptOp.TreeNode:
{
// Open state lives in the ImGui context: a window drawn in a new one (popped
// out, or back in) starts as the script recorded it, not closed. Once = only
// where this context has no state for the node; elsewhere the player's wins.
ImGuiNative.igSetNextItemOpen(op.Flag != 0 ? (byte)1 : (byte)0, ImGuiCond.Once);
byte live = ImGuiNative.igTreeNodeEx_Str(str, (ImGuiTreeNodeFlags)op.Flags);
ReportOpen(w, ref op, live, frame);
if (live != 0 && op.Flag != 0 && open < Scopes.Length)
@ -480,6 +486,7 @@ internal static unsafe class ScriptWindowReplay
}
case ScriptOp.CollapsingHeader:
{
ImGuiNative.igSetNextItemOpen(op.Flag != 0 ? (byte)1 : (byte)0, ImGuiCond.Once); // as TreeNode
byte live = ImGuiNative.igCollapsingHeader_TreeNodeFlags(str, (ImGuiTreeNodeFlags)op.Flags);
ReportOpen(w, ref op, live, frame);
// Just closed by the player: the recorded contents follow; hide them until the