Snapshot for release 2026.10.31.2 (internal 4a0710c)
This commit is contained in:
parent
76aca938b6
commit
d54613aa63
50 changed files with 5824 additions and 179 deletions
|
|
@ -9,6 +9,18 @@
|
|||
// it in game; right-click for /rn commands. Looks: Shared/RynthUi (the
|
||||
// player's theme). AC's render thread: it reads the published rows and the
|
||||
// pose, and queues everything it does for the plugin tick.
|
||||
//
|
||||
// Two looks (2026-10-31, CharactersLook.cs; /rn view, kept per character):
|
||||
// minimal the default, in item-counter.lua's style: one line per
|
||||
// character (status dot, name coloured by its health, three thin
|
||||
// vital bars, the arrow and distance when there is room), no frame
|
||||
// or background on an engine with frameless windows (v90). Hover
|
||||
// it for the pencil that brings the full look back.
|
||||
// full every column, as before. On a v90 engine the window is
|
||||
// frameless, so this look paints its own frame and title row:
|
||||
// drag it to move, Ctrl+wheel for the text size, the buttons for
|
||||
// the minimal look, pop-out and close; the corner resizes it.
|
||||
// Both ask for the height they need (the window fits it, "fitHeight").
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
|
|
@ -23,10 +35,12 @@ namespace RynthCore.Plugin.RynthNet.Characters;
|
|||
|
||||
internal sealed class CharactersWindow
|
||||
{
|
||||
private readonly RynthCoreHost _host;
|
||||
private readonly Action<uint> _select;
|
||||
private readonly Action<string, string> _tell;
|
||||
private readonly Action _followMeAll;
|
||||
private readonly Func<(bool Ok, float Heading)> _heading;
|
||||
private readonly Action<CharactersViewMode> _setView;
|
||||
|
||||
// The vitals colours of RynthAi's dashboard (fixed, whatever the theme).
|
||||
private static readonly uint HpCol = Argb(0xFFD93333), StCol = Argb(0xFF40D973), MpCol = Argb(0xFF268CF2),
|
||||
|
|
@ -42,6 +56,8 @@ internal sealed class CharactersWindow
|
|||
"Click a row to select that character in game (when this client can see it). Right-click for commands: " +
|
||||
"follow me, stop following, start or stop the macro. They go through RynthNet, so the other client's " +
|
||||
"remote command setting (/rn remote) decides whether they run.\n\n" +
|
||||
"The arrows-in button (or /rn view minimal) shows one line per character without the frame; " +
|
||||
"hover it for the pencil (or /rn view full) to come back here. Kept per character.\n\n" +
|
||||
"/rc characters opens and closes this window.";
|
||||
|
||||
private float _k = 1f;
|
||||
|
|
@ -53,33 +69,64 @@ internal sealed class CharactersWindow
|
|||
private bool _menuInView, _menuOtherWorld, _menuSelf, _menuLoggedOut;
|
||||
private bool _openMenu;
|
||||
|
||||
public CharactersWindow(Action<uint> select, Action<string, string> tell, Action followMeAll, Func<(bool, float)> heading)
|
||||
public CharactersWindow(RynthCoreHost host, Action<uint> select, Action<string, string> tell, Action followMeAll,
|
||||
Func<(bool, float)> heading, Action<CharactersViewMode> setView)
|
||||
{
|
||||
_host = host;
|
||||
_select = select;
|
||||
_tell = tell;
|
||||
_followMeAll = followMeAll;
|
||||
_heading = heading;
|
||||
_setView = setView;
|
||||
}
|
||||
|
||||
/// <summary>Draws the window body into the current ImGui window. Render thread.</summary>
|
||||
public void Draw(CharactersView view)
|
||||
/// <summary>
|
||||
/// Draws the window body into the current ImGui window in <paramref name="mode"/>'s look.
|
||||
/// <paramref name="frameless"/>: the engine gave the window no frame (v90), so the full look paints
|
||||
/// its own. <paramref name="popped"/>: drawn in its own OS window, so the minimal look keeps a
|
||||
/// background. Returns the height it needs (pixels; 0 = whatever the window is). Render thread.
|
||||
/// </summary>
|
||||
public float Draw(CharactersView view, CharactersViewMode mode, bool frameless, bool popped = false)
|
||||
{
|
||||
_k = Math.Max(0.5f, Font(RynthUiFont.Ui10).FontSize / 10f);
|
||||
if (mode == CharactersViewMode.Full) return DrawFull(view, ownFrame: frameless);
|
||||
if (popped)
|
||||
{
|
||||
Vector2 o = ImGui.GetCursorScreenPos();
|
||||
ImGui.GetWindowDrawList().AddRectFilled(o, o + ImGui.GetContentRegionAvail(), Background, 4);
|
||||
}
|
||||
return DrawMinimal(view, frameless && !popped);
|
||||
}
|
||||
|
||||
// ── Full look ───────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Every column. <paramref name="ownFrame"/>: paint the frame and a title row (the engine gave none)
|
||||
/// and return the height the rows need; otherwise fill the engine's frame and return 0.
|
||||
/// </summary>
|
||||
private float DrawFull(CharactersView view, bool ownFrame)
|
||||
{
|
||||
Vector2 origin = ImGui.GetCursorScreenPos();
|
||||
Vector2 size = ImGui.GetContentRegionAvail();
|
||||
if (size.X < 40 || size.Y < 30) return;
|
||||
float titleH = ownFrame ? Px(20) : 0f;
|
||||
float rowsH = view.Rows.Length == 0 ? Px(30) : view.Rows.Length * RowH;
|
||||
// Margin, title, the status line, the rows, and room under them for the corner grip.
|
||||
float want = MathF.Ceiling(6 + titleH + Px(24) + rowsH + 6 + Px(12));
|
||||
if (ownFrame) size.Y = Math.Max(size.Y, want); // a frame late: draw at the height asked for
|
||||
if (size.X < 40 || size.Y < 30) return ownFrame ? want : 0f;
|
||||
ImDrawListPtr frame = ImGui.GetWindowDrawList();
|
||||
frame.AddRectFilled(origin, origin + size, Background, 4);
|
||||
using (PushFont(RynthUiFont.Ui10))
|
||||
{
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 4));
|
||||
ImGui.SetCursorScreenPos(origin + new Vector2(6, 6));
|
||||
if (ownFrame) DrawTitle(origin, size.X, titleH);
|
||||
ImGui.SetCursorScreenPos(origin + new Vector2(6, 6 + titleH));
|
||||
ImGui.Indent(6);
|
||||
float w = size.X - 12;
|
||||
DrawTop(view, w);
|
||||
DrawTop(view, w, minimalButton: !ownFrame); // framed by the engine: no title row, so the button sits here
|
||||
|
||||
// The host's resize grip sits over the bottom-right corner: the rows end above it.
|
||||
float bodyH = Math.Max(Px(30), origin.Y + size.Y - 6 - ImGui.GetCursorScreenPos().Y - Px(12));
|
||||
float bodyH = ownFrame ? rowsH : Math.Max(Px(30), origin.Y + size.Y - 6 - ImGui.GetCursorScreenPos().Y - Px(12));
|
||||
ImGui.PushStyleColor(ImGuiCol.ChildBg, Field);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
|
||||
ImGui.BeginChild("##chars_rows", new Vector2(w, bodyH));
|
||||
|
|
@ -93,22 +140,245 @@ internal sealed class CharactersWindow
|
|||
DrawMenu(view);
|
||||
}
|
||||
frame.AddRect(origin, origin + size, Border, 4);
|
||||
return ownFrame ? want : 0f;
|
||||
}
|
||||
|
||||
/// <summary>The full look's own title row (frameless window): drag to move; minimal, pop-out and close.</summary>
|
||||
private void DrawTitle(Vector2 origin, float width, float h)
|
||||
{
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
float bw = Px(20), gap = Px(3);
|
||||
float buttons = 3 * bw + 2 * gap + 6;
|
||||
var top = new Vector2(origin.X, origin.Y + 3);
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.InvisibleButton("##chars_title", new Vector2(Math.Max(10, width - buttons), h + 3));
|
||||
_host.PanelDragWithLastItem();
|
||||
SafeImGui.SetItemTooltip("Drag to move. Ctrl+wheel: text size. The corner resizes it.");
|
||||
ImFontPtr bold = Font(RynthUiFont.UiBold11);
|
||||
DrawCentered(dl, Font(RynthUiFont.Ui11), RynthIcons.UsersThree, new Vector2(origin.X + 6, top.Y), new Vector2(Px(14), h), Accent);
|
||||
dl.AddText(bold, bold.FontSize, new Vector2(origin.X + 6 + Px(18), top.Y + (h - bold.FontSize) * 0.5f), Text, CharactersManifest.Title);
|
||||
|
||||
float bx = origin.X + width - 6 - 3 * bw - 2 * gap;
|
||||
var bsize = new Vector2(bw, h - Px(2));
|
||||
if (IconButton("##chars_minimal", RynthIcons.ArrowsInLineVertical, new Vector2(bx, top.Y), bsize, Text, ButtonFill, font: RynthUiFont.Ui11))
|
||||
_setView(CharactersViewMode.Minimal);
|
||||
ImGui.SetItemTooltip("Minimal: one line per character, no frame (/rn view minimal)");
|
||||
if (IconButton("##chars_popout", RynthIcons.ArrowSquareOut, new Vector2(bx + bw + gap, top.Y), bsize, Text, ButtonFill, font: RynthUiFont.Ui11))
|
||||
_host.SetPanelPopOut(CharactersManifest.Title, RynthPanelPopOut.Toggle);
|
||||
ImGui.SetItemTooltip("Pop out into its own window, or dock it back");
|
||||
if (IconButton("##chars_close", RynthIcons.X, new Vector2(bx + 2 * (bw + gap), top.Y), bsize, Text, ButtonFill, font: RynthUiFont.Ui11))
|
||||
_host.SetPanelOpen(CharactersManifest.Title, RynthPanelOpen.Close);
|
||||
ImGui.SetItemTooltip("Close (/rc characters opens it again)");
|
||||
}
|
||||
|
||||
// ── Minimal look ────────────────────────────────────────────────────
|
||||
|
||||
private static readonly uint Shadow = 0xB0000000;
|
||||
|
||||
/// <summary>
|
||||
/// One line per character: status dot, name (its health's colour), three thin bars, arrow and
|
||||
/// distance when there's room. <paramref name="frameless"/>: no frame or background, the text
|
||||
/// shadowed so it reads over the game. Returns the height it needs.
|
||||
/// </summary>
|
||||
private float DrawMinimal(CharactersView view, bool frameless)
|
||||
{
|
||||
Vector2 origin = ImGui.GetCursorScreenPos();
|
||||
float width = ImGui.GetContentRegionAvail().X;
|
||||
CharacterRow[] rows = view.Rows;
|
||||
float want = CharactersLook.MinimalHeight(rows.Length, _k);
|
||||
if (width < 20) return want;
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
using (PushFont(RynthUiFont.Ui10))
|
||||
{
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
|
||||
float fontH = ImGui.GetFontSize();
|
||||
float rowH = MathF.Max(Px(CharactersLook.RowHeight), MathF.Ceiling(fontH + 3));
|
||||
want = MathF.Max(want, MathF.Ceiling(Math.Max(1, rows.Length) * rowH + 4));
|
||||
var start = new Vector2(origin.X + 2, origin.Y + 2);
|
||||
bool windowHot = ImGui.IsWindowHovered(ImGuiHoveredFlags.ChildWindows | ImGuiHoveredFlags.AllowWhenBlockedByActiveItem);
|
||||
float lineW;
|
||||
|
||||
if (rows.Length == 0)
|
||||
{
|
||||
// Nothing to list: the status, faint (and the pencil on hover).
|
||||
DrawDot(dl, new Vector2(start.X + Px(CharactersLook.DotWidth) * 0.5f, start.Y + rowH * 0.5f), CharDot.Off);
|
||||
string s = view.Status;
|
||||
float tw = Math.Min(ImGui.CalcTextSize(s).X, width - Px(CharactersLook.DotWidth) - Px(30));
|
||||
ShadowClip(dl, s, start.X + Px(CharactersLook.DotWidth), start.Y + (rowH - fontH) * 0.5f, tw, Faded(Text), frameless);
|
||||
lineW = Px(CharactersLook.DotWidth) + Math.Max(0, tw);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Columns from the longest name and distance, so the bars line up.
|
||||
float nameW = 0, distW = 0;
|
||||
foreach (CharacterRow r in rows)
|
||||
{
|
||||
nameW = MathF.Max(nameW, ImGui.CalcTextSize(r.Name).X);
|
||||
if (ShowsDistance(r)) distW = MathF.Max(distW, ImGui.CalcTextSize(r.DistanceText).X);
|
||||
}
|
||||
nameW = MathF.Ceiling(nameW + Px(2));
|
||||
float editRoom = Px(20);
|
||||
MinimalLine line = CharactersLook.Minimal(width - 4 - editRoom, nameW, distW, _k);
|
||||
lineW = line.Width(_k, distW);
|
||||
(bool haveHeading, float heading) = _heading();
|
||||
int hovered = -1;
|
||||
for (int i = 0; i < rows.Length; i++)
|
||||
{
|
||||
CharacterRow r = rows[i];
|
||||
var p = new Vector2(start.X, start.Y + i * rowH);
|
||||
ImGui.SetCursorScreenPos(p);
|
||||
ImGui.PushID(i);
|
||||
bool clicked = ImGui.InvisibleButton("##mrow", new Vector2(Math.Max(1, lineW), rowH),
|
||||
ImGuiButtonFlags.MouseButtonLeft | ImGuiButtonFlags.MouseButtonRight);
|
||||
bool hot = ImGui.IsItemHovered();
|
||||
bool right = clicked && ImGui.IsMouseReleased(ImGuiMouseButton.Right);
|
||||
ImGui.PopID();
|
||||
if (hot) hovered = i;
|
||||
if (clicked && !right && r.InView && r.Id != 0 && !r.IsSelf) _select(r.Id);
|
||||
if (right) OpenMenu(r);
|
||||
DrawMinimalRow(dl, r, p, line, lineW, rowH, fontH, hot, r.Id != 0 && r.Id == view.SelectedId,
|
||||
heading, haveHeading, distW, frameless);
|
||||
}
|
||||
if (hovered >= 0 && rows[hovered].Tooltip.Length > 0 && !ImGui.IsPopupOpen("##chars_menu"))
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
ImGui.TextUnformatted(rows[hovered].Tooltip);
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
// The pencil: back to the full look (shown while the mouse is on the window).
|
||||
if (windowHot)
|
||||
{
|
||||
float bs = rowH - 2;
|
||||
var bp = new Vector2(Math.Min(start.X + lineW + Px(4), origin.X + width - bs - 2), start.Y + 1);
|
||||
if (IconButton("##chars_full", RynthIcons.PencilSimple, bp, new Vector2(bs, bs), Text, WithAlpha(Background, 0xE0),
|
||||
font: RynthUiFont.Ui11))
|
||||
_setView(CharactersViewMode.Full);
|
||||
ImGui.SetItemTooltip("Edit: the full window with every column, to move or resize it (/rn view full)");
|
||||
}
|
||||
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.Dummy(new Vector2(Math.Max(1, width), Math.Max(1, want - 1)));
|
||||
ImGui.PopStyleVar();
|
||||
DrawMenu(view);
|
||||
}
|
||||
return want;
|
||||
}
|
||||
|
||||
private static bool ShowsDistance(CharacterRow r) => !r.IsSelf && !r.LoggedOut && r.DistanceText.Length > 0;
|
||||
|
||||
private void DrawMinimalRow(ImDrawListPtr dl, CharacterRow r, Vector2 p, MinimalLine line, float lineW, float rowH, float fontH,
|
||||
bool hot, bool isSel, float heading, bool haveHeading, float distW, bool frameless)
|
||||
{
|
||||
if (hot) dl.AddRectFilled(p, p + new Vector2(lineW, rowH), WithAlpha(Background, 0xB0), 2);
|
||||
if (isSel) dl.AddRect(p, p + new Vector2(lineW, rowH), Accent, 2);
|
||||
float dim = r.IsSelf || r.LoggedOut ? 0.6f : 1f;
|
||||
float x = p.X;
|
||||
float ty = p.Y + (rowH - fontH) * 0.5f;
|
||||
|
||||
DrawDot(dl, new Vector2(x + Px(CharactersLook.DotWidth) * 0.5f, p.Y + rowH * 0.5f), CharactersLook.Dot(r));
|
||||
x += Px(CharactersLook.DotWidth);
|
||||
|
||||
ShadowClip(dl, r.Name, x, ty, line.NameWidth, Fade(NameColor(r), dim), frameless);
|
||||
x += line.NameWidth;
|
||||
|
||||
if (line.Bars)
|
||||
{
|
||||
x += Px(CharactersLook.Gap);
|
||||
float bh = Math.Max(2f, Px(CharactersLook.BarHeight)), by = MathF.Round(p.Y + (rowH - bh) * 0.5f), gap = Px(CharactersLook.BarGap);
|
||||
if (r.HasVitals)
|
||||
{
|
||||
ThinBar(dl, x, by, line.BarWidth, bh, r.Hp.Fraction, Fade(HpCol, dim));
|
||||
ThinBar(dl, x + line.BarWidth + gap, by, line.BarWidth, bh, r.St.Fraction, Fade(StCol, dim));
|
||||
ThinBar(dl, x + 2 * (line.BarWidth + gap), by, line.BarWidth, bh, r.Mp.Fraction, Fade(MpCol, dim));
|
||||
}
|
||||
x += 3 * line.BarWidth + 2 * gap;
|
||||
}
|
||||
|
||||
if (line.Distance && ShowsDistance(r))
|
||||
{
|
||||
x += Px(CharactersLook.Gap);
|
||||
var mid = new Vector2(x + Px(CharactersLook.ArrowWidth) * 0.5f, p.Y + rowH * 0.5f);
|
||||
uint col = Fade(r.Measured ? Text : Faded(Mute), dim);
|
||||
if (r.Measured && haveHeading && !float.IsNaN(r.Bearing))
|
||||
{
|
||||
if (frameless) DrawArrow(dl, mid + new Vector2(1, 1), r.Bearing - heading, Shadow, _k * 0.8f);
|
||||
DrawArrow(dl, mid, r.Bearing - heading, Fade(StateColor(r), dim), _k * 0.8f);
|
||||
}
|
||||
else if (r.Measured)
|
||||
dl.AddCircleFilled(mid, Px(2f), col);
|
||||
x += Px(CharactersLook.ArrowWidth);
|
||||
ShadowClip(dl, r.DistanceText, x, ty, distW + 1, col, frameless);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The name's colour: its health's warning (amber low, red critical or dead), else the text colour.</summary>
|
||||
private static uint NameColor(CharacterRow r) => r.IsSelf ? Text : CharactersLook.Hp(r) switch
|
||||
{
|
||||
HpWarn.Dead or HpWarn.Critical => Red,
|
||||
HpWarn.Low => Highlight,
|
||||
HpWarn.Unknown when r.LoggedOut => Faded(Mute),
|
||||
_ => Text,
|
||||
};
|
||||
|
||||
private void DrawDot(ImDrawListPtr dl, Vector2 c, CharDot dot)
|
||||
{
|
||||
float r = Px(3f);
|
||||
switch (dot)
|
||||
{
|
||||
case CharDot.Off: dl.AddCircle(c, r, Faded(Mute), 12, Px(1.2f)); break;
|
||||
case CharDot.Stale: dl.AddCircle(c, r, Highlight, 12, Px(1.6f)); break;
|
||||
case CharDot.Self: dl.AddCircleFilled(c, r, Mute, 12); break;
|
||||
case CharDot.Dead: dl.AddCircleFilled(c, r, Red, 12); break;
|
||||
case CharDot.Portal: dl.AddCircleFilled(c, r, Purple, 12); break;
|
||||
case CharDot.Fighting: dl.AddCircleFilled(c, r, Highlight, 12); break;
|
||||
case CharDot.Botting: dl.AddCircleFilled(c, r, Green, 12); break;
|
||||
default: dl.AddCircleFilled(c, r, Faded(Mute), 12); break; // idle
|
||||
}
|
||||
}
|
||||
|
||||
private static void ThinBar(ImDrawListPtr dl, float x, float y, float w, float h, float fraction, uint color)
|
||||
{
|
||||
if (w <= 1) return;
|
||||
fraction = float.IsFinite(fraction) ? Math.Clamp(fraction, 0f, 1f) : 0f;
|
||||
dl.AddRectFilled(new Vector2(x, y), new Vector2(x + w, y + h), WithAlpha(BarBg, 0xD0), 1);
|
||||
if (fraction > 0) dl.AddRectFilled(new Vector2(x, y), new Vector2(x + w * fraction, y + h), color, 1);
|
||||
}
|
||||
|
||||
/// <summary>Text clipped to <paramref name="width"/>, with a 1 px shadow when it sits over the game.</summary>
|
||||
private static void ShadowClip(ImDrawListPtr dl, string text, float x, float y, float width, uint color, bool shadow)
|
||||
{
|
||||
if (text.Length == 0 || width <= 0) return;
|
||||
dl.PushClipRect(new Vector2(x, y - 2), new Vector2(x + width + 1, y + 40), true);
|
||||
if (shadow) dl.AddText(new Vector2(x + 1, y + 1), Shadow, text);
|
||||
dl.AddText(new Vector2(x, y), color, text);
|
||||
dl.PopClipRect();
|
||||
}
|
||||
|
||||
// ── Top line ────────────────────────────────────────────────────────
|
||||
|
||||
private void DrawTop(CharactersView view, float w)
|
||||
private void DrawTop(CharactersView view, float w, bool minimalButton)
|
||||
{
|
||||
Vector2 start = ImGui.GetCursorScreenPos();
|
||||
float h = Px(20), iconW = Px(22);
|
||||
int icons = minimalButton ? 3 : 2;
|
||||
float fontH = ImGui.GetFontSize();
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
float textW = Math.Max(10, w - 2 * iconW - Px(8));
|
||||
float textW = Math.Max(10, w - icons * iconW - Px(4) * icons);
|
||||
dl.PushClipRect(start, start + new Vector2(textW, h), true);
|
||||
dl.AddText(new Vector2(start.X, start.Y + (h - fontH) * 0.5f), Mute, view.Status);
|
||||
dl.PopClipRect();
|
||||
|
||||
float bx = start.X + w - 2 * iconW - Px(4);
|
||||
float bx = start.X + w - icons * iconW - Px(4) * (icons - 1);
|
||||
if (minimalButton)
|
||||
{
|
||||
if (IconButton("##chars_minimal", RynthIcons.ArrowsInLineVertical, new Vector2(bx, start.Y), new Vector2(iconW, h), Text, ButtonFill,
|
||||
font: RynthUiFont.Ui11))
|
||||
_setView(CharactersViewMode.Minimal);
|
||||
ImGui.SetItemTooltip("Minimal: one line per character (/rn view minimal)");
|
||||
bx += iconW + Px(4);
|
||||
}
|
||||
bool canFollow = view.MyName.Length > 0;
|
||||
if (IconButton("##chars_followall", RynthIcons.Footprints, new Vector2(bx, start.Y), new Vector2(iconW, h), Text, ButtonFill,
|
||||
enabled: canFollow, font: RynthUiFont.Ui11))
|
||||
|
|
|
|||
Loading…
Reference in a new issue