diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-30 22:16:07 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-30 22:16:07 +0300 |
commit | be1962973deaa161491b6592cbf21eb3e6700cc9 (patch) | |
tree | 5ddbba2e492cab6614e815c98f9bee9edc7bf2ba | |
parent | ce1919c195962ef683ad0af7ee33ce7973c0f03c (diff) | |
download | plus-be1962973deaa161491b6592cbf21eb3e6700cc9.tar.gz plus-be1962973deaa161491b6592cbf21eb3e6700cc9.tar.bz2 plus-be1962973deaa161491b6592cbf21eb3e6700cc9.tar.xz plus-be1962973deaa161491b6592cbf21eb3e6700cc9.zip |
Allow drag&drop items inside npc item container.
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 48 | ||||
-rw-r--r-- | src/inventory.cpp | 2 |
2 files changed, 46 insertions, 4 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index b7af26a95..ad9f868ad 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -795,11 +795,50 @@ void ItemContainer::mouseReleased(MouseEvent &event) } return; } -#ifdef EATHENA_SUPPORT - else if (src == DRAGDROP_SOURCE_NPC || src == DRAGDROP_SOURCE_MAIL) -#else else if (src == DRAGDROP_SOURCE_NPC) -#endif + { + if (dst == DRAGDROP_SOURCE_NPC) + { + const Item *const item = mInventory->getItem( + dragDrop.getTag()); + const int index = getSlotByXY(event.getX(), event.getY()); + if (index == Inventory::NO_SLOT_INDEX) + { + mInventory->removeItemAt(dragDrop.getTag()); + return; + } + mInventory->removeItemAt(index); + mInventory->setItem(index, + item->getId(), + item->getType(), + 1, + 1, + item->getColor(), + item->getIdentified(), + item->getDamaged(), + item->getFavorite(), + Equipm_false, + Equipped_false); + Item *const item2 = mInventory->getItem(index); + if (item2) + item2->setTag(item->getTag()); + mInventory->removeItemAt(dragDrop.getTag()); + } + else + { + inventory = PlayerInfo::getInventory(); + if (inventory) + { + const Item *const item = inventory->getItem( + dragDrop.getTag()); + if (item) + mInventory->removeItemAt(dragDrop.getTag()); + } + return; + } + } +#ifdef EATHENA_SUPPORT + else if (src == DRAGDROP_SOURCE_MAIL) { inventory = PlayerInfo::getInventory(); if (inventory) @@ -810,6 +849,7 @@ void ItemContainer::mouseReleased(MouseEvent &event) } return; } +#endif if (inventory) { diff --git a/src/inventory.cpp b/src/inventory.cpp index 5ee1e34c0..61434754f 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -199,6 +199,8 @@ void Inventory::removeItem(const int id) void Inventory::removeItemAt(const int index) { + if (!mItems[index]) + return; delete2(mItems[index]); mUsed--; if (mUsed < 0) // Already at 0, no need to distribute event |