feat(miniremote): host RynthAi's Mini Remote in the engine window; resizable quick-launch boxes

See Changelog/2026-10-11-mini-remote-merge.md.
This commit is contained in:
BlankenshipG 2026-10-12 00:31:51 -04:00
commit 5428f6b403
5 changed files with 282 additions and 34 deletions

View file

@ -0,0 +1,40 @@
# Mini Remote: one window, resizable quick-launch boxes
## What changed
RynthCore's "Mini Remote" window and RynthAi's floating "MINI REMOTE" are merged into one window.
- **`MiniRemoteFace` hosts RynthAi's Mini Remote** through the new plugin embed surface
`"miniremote-window"`. That covers stats, target, pet, item slots, toggles, bank, rebuff,
translate and the guardian answer, with RynthAi's own Options menu.
- The window fits itself to the size the plugin asks for (`FitWindow`, capped to the screen
height; popped-out windows are left alone).
- RynthAi hides its floating copy while this window shows it.
- Without RynthAi, or when its embed fails, the window falls back to the engine's own slot grid
(per-character `item_huds.txt` slots, More/Fewer slots, drag-and-drop), as before.
- **Grow and shrink the quick-launch boxes** in the fallback grid:
- Ctrl+mouse wheel over the grid changes the box size by 4 px per notch.
- The right-click menu has "Bigger boxes (N px now)", "Smaller boxes" and "Default box size".
- Saved per character in `item_huds.txt` as `slotsize=<px>` (24-72, default 36). The line is
written only when the size isn't the default, so existing files don't change.
- RynthAi's hosted grid has its own size control: Ctrl+wheel, or Options > Slot size.
- **Hub launcher** on the RynthAi dashboard: left-click now toggles this Mini Remote window instead
of RynthAi's floating one. Right-click still opens the Mini Remote drawer, or the window when
the dashboard is popped out.
## Files
- `src/RynthCore.Engine/ImGui/Panels/MiniRemoteFace.cs`: rewritten to host the plugin, with the
fallback grid, the box size controls and the window fit.
- `src/RynthCore.Engine/UI/Data/ItemHudModel.cs`: `ItemHudCharacter.SlotSize`, `WithSlotSize`,
and parsing and writing `slotsize=`.
- `src/RynthCore.Engine/ImGui/Panels/RynthAiFace.cs`: the Hub launcher opens the Mini Remote window.
- `tools/ItemHudTests/Program.cs`: new `SlotSizes` case covering clamping, edits, round-trip,
default not written, and bad values.
Works best with the matching RynthAi change. An older plugin doesn't know `"miniremote-window"`, so
the window shows the engine grid instead.
## Tests
- ItemHudTests: PASS (63 assertions).

View file

