diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-11-03 15:54:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-11-03 15:54:23 +0300 |
commit | cd636f7e367cfb7fa2c348d00071301a480d62c3 (patch) | |
tree | 2ed2f2565362aec0b02a1de0f4bdc5d6f6c3bc6e | |
parent | b86f75e0faf7d646d5414cb6a6893bbb07131315 (diff) | |
download | plus-cd636f7e367cfb7fa2c348d00071301a480d62c3.tar.gz plus-cd636f7e367cfb7fa2c348d00071301a480d62c3.tar.bz2 plus-cd636f7e367cfb7fa2c348d00071301a480d62c3.tar.xz plus-cd636f7e367cfb7fa2c348d00071301a480d62c3.zip |
Fix removing items from npc inventory (restore amount in player inventory)
-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; |