From aa0f65d2a2bed67e9784fcf78c5b3579c011c866 Mon Sep 17 00:00:00 2001 From: BlankenshipG Date: Sun, 4 Oct 2026 20:38:26 -0400 Subject: [PATCH] feat(engine): Shields section and Add Selected Shield in the Avalonia Items panel Co-authored-by: Cursor --- Changelog/2026-10-04-items-panel-shields.md | 39 +++++ src/RynthCore.Engine/UI/Panels/ItemsPanel.cs | 175 +++++++++++++++++-- 2 files changed, 198 insertions(+), 16 deletions(-) create mode 100644 Changelog/2026-10-04-items-panel-shields.md diff --git a/Changelog/2026-10-04-items-panel-shields.md b/Changelog/2026-10-04-items-panel-shields.md new file mode 100644 index 0000000..fcddecb --- /dev/null +++ b/Changelog/2026-10-04-items-panel-shields.md @@ -0,0 +1,39 @@ +# Items panel: Shields section and "Add Selected Shield" (2026-10-04) + +Engine Avalonia `ItemsPanel` plus RynthAi 0.6.20. Ships in the next installer after 2026.10.4.16. + +## Problem + +RynthAi stores off-hand shields in its item list (`ItemRule.Action = "Shield"`), and its +ImGui Items tab has a Shields section. The engine's Avalonia Items window (the one +opened from the dashboard) never got that section: + +- "Add Selected Weapon" rejects shields with "That is a shield — use Add Selected Shield", + but that button didn't exist in the engine panel, so shields couldn't be added there. +- Shields already in the list showed up under Weapons with an element picker. + +## Engine (`UI/Panels/ItemsPanel.cs`) + +- New **Shields (off-hand)** section between Weapons and Consumables: + - an "Auto-equip with one-handed melee weapons" ON/OFF toggle with a tooltip (shown when the + plugin reports the setting); + - a shield list with a Del button on each row; + - **Add Selected Shield**, which calls the plugin's new `RynthPluginAddSelectedShield` export. + With an older plugin the click does nothing and logs that RynthAi 0.6.20+ is required. +- The Weapons section now lists only non-shield entries. +- `WeaponEntry` carries `action` and the payload carries `autoEquipShield`; both are part of + change detection, so plugin-side edits appear within the 1 s poll. +- Deletes now remove the row's own entry instead of a list index, because the weapon and + shield rows are filtered views of one list. + +## RynthAi 0.6.20 + +- New export `RynthPluginAddSelectedShield`, which goes through `LegacyDashboardRenderer.AddSelectedShield` + to the existing `LegacyWeaponsUi.AddSelectedShield` and then saves settings. +- `ItemsBridgePayload.AutoEquipShield` (`bool?`) is sent to the panel. It's applied on write-back + only when present, so older engine panels leave the setting alone. +- `ApplyItemsJson`: + - new entries keep the `Shield` action the panel sends (anything else becomes `Weapon`); + - deleting a shield from the engine panel clears any monster off-hand that pointed at it and + saves the monsters file (the same cleanup as the ImGui Del button). +- Version bumped to 0.6.20 (`csproj`, `RynthAiPlugin.VersionPointer`). diff --git a/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs b/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs index 14d6fc6..298c522 100644 --- a/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs +++ b/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs @@ -2,8 +2,9 @@ // RynthCore.Engine — UI/Panels/ItemsPanel.cs // Avalonia replica of the ImGui Items tab (LegacyWeaponsUi.cs). // -// Three sections: -// Weapons — Name, Element picker, Delete +// Four sections: +// Weapons — Name, Element picker, Delete (ItemRules with Action != "Shield") +// Shields — Auto-equip toggle, Name, Delete (ItemRules with Action == "Shield") // Consumables — Name, Type picker, Delete // Mana Stones — Enable tapping toggle, keep count, min mana threshold // @@ -11,6 +12,8 @@ // RynthPluginGetItemsJson → polled every 1s for external edits // RynthPluginSetItemsJson → write-back on edit // RynthPluginAddSelectedWeapon → add currently selected inventory item as weapon +// RynthPluginAddSelectedShield → add currently selected inventory item as off-hand shield +// (RynthAi 0.6.20+; button explains when missing) // RynthPluginAddSelectedConsumable → add currently selected inventory item as consumable // ============================================================================ @@ -48,8 +51,12 @@ internal static class ItemsPanel private static GetItemsJsonFn? _getItemsJson; private static SetItemsJsonFn? _setItemsJson; private static VoidFn? _addSelectedWeapon; + private static VoidFn? _addSelectedShield; private static VoidFn? _addSelectedConsumable; + /// ItemRule.Action value the plugin uses for off-hand shields. + private const string ShieldAction = "Shield"; + private static readonly IBrush ColAmber = new SolidColorBrush(Color.FromRgb(0xE8, 0xB3, 0x33)); private static readonly IBrush ColRed = new SolidColorBrush(Color.FromRgb(0xFF, 0x55, 0x55)); private static readonly IBrush ColTeal = new SolidColorBrush(Color.FromRgb(0x26, 0xD9, 0xE6)); @@ -76,6 +83,8 @@ internal static class ItemsPanel [JsonPropertyName("manaTapMinMana")] public int ManaTapMinMana { get; set; } = 2500; [JsonPropertyName("manaStoneKeepCount")]public int ManaStoneKeepCount{ get; set; } = 5; [JsonPropertyName("currentTargetName")] public string CurrentTargetName { get; set; } = string.Empty; + // Null when the plugin predates shields (RynthAi < 0.6.20); the plugin then ignores it on write-back. + [JsonPropertyName("autoEquipShield")] public bool? AutoEquipShield { get; set; } } internal sealed class WeaponEntry @@ -83,6 +92,10 @@ internal static class ItemsPanel [JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("name")] public string Name { get; set; } = string.Empty; [JsonPropertyName("element")] public string Element { get; set; } = "Slash"; + // "Weapon" or "Shield" (older settings may hold "Loot"). Round-tripped untouched. + [JsonPropertyName("action")] public string Action { get; set; } = "Weapon"; + + public bool IsShield => string.Equals(Action, ShieldAction, StringComparison.OrdinalIgnoreCase); } internal sealed class ConsumableEntry @@ -222,29 +235,33 @@ internal static class ItemsPanel { body.Children.Clear(); + // Weapons and shields share the plugin's ItemRules list (state.Data.Weapons); + // rows are split by Action, so deletes remove by reference, not by index. + void DeleteItem(WeaponEntry entry) + { + state.Data.Weapons.Remove(entry); + state.Dirty = true; + PushChanges(state); + Refresh(); + } + // ── Weapons ────────────────────────────────────────────────────── body.Children.Add(BuildSectionHeader("Weapons")); - if (state.Data.Weapons.Count == 0) + var weapons = state.Data.Weapons.Where(w => !w.IsShield).ToList(); + if (weapons.Count == 0) { body.Children.Add(BuildEmptyRow("No weapons configured")); } else { body.Children.Add(BuildTableHeader(new[] { "Item Name", "Element", "" }, new[] { true, false, false }, new double[] { 0, 100, 46 })); - for (int i = 0; i < state.Data.Weapons.Count; i++) + for (int i = 0; i < weapons.Count; i++) { - var w = state.Data.Weapons[i]; - int wi = i; - body.Children.Add(BuildWeaponRow(w, wi % 2 == 0, ShowPicker, + var w = weapons[i]; + body.Children.Add(BuildWeaponRow(w, i % 2 == 0, ShowPicker, onChanged: () => { state.Dirty = true; PushChanges(state); }, - onDelete: () => - { - state.Data.Weapons.RemoveAt(wi); - state.Dirty = true; - PushChanges(state); - Refresh(); - })); + onDelete: () => DeleteItem(w))); } } @@ -257,6 +274,50 @@ internal static class ItemsPanel body.Children.Add(BuildDivider()); + // ── Shields (off-hand) ─────────────────────────────────────────── + body.Children.Add(BuildSectionHeader("Shields (off-hand)")); + + // Plugins older than RynthAi 0.6.20 don't report the setting — hide the toggle then. + if (state.Data.AutoEquipShield is bool autoEquip) + { + body.Children.Add(BuildToggleRow("Auto-equip with one-handed melee weapons", autoEquip, + "On: in melee with a one-handed weapon, combat wields the first shield below unless the monster has its own off-hand (Damage panel or Monsters 'Offhand').\n" + + "Off: only per-monster off-hand choices are equipped.\n" + + "Never used with two-handed weapons, bows, crossbows, atlatls or casters.", + on => + { + state.Data.AutoEquipShield = on; + state.Dirty = true; + PushChanges(state); + Refresh(); + })); + } + + var shields = state.Data.Weapons.Where(w => w.IsShield).ToList(); + if (shields.Count == 0) + { + body.Children.Add(BuildEmptyRow("No shields configured")); + } + else + { + body.Children.Add(BuildTableHeader(new[] { "Shield Name", "" }, new[] { true, false }, new double[] { 0, 46 })); + for (int i = 0; i < shields.Count; i++) + { + var s = shields[i]; + body.Children.Add(BuildShieldRow(s, i % 2 == 0, onDelete: () => DeleteItem(s))); + } + } + + body.Children.Add(BuildAddButton("Add Selected Shield", "(select a shield in inventory first)", + () => + { + if (_addSelectedShield == null) TryBind(); + if (_addSelectedShield != null) _addSelectedShield(); + else RynthLog.UI("ItemsPanel: Add Selected Shield unavailable — RynthAi 0.6.20 or newer is required."); + })); + + body.Children.Add(BuildDivider()); + // ── Consumables ────────────────────────────────────────────────── body.Children.Add(BuildSectionHeader("Consumable Items")); @@ -315,7 +376,8 @@ internal static class ItemsPanel bool consumablesChanged = ConsumablesChanged(state.Data.Consumables, fresh.Consumables); bool manaChanged = state.Data.EnableManaTapping != fresh.EnableManaTapping || state.Data.ManaTapMinMana != fresh.ManaTapMinMana - || state.Data.ManaStoneKeepCount != fresh.ManaStoneKeepCount; + || state.Data.ManaStoneKeepCount != fresh.ManaStoneKeepCount + || state.Data.AutoEquipShield != fresh.AutoEquipShield; // UI deep-dive finding P0-4 (2026-07-02): state.Data = fresh used // to run unconditionally, EVERY poll tick, even when the @@ -525,6 +587,80 @@ internal static class ItemsPanel return grid; } + // ── Shield table row (name + delete; shields have no element) ───────────── + private static Control BuildShieldRow(WeaponEntry s, bool alt, Action onDelete) + { + var grid = new Grid + { + Background = alt ? ColRowAlt : ColPanelBg, + Height = 24, + ColumnDefinitions = new ColumnDefinitions("*, 46"), + }; + + var nameTb = new TextBlock + { + Text = s.Name, + Foreground = ColTextDim, + FontSize = 10, + VerticalAlignment = VerticalAlignment.Center, + Margin = new Thickness(6, 0), + TextTrimming = TextTrimming.CharacterEllipsis, + }; + Grid.SetColumn(nameTb, 0); + grid.Children.Add(nameTb); + + var del = new Button + { + Content = "Del", + Background = ColBtnFill, + Foreground = ColRed, + BorderBrush = ColBtnBord, + BorderThickness = new Thickness(1), + Padding = new Thickness(4, 2), + FontSize = 10, + Margin = new Thickness(2, 2), + }; + del.Click += (_, _) => onDelete(); + Grid.SetColumn(del, 1); + grid.Children.Add(del); + + return grid; + } + + // ── Labelled ON/OFF toggle row (same look as the mana-tapping toggle) ───── + private static Control BuildToggleRow(string label, bool value, string tooltip, Action onToggled) + { + var row = new WrapPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(4, 4, 4, 2) }; + + var btn = new Button + { + Content = value ? "ON" : "OFF", + Background = value ? new SolidColorBrush(Color.FromRgb(0x10, 0x40, 0x10)) : ColBtnFill, + Foreground = value ? new SolidColorBrush(Color.FromRgb(0x33, 0xFF, 0x33)) : ColMute, + BorderBrush = ColBtnBord, + BorderThickness = new Thickness(1), + Padding = new Thickness(8, 2), + FontSize = 10, + Width = 50, + Margin = new Thickness(0, 0, 8, 0), + }; + btn.Click += (_, _) => onToggled(!value); + ToolTip.SetTip(btn, tooltip); + row.Children.Add(btn); + + var lbl = new TextBlock + { + Text = label, + Foreground = ColTextDim, + FontSize = 10, + VerticalAlignment = VerticalAlignment.Center, + }; + ToolTip.SetTip(lbl, tooltip); + row.Children.Add(lbl); + + return row; + } + // ── Consumable table row ────────────────────────────────────────────────── private static Control BuildConsumableRow( ConsumableEntry c, bool alt, @@ -736,6 +872,7 @@ internal static class ItemsPanel _getItemsJson = null; _setItemsJson = null; _addSelectedWeapon = null; + _addSelectedShield = null; _addSelectedConsumable = null; }; @@ -760,6 +897,11 @@ internal static class ItemsPanel IntPtr p = GetProcAddress(plugin.ModuleHandle, "RynthPluginAddSelectedWeapon"); if (p != IntPtr.Zero) _addSelectedWeapon = Marshal.GetDelegateForFunctionPointer(p); } + if (_addSelectedShield == null) + { + IntPtr p = GetProcAddress(plugin.ModuleHandle, "RynthPluginAddSelectedShield"); + if (p != IntPtr.Zero) _addSelectedShield = Marshal.GetDelegateForFunctionPointer(p); + } if (_addSelectedConsumable == null) { IntPtr p = GetProcAddress(plugin.ModuleHandle, "RynthPluginAddSelectedConsumable"); @@ -810,7 +952,8 @@ internal static class ItemsPanel { if (a.Count != b.Count) return true; for (int i = 0; i < a.Count; i++) - if (a[i].Id != b[i].Id || a[i].Name != b[i].Name || a[i].Element != b[i].Element) return true; + if (a[i].Id != b[i].Id || a[i].Name != b[i].Name || a[i].Element != b[i].Element + || !string.Equals(a[i].Action, b[i].Action, StringComparison.OrdinalIgnoreCase)) return true; return false; }