@ -1,14 +1,25 @@
// ============================================================================
// RynthCore.Engine - ImGui/Panels/MiniRemoteFace.cs
// The Mini Remote: a small grid of slots the player fills with items; a click
// uses that item. Engine only, ImGui only. (An idea from Silentkelpie's rynth
// PR #1, done as an engine face.)
// The Mini Remote: one window for the quick-use item slots, whoever draws them.
//
// With RynthAi loaded it hosts RynthAi's Mini Remote (session rates, target,
// summon, item slots, toggles, bank, rebuff, Translate, Guardian and its
// Options menu), drawn by the plugin through RynthPluginRenderEmbed
// ("miniremote-window"). The window fits itself to what the plugin asks for
// whenever that changes (a section shown or hidden, bigger or smaller boxes);
// a resize by hand holds until then. While this window shows it, RynthAi keeps
// its own floating copy hidden, so there is one Mini Remote, not two.
//
// Without RynthAi (not loaded, too old for the surface, not logged in yet, or
// its embed failed) it is the engine's own grid (an idea from Silentkelpie's
// rynth PR #1, done as an engine face):
// slots the item's icon and carried count; an empty slot shows +
// click uses the slot's item (the same object if still carried, else a
// stack with its name); on an empty slot, puts the selected
// inventory item there
// right Set to the selected item, Clear, More / Fewer slots
// right Set to the selected item, Clear, More / Fewer slots,
// Bigger / Smaller boxes
// ctrl+wheel over the slots: bigger / smaller boxes
// drop drag an item from the game's inventory (or the Inventory panel)
// onto a slot to put it there (UiDropTargets, one target a slot)
// status the use waiting for the server, or how the last one ended
@ -16,7 +27,8 @@
// A click never calls AC from the render thread: it posts an InventoryModel
// Use request, which AC's main thread sends at its next tick behind the
// client's own item gate (one item action at a time; a click while one waits
// is refused, not queued). Slots are saved per character (ItemHudStore).
// is refused, not queued). Slots and box size are saved per character
// (ItemHudStore).
// ============================================================================
using System;
@ -24,6 +36,7 @@ using System.Globalization;
using System.Numerics;
using ImGuiNET;
using RynthCore.Engine.Compatibility;
using RynthCore.Engine.Plugins;
using RynthCore.Engine.UI.Data;
using RynthCore.Engine.UI.ScriptWindows;
using static RynthCore.Engine.ImGuiBackend.Panels.FaceKit;
@ -42,7 +55,12 @@ internal sealed class MiniRemoteFace : IImGuiPanel
ItemHudStore.EnsureLoadQueued();
}
private const float Slot = 36f, Gap = 4f, IconSize = 32f, StatusH = 18f;
/// <summary>The RynthAi surface for this window (NUL-terminated for the export).</summary>
private static ReadOnlySpan<byte> Surface => "miniremote-window\0"u8;
private const float Gap = 4f, StatusH = 18f;
/// <summary>Pixels a Ctrl+wheel notch or a Bigger / Smaller menu click changes the box edge by.</summary>
private const int SlotSizeStep = 4;
private const string MenuId = "##miniremote_menu";
private static readonly string[] DropKeys = BuildDropKeys();
@ -66,34 +84,144 @@ internal sealed class MiniRemoteFace : IImGuiPanel
private uint[] _slotItem = Array.Empty<uint>();
private string[] _slotCount = Array.Empty<string>();
// RynthAi hosting: it drew last frame; its export failed this session; the size it last asked for.
private bool _hosted;
private bool _embedOff;
private Vector2 _lastWant;
// The engine grid: the box size it last fitted the window to (0 = fit on the next frame).
private int _fittedSlotSize;
// The window size last requested (logical units), so the same request isn't repeated.
private Vector2 _requested;
public void OnShown()
{
ItemHudStore.EnsureLoadQueued();
InventoryModel.Subscribe();
_lastWant = Vector2.Zero;
_fittedSlotSize = 0;
_requested = Vector2.Zero;
}
public void OnHidden()
{
InventoryModel.Unsubscribe();
_menuSlot = -1;
_hosted = false;
}
public void Draw()
{
float w = Begin(out Vector2 origin, out Vector2 size);
if (DrawRynthAi(w, origin, size))
{
End(origin, size);
return;
}
InventoryView view = InventoryModel.Current;
HudItem[] items = _items.Get(view);
ItemHudCharacter data = ItemHudStore.Current;
bool ready = ItemHudStore.Loaded && ItemHudStore.HasCharacter && view.PlayerId != 0;
Resolve(data, items);
float gridH = Math.Max(Slot, Remaining(origin, size) - StatusH - GripOverlap());
float haveH = Remaining(origin, size);
float gridH = Math.Max(data.SlotSize, haveH - StatusH - GripOverlap());
DrawGrid(data, items, w, gridH, ready);
DrawStatus(ready);
FitGrid(data, w, haveH);
End(origin, size);
DrawMenu(data, items);
}
// ── RynthAi's Mini Remote ───────────────────────────────────────────
/// <summary>
/// Lets RynthAi draw its Mini Remote here. True when it did (or is mid-layout after
/// drawing last frame); false means the engine grid draws instead. The plugin draws
/// nothing when it declines, and the auto-height child it would have filled stays
/// empty, so the grid can take the space the same frame.
/// </summary>
private bool DrawRynthAi(float w, Vector2 origin, Vector2 size)
{
if (_embedOff) return false;
float haveH = Remaining(origin, size);
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
bool open = ImGuiNET.ImGui.BeginChild("##mr_rynthai", new Vector2(w, 0), ImGuiChildFlags.AutoResizeY,
ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoScrollbar);
ImGuiNET.ImGui.PopStyleVar();
int result = PluginManager.EmbedNotReady;
Vector2 want = Vector2.Zero;
try
{
if (open)
{
// The plugin's widgets use the default UI font, as in its floating Mini Remote.
ImGuiNET.ImGui.PushFont(ImGuiFonts.Get(UiFont.Ui11));
try { result = PluginManager.RenderEmbed("RynthAi", Surface, new Vector2(w, Math.Max(1f, haveH)), out want); }
finally { ImGuiNET.ImGui.PopFont(); }
}
}
finally { ImGuiNET.ImGui.EndChild(); }
if (result == PluginManager.EmbedFailed) _embedOff = true;
// A clipped child (open == false) draws nothing; keep the last frame's answer so the
// window doesn't flick to the engine grid for that frame.
_hosted = open ? result == PluginManager.EmbedDrawn : _hosted && !_embedOff;
if (!_hosted) { _lastWant = Vector2.Zero; return false; }
if (result == PluginManager.EmbedDrawn && want.X > 0 && want.Y > 0
&& Vector2.DistanceSquared(want, _lastWant) > 1f)
{
_lastWant = want;
// + the grip's reach, so the plugin's last row isn't under the resize grip.
FitWindow(new Vector2(want.X, want.Y + GripOverlap()), w, haveH);
}
return true;
}
// ── Window fit ──────────────────────────────────────────────────────
/// <summary>
/// Sizes the window so the body area (<paramref name="haveW"/> × <paramref name="haveH"/>
/// now) becomes <paramref name="wantPx"/>; never taller than the screen. Docked only:
/// popped out the OS window keeps its size, as other faces do (RynthNavArrowFace).
/// </summary>
private void FitWindow(Vector2 wantPx, float haveW, float haveH)
{
if (ImGuiPopOuts.InPopOutFrame) return;
float place = ImGuiPanelHost.PlacementScale();
float extraW = ImGuiNET.ImGui.GetWindowWidth() - haveW; // anything around the body
float extraH = ImGuiNET.ImGui.GetWindowHeight() - haveH;
var want = new Vector2(MathF.Ceiling((wantPx.X + extraW) / place), MathF.Ceiling((wantPx.Y + extraH) / place));
float screenH = ImGuiNET.ImGui.GetIO().DisplaySize.Y / place;
if (screenH > 1) want.Y = MathF.Min(want.Y, screenH - 8);
if (Vector2.DistanceSquared(want, _requested) < 1f) return;
_requested = want;
ImGuiPanelHost.RequestSize(Title, want);
}
/// <summary>
/// The engine grid: after the box size changes (and on the first frame shown), fits the
/// window to the slots at the same number of columns, plus the status line.
/// </summary>
private void FitGrid(ItemHudCharacter data, float w, float haveH)
{
if (_fittedSlotSize == data.SlotSize || !ItemHudStore.Loaded) return;
bool first = _fittedSlotSize == 0;
int oldSlot = first ? data.SlotSize : _fittedSlotSize;
_fittedSlotSize = data.SlotSize;
// First show: keep the window the player left (only a box-size change refits it).
if (first) return;
int cols = Math.Max(1, (int)((w + Gap) / (oldSlot + Gap)));
int rows = (data.Slots.Length + cols - 1) / cols;
float slot = data.SlotSize;
var body = new Vector2(cols * (slot + Gap) - Gap, rows * (slot + Gap) - Gap + StatusH + GripOverlap());
FitWindow(body, w, haveH);
}
// ── Engine grid ─────────────────────────────────────────────────────
private void Resolve(ItemHudCharacter data, HudItem[] items)
{
if (ReferenceEquals(data, _resolvedFor) && _resolvedItemsVersion == _items.Version) return;
@ -112,20 +240,20 @@ internal sealed class MiniRemoteFace : IImGuiPanel
}
}
// ── Grid ────────────────────────────────────────────────────────────
private void DrawGrid(ItemHudCharacter data, HudItem[] items, float w, float h, bool ready)
{
Vector2 start = ImGuiNET.ImGui.GetCursorScreenPos();
var dl = ImGuiNET.ImGui.GetWindowDrawList();
int cols = Math.Max(1, (int)((w + Gap) / (Slot + Gap)));
float slot = data.SlotSize;
float iconSize = slot - 4f;
int cols = Math.Max(1, (int)((w + Gap) / (slot + Gap)));
bool dragging = ready && UiDropTargets.AnyDragInProgress;
int clicked = -1;
for (int i = 0; i < data.Slots.Length; i++)
{
var p = new Vector2(start.X + (i % cols) * (Slot + Gap), start.Y + (i / cols) * (Slot + Gap));
var max = p + new Vector2(Slot, Slot);
var p = new Vector2(start.X + (i % cols) * (slot + Gap), start.Y + (i / cols) * (slot + Gap));
var max = p + new Vector2(slot, slot);
RemoteSlot? s = data.Slots[i];
// One drop target a slot, so the item lands where it was let go.
@ -135,7 +263,7 @@ internal sealed class MiniRemoteFace : IImGuiPanel
ImGuiNET.ImGui.SetCursorScreenPos(p);
ImGuiNET.ImGui.PushID(i);
if (ImGuiNET.ImGui.InvisibleButton("##slot", new Vector2(Slot, Slot))) clicked = i;
if (ImGuiNET.ImGui.InvisibleButton("##slot", new Vector2(slot, slot))) clicked = i;
bool hot = ImGuiNET.ImGui.IsItemHovered();
if (ImGuiNET.ImGui.IsItemClicked(ImGuiMouseButton.Right)) { _menuSlot = i; _openMenu = true; }
ImGuiNET.ImGui.PopID();
@ -145,20 +273,20 @@ internal sealed class MiniRemoteFace : IImGuiPanel
dl.AddRect(p, max, dropHot || dragging ? Teal : BtnBord, 3);
uint id = s != null && i < _slotItem.Length ? _slotItem[i] : 0;
Vector2 ip = p + new Vector2((Slot - IconSize) * 0.5f, (Slot - IconSize) * 0.5f);
Vector2 ip = p + new Vector2((slot - iconSize) * 0.5f, (slot - iconSize) * 0.5f);
if (s == null)
{
PhosphorIcons.DrawCentered(dl, ImGuiFonts.Get(UiFont.Ui14), PhosphorIcons.Plus, p, new Vector2(Slot, Slot), Faded(Mute));
if (hot) ImGuiNET.ImGui.SetItemTooltip("Empty slot: click to put the selected inventory item here, or drag an item onto it.");
PhosphorIcons.DrawCentered(dl, ImGuiFonts.Get(UiFont.Ui14), PhosphorIcons.Plus, p, new Vector2(slot, slot), Faded(Mute));
if (hot) ImGuiNET.ImGui.SetItemTooltip("Empty slot: click to put the selected inventory item here, or drag an item onto it.\nCtrl+wheel: bigger / smaller boxes.");
continue;
}
if (id != 0 && ScriptIcons.TryGet(ScriptIconKind.Object, id, out IntPtr tex))
dl.AddImage(tex, ip, ip + new Vector2(IconSize, IconSize));
dl.AddImage(tex, ip, ip + new Vector2(iconSize, iconSize));
else
{
string initial = s.Name.Length > 0 ? s.Name[..1].ToUpperInvariant() : "?";
Vector2 ts = ImGuiNET.ImGui.CalcTextSize(initial);
dl.AddText(p + (new Vector2(Slot, Slot) - ts) * 0.5f, Faded(Text), initial);
dl.AddText(p + (new Vector2(slot, slot) - ts) * 0.5f, Faded(Text), initial);
}
string count = _slotCount[i];
if (count.Length > 0)
@ -174,13 +302,30 @@ internal sealed class MiniRemoteFace : IImGuiPanel
: $"{s.Name} ({count switch { "" => "1", _ => count }} carried)\nClick to use. Right-click for options.");
}
int rows = (data.Slots.Length + cols - 1) / cols;
float shownH = Math.Min(h, rows * (slot + Gap));
ImGuiNET.ImGui.SetCursorScreenPos(start);
ImGuiNET.ImGui.Dummy(new Vector2(w, Math.Min(h, rows * (Slot + Gap))));
ImGuiNET.ImGui.Dummy(new Vector2(w, shownH));
// Ctrl+wheel over the slots: bigger / smaller boxes (saved per character).
ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();
if (ready && io.KeyCtrl && io.MouseWheel != 0
&& ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.ChildWindows)
&& ImGuiNET.ImGui.IsMouseHoveringRect(start, start + new Vector2(w, shownH)))
ResizeSlots(io.MouseWheel > 0 ? SlotSizeStep : -SlotSizeStep);
if (clicked >= 0 && ready) Click(data, items, clicked);
else if (clicked >= 0) ShowMessage(ItemHudStore.Loaded ? "Waiting for your character..." : "Loading...", Amber);
}
/// <summary>Grows (+) or shrinks (-) the boxes by <paramref name="delta"/> pixels, within the saved range.</summary>
private void ResizeSlots(int delta)
{
if (!ItemHudStore.Update(d => d.WithSlotSize(d.SlotSize + delta), out string why))
ShowMessage(why, Amber);
else
ShowMessage($"Box size {ItemHudStore.Current.SlotSize} px.", Mute);
}
private void Click(ItemHudCharacter data, HudItem[] items, int i)
{
RemoteSlot? s = data.Slots[i];
@ -228,7 +373,7 @@ internal sealed class MiniRemoteFace : IImGuiPanel
else if (pending != null) { text = pending.WaitingForGame ? "Waiting for the game: " + pending.Label : pending.Label + "..."; color = Teal; }
else if (last != null && nowTicks - last.AtTicks < System.Diagnostics.Stopwatch.Frequency * 4) { text = last.Text; color = last.Ok ? Green : Amber; }
else if (!ready) { text = ItemHudStore.Loaded ? "Waiting for your character..." : "Loading..."; color = Mute; }
else { text = "Click: use. Right-click: options."; color = Faded(Mute); }
else { text = "Click: use. Right-click: options. Ctrl+wheel: box size."; color = Faded(Mute); }
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
var dl = ImGuiNET.ImGui.GetWindowDrawList();
float w = ImGuiNET.ImGui.GetContentRegionAvail().X - BodyGripRoom();
@ -273,6 +418,14 @@ internal sealed class MiniRemoteFace : IImGuiPanel
ItemHudStore.Update(d => d.WithSlotCount(d.Slots.Length + 4), out _);
if (ImGuiNET.ImGui.MenuItem("Fewer slots (drops the last 4)", "", false, n > ItemHudCharacter.MinSlots))
ItemHudStore.Update(d => d.WithSlotCount(d.Slots.Length - 4), out _);
ImGuiNET.ImGui.Separator();
int px = data.SlotSize;
if (ImGuiNET.ImGui.MenuItem($"Bigger boxes ({px} px now)", "Ctrl+wheel up", false, px < ItemHudCharacter.MaxSlotSize))
ResizeSlots(SlotSizeStep);
if (ImGuiNET.ImGui.MenuItem("Smaller boxes", "Ctrl+wheel down", false, px > ItemHudCharacter.MinSlotSize))
ResizeSlots(-SlotSizeStep);
if (ImGuiNET.ImGui.MenuItem("Default box size", "", false, px != ItemHudCharacter.DefaultSlotSize))
ResizeSlots(ItemHudCharacter.DefaultSlotSize - px);
ImGuiNET.ImGui.EndPopup();
}
}

