Fix dragging slots over each other
This commit is contained in:
@@ -4,9 +4,13 @@ namespace AetherBags.Inventory;
|
|||||||
|
|
||||||
public readonly record struct InventoryLocation(InventoryType Container, ushort Slot)
|
public readonly record struct InventoryLocation(InventoryType Container, ushort Slot)
|
||||||
{
|
{
|
||||||
public static readonly InventoryLocation Invalid = new(0, 0);
|
public static readonly InventoryLocation Invalid = new((InventoryType)uint.MaxValue, ushort.MaxValue);
|
||||||
|
|
||||||
public bool IsValid => Container != 0;
|
public bool IsValid => Container.IsMainInventory ||
|
||||||
|
Container.IsSaddleBag ||
|
||||||
|
Container.IsArmory ||
|
||||||
|
Container.IsRetainer ||
|
||||||
|
Container == InventoryType.EquippedItems;
|
||||||
|
|
||||||
public override string ToString() => $"{Container}@{Slot}";
|
public override string ToString() => $"{Container}@{Slot}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,10 +260,14 @@ public class InventoryCategoryNode : SimpleComponentNode
|
|||||||
AgentInventoryContext.Instance()->DiscardItem(item.Item.GetLinkedItem(), item.Item.Container, item.Item.Slot, addonId);
|
AgentInventoryContext.Instance()->DiscardItem(item.Item.GetLinkedItem(), item.Item.Container, item.Item.Slot, addonId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPayloadAccepted(DragDropNode _, DragDropPayload payload, ItemInfo targetItemInfo)
|
private void OnPayloadAccepted(DragDropNode node, DragDropPayload payload, ItemInfo targetItemInfo)
|
||||||
{
|
{
|
||||||
|
InventoryItem item = targetItemInfo.Item;
|
||||||
if (!payload.IsValidInventoryPayload)
|
if (!payload.IsValidInventoryPayload)
|
||||||
|
{
|
||||||
|
Services.Logger.Warning($"[OnPayload] Invalid payload type: {payload.Type}");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
InventoryLocation sourceLocation = payload.InventoryLocation;
|
InventoryLocation sourceLocation = payload.InventoryLocation;
|
||||||
|
|
||||||
@@ -274,15 +278,25 @@ public class InventoryCategoryNode : SimpleComponentNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
InventoryLocation targetLocation = new InventoryLocation(
|
InventoryLocation targetLocation = new InventoryLocation(
|
||||||
targetItemInfo.Item.Container,
|
item.Container,
|
||||||
(ushort)targetItemInfo.Item.Slot
|
(ushort)item.Slot
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (sourceLocation.Container.IsSameContainerGroup(targetLocation.Container))
|
||||||
|
{
|
||||||
|
Services.Logger.Debug($"[OnPayload] Source and target are in the same container group; no move performed");
|
||||||
|
node.Payload = payload;
|
||||||
|
node.IconId = item.IconId;
|
||||||
|
System.AddonInventoryWindow.ManualInventoryRefresh();
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
Services.Logger.Debug($"[OnPayload] Moving {sourceLocation} -> {targetLocation}");
|
Services.Logger.Debug($"[OnPayload] Moving {sourceLocation} -> {targetLocation}");
|
||||||
|
|
||||||
InventoryMoveHelper.MoveItem(
|
InventoryMoveHelper.MoveItem(
|
||||||
sourceLocation.Container, sourceLocation.Slot,
|
sourceLocation.Container, sourceLocation.Slot,
|
||||||
targetLocation.Container, targetLocation.Slot
|
targetLocation.Container, targetLocation.Slot
|
||||||
);
|
);
|
||||||
|
System.AddonInventoryWindow.ManualInventoryRefresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user