feat(engine): drag items from the game or a popped-out Inventory onto Mini Remote slots

- ItemDragBridge republishes popped-out Inventory drags and AC inventory drags in the main ImGui context (RYNTH_INV_ITEM / RYNTH_GAME_ITEM payloads)
- Win32Backend hands a game drag released over ImGui back to AC at its start so items never drop to the ground
- Inventory clicks select the item in the game; right-click 'Add to Mini Remote' (remoteslot command)
- Char menu: Guardian window entry
- Changelog 2026-10-05-guardian-and-remote-slots.md

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
BlankenshipG 2026-10-05 12:19:35 -04:00
commit 0bff493184
7 changed files with 363 additions and 4 deletions

View file

@ -691,6 +691,9 @@ internal static class EngineFrameController
ImGuiNET.ImGui.NewFrame();
frameStarted = true;
// Before any window: a drag from a popped-out Inventory or AC's inventory becomes
// a payload the client's drop targets (Mini Remote slots) see this frame.
ItemDragBridge.SubmitMainFrame(io);
ImGuiTextFocus.BeginFrame();
if (_dropImGuiTextFocus)
{

View file

@ -0,0 +1,216 @@
// ============================================================================
// RynthCore.Engine - ImGui/ItemDragBridge.cs
// Carries an item drag into the MAIN ImGui context when it didn't start there,
// so drop targets in the client (RynthAi's Mini Remote slots) can take it:
//
// • A popped-out Inventory: the pop-out has its own ImGui context and holds
// mouse capture for the whole drag, so the main context never sees it.
// The pop-out face reports the dragged item (NotePopOutDrag); the main
// frame republishes it as an extern payload. The main context sees no
// button press, so the payload uses PayloadAutoExpire: it is delivered to
// the hovered target on the first frame it is no longer submitted.
// • AC's own inventory: a press that began on the game belongs to the game,
// and ImGui ignores hovering for it. A left drag that starts with a carried
// item selected (AC selects the item under the press) is republished the
// same way, under NativePayloadType, and delivered when ImGui sees the
// button go up.
//
// A native drag released over an ImGui window would otherwise complete in AC
// as a drop on the 3D view (the item lands on the ground). TryRedirectNativeDrop
// moves that button-up back to where the drag began, which AC treats as
// putting the item back.
//
// Threads: AC's main thread only (game WndProc, EndScene, pop-out frames).
// ============================================================================
using System;
using System.Diagnostics;
using ImGuiNET;
using RynthCore.Engine.Compatibility;
namespace RynthCore.Engine.ImGuiBackend;
internal static unsafe class ItemDragBridge
{
/// <summary>Payload type for one item (uint object id). Must match RynthAi's MiniRemoteHud.ItemPayloadType.</summary>
public const string PayloadType = "RYNTH_INV_ITEM";
/// <summary>
/// Payload type for a drag that began in AC's own UI (uint object id). Any game left-drag with
/// a carried item selected looks like this (moving an AC panel too), so targets should take it
/// only where a wrong item does no harm (RynthAi: empty slots). Must match MiniRemoteHud.GameItemPayloadType.
/// </summary>
public const string NativePayloadType = "RYNTH_GAME_ITEM";
private const uint WM_MOUSEMOVE = 0x0200, WM_LBUTTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202;
private const int MK_LBUTTON = 0x0001, MK_OTHER = 0x0002 | 0x0010 | 0x0020 | 0x0040;
/// <summary>Movement (px, squared) before a game press counts as a drag.</summary>
private const int DragThresholdSq = 5 * 5;
/// <summary>AC may select the pressed item a few messages after the press: keep re-reading it this long.</summary>
private static readonly long SelectionSettleTicks = Stopwatch.Frequency / 2;
/// <summary>A pop-out drag with no report for this long is over (the pop-out closed mid-drag).</summary>
private static readonly long PopOutStaleTicks = Stopwatch.Frequency;
// Popped-out Inventory drag.
private static uint _popOutItem;
private static long _popOutSeenAt;
// Native (AC inventory) drag.
private static bool _pressPending;
private static IntPtr _pressLParam;
private static int _pressX, _pressY;
private static long _pressAt;
private static uint _nativeItem;
private static bool _nativeReleased;
/// <summary>The cursor was over an ImGui window in the last main frame (only tracked during a native drag).</summary>
private static bool _overImGui;
// ── Popped-out Inventory ────────────────────────────────────────────────
/// <summary>A popped-out Inventory is dragging <paramref name="itemId"/> (call every pop-out frame of the drag).</summary>
public static void NotePopOutDrag(uint itemId)
{
if (itemId == 0) return;
if (_popOutItem != itemId)
RynthLog.UI($"ItemDragBridge: pop-out drag 0x{itemId:X8} published to the client.");
_popOutItem = itemId;
_popOutSeenAt = Stopwatch.GetTimestamp();
}
/// <summary>The popped-out Inventory's drag ended (dropped or cancelled).</summary>
public static void EndPopOutDrag() => _popOutItem = 0;
// ── Native drag (game WndProc) ──────────────────────────────────────────
/// <summary>
/// Every game-window mouse message, after the backend decided who owns the held buttons.
/// <paramref name="gameOwned"/>: the current press began on the game, not on ImGui.
/// </summary>
public static void OnGameMouse(uint msg, IntPtr wParam, IntPtr lParam, bool gameOwned)
{
int keys = (int)((long)wParam & 0xFFFF);
switch (msg)
{
case WM_LBUTTONDOWN:
// Only a plain left press that belongs to the game can be an inventory drag.
_pressPending = gameOwned && (keys & MK_OTHER) == 0;
_pressLParam = lParam;
_pressX = LoWord(lParam);
_pressY = HiWord(lParam);
_pressAt = Stopwatch.GetTimestamp();
if (_pressPending) { _nativeItem = 0; _nativeReleased = false; }
break;
case WM_MOUSEMOVE:
if ((keys & MK_LBUTTON) == 0)
{
// A release we never saw (outside the window): finish the drag.
_pressPending = false;
if (_nativeItem != 0) _nativeReleased = true;
break;
}
if (_pressPending)
{
int dx = LoWord(lParam) - _pressX, dy = HiWord(lParam) - _pressY;
if (dx * dx + dy * dy >= DragThresholdSq)
{
_pressPending = false;
_nativeItem = CarriedSelection();
if (_nativeItem != 0)
RynthLog.UI($"ItemDragBridge: native inventory drag 0x{_nativeItem:X8} published to ImGui.");
}
}
else if (_nativeItem != 0 && !_nativeReleased && Stopwatch.GetTimestamp() - _pressAt < SelectionSettleTicks)
{
// The selection can trail the press by a few messages: follow it while it settles.
uint sel = CarriedSelection();
if (sel != 0) _nativeItem = sel;
}
break;
case WM_LBUTTONUP:
_pressPending = false;
if (_nativeItem != 0) _nativeReleased = true;
break;
}
}
/// <summary>
/// A native item drag is being released over an ImGui window: returns the press position
/// to send AC instead, so AC puts the item back rather than dropping it on the ground.
/// </summary>
public static bool TryRedirectNativeDrop(uint msg, out IntPtr pressLParam)
{
pressLParam = _pressLParam;
if (msg != WM_LBUTTONUP || _nativeItem == 0 || !_overImGui) return false;
RynthLog.UI($"ItemDragBridge: native drag 0x{_nativeItem:X8} released over an ImGui window; AC gets the drop back at its start ({_pressX},{_pressY}).");
return true;
}
// ── Main frame (after ImGui.NewFrame, before any window) ────────────────
/// <summary>Republishes a pop-out or native drag in the main context for this frame.</summary>
public static void SubmitMainFrame(ImGuiIOPtr io)
{
uint id = 0;
string type = PayloadType;
if (_popOutItem != 0)
{
if (Stopwatch.GetTimestamp() - _popOutSeenAt > PopOutStaleTicks) _popOutItem = 0;
else id = _popOutItem;
}
if (id == 0 && _nativeItem != 0)
{
type = NativePayloadType;
// After the button-up, stop once ImGui itself sees the button up: that frame
// delivers the drop (the payload outlives its last submission by one frame).
if (_nativeReleased && !io.MouseDown[0])
{
_nativeItem = 0;
_nativeReleased = false;
_overImGui = false;
return;
}
id = _nativeItem;
_overImGui = ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AnyWindow | ImGuiHoveredFlags.AllowWhenBlockedByActiveItem);
}
if (id == 0) return;
const ImGuiDragDropFlags flags = ImGuiDragDropFlags.SourceExtern | ImGuiDragDropFlags.SourceNoPreviewTooltip
| ImGuiDragDropFlags.PayloadAutoExpire;
if (ImGuiNET.ImGui.BeginDragDropSource(flags))
{
ImGuiNET.ImGui.SetDragDropPayload(type, (IntPtr)(&id), sizeof(uint));
ImGuiNET.ImGui.EndDragDropSource();
}
}
/// <summary>Forget every drag (focus lost, logout, engine shutdown).</summary>
public static void Reset()
{
_popOutItem = 0;
_pressPending = false;
_nativeItem = 0;
_nativeReleased = false;
_overImGui = false;
}
/// <summary>The game's selected object when the player carries it (pack, side pack or worn), else 0.</summary>
private static uint CarriedSelection()
{
uint id = ClientHelperHooks.GetSelectedItemId();
if (id == 0 || !ClientHelperHooks.HasGetPlayerId) return 0;
uint player = ClientHelperHooks.GetPlayerId();
if (player == 0 || id == player) return 0;
if (!ClientObjectHooks.TryGetObjectOwnershipInfo(id, out uint container, out uint wielder, out _)) return 0;
if (wielder == player || container == player) return id;
// Side pack in the main pack.
if (container != 0 && ClientObjectHooks.TryGetObjectOwnershipInfo(container, out uint outer, out _, out _) && outer == player)
return id;
return 0;
}
private static int LoWord(IntPtr l) => unchecked((short)((long)l & 0xFFFF));
private static int HiWord(IntPtr l) => unchecked((short)(((long)l >> 16) & 0xFFFF));
}

