InventoryDragDropHandler

Class

Namespace: GGG.Inventory.UI

Handles drag/drop behavior local to an Inventory.

Responsibilities:

  • tracks Inventory slot drag state
  • tracks externally supplied ItemInstance drag state
  • moves Inventory slots
  • adds external items to targeted Inventory slots
  • removes the contents of a dragged Inventory slot

Drops that cannot be interpreted locally are surfaced through UnhandledSlotDropReceived so higher-level integrations can decide what they mean.

public sealed class InventoryDragDropHandler : IDisposable

Inheritance

object ← InventoryDragDropHandler

Implements

IDisposable

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

InventoryDragDropHandler(IInventory, IReadOnlyList<InventorySlotView>)

Creates a new InventoryDragDropHandler instance.

public InventoryDragDropHandler(IInventory inventory, IReadOnlyList<InventorySlotView> slotViews)

Parameters

inventory IInventory

The source inventory.

slotViews IReadOnlyList<InventorySlotView>

The slot views managed by this handler.

Properties

DraggedItem

Gets the runtime item currently being dragged, when applicable.

public ItemInstance DraggedItem { get; }

Property Value

ItemInstance

DraggedSlotIndex

Gets the source inventory slot index for the current drag, when applicable.

public int DraggedSlotIndex { get; }

Property Value

int

IsDragging

Gets whether an item drag operation is active.

public bool IsDragging { get; }

Property Value

bool

IsDraggingExternalItem

Gets whether a drag originating outside this view is active.

public bool IsDraggingExternalItem { get; }

Property Value

bool

IsDraggingInventorySlot

Gets whether a drag originating in an inventory slot is active.

public bool IsDraggingInventorySlot { get; }

Property Value

bool

Methods

BeginExternalItemDrag(ItemInstance)

Begins dragging an ItemInstance that does not currently belong to this Inventory.

public bool BeginExternalItemDrag(ItemInstance item)

Parameters

item ItemInstance

Returns

bool

Disable()

Stops processing interaction events.

public void Disable()

Dispose()

Releases event subscriptions and other resources used by the handler.

public void Dispose()

DropDraggedInventorySlot(out IReadOnlyList<ItemInstance>)

Removes the complete contents represented by the currently dragged Inventory slot.

The caller decides what the returned ItemInstances mean: discard them, spawn them into the world, transfer them elsewhere, etc.

public bool DropDraggedInventorySlot(out IReadOnlyList<ItemInstance> removedItems)

Parameters

removedItems IReadOnlyList<ItemInstance>

Returns

bool

Enable()

Enables processing of interaction events.

public void Enable()

EndDrag()

Explicitly clears the current drag state.

Useful to higher-level integrations after they consume a cross-module drop.

public void EndDrag()

EndExternalItemDrag()

Ends the current external-item drag operation.

public void EndExternalItemDrag()

ExternalItemDragging(Vector2)

Updates the pointer position for an active external-item drag.

public void ExternalItemDragging(Vector2 position)

Parameters

position Vector2

The current pointer position.

OnDrag

Raised when an active item drag moves.

public event Action<ItemInstance, Vector2> OnDrag

Event Type

Action<ItemInstance, Vector2>

OnDragStarted

Raised when an item drag begins.

public event Action<ItemInstance> OnDragStarted

Event Type

Action<ItemInstance>

OnDrop

Raised when an item is dropped.

public event Action<ItemInstance> OnDrop

Event Type

Action<ItemInstance>

OperationCompleted

Raised after a drag-and-drop operation has completed.

public event Action<InventoryDragDropResult> OperationCompleted

Event Type

Action<InventoryDragDropResult>

UnhandledSlotDropReceived

Raised when a drop cannot be resolved by the handler.

public event Action<int> UnhandledSlotDropReceived

Event Type

Action<int>