From 3a3498f766c2cf8dc47a9b2b0dd63afe90dda68e Mon Sep 17 00:00:00 2001 From: Andrew James Date: Tue, 3 Dec 2024 22:15:20 +1100 Subject: [PATCH] dedupe code for moving from inv to stash also reorganising belt to stash checks to match --- Source/controls/plrctrls.cpp | 37 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 599121272..ee86511be 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -1106,9 +1106,9 @@ void StashMove(AxisDirection dir) Item &holdItem = MyPlayer->HoldItem; Size itemSize = holdItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(holdItem); - // Jump from belt to stash - if (BeltReturnsToStash && Slot >= SLOTXY_BELT_FIRST && Slot <= SLOTXY_BELT_LAST) { - if (dir.y == AxisDirectionY_UP) { + if (dir.y == AxisDirectionY_UP) { + // Check if we need to jump from belt to stash + if (BeltReturnsToStash && Slot >= SLOTXY_BELT_FIRST && Slot <= SLOTXY_BELT_LAST) { int beltSlot = Slot - SLOTXY_BELT_FIRST; InvalidateInventorySlot(); ActiveStashSlot = { 2 + beltSlot, 10 - itemSize.height }; @@ -1116,30 +1116,21 @@ void StashMove(AxisDirection dir) } } - // Jump from general inventory to stash - if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { + if (dir.x == AxisDirectionX_LEFT) { + // Check if we need to jump from general inventory to stash int firstSlot = Slot; - if (MyPlayer->HoldItem.isEmpty()) { - int8_t itemId = GetItemIdOnSlot(Slot); - if (itemId != 0) { - firstSlot = FindFirstSlotOnItem(itemId); - } - } - if (IsAnyOf(firstSlot, SLOTXY_INV_ROW1_FIRST, SLOTXY_INV_ROW2_FIRST, SLOTXY_INV_ROW3_FIRST, SLOTXY_INV_ROW4_FIRST)) { - if (dir.x == AxisDirectionX_LEFT) { - Point slotCoord = GetSlotCoord(Slot); - InvalidateInventorySlot(); - ActiveStashSlot = FindClosestStashSlot(slotCoord) - Displacement { itemSize.width - 1, 0 }; - dir.x = AxisDirectionX_NONE; + if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { + if (MyPlayer->HoldItem.isEmpty()) { + int8_t itemId = GetItemIdOnSlot(Slot); + if (itemId != 0) { + firstSlot = FindFirstSlotOnItem(itemId); + } } } - } - bool isHeadSlot = SLOTXY_HEAD == Slot; - bool isLeftHandSlot = SLOTXY_HAND_LEFT == Slot; - bool isLeftRingSlot = Slot == SLOTXY_RING_LEFT; - if (isHeadSlot || isLeftHandSlot || isLeftRingSlot) { - if (dir.x == AxisDirectionX_LEFT) { + // If we're in the leftmost column (or hovering over an item on the left side of the inventory) or + // left side of the body and we're moving left we need to move into the closest stash column + if (IsAnyOf(firstSlot, SLOTXY_HEAD, SLOTXY_HAND_LEFT, SLOTXY_RING_LEFT, SLOTXY_INV_ROW1_FIRST, SLOTXY_INV_ROW2_FIRST, SLOTXY_INV_ROW3_FIRST, SLOTXY_INV_ROW4_FIRST)) { Point slotCoord = GetSlotCoord(Slot); InvalidateInventorySlot(); ActiveStashSlot = FindClosestStashSlot(slotCoord) - Displacement { itemSize.width - 1, 0 };