summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-10-30 00:11:35 +0300
committerAndrei Karas <akaras@inbox.ru>2015-10-30 00:11:35 +0300
commit1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b (patch)
treede98074d774b203053c4215a49764837a3b007ed
parent598de45a1e77e5f10c69694f607941336163673f (diff)
downloadplus-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.tar.gz
plus-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.tar.bz2
plus-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.tar.xz
plus-1b653c7c1a3e6c5d7b2739f881ea6b11ca46cd3b.zip
Allow add item by drag&drop into npc inventory to exact position.
-rw-r--r--src/gui/widgets/itemcontainer.cpp5
-rw-r--r--src/gui/windows/npcdialog.cpp2
-rw-r--r--src/inventory.cpp42
-rw-r--r--src/inventory.h3
4 files changed, 36 insertions, 16 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 8fc8b09e4..fec14b814 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -631,8 +631,9 @@ void ItemContainer::mouseReleased(MouseEvent &event)
inventory = PlayerInfo::getInventory();
if (inventory)
{
- mInventory->addVirtualItem(inventory->getItem(
- dragDrop.getTag()));
+ mInventory->addVirtualItem(
+ inventory->getItem(dragDrop.getTag()),
+ getSlotIndex(event.getX(), event.getY()));
}
return;
}
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 5cc538e34..f601c6405 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -542,7 +542,7 @@ void NpcDialog::action(const ActionEvent &event)
else if (eventId == "add")
{
if (inventoryWindow)
- mInventory->addVirtualItem(inventoryWindow->getSelectedItem());
+ mInventory->addVirtualItem(inventoryWindow->getSelectedItem(), 0);
}
else if (eventId.find("skin_") == 0)
{
diff --git a/src/inventory.cpp b/src/inventory.cpp
index eecaacd6c..c91a7411a 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -362,24 +362,42 @@ int Inventory::findIndexByTag(const int tag) const
return -1;
}
-void Inventory::addVirtualItem(const Item *const item)
+void Inventory::addVirtualItem(const Item *const item,
+ int index)
{
if (item && !PlayerInfo::isItemProtected(item->getId()))
{
if (findIndexByTag(item->getInvIndex()) != -1)
return;
- const int index = addItem(item->getId(),
- item->getType(),
- 1,
- 1,
- item->getColor(),
- item->getIdentified(),
- item->getDamaged(),
- item->getFavorite(),
- Equipm_false,
- Equipped_false);
- Item *const item2 = getItem(index);
+ if (index >= 0 && index < mSize && mItems[index] == nullptr)
+ {
+ setItem(index,
+ item->getId(),
+ item->getType(),
+ 1,
+ 1,
+ item->getColor(),
+ item->getIdentified(),
+ item->getDamaged(),
+ item->getFavorite(),
+ Equipm_false,
+ Equipped_false);
+ }
+ else
+ {
+ index = addItem(item->getId(),
+ item->getType(),
+ 1,
+ 1,
+ item->getColor(),
+ item->getIdentified(),
+ item->getDamaged(),
+ item->getFavorite(),
+ Equipm_false,
+ Equipped_false);
+ }
+ Item *const item2 = getItem(index);
if (item2)
item2->setTag(item->getInvIndex());
}
diff --git a/src/inventory.h b/src/inventory.h
index e20010c23..1d1f49ebe 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -174,7 +174,8 @@ class Inventory final
int findIndexByTag(const int tag) const;
- void addVirtualItem(const Item *const item);
+ void addVirtualItem(const Item *const item,
+ int index);
protected:
typedef std::list<InventoryListener*> InventoryListenerList;