View file

@ -549,16 +549,17 @@ internal sealed partial class RynthAiFace : IImGuiPanel
ImGuiNET.ImGui.OpenPopup("##charmenu");
}
x += bw + LauncherGap;
// Right-click is the Mini Remote drawer, as Patrol's is its drawer; popped out there are
// no drawers, so it shows the floating Mini Remote. Inventory HUDs setup is in the
// Mini Remote's Options menu.
// Left-click is the Mini Remote window (MiniRemoteFace, which hosts RynthAi's remote, the
// same window as the bar button). Right-click is the Mini Remote drawer, as Patrol's is
// its drawer; popped out there are no drawers, so it opens the window. Inventory HUDs
// setup is in the Mini Remote's Options menu.
Launcher("##l_hub", PhosphorIcons.SquaresFour, "Hub",
popped ? "Hub. Left-click: floating Mini Remote (/ra remote). Right-click: show the floating Mini Remote."
: "Hub. Left-click: floating Mini Remote (/ra remote). Right-click: the Mini Remote drawer (left), with its Options.",
x, y, bw, labels, () => RynthAiCommands.ApplyRemoteCommand("remote", "toggle"));
popped ? "Hub. Left-click: the Mini Remote window (/rc miniremote). Right-click: open the Mini Remote window."
: "Hub. Left-click: the Mini Remote window (/rc miniremote). Right-click: the Mini Remote drawer (left), with its Options.",
x, y, bw, labels, () => PanelRouter.Toggle(MiniRemoteFace.Title));
if (ImGuiNET.ImGui.IsItemClicked(ImGuiMouseButton.Right))
{
if (popped) RynthAiCommands.ApplyRemoteCommand("remote", "show");
if (popped) ImGuiPanelHost.Open(MiniRemoteFace.Title);
else _drawers.Toggle(_remote);
}

