summaryrefslogtreecommitdiff
path: root/src/resources/inventory/inventory.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-08 20:27:29 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-08 20:27:29 +0300
commit5d0b4c09a67f279847337aa06bc3066c07f63114 (patch)
treeb2f8bbdb3252222c9bc50efa04a5689faa3b1760 /src/resources/inventory/inventory.cpp
parent4b014aa3f403ae02587f6a3d89180f75161d4b78 (diff)
downloadplus-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.gz
plus-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.bz2
plus-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.xz
plus-5d0b4c09a67f279847337aa06bc3066c07f63114.zip
Impliment craft inventory for moving items one by one.
Diffstat (limited to 'src/resources/inventory/inventory.cpp')
-rw-r--r--src/resources/inventory/inventory.cpp29
1 files changed, 26 insertions, 3 deletions
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<int>(mSize) ||
+ index2 < 0 ||
+ index2 >= static_cast<int>(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();
+}