View file

@ -620,7 +620,7 @@ internal sealed partial class InventoryFace
_hover = it;
if (ImGuiNET.ImGui.IsMouseClicked(ImGuiMouseButton.Left))
{
_selected = it.Id;
SelectItem(it);
_pressItem = it;
_pressAt = ImGuiNET.ImGui.GetMousePos();
}

View file

@ -122,6 +122,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
InventoryModel.Hover(0);
InventoryModel.Unsubscribe();
_dragItem = _pressItem = null;
ItemDragBridge.EndPopOutDrag();
_lootAdd.Cancel();
}
@ -475,7 +476,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
if (hot != null && ImGuiNET.ImGui.IsMouseClicked(ImGuiMouseButton.Left))
{
_selected = hot.Id;
SelectItem(hot);
_pressItem = hot;
_pressAt = mouse;
}
@ -749,6 +750,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
_dragItem = null;
_pressItem = null;
if (item == null) return;
ItemDragBridge.EndPopOutDrag();
Vector2 m = ImGuiNET.ImGui.GetMousePos();
foreach (Target t in _targets)
{
@ -759,13 +761,50 @@ internal sealed partial class InventoryFace : IImGuiPanel
}
}
private void DrawDragGhost()
/// <summary>
/// ImGui drag-and-drop payload type for one item (uint object id), published while an item is
/// dragged so other ImGui windows (RynthAi's Mini Remote slots) can accept the drop. Must
/// match MiniRemoteHud.ItemPayloadType in RynthAi.
/// </summary>
public const string ItemPayloadType = "RYNTH_INV_ITEM";
/// <summary>
/// Selects <paramref name="it"/> here and in the game, like a click in the retail inventory, so
/// "selected item" features (Mini Remote slots, item info, loot rules) see it too.
/// </summary>
private void SelectItem(InventoryItem it)
{
_selected = it.Id;
// Queued, not called inline: Draw runs inside EndScene, and AC's SetSelectedObject rebuilds
// UI elements, so it runs at the main-thread queue's drain point instead.
if (ClientHelperHooks.GetSelectedItemId() != it.Id)
AcMainThreadQueue.EnqueueSetSelectedObject(it.Id);
}
private unsafe void DrawDragGhost()
{
if (_dragItem == null) return;
var fg = ImGuiNET.ImGui.GetForegroundDrawList();
Vector2 m = ImGuiNET.ImGui.GetMousePos() - new Vector2(Icon * 0.5f, Icon * 0.5f);
DrawItemIcon(fg, _dragItem.Id, m, Icon, 0xD0FFFFFF);
ImGuiNET.ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
// A popped-out Inventory draws in its own ImGui context: the client's drop targets
// only see the drag through the bridge, which republishes it in the main context.
if (ImGuiPopOuts.InPopOutFrame)
{
ItemDragBridge.NotePopOutDrag(_dragItem.Id);
return;
}
// Re-submitted every frame of the drag (an extern source expires when it isn't); the
// ghost above is the preview, so no ImGui tooltip.
if (ImGuiNET.ImGui.BeginDragDropSource(ImGuiDragDropFlags.SourceExtern | ImGuiDragDropFlags.SourceNoPreviewTooltip))
{
uint id = _dragItem.Id;
ImGuiNET.ImGui.SetDragDropPayload(ItemPayloadType, (IntPtr)(&id), sizeof(uint));
ImGuiNET.ImGui.EndDragDropSource();
}
}
// ── Tooltip ─────────────────────────────────────────────────────────
@ -896,6 +935,7 @@ internal sealed partial class InventoryFace : IImGuiPanel
UI.Data.RynthAiCommands.ApplyRemoteCommand("itemhudadd", it.Name);
if (ImGuiNET.ImGui.IsItemHovered())
ImGuiNET.ImGui.SetTooltip("Track how many of these you carry on RynthAi's floating item count HUD (/ra itemhud add)");
if (!it.IsPack) MiniRemoteMenu(it);
if (!idle)
ImGuiNET.ImGui.TextDisabled("(an item action is waiting)");
}
@ -906,6 +946,36 @@ internal sealed partial class InventoryFace : IImGuiPanel
}
}
/// <summary>RynthAi Mini Remote quick-use grid size (HudState.MiniRemoteSlotCount, 6 rows of 5).</summary>
private const int MiniRemoteSlots = 30, MiniRemoteColumns = 5;
/// <summary>
/// "Add to Mini Remote" submenu: first empty slot, or a numbered grid laid out like the
/// remote's own slots. RynthAi validates the item and reports the result in chat.
/// </summary>
private static void MiniRemoteMenu(InventoryItem it)
{
if (!ImGuiNET.ImGui.BeginMenu("Add to Mini Remote")) return;
if (ImGuiNET.ImGui.MenuItem("First empty slot"))
UI.Data.RynthAiCommands.ApplyRemoteCommand("remoteslot", "first " + it.Id.ToString(CultureInfo.InvariantCulture));
ImGuiNET.ImGui.Separator();
ImGuiNET.ImGui.TextDisabled("Or pick a slot (replaces what's there):");
for (int i = 0; i < MiniRemoteSlots; i++)
{
if (i % MiniRemoteColumns != 0) ImGuiNET.ImGui.SameLine();
string label = (i + 1).ToString("00", CultureInfo.InvariantCulture);
if (ImGuiNET.ImGui.Button(label, new Vector2(28, 0)))
{
UI.Data.RynthAiCommands.ApplyRemoteCommand("remoteslot",
(i + 1).ToString(CultureInfo.InvariantCulture) + " " + it.Id.ToString(CultureInfo.InvariantCulture));
ImGuiNET.ImGui.CloseCurrentPopup();
}
}
ImGuiNET.ImGui.Separator();
ImGuiNET.ImGui.TextDisabled("Tip: you can also drag the item onto a slot.");
ImGuiNET.ImGui.EndMenu();
}
// ── Split dialog ────────────────────────────────────────────────────
private void SplitDialog(InventoryView view)