View file

@ -11,9 +11,11 @@
// count=Mana Scarab
// count=Prismatic Taper
// slots=8
// slotsize=44
// slot=0|0x80123456|Healing Kit
// slot=3|0x8012ABCD|Stamina Elixir
// Lines this version doesn't know are kept where they were.
// slotsize (the remote's box edge in pixels) is written only when it isn't
// the default. Lines this version doesn't know are kept where they were.
// ============================================================================
using System;
@ -34,15 +36,18 @@ internal sealed class ItemHudCharacter
{
public const int MaxCounts = 30;
public const int MinSlots = 4, MaxSlots = 24, DefaultSlots = 8;
/// <summary>Mini Remote box edge in pixels (before UI scaling): the grow / shrink range.</summary>
public const int MinSlotSize = 24, MaxSlotSize = 72, DefaultSlotSize = 36;
public const int MaxNameLength = 64;
public static readonly ItemHudCharacter Empty = new(Array.Empty<string>(), new RemoteSlot?[DefaultSlots], Array.Empty<string>());
public ItemHudCharacter(string[] counts, RemoteSlot?[] slots, string[] other)
public ItemHudCharacter(string[] counts, RemoteSlot?[] slots, string[] other, int slotSize = DefaultSlotSize)
{
Counts = counts;
Slots = slots;
Other = other;
SlotSize = Math.Clamp(slotSize, MinSlotSize, MaxSlotSize);
}
/// <summary>Item names on the Item Count list, in the order added.</summary>
@ -51,6 +56,8 @@ internal sealed class ItemHudCharacter
public RemoteSlot?[] Slots { get; }
/// <summary>Lines of this section the file had that this version doesn't know.</summary>
public string[] Other { get; }
/// <summary>The remote's box edge in pixels, <see cref="MinSlotSize"/>..<see cref="MaxSlotSize"/>.</summary>
public int SlotSize { get; }
public bool HasCount(string name) => IndexOfCount(name) >= 0;
@ -78,7 +85,7 @@ internal sealed class ItemHudCharacter
Array.Copy(Counts, next, Counts.Length);
next[^1] = name;
message = $"Counting \"{name}\".";
return new ItemHudCharacter(next, Slots, Other);
return new ItemHudCharacter(next, Slots, Other, SlotSize);
}
public ItemHudCharacter WithoutCount(int index)
@ -87,7 +94,7 @@ internal sealed class ItemHudCharacter
var next = new string[Counts.Length - 1];
Array.Copy(Counts, 0, next, 0, index);
Array.Copy(Counts, index + 1, next, index, Counts.Length - index - 1);
return new ItemHudCharacter(next, Slots, Other);
return new ItemHudCharacter(next, Slots, Other, SlotSize);
}
public ItemHudCharacter WithSlot(int index, RemoteSlot? slot)
@ -95,7 +102,7 @@ internal sealed class ItemHudCharacter
if (index < 0 || index >= Slots.Length) return this;
var next = (RemoteSlot?[])Slots.Clone();
next[index] = slot == null ? null : slot with { Name = Clean(slot.Name) };
return new ItemHudCharacter(Counts, next, Other);
return new ItemHudCharacter(Counts, next, Other, SlotSize);
}
/// <summary>More or fewer slots (clamped); slots past the new end are dropped.</summary>
@ -105,7 +112,14 @@ internal sealed class ItemHudCharacter
if (count == Slots.Length) return this;
var next = new RemoteSlot?[count];
Array.Copy(Slots, next, Math.Min(count, Slots.Length));
return new ItemHudCharacter(Counts, next, Other);
return new ItemHudCharacter(Counts, next, Other, SlotSize);
}
/// <summary>Bigger or smaller remote boxes (clamped). Same instance when nothing changes.</summary>
public ItemHudCharacter WithSlotSize(int size)
{
size = Math.Clamp(size, MinSlotSize, MaxSlotSize);
return size == SlotSize ? this : new ItemHudCharacter(Counts, Slots, Other, size);
}
}
@ -183,11 +197,12 @@ internal static class ItemHudFile
string? key = null;
List<string>? counts = null, other = null;
RemoteSlot?[]? slots = null;
int slotSize = ItemHudCharacter.DefaultSlotSize;
void Flush()
{
if (key == null) return;
result.Set(key, new ItemHudCharacter(counts!.ToArray(), slots!, other!.ToArray()));
result.Set(key, new ItemHudCharacter(counts!.ToArray(), slots!, other!.ToArray(), slotSize));
}
foreach (string raw in lines)
@ -201,6 +216,7 @@ internal static class ItemHudFile
counts = new List<string>();
other = new List<string>();
slots = new RemoteSlot?[ItemHudCharacter.DefaultSlots];
slotSize = ItemHudCharacter.DefaultSlotSize;
continue;
}
if (key == null)
@ -229,6 +245,11 @@ internal static class ItemHudFile
slots = resized;
}
break;
case "slotsize":
// Clamped by the constructor; an unreadable value keeps the default.
if (int.TryParse(val.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int px))
slotSize = px;
break;
case "slot":
{
// slot=<index>|<0xid>|<name>
@ -276,6 +297,8 @@ internal static class ItemHudFile
sb.Append('\n').Append('[').Append(key).Append("]\n");
foreach (string n in ch.Counts) sb.Append("count=").Append(n).Append('\n');
sb.Append("slots=").Append(ch.Slots.Length.ToString(CultureInfo.InvariantCulture)).Append('\n');
if (ch.SlotSize != ItemHudCharacter.DefaultSlotSize)
sb.Append("slotsize=").Append(ch.SlotSize.ToString(CultureInfo.InvariantCulture)).Append('\n');
for (int i = 0; i < ch.Slots.Length; i++)
{
RemoteSlot? s = ch.Slots[i];

View file

@ -19,6 +19,7 @@ internal static class Program
UnknownLinesKept();
BadFileValues();
EditsAreImmutable();
SlotSizes();
Console.WriteLine(_failed == 0 ? $"PASS ({_checks} assertions)" : $"FAIL ({_failed} of {_checks} assertions)");
return _failed == 0 ? 0 : 1;
@ -200,4 +201,34 @@ internal static class Program
Check(b.Counts.Length == 2 && b.Slots[0] == null && b.Slots.Length == 12, "the new ones have the edits");
Check(ItemHudCharacter.Empty.Counts.Length == 0 && ItemHudCharacter.Empty.Slots.All(s => s == null), "Empty stays empty");
}
/// <summary>The Mini Remote's box size: clamped, kept through edits, and saved only when not the default.</summary>
private static void SlotSizes()
{
Case("SlotSizes");
var c = ItemHudCharacter.Empty;
Check(c.SlotSize == ItemHudCharacter.DefaultSlotSize, "default size");
Check(ReferenceEquals(c.WithSlotSize(ItemHudCharacter.DefaultSlotSize), c), "the same size: no change");
Check(c.WithSlotSize(1).SlotSize == ItemHudCharacter.MinSlotSize, "clamped to the minimum");
Check(c.WithSlotSize(1000).SlotSize == ItemHudCharacter.MaxSlotSize, "clamped to the maximum");
var big = c.WithSlotSize(48);
var edited = big.WithCount("Mana Scarab", out _).WithSlot(0, new RemoteSlot(1, "Pyreal")).WithSlotCount(12);
Check(edited.SlotSize == 48, "other edits keep the size");
var file = new ItemHudFile.Contents();
file.Set("A/Big", big);
file.Set("A/Plain", c.WithCount("Healing Kit", out _));
string text = ItemHudFile.Write(file);
Check(text.Contains("slotsize=48\n"), "a non-default size is written");
Check(text.Split("slotsize=").Length == 2, "the default size isn't written");
var back = RoundTrip(file);
Check(back.For("A/Big").SlotSize == 48 && back.For("A/Plain").SlotSize == ItemHudCharacter.DefaultSlotSize,
"sizes read back per character");
string[] bad = { "[A/B]", "slotsize=banana", "[A/C]", "slotsize=5", "[A/D]", "slotsize=999" };
var parsed = ItemHudFile.Parse(bad);
Check(parsed.For("A/B").SlotSize == ItemHudCharacter.DefaultSlotSize, "an unreadable size keeps the default");
Check(parsed.For("A/C").SlotSize == ItemHudCharacter.MinSlotSize, "a small size clamps up");
Check(parsed.For("A/D").SlotSize == ItemHudCharacter.MaxSlotSize, "a large size clamps down");
}
}