Snapshot for release 2026.10.12.1 (internal ef4d41d)
This commit is contained in:
parent
08b80eed86
commit
b0f9d74b21
54 changed files with 5062 additions and 935 deletions
|
|
@ -5,7 +5,9 @@
|
|||
// Same content as the Avalonia bar, as square Phosphor icon buttons with
|
||||
// the names in tooltips: the grip (RC: build stamp tooltip), one button per
|
||||
// registered panel except the ones the RynthAi launcher opens (PanelIcons;
|
||||
// an unknown panel shows its first letter), reload (RL) and pop out.
|
||||
// an unknown panel shows its first letter), one per plugin script window that
|
||||
// asked for a button (WindowFlags.BarButton: RynthSort, Oracle, ...; tooltip =
|
||||
// its title; the set is rebuilt as plugins come and go), reload (RL) and pop out.
|
||||
// Dragging the grip moves the bar; the position is the shared bar= row in
|
||||
// panel_state.txt. Right-click a panel button (or the grip for the bar
|
||||
// itself) to choose which face shows it docked; the grip's menu also has the
|
||||
|
|
@ -48,8 +50,10 @@ internal static class ImGuiBar
|
|||
private static readonly PanelFace[] Faces = { PanelFace.Avalonia, PanelFace.ImGui, PanelFace.Both };
|
||||
private static readonly string[] FaceNames = { "Avalonia", "ImGui", "Both (side by side)" };
|
||||
|
||||
// Window: a plugin's script window with a bar button of its own (WindowFlags.BarButton);
|
||||
// the button toggles it through ScriptWindowRegistry, like the Scripts menu does.
|
||||
private sealed record ButtonInfo(string Title, string Id, string PopupId, string Icon, bool Letter, string Tooltip,
|
||||
bool ImGuiOnly = false);
|
||||
bool ImGuiOnly = false, ScriptWindow? Window = null);
|
||||
|
||||
// Engine panels with an ImGui face only (no OverlayHost entry) that get a bar button.
|
||||
private static readonly string[] ImGuiOnlyBarPanels =
|
||||
|
|
@ -84,6 +88,10 @@ internal static class ImGuiBar
|
|||
["Log"] = PhosphorIcons.TerminalWindow,
|
||||
["Item Count"] = PhosphorIcons.Bag,
|
||||
["Mini Remote"] = PhosphorIcons.SquaresFour,
|
||||
// Plugin windows with a bar button of their own (script windows, by title).
|
||||
["RynthSort"] = PhosphorIcons.SortAscending,
|
||||
["Oracle"] = PhosphorIcons.Sparkle,
|
||||
["Global Inventory"] = PhosphorIcons.GlobeHemisphereWest,
|
||||
};
|
||||
|
||||
/// <summary>A panel's bar icon: its Phosphor icon, else its first letter (letter = true).</summary>
|
||||
|
|
@ -111,6 +119,10 @@ internal static class ImGuiBar
|
|||
}
|
||||
|
||||
private static ButtonInfo[]? _buttons;
|
||||
// What _buttons was built from: the plugin windows' snapshot (a new array on every change)
|
||||
// and which ImGui-only panels had a face. Either changing rebuilds the buttons.
|
||||
private static ScriptBarItem[]? _builtScriptButtons;
|
||||
private static int _builtImGuiOnlyMask;
|
||||
private static string _tooltip = "";
|
||||
private static bool _placed;
|
||||
private static Vector2 _pos, _persistedPos;
|
||||
|
|
@ -366,8 +378,11 @@ internal static class ImGuiBar
|
|||
{
|
||||
ImGuiNET.ImGui.SameLine();
|
||||
if (IconButton(b.Id, b.Letter ? letterFont : iconFont, b.Icon, square, RynthTheme.BarText))
|
||||
PanelRouter.Toggle(b.Title);
|
||||
ImGuiNET.ImGui.SetItemTooltip(b.Tooltip);
|
||||
{
|
||||
if (b.Window != null) ScriptWindowRegistry.PlayerSetVisible(b.Window, !ImGuiPanelHost.IsOpen(b.Window.PanelKey));
|
||||
else PanelRouter.Toggle(b.Title);
|
||||
}
|
||||
ImGuiNET.ImGui.SetItemTooltip(b.Tooltip); // a plugin window's title arrives with '%' doubled (EnsureButtons)
|
||||
if (b.ImGuiOnly) continue; // no Avalonia face: no face to choose
|
||||
if (ImGuiNET.ImGui.IsItemClicked(ImGuiMouseButton.Right))
|
||||
ImGuiNET.ImGui.OpenPopup(b.PopupId);
|
||||
|
|
@ -390,8 +405,8 @@ internal static class ImGuiBar
|
|||
}
|
||||
|
||||
// Script windows (decision 2): one button with a menu, only while a ShowInBar
|
||||
// script window exists. They never get buttons of their own (EnsureButtons
|
||||
// lists OverlayHost's engine panels only; script windows are dynamic entries).
|
||||
// script window exists. A window that also sets BarButton (plugin windows such as
|
||||
// RynthSort's) has a button of its own instead (EnsureButtons) and isn't listed here.
|
||||
ScriptBarItem[] scripts = ScriptWindowRegistry.BarItems;
|
||||
if (scripts.Length > 0)
|
||||
{
|
||||
|
|
@ -591,9 +606,27 @@ internal static class ImGuiBar
|
|||
ImGuiNET.ImGui.PopStyleVar(3);
|
||||
}
|
||||
|
||||
/// <summary>Bit i set: ImGuiOnlyBarPanels[i] has a face now.</summary>
|
||||
private static int ImGuiOnlyMask()
|
||||
{
|
||||
int mask = 0;
|
||||
for (int i = 0; i < ImGuiOnlyBarPanels.Length; i++)
|
||||
if (ImGuiPanelHost.HasFace(ImGuiOnlyBarPanels[i])) mask |= 1 << i;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The bar's buttons, rebuilt when the set changes: a plugin window with a bar button
|
||||
/// appeared, went (plugin unloaded, window dropped) or was renamed, or an ImGui-only
|
||||
/// panel's face was registered or removed. AC thread, every frame (two cheap checks).
|
||||
/// </summary>
|
||||
private static void EnsureButtons()
|
||||
{
|
||||
if (_buttons != null) return;
|
||||
ScriptBarItem[] scriptButtons = ScriptWindowRegistry.BarButtons;
|
||||
int mask = ImGuiOnlyMask();
|
||||
if (_buttons != null && ReferenceEquals(scriptButtons, _builtScriptButtons) && mask == _builtImGuiOnlyMask) return;
|
||||
_builtScriptButtons = scriptButtons;
|
||||
_builtImGuiOnlyMask = mask;
|
||||
var list = new List<ButtonInfo>();
|
||||
foreach (var (title, _) in OverlayHost.GetPanels())
|
||||
if (!LauncherOnly.Contains(title))
|
||||
|
|
@ -608,6 +641,17 @@ internal static class ImGuiBar
|
|||
string icon = IconFor(title, out bool letter);
|
||||
list.Add(new ButtonInfo(title, "##bar_" + title, "##face_" + title, icon, letter, title, ImGuiOnly: true));
|
||||
}
|
||||
// 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.
|
||||
foreach (ScriptBarItem item in scriptButtons)
|
||||
{
|
||||
ScriptWindow w = item.Window;
|
||||
string title = w.Title.Length > 0 ? w.Title : w.Key;
|
||||
string icon = IconFor(title, out bool letter);
|
||||
string id = "##bar_sw" + w.Hash.ToString("X8");
|
||||
// The tooltip goes through SetItemTooltip, a format function: the plugin's text with '%' doubled.
|
||||
list.Add(new ButtonInfo(title, id, id + "_face", icon, letter, title.Replace("%", "%%"), ImGuiOnly: true, Window: w));
|
||||
}
|
||||
_buttons = list.ToArray();
|
||||
_tooltip = $"RynthCore {EntryPoint.BuildStamp}\nDrag here to move the bar. Right-click: bar face and size. Ctrl+wheel over the bar: size.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ internal static unsafe class ImGuiFonts
|
|||
// dashes are in MainRanges.
|
||||
private static readonly ushort[] SymbolCodepoints =
|
||||
{
|
||||
0x2264, 0x2265, // ≤ ≥ (Meta rule list: "Prismatic Taper ≤ 50")
|
||||
0x25CF, // ● (Meta source: unapplied edits)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@
|
|||
// from it: move / copy lines like it to a tab, hide them, colour them. A line
|
||||
// with map coordinates in it ("42.1N, 33.6E") also offers "Arrow to" and "Go
|
||||
// to" them, sent to RynthNav (UI/Data/ChatCoords.cs finds them).
|
||||
// Follows the newest line until you scroll up.
|
||||
// Follows the newest line until you scroll up; the scroll for new lines is set
|
||||
// in the same frame they're drawn (DrawLines; until 2026-10-11 it landed a frame
|
||||
// late and the text bounced). Scrolled up, the view holds still. The history is
|
||||
// as long as the "Chat history" setting (ChatHistory, up to 10,000 lines): no
|
||||
// per-frame work walks all of it, and re-measuring after a resize is time-sliced.
|
||||
//
|
||||
// The input line belongs to ChatModel (UI/Data/ChatData.cs): Win32Backend
|
||||
// turns the chat keys into ChatModel edits on AC's thread, which is also
|
||||
|
|
@ -74,7 +78,11 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
private readonly List<float> _h = new(512);
|
||||
private readonly List<SpanLayout?> _lay = new(512);
|
||||
private float[] _tops = new float[1];
|
||||
private int _heightsFrom; // first line whose height needs measuring
|
||||
private int _heightsFrom; // first new line: not measured at all yet
|
||||
// Lines below this index were measured for another width or font, or not at all (a
|
||||
// rebuild gives them one row each until then): MeasureLines catches up a few ms a frame.
|
||||
private int _measuredFrom;
|
||||
private float _rowH = 13f; // one row of the chat font: an unmeasured line's height
|
||||
private bool _topsDirty = true;
|
||||
private long _seenLinesVersion = -1, _seenRoutes = -1, _lastId;
|
||||
private string _seenTab = "", _seenSearch = "";
|
||||
|
|
@ -88,6 +96,13 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
// tail: the view is moved up by as much, so the lines being read stay put instead of
|
||||
// sliding away.
|
||||
private float _droppedAbove;
|
||||
// The part of a dropped-lines move ImGui's whole-pixel scroll couldn't take, carried
|
||||
// into the next one (heights can be fractional at some DPI scales).
|
||||
private float _scrollCarry;
|
||||
// The list's scrollbar width (always shown), and a correction to the list width
|
||||
// DrawLines works out before its BeginChild, should the child ever report another.
|
||||
private const float ListScrollbarW = 10f;
|
||||
private float _wrapFix;
|
||||
private float _inputScroll;
|
||||
|
||||
// Selection: indices into _vis.
|
||||
|
|
@ -100,12 +115,14 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
// Unread lines per tab since it was last on screen (Id of the newest line seen there).
|
||||
private readonly Dictionary<string, long> _seenId = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, (int Count, bool Mention)> _unread = new(StringComparer.OrdinalIgnoreCase);
|
||||
private long _unreadLines = -1, _unreadRoutes = -1, _unreadTabsVersion = -1;
|
||||
private long _unreadLines = -1, _unreadRoutes = -1, _unreadTabsVersion = -1, _unreadCountedTo;
|
||||
private string _unreadTab = "";
|
||||
|
||||
private bool _openSettings, _openNewTab, _focusNewTab, _openTabMenu, _openLineMenu, _openRename;
|
||||
/// <summary>A line colour changed and isn't saved yet (saved once the picker is let go).</summary>
|
||||
private bool _coloursDirty;
|
||||
/// <summary>The Chat history slider's value while it's held (0: not held).</summary>
|
||||
private int _historyEdit;
|
||||
private string? _ctxTab, _renameFrom;
|
||||
private ChatLine? _ctxLine;
|
||||
private string _ctxPattern = "";
|
||||
|
|
@ -129,7 +146,7 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
_stick = true;
|
||||
_seenRoutes = -1; // full rebuild on the first frame
|
||||
_seenId.Clear(); // every tab starts read
|
||||
_unreadLines = -1;
|
||||
_unreadLines = _unreadRoutes = -1; // a full recount
|
||||
}
|
||||
|
||||
public void OnHidden()
|
||||
|
|
@ -351,22 +368,30 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
long newest = lines.Length > 0 ? lines[^1].Id : 0;
|
||||
_seenId[current] = newest;
|
||||
long routes = ChatModel.RoutesVersion, tabsVersion = ChatModel.FiltersVersion;
|
||||
if (linesVersion == _unreadLines && routes == _unreadRoutes && tabsVersion == _unreadTabsVersion
|
||||
&& string.Equals(current, _unreadTab, StringComparison.Ordinal)) return;
|
||||
bool recount = routes != _unreadRoutes || tabsVersion != _unreadTabsVersion
|
||||
|| !string.Equals(current, _unreadTab, StringComparison.Ordinal);
|
||||
if (!recount && linesVersion == _unreadLines) return;
|
||||
_unreadLines = linesVersion;
|
||||
_unreadRoutes = routes;
|
||||
_unreadTabsVersion = tabsVersion;
|
||||
_unreadTab = current;
|
||||
_unread.Clear();
|
||||
// Only new lines arrived: count just those (lines past _unreadCountedTo). A full recount
|
||||
// walks every unread line of every tab - up to the whole history per tab (3.7 ms at
|
||||
// 10,000 lines, tools/ChatHistoryBench), which used to run on every new batch.
|
||||
if (recount) _unread.Clear();
|
||||
foreach (string tab in ChatModel.AllTabs())
|
||||
{
|
||||
if (!_seenId.TryGetValue(tab, out long seen)) { _seenId[tab] = newest; continue; } // a new tab starts read
|
||||
long from = recount ? seen : Math.Max(seen, _unreadCountedTo);
|
||||
int count = 0;
|
||||
bool mention = false;
|
||||
for (int i = lines.Length - 1; i >= 0 && lines[i].Id > seen; i--)
|
||||
for (int i = lines.Length - 1; i >= 0 && lines[i].Id > from; i--)
|
||||
if (ChatModel.LineInTab(lines[i], tab)) { count++; mention |= lines[i].Route.Mention; }
|
||||
if (count > 0) _unread[tab] = (count, mention);
|
||||
if (count == 0) continue;
|
||||
_unread.TryGetValue(tab, out var had);
|
||||
_unread[tab] = (had.Count + count, had.Mention || mention);
|
||||
}
|
||||
_unreadCountedTo = newest;
|
||||
}
|
||||
|
||||
private void DrawSearch(Vector2 p, float w)
|
||||
|
|
@ -399,9 +424,9 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
_h.Clear();
|
||||
_lay.Clear();
|
||||
foreach (ChatLine line in lines)
|
||||
if (ChatModel.LineVisible(line, tab, search)) { _vis.Add(line); _h.Add(0); _lay.Add(null); }
|
||||
if (ChatModel.LineVisible(line, tab, search)) { _vis.Add(line); _h.Add(_rowH); _lay.Add(null); }
|
||||
_lastId = lines.Length > 0 ? lines[^1].Id : _lastId;
|
||||
_heightsFrom = 0;
|
||||
_heightsFrom = _measuredFrom = _vis.Count; // all unmeasured: MeasureLines, newest first
|
||||
_topsDirty = true;
|
||||
ClearSelection();
|
||||
_stick = true; // a rebuild re-pins to the newest line
|
||||
|
|
@ -423,6 +448,7 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
_h.RemoveRange(0, drop);
|
||||
_lay.RemoveRange(0, drop);
|
||||
_heightsFrom = Math.Max(0, _heightsFrom - drop);
|
||||
_measuredFrom = Math.Max(0, _measuredFrom - drop);
|
||||
if (_selAnchor >= 0) { _selAnchor -= drop; _selEnd -= drop; if (_selAnchor < 0 || _selEnd < 0) ClearSelection(); }
|
||||
_topsDirty = true;
|
||||
}
|
||||
|
|
@ -433,7 +459,7 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
if (!ChatModel.LineVisible(line, tab, search)) continue;
|
||||
if (_heightsFrom > _vis.Count) _heightsFrom = _vis.Count;
|
||||
_vis.Add(line);
|
||||
_h.Add(0);
|
||||
_h.Add(_rowH);
|
||||
_lay.Add(null);
|
||||
_topsDirty = true;
|
||||
}
|
||||
|
|
@ -444,81 +470,85 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
|
||||
private void DrawLines(Vector2 size)
|
||||
{
|
||||
// Lines left the top of a full buffer while not following: scroll up by as much
|
||||
// in THIS frame's BeginChild. (SetScrollY only lands in the next frame's Begin,
|
||||
// after this frame has drawn the shortened list at the old scroll - the text
|
||||
// jumped up for a frame and a strip at the bottom went blank, several times a
|
||||
// second in busy chat.) A frame with wheel input waits a frame: this would
|
||||
// override the wheel's own scroll.
|
||||
bool compensated = false;
|
||||
if (_droppedAbove > 0f)
|
||||
{
|
||||
if (Following) _droppedAbove = 0f;
|
||||
else if (ImGuiNET.ImGui.GetIO().MouseWheel == 0f)
|
||||
{
|
||||
ImGuiNET.ImGui.SetNextWindowScroll(new Vector2(-1f, Math.Max(0f, _lastScrollY - _droppedAbove)));
|
||||
_droppedAbove = 0f;
|
||||
compensated = true;
|
||||
}
|
||||
}
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.ChildBg, 0u);
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.ScrollbarBg, 0u);
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0));
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ScrollbarSize, 10f);
|
||||
bool open = ImGuiNET.ImGui.BeginChild("##chat_lines", size, ImGuiChildFlags.None, ImGuiWindowFlags.AlwaysVerticalScrollbar);
|
||||
ImGuiNET.ImGui.PopStyleVar(2);
|
||||
ImGuiNET.ImGui.PopStyleColor(2);
|
||||
if (!open) { ImGuiNET.ImGui.EndChild(); return; }
|
||||
|
||||
float fontSize = ChatModel.FontSize;
|
||||
ImFontPtr font = ImGuiFonts.Chat(fontSize);
|
||||
ImGuiNET.ImGui.PushFont(font);
|
||||
bool showTs = ChatModel.ShowTimestamps;
|
||||
float wrapW = Math.Max(20, ImGuiNET.ImGui.GetContentRegionAvail().X - 6);
|
||||
// The text starts after the timestamp and wraps under itself.
|
||||
|
||||
// The lines are measured BEFORE the list's BeginChild, so this frame's scroll can be
|
||||
// set for this frame's lines (see "Where the view goes" below). The width they wrap
|
||||
// to is the child's: its width less its scrollbar (always shown) and a margin;
|
||||
// _wrapFix corrects that guess if the child ever reports otherwise.
|
||||
float wrapW = Math.Max(20, MathF.Floor(size.X) - ListScrollbarW - 6 + _wrapFix);
|
||||
float tsW = showTs ? ImGuiNET.ImGui.CalcTextSize("00:00:00 ").X : 0;
|
||||
MeasureLines(font, wrapW, tsW, fontSize, showTs, MathF.Floor(size.Y));
|
||||
float total = _tops[_vis.Count];
|
||||
|
||||
// Where the view goes this frame. (2026-10-11, the chat "bouncing": until now the
|
||||
// view followed the newest line with SetScrollHereY at the end of the frame, which
|
||||
// only lands in the NEXT frame's Begin. So every batch of new lines was first drawn
|
||||
// at the old scroll: with the buffer full, lines leave the top as others arrive,
|
||||
// and the text jumped by the difference - up and back down when a long line left
|
||||
// and a short one came - then snapped into place a frame later. A popped-out chat
|
||||
// redraws at 5 Hz while idle, so the wrong frame stayed up for 200 ms.) Now the
|
||||
// content height and the scroll are both handed to this frame's BeginChild:
|
||||
// • the content size, so ImGui's scroll limit is this frame's and not last frame's
|
||||
// (it clamps any scroll set before Begin to the limit it knows);
|
||||
// • following: the bottom (the limit clamps 'total' to exactly the bottom);
|
||||
// • not following: only the lines dropped off a full buffer's top, so what is
|
||||
// being read stays put (fractions carried, so rounding can't creep the view).
|
||||
// A frame with wheel input over the list leaves the scroll to the wheel (this would
|
||||
// override it); a drag-select scrolls the list itself.
|
||||
Vector2 listPos = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
bool wheelHere = ImGuiNET.ImGui.GetIO().MouseWheel != 0f
|
||||
&& ImGuiNET.ImGui.IsMouseHoveringRect(listPos, listPos + size, false);
|
||||
ImGuiNET.ImGui.SetNextWindowContentSize(new Vector2(0f, total));
|
||||
bool compensated = false;
|
||||
if (Following)
|
||||
{
|
||||
_droppedAbove = 0f;
|
||||
_scrollCarry = 0f;
|
||||
// Not counted as "our move": a scrollbar drag in this Begin overrides it, and the
|
||||
// check below must see that to stop following.
|
||||
if (!wheelHere && !_selDragging)
|
||||
ImGuiNET.ImGui.SetNextWindowScroll(new Vector2(-1f, total));
|
||||
}
|
||||
else if (_droppedAbove != 0f && !wheelHere)
|
||||
{
|
||||
float target = _lastScrollY + _scrollCarry - _droppedAbove;
|
||||
float applied = MathF.Round(Math.Max(0f, target)); // ImGui rounds scroll to whole pixels
|
||||
_scrollCarry = target > 0f ? target - applied : 0f;
|
||||
ImGuiNET.ImGui.SetNextWindowScroll(new Vector2(-1f, applied));
|
||||
_droppedAbove = 0f;
|
||||
compensated = true;
|
||||
}
|
||||
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.ChildBg, 0u);
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.ScrollbarBg, 0u);
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0));
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ScrollbarSize, ListScrollbarW);
|
||||
bool open = ImGuiNET.ImGui.BeginChild("##chat_lines", size, ImGuiChildFlags.None, ImGuiWindowFlags.AlwaysVerticalScrollbar);
|
||||
ImGuiNET.ImGui.PopStyleVar(2);
|
||||
ImGuiNET.ImGui.PopStyleColor(2);
|
||||
if (!open) { ImGuiNET.ImGui.EndChild(); ImGuiNET.ImGui.PopFont(); return; }
|
||||
|
||||
// The child's real width, should the guess above ever be off (a style change):
|
||||
// measured again now, and the guess corrected from the next frame on.
|
||||
float realWrapW = Math.Max(20, ImGuiNET.ImGui.GetContentRegionAvail().X - 6);
|
||||
if (Math.Abs(realWrapW - wrapW) > 0.5f)
|
||||
{
|
||||
_wrapFix += realWrapW - wrapW;
|
||||
wrapW = realWrapW;
|
||||
MeasureLines(font, wrapW, tsW, fontSize, showTs, MathF.Floor(size.Y));
|
||||
total = _tops[_vis.Count];
|
||||
}
|
||||
float textW = Math.Max(20, wrapW - tsW);
|
||||
if (wrapW != _seenWrap || fontSize != _seenFont || showTs != _seenTs)
|
||||
{
|
||||
_seenWrap = wrapW;
|
||||
_seenFont = fontSize;
|
||||
_seenTs = showTs;
|
||||
_heightsFrom = 0;
|
||||
}
|
||||
if (_heightsFrom < _vis.Count)
|
||||
{
|
||||
for (int i = _heightsFrom; i < _vis.Count; i++)
|
||||
{
|
||||
ChatLine line = _vis[i];
|
||||
ChatSpan[]? spans = line.Route.Spans;
|
||||
if (spans != null)
|
||||
{
|
||||
SpanLayout lay = LayoutSpans(font, line.Text, spans, textW);
|
||||
_lay[i] = lay;
|
||||
_h[i] = lay.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lay[i] = null;
|
||||
_h[i] = ImGuiNET.ImGui.CalcTextSize(line.Text, false, textW).Y;
|
||||
}
|
||||
}
|
||||
_heightsFrom = _vis.Count;
|
||||
_topsDirty = true;
|
||||
}
|
||||
if (_topsDirty)
|
||||
{
|
||||
if (_tops.Length < _vis.Count + 1) _tops = new float[Math.Max(_vis.Count + 1, _tops.Length * 2)];
|
||||
_tops[0] = 0;
|
||||
for (int i = 0; i < _vis.Count; i++) _tops[i + 1] = _tops[i] + _h[i];
|
||||
_topsDirty = false;
|
||||
}
|
||||
int n = _vis.Count;
|
||||
float total = _tops[n];
|
||||
|
||||
// Following the tail until the user scrolls away from it.
|
||||
float scrollY = ImGuiNET.ImGui.GetScrollY(), maxY = ImGuiNET.ImGui.GetScrollMaxY();
|
||||
if (compensated) _lastScrollY = scrollY; // our move, not the user's
|
||||
else if (Math.Abs(scrollY - _lastScrollY) > 0.5f) _scrollCarry = 0f; // the user's: start afresh
|
||||
// Wheel up over the chat stops following at once; reaching the bottom again resumes it.
|
||||
// Not while it has nothing to scroll: no scroll change would ever turn following back on.
|
||||
if (maxY > 0f && ImGuiNET.ImGui.IsWindowHovered() && ImGuiNET.ImGui.GetIO().MouseWheel > 0f)
|
||||
|
|
@ -555,8 +585,6 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
HandleLineMenu(basePos, wrapW, n);
|
||||
|
||||
_lastScrollY = scrollY;
|
||||
if (ChatModel.AutoScroll && _stick && !_selDragging && total > viewH)
|
||||
ImGuiNET.ImGui.SetScrollHereY(1f);
|
||||
|
||||
// "Copied N lines" / "Rule added", top-right, for a moment.
|
||||
if (_flash != null)
|
||||
|
|
@ -574,8 +602,93 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
}
|
||||
}
|
||||
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
ImGuiNET.ImGui.EndChild();
|
||||
ImGuiNET.ImGui.PopFont(); // pushed before the child, for MeasureLines
|
||||
}
|
||||
|
||||
/// <summary>Time MeasureLines may spend a frame catching up on lines measured for another width.</summary>
|
||||
private const double MeasureBudgetMs = 2.0;
|
||||
private static readonly long MeasureBudgetTicks = (long)(System.Diagnostics.Stopwatch.Frequency * MeasureBudgetMs / 1000);
|
||||
|
||||
/// <summary>
|
||||
/// Brings the line heights and tops up to date for this wrap width, font and timestamp
|
||||
/// setting. Chat font pushed. New lines are measured at once. When the width, font or
|
||||
/// timestamps change (or after a rebuild) every line needs measuring again: 16 ms at
|
||||
/// 10,000 lines (tools/ChatHistoryBench), every frame of a resize drag. So that is done
|
||||
/// a slice at a time: the lines in view first, then from the newest line up, for
|
||||
/// MeasureBudgetMs a frame; the others keep their old height meanwhile. Scrolled up,
|
||||
/// the view is moved by however much the lines above it grew or shrank, so what's being
|
||||
/// read stays put (the same way as lines dropping off the top).
|
||||
/// </summary>
|
||||
private void MeasureLines(ImFontPtr font, float wrapW, float tsW, float fontSize, bool showTs, float viewH)
|
||||
{
|
||||
// The text starts after the timestamp and wraps under itself.
|
||||
float textW = Math.Max(20, wrapW - tsW);
|
||||
_rowH = font.FontSize;
|
||||
if (wrapW != _seenWrap || fontSize != _seenFont || showTs != _seenTs)
|
||||
{
|
||||
_seenWrap = wrapW;
|
||||
_seenFont = fontSize;
|
||||
_seenTs = showTs;
|
||||
_measuredFrom = Math.Min(_heightsFrom, _vis.Count); // all measured so far is stale
|
||||
}
|
||||
bool changed = false;
|
||||
for (int i = _heightsFrom; i < _vis.Count; i++) { MeasureLine(font, i, textW); changed = true; }
|
||||
_heightsFrom = _vis.Count;
|
||||
|
||||
if (_measuredFrom > 0)
|
||||
{
|
||||
UpdateTops();
|
||||
int n = _vis.Count;
|
||||
bool following = Following;
|
||||
// Where the view will be (last frame's scroll, less any move still to come).
|
||||
float viewTop = _lastScrollY + _scrollCarry - _droppedAbove;
|
||||
int firstVisible = following || n == 0 ? int.MaxValue : FirstAtOrBelow(Math.Max(0f, viewTop), n);
|
||||
if (!following)
|
||||
for (int i = firstVisible; i < Math.Min(n, _measuredFrom) && _tops[i] < viewTop + viewH; i++)
|
||||
MeasureLine(font, i, textW);
|
||||
float grewAbove = 0f;
|
||||
long t0 = System.Diagnostics.Stopwatch.GetTimestamp();
|
||||
int count = 0;
|
||||
while (_measuredFrom > 0)
|
||||
{
|
||||
int i = --_measuredFrom;
|
||||
float old = _h[i];
|
||||
MeasureLine(font, i, textW);
|
||||
if (i < firstVisible) grewAbove += _h[i] - old;
|
||||
if ((++count & 15) == 0 && System.Diagnostics.Stopwatch.GetTimestamp() - t0 > MeasureBudgetTicks) break;
|
||||
}
|
||||
if (!following) _droppedAbove -= grewAbove;
|
||||
changed = true;
|
||||
}
|
||||
if (changed) _topsDirty = true;
|
||||
UpdateTops();
|
||||
}
|
||||
|
||||
private void MeasureLine(ImFontPtr font, int i, float textW)
|
||||
{
|
||||
ChatLine line = _vis[i];
|
||||
ChatSpan[]? spans = line.Route.Spans;
|
||||
if (spans != null)
|
||||
{
|
||||
SpanLayout lay = LayoutSpans(font, line.Text, spans, textW);
|
||||
_lay[i] = lay;
|
||||
_h[i] = lay.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lay[i] = null;
|
||||
_h[i] = ImGuiNET.ImGui.CalcTextSize(line.Text, false, textW).Y;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTops()
|
||||
{
|
||||
if (!_topsDirty && _tops.Length > _vis.Count) return;
|
||||
if (_tops.Length < _vis.Count + 1) _tops = new float[Math.Max(_vis.Count + 1, _tops.Length * 2)];
|
||||
_tops[0] = 0;
|
||||
for (int i = 0; i < _vis.Count; i++) _tops[i + 1] = _tops[i] + _h[i];
|
||||
_topsDirty = false;
|
||||
}
|
||||
|
||||
private void Flash(string message, double seconds = 2.0)
|
||||
|
|
@ -871,6 +984,18 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
if (ImGuiNET.ImGui.SliderInt("Background", ref pct, 0, 100, "%d%%"))
|
||||
ChatModel.BackgroundAlpha = (int)MathF.Round(pct * 2.55f);
|
||||
if (ImGuiNET.ImGui.IsItemDeactivatedAfterEdit()) ChatModel.SaveSettings();
|
||||
// How many lines the chat keeps (ChatHistory): applied when the slider is let go, so
|
||||
// dragging it down doesn't cut the history at every step on the way.
|
||||
int history = _historyEdit > 0 ? _historyEdit : ChatModel.HistoryLines;
|
||||
if (ImGuiNET.ImGui.SliderInt("Chat history", ref history, ChatHistory.MinLines, ChatHistory.MaxLines, "%d lines"))
|
||||
_historyEdit = ChatHistory.Clamp(history);
|
||||
if (ImGuiNET.ImGui.IsItemDeactivated() && _historyEdit > 0)
|
||||
{
|
||||
ChatModel.SetHistoryLines(_historyEdit);
|
||||
_historyEdit = 0;
|
||||
}
|
||||
ImGuiNET.ImGui.SetItemTooltip("How many lines the chat keeps, all tabs together (default 2000).\n" +
|
||||
"About 2 MB of memory per 1000 lines. Lowering it drops the oldest lines.");
|
||||
ImGuiNET.ImGui.PopItemWidth();
|
||||
|
||||
bool ts = ChatModel.ShowTimestamps;
|
||||
|
|
|
|||
|
|
@ -87,6 +87,8 @@ internal sealed class DamageFace : IImGuiPanel
|
|||
private sealed class RowText
|
||||
{
|
||||
public string Wcid = "", Tier = "", Crit = "", NonCrit = "", Casts = "", Kills = "";
|
||||
/// <summary>The name as shown: "Rampager (2 kinds)" for a row of several wcids.</summary>
|
||||
public string NameShown = "", NameTip = "";
|
||||
public string Weapon = "", Offhand = "", Pet = "", WeakTop = "", Sec = "", SecTip = "";
|
||||
public bool CritSet, NonCritSet, WeaponGold, OffhandGold, PetGold;
|
||||
public string[] TierLines = Array.Empty<string>();
|
||||
|
|
@ -250,7 +252,8 @@ internal sealed class DamageFace : IImGuiPanel
|
|||
if (_filterWid != 0 && r.Wid != _filterWid) continue;
|
||||
if (_searchText.Length > 0
|
||||
&& r.Name.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) < 0
|
||||
&& !r.Wcid.ToString(CultureInfo.InvariantCulture).Contains(_searchText, StringComparison.Ordinal))
|
||||
&& !r.Wcid.ToString(CultureInfo.InvariantCulture).Contains(_searchText, StringComparison.Ordinal)
|
||||
&& !Array.Exists(r.Wcids, w => w.ToString(CultureInfo.InvariantCulture).Contains(_searchText, StringComparison.Ordinal)))
|
||||
continue;
|
||||
}
|
||||
_shown.Add(r);
|
||||
|
|
@ -306,6 +309,20 @@ internal sealed class DamageFace : IImGuiPanel
|
|||
}
|
||||
BuildPrio(r.Name, t);
|
||||
t.Wcid = r.Wcid.ToString(inv);
|
||||
const string DetailTip = "Details: weaknesses, accuracy, damage, summons, damage taken and spell settings (wcid ";
|
||||
if (r.Wcids.Length > 1)
|
||||
{
|
||||
// Monsters of one name with several weenies (retail has five Rampagers): one row.
|
||||
t.NameShown = r.Name + " (" + r.Wcids.Length.ToString(inv) + " kinds)";
|
||||
t.NameTip = r.Wcids.Length.ToString(inv) + " kinds of " + r.Name + ": wcids " + string.Join(", ", r.Wcids) + ".\n"
|
||||
+ "Kills and fights are added up; a weapon, offhand, pet or HP set here applies to all of them.\n"
|
||||
+ DetailTip + t.Wcid + ", the one with the most kills).";
|
||||
}
|
||||
else
|
||||
{
|
||||
t.NameShown = r.Name;
|
||||
t.NameTip = DetailTip + t.Wcid + ").";
|
||||
}
|
||||
t.Tier = DamageSource.FormatTier(r.Tier);
|
||||
t.CritSet = r.CritN > 0;
|
||||
t.Crit = t.CritSet ? r.Crit.ToString("0", inv) : "—";
|
||||
|
|
@ -762,10 +779,10 @@ internal sealed class DamageFace : IImGuiPanel
|
|||
}
|
||||
}
|
||||
ImGuiNET.ImGui.SetItemTooltip("Follow the Default config (spells, weapon). Uncheck to customize this monster.");
|
||||
if (NameLink("##name", r.Name, new Vector2(p.X + ColX[ColMonster] + 22, p.Y), ColW[ColMonster] - 24, custom ? Gold : White,
|
||||
if (NameLink("##name", t.NameShown, new Vector2(p.X + ColX[ColMonster] + 22, p.Y), ColW[ColMonster] - 24, custom ? Gold : White,
|
||||
ImGuiFonts.Get(UiFont.Ui11)))
|
||||
DamageDetailFace.Show(r.Wcid, r.Name);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Details: weaknesses, accuracy, damage, summons, damage taken and spell settings (wcid " + t.Wcid + ").");
|
||||
ImGuiNET.ImGui.SetItemTooltip(t.NameTip);
|
||||
|
||||
PrioCell(r.Key, r.Name, t.PrioCopyFrom, t, p);
|
||||
HpCell(r, p);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
// RynthCore.Engine - ImGui/Panels/ItemsFace.cs
|
||||
// ImGui face of the Items panel (UI/Panels/ItemsPanel.cs): weapons (name,
|
||||
// element, Del), consumables (name, type, Del), each with "Add Selected",
|
||||
// and mana stone tapping (on/off, keep count, min max-mana to tap).
|
||||
// and mana stone tapping (on/off, keep count, min max-mana to tap). A listed
|
||||
// weapon the character no longer carries (RynthAi's missingIds) shows in amber
|
||||
// with a warning icon and "(missing)", and says what to do in its tooltip.
|
||||
//
|
||||
// Edits change a private copy and save the whole payload (ItemsCommands,
|
||||
// pump thread). A newer snapshot replaces the copy; snapshots from before
|
||||
|
|
@ -62,7 +64,7 @@ internal sealed class ItemsFace : IImGuiPanel
|
|||
{
|
||||
ItemsPanel.WeaponEntry wpn = _data.Weapons[i];
|
||||
ImGuiNET.ImGui.PushID("w" + i);
|
||||
int r = Row(wpn.Name, wpn.Element, i, bw);
|
||||
int r = Row(wpn.Name, wpn.Element, i, bw, _data.MissingIds.Contains(wpn.Id));
|
||||
ImGuiNET.ImGui.PopID();
|
||||
if (r == 1)
|
||||
{
|
||||
|
|
@ -94,7 +96,7 @@ internal sealed class ItemsFace : IImGuiPanel
|
|||
{
|
||||
ItemsPanel.ConsumableEntry c = _data.Consumables[i];
|
||||
ImGuiNET.ImGui.PushID("c" + i);
|
||||
int r = Row(c.Name, c.Type, i, bw);
|
||||
int r = Row(c.Name, c.Type, i, bw, missing: false);
|
||||
ImGuiNET.ImGui.PopID();
|
||||
if (r == 1)
|
||||
{
|
||||
|
|
@ -200,16 +202,38 @@ internal sealed class ItemsFace : IImGuiPanel
|
|||
ImGuiNET.ImGui.Dummy(new Vector2(w, 22));
|
||||
}
|
||||
|
||||
/// <summary>Name | [value picker] | Del. Returns 1 when the picker was clicked, 2 for Del, else 0.</summary>
|
||||
private static int Row(string name, string value, int index, float w)
|
||||
private const string MissingSuffix = " (missing)";
|
||||
|
||||
/// <summary>
|
||||
/// Name | [value picker] | Del. Returns 1 when the picker was clicked, 2 for Del, else 0.
|
||||
/// <paramref name="missing"/>: the item isn't carried any more (amber, a warning icon,
|
||||
/// "(missing)" and a tooltip saying what to do).
|
||||
/// </summary>
|
||||
private static int Row(string name, string value, int index, float w, bool missing)
|
||||
{
|
||||
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
dl.AddRectFilled(p, p + new Vector2(w, 24), index % 2 == 0 ? RowAlt : PanelBg);
|
||||
float nameW = w - 146;
|
||||
float ty = p.Y + (24 - ImGuiNET.ImGui.GetFontSize()) * 0.5f;
|
||||
dl.PushClipRect(p, p + new Vector2(nameW, 24), true);
|
||||
dl.AddText(new Vector2(p.X + 6, p.Y + (24 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Text, name);
|
||||
if (missing)
|
||||
{
|
||||
float x = p.X + 6;
|
||||
dl.AddText(new Vector2(x, ty), Amber, PhosphorIcons.Warning);
|
||||
x += ImGuiNET.ImGui.CalcTextSize(PhosphorIcons.Warning).X + 4;
|
||||
dl.AddText(new Vector2(x, ty), Amber, name);
|
||||
x += ImGuiNET.ImGui.CalcTextSize(name).X;
|
||||
dl.AddText(new Vector2(x, ty), Amber, MissingSuffix);
|
||||
}
|
||||
else
|
||||
{
|
||||
dl.AddText(new Vector2(p.X + 6, ty), Text, name);
|
||||
}
|
||||
dl.PopClipRect();
|
||||
if (missing && ImGuiNET.ImGui.IsWindowHovered() && ImGuiNET.ImGui.IsMouseHoveringRect(p, p + new Vector2(nameW, 24)))
|
||||
ImGuiNET.ImGui.SetTooltip("Not in your pack any more - select the item in your inventory and click\n"
|
||||
+ "Add Selected Weapon again, or remove this entry.");
|
||||
int result = 0;
|
||||
if (Button("##pick", value, new Vector2(p.X + nameW + 2, p.Y + 2), new Vector2(96, 20), Text, BtnFill)) result = 1;
|
||||
if (IconButton("##del", PhosphorIcons.Trash, new Vector2(p.X + nameW + 102, p.Y + 2), new Vector2(42, 20), Red, BtnFill)) result = 2;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
//
|
||||
// [<- Back] Edit rule Saved
|
||||
// State: [Combat v]
|
||||
// Name: [Optional: a name to find this rule by ]
|
||||
// +- Conditions ------ [+ Add] -+ +- Actions --------- [+ Add] -+
|
||||
// | [Landblock == v] | | [Chat Command v] |
|
||||
// | [A9B40000 ][Set current] | | [/say hello ] |
|
||||
|
|
@ -15,6 +16,13 @@
|
|||
// first of an All (a single action into the first of a DoAll), or adds one
|
||||
// more to an All / Any / DoAll.
|
||||
//
|
||||
// Groups (2026-10-11): an All / Any / Not, nested or the column's own, and a
|
||||
// DoAll is a box (tint, border and left bar in its colour: All teal, Any
|
||||
// amber, Not rose) around its picker and everything in it, so a box inside
|
||||
// a box shows what belongs where; a nested group's line says what it means
|
||||
// ("any of the conditions inside"). Rows alternate a light shade; a DoAll's
|
||||
// actions are numbered in the order they run.
|
||||
//
|
||||
// Saving: every change marks the rule dirty (MetaAutosave); 0.75 s after the
|
||||
// last change, and never while a text box is being typed in, the rule goes
|
||||
// to RynthAi as add_rule (a new rule, the first time, and only once its
|
||||
|
|
@ -68,6 +76,11 @@ internal sealed partial class MetaFace
|
|||
private string? _nameProblem;
|
||||
private const string NewStateEntry = PhosphorIcons.Plus + " New state...";
|
||||
|
||||
// The rule's Name box (MetaRuleDto.Name; one line, MaxNameLength bytes of UTF-8).
|
||||
private readonly byte[] _ruleNameBytes = new byte[MetaRuleEdit.MaxNameLength + 1];
|
||||
private string? _ruleNameShown; // the name the box was last filled from
|
||||
private bool _ruleNameActive, _focusRuleName;
|
||||
|
||||
private const string BackLabel = PhosphorIcons.ArrowLeft + " Back";
|
||||
private const string AddLabel = PhosphorIcons.Plus + " Add";
|
||||
private const string SetCurrentLabel = PhosphorIcons.MapPin + " Set current";
|
||||
|
|
@ -86,6 +99,7 @@ internal sealed partial class MetaFace
|
|||
_lastSaved = index >= 0 ? rule.Clone() : null;
|
||||
_autosave.Clear();
|
||||
_fields.Clear();
|
||||
_ruleNameShown = null;
|
||||
_editConfirmDelete = false;
|
||||
_editTyping = false;
|
||||
CancelNaming();
|
||||
|
|
@ -136,6 +150,7 @@ internal sealed partial class MetaFace
|
|||
}
|
||||
if (!_autosave.Take()) return;
|
||||
MetaRuleDto send = _editRule.Clone();
|
||||
send.Name = send.Name.Trim(); // the box keeps a space you just typed; the rule doesn't
|
||||
if (_editIndex < 0)
|
||||
{
|
||||
_editIndex = _data.Rules.Count; // add_rule appends
|
||||
|
|
@ -163,7 +178,6 @@ internal sealed partial class MetaFace
|
|||
{
|
||||
SendEdit(new MetaCmd { Op = "delete_rule", Index = index });
|
||||
_data.Rules.RemoveAt(index);
|
||||
_expanded.Clear();
|
||||
RebuildCaches();
|
||||
}
|
||||
}
|
||||
|
|
@ -195,7 +209,7 @@ internal sealed partial class MetaFace
|
|||
float indW = SaveIndicatorWidth(editor: true);
|
||||
ImFontPtr bold = ImGuiFonts.Get(UiFont.UiBold11);
|
||||
float tx = top.X + backW + 8;
|
||||
string title = _editIndex < 0 ? "New rule" : "Edit rule";
|
||||
string title = _editIndex < 0 ? "New rule" : r.Name.Trim().Length > 0 ? r.Name.Trim() : "Edit rule";
|
||||
ImGuiNET.ImGui.PushFont(bold);
|
||||
dl.AddText(new Vector2(tx, top.Y + (22 - bold.FontSize) * 0.5f), Teal, Fit(title, Math.Max(10, top.X + w - indW - 8 - tx)));
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
|
|
@ -203,7 +217,7 @@ internal sealed partial class MetaFace
|
|||
|
||||
// State: [picker]
|
||||
float y = top.Y + 26;
|
||||
float lw = ImGuiNET.ImGui.CalcTextSize("State:").X + 6;
|
||||
float lw = Math.Max(ImGuiNET.ImGui.CalcTextSize("State:").X, ImGuiNET.ImGui.CalcTextSize("Name:").X) + 6;
|
||||
dl.AddText(new Vector2(top.X, y + (22 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Mute, "State:");
|
||||
string? state = StatePicker("##ed_state", r.State, _statePicks, IndexOf(_statePicks, r.State),
|
||||
new Vector2(top.X + lw, y), w - lw, out _);
|
||||
|
|
@ -212,7 +226,12 @@ internal sealed partial class MetaFace
|
|||
r.State = state; // a new state is made by moving this rule into it
|
||||
_editChanged = true;
|
||||
}
|
||||
y += 22 + ProblemLine("##ed_state", new Vector2(top.X + lw, y + 22), w - lw) + 6;
|
||||
y += 22 + ProblemLine("##ed_state", new Vector2(top.X + lw, y + 22), w - lw) + 4;
|
||||
|
||||
// Name: [optional]
|
||||
dl.AddText(new Vector2(top.X, y + (22 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Mute, "Name:");
|
||||
NameBox(new Vector2(top.X + lw, y), w - lw);
|
||||
y += 22 + 6;
|
||||
|
||||
// Conditions | Actions
|
||||
const float footerH = 24;
|
||||
|
|
@ -279,44 +298,191 @@ internal sealed partial class MetaFace
|
|||
|
||||
private void ConditionsBody(MetaRuleDto r, float w)
|
||||
{
|
||||
int picked = FlowPicker("##ed_cond", MetaVocabulary.ConditionName(r.Condition), MetaVocabulary.ConditionNames, r.Condition, w);
|
||||
if (picked >= 0 && picked != r.Condition)
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
BeginBacks(dl);
|
||||
try
|
||||
{
|
||||
SetCondition(r, picked);
|
||||
_editChanged = true;
|
||||
// An All / Any / Not is a box around its picker and everything in it.
|
||||
bool card = MetaVocabulary.IsCompositeCondition(r.Condition);
|
||||
Vector2 top = CardOpen(card);
|
||||
float iw = card ? w - CardInset - CardPadR : w;
|
||||
int picked = FlowPicker("##ed_cond", MetaVocabulary.ConditionName(r.Condition), MetaVocabulary.ConditionNames, r.Condition, iw);
|
||||
if (picked >= 0 && picked != r.Condition)
|
||||
{
|
||||
SetCondition(r, picked);
|
||||
_editChanged = true;
|
||||
}
|
||||
if (!card || !MetaVocabulary.IsCompositeCondition(r.Condition))
|
||||
{
|
||||
if (!MetaVocabulary.IsCompositeCondition(r.Condition)) ConditionField("##ed_cdata", r, iw, 22);
|
||||
CardClose(card, top, w, GroupColor(r.Condition, false), GroupTint(r.Condition, false), 0);
|
||||
return;
|
||||
}
|
||||
GroupLabel(r.Condition switch
|
||||
{
|
||||
MetaRuleEdit.Not => "Not: true while the condition inside is false",
|
||||
MetaRuleEdit.All => "All of these:",
|
||||
_ => "Any of these:",
|
||||
}, GroupColor(r.Condition, false));
|
||||
if (r.Children.Count == 0) Note("None yet: + Add (top right).");
|
||||
SubRules(r.Children, action: false, 0, r.Condition == MetaRuleEdit.Not ? 1 : int.MaxValue, iw);
|
||||
CardClose(card, top, w, GroupColor(r.Condition, false), GroupTint(r.Condition, false), 0);
|
||||
}
|
||||
if (!MetaVocabulary.IsCompositeCondition(r.Condition))
|
||||
finally
|
||||
{
|
||||
ConditionField("##ed_cdata", r, w, 22);
|
||||
return;
|
||||
EndBacks(dl);
|
||||
}
|
||||
SmallLabel(r.Condition switch
|
||||
{
|
||||
MetaRuleEdit.Not => "Not: true while this one is false",
|
||||
MetaRuleEdit.All => "All of these:",
|
||||
_ => "Any of these:",
|
||||
});
|
||||
if (r.Children.Count == 0) Note("None yet: + Add (top right).");
|
||||
SubRules(r.Children, action: false, 0, r.Condition == MetaRuleEdit.Not ? 1 : int.MaxValue, w);
|
||||
}
|
||||
|
||||
private void ActionsBody(MetaRuleDto r, float w)
|
||||
{
|
||||
int picked = FlowPicker("##ed_act", MetaVocabulary.ActionName(r.Action), MetaVocabulary.ActionNames, r.Action, w);
|
||||
if (picked >= 0 && picked != r.Action)
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
BeginBacks(dl);
|
||||
try
|
||||
{
|
||||
r.Action = picked;
|
||||
if (!MetaVocabulary.IsAllAction(picked)) r.ActionChildren.Clear();
|
||||
bool card = MetaVocabulary.IsAllAction(r.Action); // a DoAll is a box around its actions
|
||||
Vector2 top = CardOpen(card);
|
||||
float iw = card ? w - CardInset - CardPadR : w;
|
||||
int picked = FlowPicker("##ed_act", MetaVocabulary.ActionName(r.Action), MetaVocabulary.ActionNames, r.Action, iw);
|
||||
if (picked >= 0 && picked != r.Action)
|
||||
{
|
||||
r.Action = picked;
|
||||
if (!MetaVocabulary.IsAllAction(picked)) r.ActionChildren.Clear();
|
||||
_editChanged = true;
|
||||
}
|
||||
if (!card || !MetaVocabulary.IsAllAction(r.Action))
|
||||
{
|
||||
if (!MetaVocabulary.IsAllAction(r.Action)) ActionField("##ed_adata", r, iw, 22, problemLine: true);
|
||||
CardClose(card, top, w, GroupColor(MetaRuleEdit.DoAll, true), GroupTint(MetaRuleEdit.DoAll, true), 0);
|
||||
return;
|
||||
}
|
||||
GroupLabel("All of these, in order:", GroupColor(MetaRuleEdit.DoAll, true));
|
||||
if (r.ActionChildren.Count == 0) Note("None yet: + Add (top right).");
|
||||
SubRules(r.ActionChildren, action: true, 0, int.MaxValue, iw);
|
||||
CardClose(card, top, w, GroupColor(MetaRuleEdit.DoAll, true), GroupTint(MetaRuleEdit.DoAll, true), 0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndBacks(dl);
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Group boxes and row stripes (2026-10-11: "hard to see what's what in All and Any")
|
||||
// =====================================================================
|
||||
//
|
||||
// An All / Any / Not (and a DoAll) is a box: a tint and a border in the group's colour (All
|
||||
// teal, Any amber, Not rose), an accent bar down its left, around its picker and everything in
|
||||
// it; a box inside a box is another, so what belongs where shows at a glance. Rows of a list
|
||||
// alternate a light shade. A box's height is known only after its contents are laid out, so
|
||||
// boxes and stripes are recorded while the rows are placed and drawn at the end on a channel
|
||||
// under them (outer boxes first, each list's stripes over its box).
|
||||
|
||||
private const float CardInset = 9, CardPadR = 5, CardPadT = 5, CardPadB = 4;
|
||||
private static readonly uint Rose = C(0xFFE07A9A), StripeOver = C(0x12FFFFFF);
|
||||
private readonly List<(Vector2 Min, Vector2 Max, uint Fill, uint Border, uint Accent, int Order)> _backs = new();
|
||||
|
||||
private void BeginBacks(ImDrawListPtr dl)
|
||||
{
|
||||
_backs.Clear();
|
||||
dl.ChannelsSplit(2);
|
||||
dl.ChannelsSetCurrent(1); // widgets over the boxes
|
||||
}
|
||||
|
||||
private void EndBacks(ImDrawListPtr dl)
|
||||
{
|
||||
dl.ChannelsSetCurrent(0);
|
||||
// Outer before inner (Order = 2 x depth for a box, + 1 for its list's stripes).
|
||||
_backs.Sort((x, y) => x.Order.CompareTo(y.Order));
|
||||
foreach (var b in _backs)
|
||||
{
|
||||
if (b.Fill != 0) dl.AddRectFilled(b.Min, b.Max, b.Fill, b.Border != 0 ? 4f : 0f);
|
||||
if (b.Accent != 0) dl.AddRectFilled(b.Min, new Vector2(b.Min.X + 3, b.Max.Y), b.Accent, 2f);
|
||||
if (b.Border != 0) dl.AddRect(b.Min, b.Max, b.Border, 4f);
|
||||
}
|
||||
_backs.Clear();
|
||||
dl.ChannelsMerge();
|
||||
}
|
||||
|
||||
/// <summary>Starts a box at the cursor when <paramref name="card"/> (its contents indented); returns its top-left.</summary>
|
||||
private static Vector2 CardOpen(bool card)
|
||||
{
|
||||
Vector2 top = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
if (!card) return top;
|
||||
ImGuiNET.ImGui.Indent(CardInset); // moves the cursor in; the box's rows keep to it
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(ImGuiNET.ImGui.GetCursorScreenPos().X, top.Y + CardPadT));
|
||||
return top;
|
||||
}
|
||||
|
||||
/// <summary>Ends a box opened at <paramref name="top"/>, <paramref name="w"/> wide, and records it.</summary>
|
||||
private void CardClose(bool card, Vector2 top, float w, uint color, uint tint, int depth)
|
||||
{
|
||||
if (!card) return;
|
||||
float endY = ImGuiNET.ImGui.GetCursorScreenPos().Y - ImGuiNET.ImGui.GetStyle().ItemSpacing.Y + CardPadB;
|
||||
ImGuiNET.ImGui.Unindent(CardInset);
|
||||
_backs.Add((top, new Vector2(top.X + w, endY), tint, (color & 0x00FFFFFF) | 0x80000000u, color, depth * 2));
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(top.X, endY + 3));
|
||||
ImGuiNET.ImGui.Dummy(new Vector2(0, 0));
|
||||
}
|
||||
|
||||
/// <summary>A group's colour: All (and DoAll) teal, Any amber, Not rose.</summary>
|
||||
private static uint GroupColor(int kind, bool action) => action ? Teal : kind switch
|
||||
{
|
||||
MetaRuleEdit.Any => Amber,
|
||||
MetaRuleEdit.Not => Rose,
|
||||
_ => Teal,
|
||||
};
|
||||
|
||||
/// <summary>A group box's fill: its colour, faint, over the column.</summary>
|
||||
private static uint GroupTint(int kind, bool action) => action ? C(0xFF10262E) : kind switch
|
||||
{
|
||||
MetaRuleEdit.Any => C(0xFF2A2412),
|
||||
MetaRuleEdit.Not => C(0xFF2C1622),
|
||||
_ => C(0xFF10262E),
|
||||
};
|
||||
|
||||
/// <summary>What a nested group's line says after its picker.</summary>
|
||||
private static string GroupWords(int kind) => kind switch
|
||||
{
|
||||
MetaRuleEdit.All => "all of the conditions inside",
|
||||
MetaRuleEdit.Any => "any of the conditions inside",
|
||||
_ => "true while the condition inside is false",
|
||||
};
|
||||
|
||||
private static void GroupLabel(string text, uint color)
|
||||
{
|
||||
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui9));
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.Text, color);
|
||||
ImGuiNET.ImGui.TextUnformatted(text);
|
||||
ImGuiNET.ImGui.PopStyleColor();
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
}
|
||||
|
||||
/// <summary>The rule's name: optional, one line; saves like every other change.</summary>
|
||||
private void NameBox(Vector2 pos, float width)
|
||||
{
|
||||
if (!_ruleNameActive && !ReferenceEquals(_ruleNameShown, _editRule.Name))
|
||||
{
|
||||
WriteUtf8(_ruleNameBytes, _editRule.Name);
|
||||
_ruleNameShown = _editRule.Name;
|
||||
}
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(pos);
|
||||
if (_focusRuleName)
|
||||
{
|
||||
ImGuiNET.ImGui.SetKeyboardFocusHere();
|
||||
_focusRuleName = false;
|
||||
}
|
||||
bool edited = TextBox("##ed_name", _ruleNameBytes, width, "Optional: a name to find this rule by",
|
||||
ImGuiInputTextFlags.None, out _ruleNameActive);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Shown in bold over the rule in the list (and instead of its condition in Compact).");
|
||||
_typingNow |= _ruleNameActive; // autosave waits until the box is left
|
||||
if (edited)
|
||||
{
|
||||
string typed = MetaRuleEdit.CleanName(Utf8(_ruleNameBytes));
|
||||
_editRule.Name = typed;
|
||||
_ruleNameShown = typed;
|
||||
_editChanged = true;
|
||||
}
|
||||
if (!MetaVocabulary.IsAllAction(r.Action))
|
||||
{
|
||||
ActionField("##ed_adata", r, w, 22, problemLine: true);
|
||||
return;
|
||||
}
|
||||
SmallLabel("All of these, in order:");
|
||||
if (r.ActionChildren.Count == 0) Note("None yet: + Add (top right).");
|
||||
SubRules(r.ActionChildren, action: true, 0, int.MaxValue, w);
|
||||
}
|
||||
|
||||
private static void SetCondition(MetaRuleDto c, int picked)
|
||||
|
|
@ -385,15 +551,21 @@ internal sealed partial class MetaFace
|
|||
}
|
||||
if (problemLine) extra = ProblemLine(id, new Vector2(p.X, p.Y + height), width);
|
||||
}
|
||||
else if (a.Action == 3) // Embedded Nav Route
|
||||
else if (a.Action == 3) // Embedded Nav Route: Patrol, nav files, the meta's routes
|
||||
{
|
||||
int picked = Picker(id, a.ActionData.Length == 0 ? "Select route..." : a.ActionData, _routePicks,
|
||||
Array.IndexOf(_routePicks, a.ActionData), p, width, height);
|
||||
if (picked >= 0 && _routePicks[picked] != a.ActionData)
|
||||
int sel = IndexOf(_routeValues, a.ActionData);
|
||||
string shown = a.ActionData.Length == 0 ? "Select route..." : sel >= 0 ? _routeLabels[sel] : a.ActionData;
|
||||
int picked = Picker(id, shown, _routeLabels, sel, p, width, height);
|
||||
if (picked >= 0 && _routeValues[picked] != a.ActionData)
|
||||
{
|
||||
a.ActionData = _routePicks[picked];
|
||||
a.ActionData = _routeValues[picked]; // the name RynthAi looks up, not the list's label
|
||||
_editChanged = true;
|
||||
}
|
||||
// (The picker's last item is a spacer, so the hover is checked on its rectangle.)
|
||||
if (MetaVocabulary.PatrolRoute.Equals(a.ActionData, StringComparison.OrdinalIgnoreCase)
|
||||
&& !MetaVocabulary.HasRoute(_data, a.ActionData)
|
||||
&& ImGuiNET.ImGui.IsWindowHovered() && ImGuiNET.ImGui.IsMouseHoveringRect(p, p + new Vector2(width, height)))
|
||||
ImGuiNET.ImGui.SetTooltip("RynthAi's dungeon patrol (/ra dunnav-patrol): a circular hunt through every room of the dungeon you're in. Needs no nav file; only works inside a dungeon.");
|
||||
}
|
||||
else if (!MetaRuleEdit.ActionTakesData(a.Action) && a.ActionData.Length == 0)
|
||||
NoteAt(p, "Nothing to set.", height);
|
||||
|
|
@ -407,58 +579,87 @@ internal sealed partial class MetaFace
|
|||
}
|
||||
|
||||
// Sub-conditions nest (All/Any/Not under All/Any/Not, MaxSubConditionDepth levels; a Not takes
|
||||
// one); DoAll's sub-actions are a flat list. Each row: [type][value][x]; in a narrow column the
|
||||
// value goes on a second line. The top level's "+ Add" is in the column header.
|
||||
// one); DoAll's sub-actions are a flat list that runs in order, so each is numbered and has up /
|
||||
// down. A row: [type][value]([up][down])[x]; every other row a light shade; in a narrow column the
|
||||
// value goes on a second line. A nested All / Any / Not is a box (its picker, what it means, then
|
||||
// its conditions inside, indented). The top level's "+ Add" is in the column header.
|
||||
private void SubRules(List<MetaRuleDto> subs, bool action, int depth, int maxCount, float w)
|
||||
{
|
||||
string[] names = action ? MetaVocabulary.ActionNames : MetaVocabulary.ConditionNames;
|
||||
bool narrow = w < 300;
|
||||
const float rh = 20, xw = 20;
|
||||
const float rh = 20, xw = 20, aw = 16, childIndent = 10;
|
||||
for (int i = 0; i < subs.Count; i++)
|
||||
{
|
||||
MetaRuleDto sub = subs[i];
|
||||
ImGuiNET.ImGui.PushID(i);
|
||||
bool nests = !action && MetaVocabulary.IsCompositeCondition(sub.Condition) && depth < MetaVocabulary.MaxSubConditionDepth;
|
||||
Vector2 cardTop = CardOpen(nests);
|
||||
float rw = nests ? w - CardInset - CardPadR : w; // the row's width (inside its box)
|
||||
float tools = xw + (action ? 2 * (aw + 2) : 0); // [up][down][x] or [x]
|
||||
float lead = action ? 16 : 0; // a DoAll's step number
|
||||
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
float pickW = narrow ? w - xw - 4 : (w - xw - 8) * 0.45f;
|
||||
float pickW = narrow ? rw - tools - lead - 4 : (rw - tools - lead - 8) * 0.45f;
|
||||
|
||||
if (action)
|
||||
{
|
||||
string step = (i + 1).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
ImGuiNET.ImGui.GetWindowDrawList().AddText(
|
||||
new Vector2(p.X + lead - 4 - ImGuiNET.ImGui.CalcTextSize(step).X, p.Y + (rh - ImGuiNET.ImGui.GetFontSize()) * 0.5f),
|
||||
Faded(Mute), step);
|
||||
}
|
||||
int current = action ? sub.Action : sub.Condition;
|
||||
string shown = action ? MetaVocabulary.ActionName(sub.Action) : MetaVocabulary.ConditionName(sub.Condition);
|
||||
int picked = Picker("##type", shown, names, current, p, pickW, rh);
|
||||
int picked = Picker("##type", shown, names, current, new Vector2(p.X + lead, p.Y), pickW, rh);
|
||||
if (picked >= 0 && picked != current)
|
||||
{
|
||||
if (action) sub.Action = picked; else SetCondition(sub, picked);
|
||||
_editChanged = true;
|
||||
}
|
||||
|
||||
bool nests = !action && MetaVocabulary.IsCompositeCondition(sub.Condition) && depth < MetaVocabulary.MaxSubConditionDepth;
|
||||
bool removed = IconButton("##rm", PhosphorIcons.X, new Vector2(p.X + w - xw, p.Y), new Vector2(xw, rh), TextDim, DelFill, BtnBord);
|
||||
ImGuiNET.ImGui.SetItemTooltip(action ? "Remove this action" : "Remove this condition");
|
||||
bool removed = IconButton("##rm", PhosphorIcons.X, new Vector2(p.X + rw - xw, p.Y), new Vector2(xw, rh), TextDim, DelFill, BtnBord);
|
||||
ImGuiNET.ImGui.SetItemTooltip(action ? "Remove this action" : nests ? "Remove this group and what is in it" : "Remove this condition");
|
||||
int moveTo = -1;
|
||||
if (action)
|
||||
{
|
||||
float ax = p.X + rw - xw - 2 - 2 * (aw + 2);
|
||||
if (IconButton("##sub_up", PhosphorIcons.ArrowUp, new Vector2(ax, p.Y), new Vector2(aw, rh), Mute, BtnFill, BtnBord, enabled: i > 0))
|
||||
moveTo = i - 1;
|
||||
ImGuiNET.ImGui.SetItemTooltip("Run this action earlier");
|
||||
if (IconButton("##sub_dn", PhosphorIcons.ArrowDown, new Vector2(ax + aw + 2, p.Y), new Vector2(aw, rh), Mute, BtnFill, BtnBord,
|
||||
enabled: i < subs.Count - 1))
|
||||
moveTo = i + 1;
|
||||
ImGuiNET.ImGui.SetItemTooltip("Run this action later");
|
||||
}
|
||||
|
||||
float rowH = rh;
|
||||
if (nests)
|
||||
{
|
||||
if (!narrow)
|
||||
NoteAt(new Vector2(p.X + pickW + 6, p.Y), sub.Condition == MetaRuleEdit.Not ? "(the condition below)" : "(the conditions below)", rh);
|
||||
NoteAt(new Vector2(p.X + pickW + 6, p.Y), GroupWords(sub.Condition), rh, GroupColor(sub.Condition, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 vp = narrow ? new Vector2(p.X + 12, p.Y + rh + 2) : new Vector2(p.X + pickW + 4, p.Y);
|
||||
float vw = narrow ? w - 12 : w - pickW - 4 - xw - 4;
|
||||
Vector2 vp = narrow ? new Vector2(p.X + lead + 12, p.Y + rh + 2) : new Vector2(p.X + lead + pickW + 4, p.Y);
|
||||
float vw = narrow ? rw - lead - 12 : rw - lead - pickW - 4 - tools - 4;
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(vp);
|
||||
if (action) ActionField("##data", sub, vw, rh, problemLine: false);
|
||||
else ConditionField("##data", sub, vw, rh);
|
||||
if (narrow) rowH = rh * 2 + 2;
|
||||
// Every other row a light shade, reaching halfway into the gaps so the shades meet.
|
||||
if (i % 2 == 1)
|
||||
_backs.Add((new Vector2(p.X - 4, p.Y - 4.5f), new Vector2(p.X + rw + 3, p.Y + rowH + 4.5f), StripeOver, 0, 0, depth * 2 + 1));
|
||||
}
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(p.X, p.Y + rowH + 2));
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(p.X, p.Y + rowH + 5));
|
||||
ImGuiNET.ImGui.Dummy(new Vector2(0, 0));
|
||||
|
||||
if (!removed && nests)
|
||||
{
|
||||
ImGuiNET.ImGui.Indent(14);
|
||||
SmallLabel(sub.Condition switch { MetaRuleEdit.Not => "Not:", MetaRuleEdit.All => "All of:", _ => "Any of:" });
|
||||
SubRules(sub.Children, action: false, depth + 1, sub.Condition == MetaRuleEdit.Not ? 1 : int.MaxValue, w - 14);
|
||||
ImGuiNET.ImGui.Unindent(14);
|
||||
ImGuiNET.ImGui.Indent(childIndent);
|
||||
if (sub.Children.Count == 0) Note("None yet: + Add below.");
|
||||
SubRules(sub.Children, action: false, depth + 1, sub.Condition == MetaRuleEdit.Not ? 1 : int.MaxValue, rw - childIndent);
|
||||
ImGuiNET.ImGui.Unindent(childIndent);
|
||||
}
|
||||
CardClose(nests, cardTop, w, GroupColor(sub.Condition, false), GroupTint(sub.Condition, false), depth + 1);
|
||||
ImGuiNET.ImGui.PopID();
|
||||
if (removed)
|
||||
{
|
||||
|
|
@ -466,6 +667,12 @@ internal sealed partial class MetaFace
|
|||
_editChanged = true;
|
||||
break; // indices shifted: the rest draws next frame
|
||||
}
|
||||
if (moveTo >= 0)
|
||||
{
|
||||
(subs[i], subs[moveTo]) = (subs[moveTo], subs[i]);
|
||||
_editChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Nested groups get their own Add; the top level's is in the column header.
|
||||
|
|
@ -539,12 +746,12 @@ internal sealed partial class MetaFace
|
|||
/// (<paramref name="isNew"/> true) once its name box is confirmed; else null.
|
||||
/// </summary>
|
||||
private string? StatePicker(string id, string shown, string[] items, int selected, Vector2 pos, float width, out bool isNew,
|
||||
float height = 22)
|
||||
float height = 22, string? badge = null)
|
||||
{
|
||||
isNew = false;
|
||||
uint key = ImGuiNET.ImGui.GetID(id);
|
||||
if (_namingKey == key) return NamingBox(id, pos, width, height, out isNew);
|
||||
int picked = Picker(id, shown, items, selected, pos, width, height, NewStateEntry);
|
||||
int picked = Picker(id, shown, items, selected, pos, width, height, NewStateEntry, badge);
|
||||
if (picked == items.Length)
|
||||
{
|
||||
_namingKey = key;
|
||||
|
|
@ -650,12 +857,6 @@ internal sealed partial class MetaFace
|
|||
return -1;
|
||||
}
|
||||
|
||||
private static void SmallLabel(string text)
|
||||
{
|
||||
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui9));
|
||||
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFE8B333), text);
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
}
|
||||
|
||||
private static void Note(string text)
|
||||
{
|
||||
|
|
@ -664,8 +865,9 @@ internal sealed partial class MetaFace
|
|||
ImGuiNET.ImGui.PopFont();
|
||||
}
|
||||
|
||||
private static void NoteAt(Vector2 p, string text, float height)
|
||||
private static void NoteAt(Vector2 p, string text, float height, uint color = 0)
|
||||
{
|
||||
ImGuiNET.ImGui.GetWindowDrawList().AddText(new Vector2(p.X + 4, p.Y + (height - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Faded(Mute), text);
|
||||
ImGuiNET.ImGui.GetWindowDrawList().AddText(new Vector2(p.X + 4, p.Y + (height - ImGuiNET.ImGui.GetFontSize()) * 0.5f),
|
||||
color != 0 ? color : Faded(Mute), text);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1069
src/RynthCore.Engine/ImGui/Panels/MetaFace.List.cs
Normal file
1069
src/RynthCore.Engine/ImGui/Panels/MetaFace.List.cs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -207,7 +207,7 @@ internal sealed partial class MetaFace
|
|||
ScheduleRuleDto r = sc.Rules[i];
|
||||
bool first = i == sc.FirstMatch && sc.Enabled;
|
||||
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
dl.AddRectFilled(p, p + new Vector2(w, h), i % 2 == 0 ? PanelBg : RowAlt);
|
||||
dl.AddRectFilled(p, p + new Vector2(w, h), i % 2 == 0 ? StripeA : StripeB);
|
||||
ImGuiNET.ImGui.PushID(1000 + i);
|
||||
bool changed = false;
|
||||
float x = p.X + 1;
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@
|
|||
// ImGui face of the Meta panel (docs/IMGUI_PARITY_PLAN.md §2.13), with the
|
||||
// Avalonia face's look and three views:
|
||||
//
|
||||
// List file picker / refresh / Save As / "Saved" indicator; Visual|Source;
|
||||
// Meta, Debug; rules grouped by state (collapsible, red while
|
||||
// firing), rows with enable, expand, up/down within the state,
|
||||
// duplicate, and delete on the far right (click twice); click a row
|
||||
// to edit it; State picker and New Rule at the bottom.
|
||||
// List (MetaFace.List.cs) file picker / refresh / Save As / "Saved"
|
||||
// indicator; Visual|Source; Meta, Debug; a filter; rules grouped
|
||||
// by state, each rule in full (every condition and action on its
|
||||
// own line, or one line in Compact) with lines between rules and
|
||||
// columns; move / duplicate / delete on the hovered row and on
|
||||
// right-click; click a row to edit it; State picker and New Rule
|
||||
// at the bottom.
|
||||
// Editor (MetaFace.Editor.cs) state; Conditions and Actions side by side
|
||||
// (stacked when the panel is narrow), each with "+ Add"; Set current
|
||||
// for landblock / landcell; every change saves on its own.
|
||||
|
|
@ -55,7 +57,7 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
private static readonly uint Teal = C(0xFF26D9E6), Amber = C(0xFFE8B333), Green = C(0xFF33CC66),
|
||||
Red = C(0xFFE04848), Mute = C(0xFFC8D6E4), TextDim = C(0xFFF2F7FC), ShellBg = C(0xFF0A0F14),
|
||||
PanelBg = C(0xFF141F29), RowAlt = C(0xFF101822), BtnFill = C(0xFF16283A), BtnBord = C(0xFF34587A),
|
||||
Fired = C(0xFF3A1212), BtnOn = C(0xFF0E2E3A), StateHdrA = C(0xFF0E1E30), StateHdrB = C(0xFF162A40),
|
||||
Fired = C(0xFF3A1212), BtnOn = C(0xFF0E2E3A), StateHdrA = C(0xFF0E1E30),
|
||||
DelFill = C(0xFF7A1414), NewFill = C(0xFF0E2E1A), PickSel = C(0xFF1A2E42);
|
||||
private static uint C(uint argb) => RynthTheme.Argb(argb);
|
||||
private static uint Faded(uint abgr) => (abgr & 0x00FFFFFF) | ((abgr >> 25) << 24); // half alpha
|
||||
|
|
@ -66,11 +68,9 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
private MetaPayload _data = new();
|
||||
private long _seenVersion = -1;
|
||||
private List<(string State, List<int> Rules)> _groups = new();
|
||||
private string[] _condText = Array.Empty<string>(), _actText = Array.Empty<string>();
|
||||
private string[] _groupLabel = Array.Empty<string>();
|
||||
private bool[] _groupFiring = Array.Empty<bool>();
|
||||
private string[] _statePicks = Array.Empty<string>(), _statesOnly = Array.Empty<string>();
|
||||
private string[] _routePicks = Array.Empty<string>(), _fileDisplays = Array.Empty<string>();
|
||||
private string[] _routeLabels = Array.Empty<string>(), _routeValues = Array.Empty<string>(), _fileDisplays = Array.Empty<string>();
|
||||
private string _fileDisplay = "-- None --", _sourceFileLabel = "File: Unsaved";
|
||||
private IReadOnlyList<string> _completionNavs = Array.Empty<string>();
|
||||
|
||||
|
|
@ -78,8 +78,8 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
private readonly Dictionary<(string Text, int Width), string> _fit = new();
|
||||
|
||||
private View _view = View.List;
|
||||
private readonly MetaStateClock _stateClock = new();
|
||||
private readonly HashSet<string> _collapsed = new();
|
||||
private readonly HashSet<int> _expanded = new();
|
||||
private bool _saveAs, _saveAsFocus;
|
||||
private readonly byte[] _saveName = new byte[128];
|
||||
|
||||
|
|
@ -195,6 +195,7 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
if (snap == null || snap.Version == _seenVersion) return;
|
||||
_seenVersion = snap.Version;
|
||||
MetaPayload fresh = snap.Value;
|
||||
_stateClock.Snapshot(fresh.Snapshot, NowMs);
|
||||
CheckApplyResult(fresh);
|
||||
_data = fresh.Clone();
|
||||
RebuildCaches();
|
||||
|
|
@ -211,21 +212,12 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
{
|
||||
List<MetaRuleDto> rules = _data.Rules;
|
||||
_groups = MetaVocabulary.GroupByState(rules);
|
||||
_condText = new string[rules.Count];
|
||||
_actText = new string[rules.Count];
|
||||
for (int i = 0; i < rules.Count; i++)
|
||||
{
|
||||
_condText[i] = MetaVocabulary.RowConditionText(rules[i]);
|
||||
_actText[i] = MetaVocabulary.RowActionText(rules[i]);
|
||||
}
|
||||
_groupLabel = new string[_groups.Count];
|
||||
_groupFiring = new bool[_groups.Count];
|
||||
for (int g = 0; g < _groups.Count; g++)
|
||||
{
|
||||
bool firing = false;
|
||||
foreach (int i in _groups[g].Rules) firing |= rules[i].LastFiredMs < 1500;
|
||||
_groupFiring[g] = firing;
|
||||
_groupLabel[g] = firing ? $"{_groups[g].State} ({_groups[g].Rules.Count}) — firing" : $"{_groups[g].State} ({_groups[g].Rules.Count})";
|
||||
}
|
||||
// States made here that the snapshot doesn't list yet (dropped once it does, or on a meta switch).
|
||||
if (!string.Equals(_statesPath, _data.CurrentMetaPath, StringComparison.OrdinalIgnoreCase))
|
||||
|
|
@ -241,47 +233,20 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
_statePicks = With(_statePicks, s);
|
||||
_statesOnly = With(_statesOnly, s);
|
||||
}
|
||||
_routePicks = MetaVocabulary.RoutePicks(_data);
|
||||
(_routeLabels, _routeValues) = MetaVocabulary.RoutePicks(_data);
|
||||
_fileDisplays = new string[_data.Files.Count];
|
||||
for (int i = 0; i < _fileDisplays.Length; i++) _fileDisplays[i] = _data.Files[i].Display;
|
||||
_fileDisplay = MetaVocabulary.CurrentFileDisplay(_data);
|
||||
_sourceFileLabel = "File: " + (string.IsNullOrEmpty(_data.CurrentMetaPath) ? "Unsaved" : System.IO.Path.GetFileName(_data.CurrentMetaPath));
|
||||
_completionNavs = MetaVocabulary.CompletionNavs(_data);
|
||||
_fit.Clear();
|
||||
RebuildListText(rules); // after the states: a Set State to a missing state shows in red
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// List view
|
||||
// File bar and mode row (the list itself: MetaFace.List.cs)
|
||||
// =====================================================================
|
||||
|
||||
private void ListView(Vector2 origin, Vector2 size)
|
||||
{
|
||||
float w = size.X;
|
||||
LoadSaveBar(w);
|
||||
Separator(w);
|
||||
ModeRow(w, source: false);
|
||||
Separator(w);
|
||||
if (_listNote.Length > 0 && NowMs - _listNoteAt < 8000)
|
||||
{
|
||||
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui9));
|
||||
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFE8B333), Fit(_listNote, w));
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
}
|
||||
|
||||
const float bottomH = 24;
|
||||
float listH = Math.Max(40, origin.Y + size.Y - ImGuiNET.ImGui.GetCursorScreenPos().Y - bottomH - 9);
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.ChildBg, 0);
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
|
||||
ImGuiNET.ImGui.BeginChild("##meta_rules", new Vector2(w, listH));
|
||||
RuleList(ImGuiNET.ImGui.GetContentRegionAvail().X);
|
||||
ImGuiNET.ImGui.EndChild();
|
||||
ImGuiNET.ImGui.PopStyleVar();
|
||||
ImGuiNET.ImGui.PopStyleColor();
|
||||
|
||||
Separator(w);
|
||||
BottomBar(w);
|
||||
}
|
||||
|
||||
private void LoadSaveBar(float w)
|
||||
{
|
||||
if (_saveAs)
|
||||
|
|
@ -458,255 +423,8 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
_editor.RequestFocus();
|
||||
}
|
||||
|
||||
// Condition/action split of the rule list (dragged in its header) and where
|
||||
// the text starts within a row (from the last row drawn).
|
||||
// Condition/action split of the rule list (dragged in its header; saved per PC).
|
||||
private static float _condFrac = Math.Clamp(RynthCore.Engine.UI.PanelColumnStore.Get("Meta.condFrac", 0.5f), 0.15f, 0.85f);
|
||||
private float _textStartOff;
|
||||
/// <summary>The far-right delete button and the gap before it: the row text ends this far from the edge.</summary>
|
||||
private const float DeleteColumnW = 30;
|
||||
|
||||
private void RuleList(float w)
|
||||
{
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
if (_groups.Count == 0)
|
||||
{
|
||||
ImGuiNET.ImGui.Dummy(new Vector2(0, 4));
|
||||
ImGuiNET.ImGui.TextColored(RynthTheme.Vec(0xFFC8D6E4), " No rules. Click New Rule to add one.");
|
||||
return;
|
||||
}
|
||||
|
||||
ImFontPtr bold = ImGuiFonts.Get(UiFont.UiBold11);
|
||||
List<MetaRuleDto> rules = _data.Rules;
|
||||
|
||||
// Condition | Action header; drag the divider to move the split (saved per PC).
|
||||
if (_textStartOff > 0)
|
||||
{
|
||||
Vector2 hp = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
const float hh = 16;
|
||||
float tx = hp.X + _textStartOff, tw = Math.Max(1, hp.X + w - DeleteColumnW - tx);
|
||||
float split = tw * _condFrac;
|
||||
float hy = hp.Y + (hh - bold.FontSize) * 0.5f;
|
||||
dl.AddText(bold, bold.FontSize, new Vector2(tx + 3, hy), C(0xFFC8D6E4), "Condition");
|
||||
dl.AddText(bold, bold.FontSize, new Vector2(tx + split + 4, hy), C(0xFFC8D6E4), "Action");
|
||||
if (FaceKit.ColumnDivider("##meta_split", tx + split, hp.Y, hh, ref split, 40,
|
||||
_ => RynthCore.Engine.UI.PanelColumnStore.Set("Meta.condFrac", _condFrac)))
|
||||
_condFrac = Math.Clamp(split / tw, 0.15f, 0.85f);
|
||||
ImGuiNET.ImGui.Dummy(new Vector2(w, hh));
|
||||
}
|
||||
|
||||
for (int g = 0; g < _groups.Count; g++)
|
||||
{
|
||||
(string state, List<int> members) = _groups[g];
|
||||
bool collapsed = _collapsed.Contains(state);
|
||||
bool firing = _groupFiring[g];
|
||||
|
||||
// Header: caret, State (n) [— firing]; click toggles.
|
||||
ImGuiNET.ImGui.Dummy(new Vector2(0, 2));
|
||||
Vector2 hp = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
float hh = bold.FontSize + 6;
|
||||
ImGuiNET.ImGui.PushID(g);
|
||||
if (ImGuiNET.ImGui.InvisibleButton("##hdr", new Vector2(w, hh)))
|
||||
{
|
||||
if (collapsed) _collapsed.Remove(state); else _collapsed.Add(state);
|
||||
}
|
||||
if (ImGuiNET.ImGui.IsItemHovered()) ImGuiNET.ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
|
||||
ImGuiNET.ImGui.PopID();
|
||||
uint hc = firing ? Red : Amber;
|
||||
dl.AddRectFilled(hp, hp + new Vector2(w, hh), g % 2 == 0 ? StateHdrA : StateHdrB);
|
||||
dl.AddText(bold, bold.FontSize, hp + new Vector2(3, 3), hc, collapsed ? PhosphorIcons.CaretRight : PhosphorIcons.CaretDown);
|
||||
dl.AddText(bold, bold.FontSize, hp + new Vector2(18, 3), hc, _groupLabel[g]);
|
||||
if (collapsed) continue;
|
||||
|
||||
for (int gi = 0; gi < members.Count; gi++)
|
||||
{
|
||||
int index = members[gi];
|
||||
if (index >= rules.Count) break;
|
||||
if (RuleRow(rules[index], index, gi, members.Count, w)) return; // the list changed: redraw next frame
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One rule row plus its expanded children. True when a click changed the list.</summary>
|
||||
private bool RuleRow(MetaRuleDto rule, int index, int gi, int groupCount, float w)
|
||||
{
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
bool firing = rule.LastFiredMs < 1500;
|
||||
bool hasChildren = (MetaVocabulary.IsCompositeCondition(rule.Condition) && rule.Children.Count > 0)
|
||||
|| (MetaVocabulary.IsAllAction(rule.Action) && rule.ActionChildren.Count > 0);
|
||||
bool expanded = _expanded.Contains(index);
|
||||
|
||||
const float h = 20;
|
||||
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
dl.AddRectFilled(p, p + new Vector2(w, h), firing ? Fired : gi % 2 == 0 ? PanelBg : RowAlt);
|
||||
ImGuiNET.ImGui.PushID(index);
|
||||
bool changed = false;
|
||||
|
||||
// Enable
|
||||
float x = p.X + 1;
|
||||
if (IconButton("##en", rule.Enabled ? PhosphorIcons.CheckSquare : PhosphorIcons.Square, new Vector2(x, p.Y + 2), new Vector2(14, 16),
|
||||
rule.Enabled ? Green : Mute, BtnFill, BtnBord))
|
||||
{
|
||||
rule.Enabled = !rule.Enabled;
|
||||
SendEdit(new MetaCmd { Op = "set_rule_enabled", Index = index, Value = rule.Enabled ? "true" : "false" });
|
||||
}
|
||||
ImGuiNET.ImGui.SetItemTooltip(rule.Enabled ? "Enabled — click to disable" : "Disabled — click to enable");
|
||||
x += 16;
|
||||
|
||||
// Expand (only with children)
|
||||
if (hasChildren && IconButton("##exp", expanded ? PhosphorIcons.Minus : PhosphorIcons.Plus, new Vector2(x + 2, p.Y + 3), new Vector2(14, 14),
|
||||
Teal, BtnFill, BtnBord))
|
||||
{
|
||||
if (expanded) _expanded.Remove(index); else _expanded.Add(index);
|
||||
}
|
||||
x += 18;
|
||||
|
||||
// Up / down within the state (Appendix A3: the plugin now swaps within the state too)
|
||||
if (IconButton("##up", PhosphorIcons.ArrowUp, new Vector2(x + 1, p.Y + 2), new Vector2(16, 16), Mute, BtnFill, BtnBord, enabled: gi > 0))
|
||||
changed |= Move(index, -1);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Move up");
|
||||
x += 18;
|
||||
if (IconButton("##dn", PhosphorIcons.ArrowDown, new Vector2(x + 1, p.Y + 2), new Vector2(16, 16), Mute, BtnFill, BtnBord,
|
||||
enabled: gi < groupCount - 1))
|
||||
changed |= Move(index, +1);
|
||||
ImGuiNET.ImGui.SetItemTooltip("Move down");
|
||||
x += 18;
|
||||
|
||||
// Duplicate
|
||||
if (IconButton("##dup", PhosphorIcons.Copy, new Vector2(x + 1, p.Y + 2), new Vector2(16, 16), Mute, BtnFill, BtnBord))
|
||||
{
|
||||
SendEdit(new MetaCmd { Op = "duplicate_rule", Index = index, Rule = rule.Clone() });
|
||||
_data.Rules.Insert(Math.Min(index + 1, _data.Rules.Count), rule.Clone());
|
||||
changed = true;
|
||||
}
|
||||
ImGuiNET.ImGui.SetItemTooltip("Duplicate rule");
|
||||
x += 20;
|
||||
|
||||
// Delete: on its own at the far right, away from the other buttons (2026-10-05). A rule
|
||||
// with anything in it takes a second click within 3 s; an empty Never -> None one goes at once.
|
||||
bool arming = _confirmDeleteIndex == index && _confirmDelete != null && NowMs < _confirmDeleteUntil
|
||||
&& MetaRuleEdit.SameContent(_confirmDelete, rule);
|
||||
float delW = arming ? BtnW("Delete?", 50) : 20;
|
||||
float delX = p.X + w - delW - 2;
|
||||
if (arming
|
||||
? Button("Delete?##del", new Vector2(delX, p.Y + 2), new Vector2(delW, 16), TextDim, DelFill, Red)
|
||||
: IconButton("##del", PhosphorIcons.Trash, new Vector2(delX, p.Y + 2), new Vector2(delW, 16), TextDim, DelFill, BtnBord))
|
||||
{
|
||||
if (arming || MetaRuleEdit.IsPlaceholder(rule))
|
||||
{
|
||||
SendEdit(new MetaCmd { Op = "delete_rule", Index = index });
|
||||
_data.Rules.RemoveAt(index);
|
||||
_expanded.Clear();
|
||||
_confirmDelete = null;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_confirmDelete = rule.Clone();
|
||||
_confirmDeleteIndex = index;
|
||||
_confirmDeleteUntil = NowMs + 3000;
|
||||
}
|
||||
}
|
||||
ImGuiNET.ImGui.SetItemTooltip(arming ? "Click again to delete this rule" : "Delete rule");
|
||||
|
||||
// Condition | action text; clicking it edits the rule.
|
||||
float textW = Math.Max(1, p.X + w - DeleteColumnW - x);
|
||||
_textStartOff = x - p.X;
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(x, p.Y));
|
||||
if (ImGuiNET.ImGui.InvisibleButton("##edit", new Vector2(textW, h)))
|
||||
OpenEditor(index, rule);
|
||||
if (ImGuiNET.ImGui.IsItemHovered()) ImGuiNET.ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
|
||||
ImGuiNET.ImGui.PopID();
|
||||
|
||||
if (!changed)
|
||||
{
|
||||
float col = textW * _condFrac;
|
||||
float ty = p.Y + (h - ImGuiNET.ImGui.GetFontSize()) * 0.5f;
|
||||
uint condCol = firing ? Red : TextDim, actCol = firing ? Amber : C(0xFFC8D8E8);
|
||||
if (!rule.Enabled) { condCol = Faded(condCol); actCol = Faded(actCol); }
|
||||
dl.AddText(new Vector2(x + 3, ty), condCol, Fit(_condText[index], col - 5));
|
||||
// The armed "Delete?" button is wider than the column gap: the action text stops short of it.
|
||||
float actW = Math.Min(textW - col - 4, delX - 6 - (x + col + 2));
|
||||
dl.AddText(new Vector2(x + col + 2, ty), actCol, Fit(_actText[index], actW));
|
||||
}
|
||||
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(p.X, p.Y + h));
|
||||
ImGuiNET.ImGui.Dummy(new Vector2(0, 0));
|
||||
|
||||
if (changed)
|
||||
{
|
||||
RebuildCaches();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasChildren && expanded) ExpandedChildren(rule);
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ExpandedChildren(MetaRuleDto rule)
|
||||
{
|
||||
ImFontPtr f9 = ImGuiFonts.Get(UiFont.Ui9);
|
||||
ImGuiNET.ImGui.PushFont(f9);
|
||||
Vector4 amber = RynthTheme.Vec(0xFFE8B333), mute = RynthTheme.Vec(0xFFC8D6E4);
|
||||
ImGuiNET.ImGui.Indent(22);
|
||||
if (MetaVocabulary.IsCompositeCondition(rule.Condition) && rule.Children.Count > 0)
|
||||
{
|
||||
ImGuiNET.ImGui.TextColored(amber, " " + MetaVocabulary.ConditionName(rule.Condition) + ":");
|
||||
foreach (MetaRuleDto child in rule.Children)
|
||||
ImGuiNET.ImGui.TextColored(mute, " • " + MetaVocabulary.CondText(child));
|
||||
}
|
||||
if (MetaVocabulary.IsAllAction(rule.Action) && rule.ActionChildren.Count > 0)
|
||||
{
|
||||
ImGuiNET.ImGui.TextColored(amber, " All (actions):");
|
||||
foreach (MetaRuleDto child in rule.ActionChildren)
|
||||
ImGuiNET.ImGui.TextColored(mute, " • " + MetaVocabulary.ActText(child));
|
||||
}
|
||||
ImGuiNET.ImGui.Unindent(22);
|
||||
ImGuiNET.ImGui.PopFont();
|
||||
}
|
||||
|
||||
private bool Move(int index, int direction)
|
||||
{
|
||||
int other = MetaVocabulary.SwapPartner(_data.Rules, index, direction);
|
||||
if (other < 0) return false;
|
||||
SendEdit(new MetaCmd { Op = direction < 0 ? "move_up" : "move_down", Index = index });
|
||||
(_data.Rules[index], _data.Rules[other]) = (_data.Rules[other], _data.Rules[index]);
|
||||
_expanded.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void BottomBar(float w)
|
||||
{
|
||||
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
float labelW = ImGuiNET.ImGui.CalcTextSize("State:").X;
|
||||
dl.AddText(new Vector2(p.X, p.Y + (24 - ImGuiNET.ImGui.GetFontSize()) * 0.5f), Mute, "State:");
|
||||
// Buttons sized from their text, so a larger panel text size can't overflow them
|
||||
// (2026-10-05: "+ New Rule" spilled past its fixed 72 px button).
|
||||
string ruleLabel = PhosphorIcons.Plus + " New Rule";
|
||||
float newW = ImGuiNET.ImGui.CalcTextSize(ruleLabel).X + 18;
|
||||
// The bar sits on the body's bottom edge: it stops short of the resize grip (GripInBody).
|
||||
float grip = ImGuiPanelHost.BodyGripReserve;
|
||||
float ruleX = p.X + w - grip - newW;
|
||||
float pickX = p.X + labelW + 4;
|
||||
float pickW = Math.Max(40, ruleX - 4 - pickX);
|
||||
|
||||
// The meta's current state. "+ New state..." at the end of the list makes one: it starts
|
||||
// with an empty Never -> None rule (that rule is what keeps it), becomes the current state
|
||||
// like any state picked here, and that rule opens in the editor.
|
||||
string? chosen = StatePicker("##cur_state", _data.CurrentState, _statePicks, Array.IndexOf(_statePicks, _data.CurrentState),
|
||||
new Vector2(pickX, p.Y + 1), pickW, out bool isNew);
|
||||
if (chosen != null)
|
||||
{
|
||||
if (isNew) CreateState(chosen, openIt: true);
|
||||
_data.CurrentState = chosen;
|
||||
MetaCommands.Simple("set_state", value: chosen);
|
||||
}
|
||||
if (Button(ruleLabel + "##new", new Vector2(ruleX, p.Y), new Vector2(newW, 24), TextDim, NewFill, Green))
|
||||
OpenEditor(-1, new MetaRuleDto { State = _data.CurrentState, Action = 1 });
|
||||
ImGuiNET.ImGui.SetItemTooltip("A new rule in the current state (added once its condition and action are filled in)");
|
||||
ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(p.X, p.Y + 24));
|
||||
ImGuiNET.ImGui.Dummy(new Vector2(0, 0));
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Source view
|
||||
|
|
@ -1125,7 +843,7 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
/// picked index or -1.
|
||||
/// </summary>
|
||||
private int Picker(string id, string shown, string[] items, int selected, Vector2 pos, float width, float height = 22,
|
||||
string? extra = null)
|
||||
string? extra = null, string? badge = null)
|
||||
{
|
||||
var dl = ImGuiNET.ImGui.GetWindowDrawList();
|
||||
ImGuiNET.ImGui.PushID(id);
|
||||
|
|
@ -1146,7 +864,16 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
const float caretW = 14;
|
||||
PhosphorIcons.DrawCentered(dl, ImGuiFonts.Get(UiFont.Ui11), PhosphorIcons.CaretDown,
|
||||
new Vector2(pos.X + width - caretW - 3, pos.Y), new Vector2(caretW, height), Mute);
|
||||
dl.AddText(pos + new Vector2(6, (height - ImGuiNET.ImGui.GetFontSize()) * 0.5f), TextDim, Fit(shown, width - 6 - caretW - 6));
|
||||
// A badge (seconds in state) sits right-aligned before the arrow; the text is cut before it.
|
||||
float badgeW = 0;
|
||||
if (!string.IsNullOrEmpty(badge))
|
||||
{
|
||||
badgeW = ImGuiNET.ImGui.CalcTextSize(badge).X + 8;
|
||||
if (badgeW > width * 0.5f) badgeW = 0;
|
||||
else dl.AddText(new Vector2(pos.X + width - caretW - 3 - badgeW + 2, pos.Y + (height - ImGuiNET.ImGui.GetFontSize()) * 0.5f),
|
||||
Faded(Teal), badge);
|
||||
}
|
||||
dl.AddText(pos + new Vector2(6, (height - ImGuiNET.ImGui.GetFontSize()) * 0.5f), TextDim, Fit(shown, width - 6 - caretW - 6 - badgeW));
|
||||
|
||||
int picked = -1;
|
||||
ImGuiNET.ImGui.PushStyleColor(ImGuiCol.PopupBg, ShellBg);
|
||||
|
|
@ -1278,9 +1005,15 @@ internal sealed partial class MetaFace : IImGuiPanel
|
|||
string shown = text;
|
||||
if (ImGuiNET.ImGui.CalcTextSize(text).X > width)
|
||||
{
|
||||
int n = text.Length;
|
||||
while (n > 0 && ImGuiNET.ImGui.CalcTextSize(text.AsSpan(0, n).ToString() + "…").X > width) n--;
|
||||
shown = text.Substring(0, n) + "…";
|
||||
// The longest start that fits with "…" (binary search: long expressions are cut often,
|
||||
// and the cache empties with every snapshot while rules fire).
|
||||
int lo = 0, hi = text.Length - 1;
|
||||
while (lo < hi)
|
||||
{
|
||||
int mid = (lo + hi + 1) / 2;
|
||||
if (ImGuiNET.ImGui.CalcTextSize(text.Substring(0, mid) + "…").X <= width) lo = mid; else hi = mid - 1;
|
||||
}
|
||||
shown = text.Substring(0, lo) + "…";
|
||||
}
|
||||
if (_fit.Count > 4000) _fit.Clear(); // widths change while a panel is resized
|
||||
_fit[key] = shown;
|
||||
|
|
|
|||
Loading…
Reference in a new issue