View file

@ -708,7 +708,7 @@ internal sealed partial class RynthAiFace : IImGuiPanel
private static readonly (string Label, string Section)[] HubSections =
{
("Character", "character"), ("Quests", "quests"), ("Pets", "pets"),
("Banking", "banking"), ("Gear", "gear"), ("Games", "games"),
("Banking", "banking"), ("Gear", "gear"), ("Games", "games"), ("Guardian", "guardian"),
};
private static void CharMenu()

View file

@ -971,11 +971,15 @@ internal static unsafe class Win32Backend
// HUD drag (keeps our SetCapture from fighting NewFrame's). No-op
// unless the HUD is drawn.
if (IsMouseMessage(msg))
{
TrackMouseButtons(msg, wParam);
ItemDragBridge.OnGameMouse(msg, wParam, lParam, _heldButtonsBelongToGame);
}
else if (msg == WM_KILLFOCUS)
{
_heldMouseButtons = 0;
_heldButtonsBelongToGame = false;
ItemDragBridge.Reset();
}
// ── Avalonia panel hit-test & input forwarding ────────────────
@ -1075,6 +1079,14 @@ internal static unsafe class Win32Backend
}
}
// An AC inventory item dragged onto an ImGui window: AC must not drop it on the
// ground behind the window. It gets the release where the drag began instead.
if (ItemDragBridge.TryRedirectNativeDrop(msg, out IntPtr pressLParam))
{
CallWindowProcA(_originalWndProc, hWnd, WM_MOUSEMOVE, (IntPtr)MK_LBUTTON, pressLParam);
return CallWindowProcA(_originalWndProc, hWnd, msg, wParam, pressLParam);
}
// Pass through to original WndProc
return CallWindowProcA(_originalWndProc, hWnd, msg, wParam, lParam);
}