From 5d0b4c09a67f279847337aa06bc3066c07f63114 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 8 Jan 2016 20:27:29 +0300 Subject: Impliment craft inventory for moving items one by one. --- src/resources/inventory/inventory.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/resources/inventory/inventory.cpp') diff --git a/src/resources/inventory/inventory.cpp b/src/resources/inventory/inventory.cpp index 180a1b4f3..c73d9d8b6 100644 --- a/src/resources/inventory/inventory.cpp +++ b/src/resources/inventory/inventory.cpp @@ -372,7 +372,8 @@ int Inventory::findIndexByTag(const int tag) const } bool Inventory::addVirtualItem(const Item *const item, - int index) + int index, + const int amount) { if (item && !PlayerInfo::isItemProtected(item->getId())) { @@ -383,7 +384,7 @@ bool Inventory::addVirtualItem(const Item *const item, setItem(index, item->getId(), item->getType(), - 1, + amount, 1, item->getColor(), item->getIdentified(), @@ -396,7 +397,7 @@ bool Inventory::addVirtualItem(const Item *const item, { index = addItem(item->getId(), item->getType(), - 1, + amount, 1, item->getColor(), item->getIdentified(), @@ -465,3 +466,25 @@ void Inventory::virtualRestore(const Item *const item, mItems[index]->mQuantity += amount; } } + +void Inventory::moveItem(const int index1, + const int index2) +{ + if (index1 < 0 || + index1 >= static_cast(mSize) || + index2 < 0 || + index2 >= static_cast(mSize)) + { + return; + } + + Item *const item1 = mItems[index1]; + Item *const item2 = mItems[index2]; + if (item1) + item1->setInvIndex(index2); + if (item2) + item2->setInvIndex(index1); + mItems[index1] = item2; + mItems[index2] = item1; + distributeSlotsChangedEvent(); +} -- cgit v1.2.3-60-g2f50