diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 7 | ||||
-rw-r--r-- | src/inventory.cpp | 16 | ||||
-rw-r--r-- | src/inventory.h | 4 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 975b865d9..c9f5298b7 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -801,6 +801,7 @@ void ItemContainer::mouseReleased(MouseEvent &event) } else if (src == DRAGDROP_SOURCE_NPC) { + inventory = PlayerInfo::getInventory(); if (dst == DRAGDROP_SOURCE_NPC) { const Item *const item = mInventory->getItem( @@ -808,6 +809,8 @@ void ItemContainer::mouseReleased(MouseEvent &event) const int index = getSlotByXY(event.getX(), event.getY()); if (index == Inventory::NO_SLOT_INDEX) { + if (inventory) + inventory->virtualRestore(item, 1); mInventory->removeItemAt(dragDrop.getTag()); return; } @@ -830,13 +833,15 @@ void ItemContainer::mouseReleased(MouseEvent &event) } else { - inventory = PlayerInfo::getInventory(); if (inventory) { const Item *const item = inventory->getItem( dragDrop.getTag()); if (item) + { + inventory->virtualRestore(item, 1); mInventory->removeItemAt(dragDrop.getTag()); + } } return; } diff --git a/src/inventory.cpp b/src/inventory.cpp index 29df424e1..3240f9d8f 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -443,3 +443,19 @@ void Inventory::restoreVirtuals() } mVirtualRemove.clear(); } + +void Inventory::virtualRestore(const Item *const item, + const int amount) +{ + const int index = item->getTag(); + const IntMapCIter it = mVirtualRemove.find(index); + if (it != mVirtualRemove.end()) + { + mVirtualRemove[index] -= amount; + if (mVirtualRemove[index] < 0) + mVirtualRemove.erase(index); + if (index < 0 || index >= static_cast<int>(mSize) || !mItems[index]) + return; + mItems[index]->mQuantity += amount; + } +} diff --git a/src/inventory.h b/src/inventory.h index 995a8ef52..311e6c5f0 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -182,7 +182,11 @@ class Inventory final void virtualRemove(Item *const item, const int amount); + void virtualRestore(const Item *const item, + const int amount); + void restoreVirtuals(); + protected: typedef std::list<InventoryListener*> InventoryListenerList; InventoryListenerList mInventoryListeners; |