summaryrefslogtreecommitdiff
path: root/src/gui/shop.cpp
diff options
context:
space:
mode:
authorMajin Sniper <majinsniper@gmx.de>2009-02-23 19:19:55 +0100
committerJared Adams <jaxad0127@gmail.com>2009-02-23 17:19:56 -0700
commite15b8c360ac5171fe73b8b73fbe00eedba8970ff (patch)
treeec7d2129c8dc35c3cdf7669a08beb71c30a7760c /src/gui/shop.cpp
parentc54b987a4e4d28d35e8bafb03e1dba33b5fda4ab (diff)
downloadmana-client-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.tar.gz
mana-client-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.tar.bz2
mana-client-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.tar.xz
mana-client-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.zip
Allow to sell non-stackable items like stackables
Make it possible to sell non-stackable items all at once by introducing "Duplicate Items" and a Shop that can handle them. Also fix a trivial bug to correctly preview you money while selling.
Diffstat (limited to 'src/gui/shop.cpp')
-rw-r--r--src/gui/shop.cpp51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp
index a5f59bac..e13e218c 100644
--- a/src/gui/shop.cpp
+++ b/src/gui/shop.cpp
@@ -23,6 +23,11 @@
#include "../utils/dtor.h"
+ShopItems::ShopItems(bool mergeDuplicates) :
+ mMergeDuplicates(mergeDuplicates)
+{
+}
+
ShopItems::~ShopItems()
{
clear();
@@ -38,16 +43,29 @@ std::string ShopItems::getElementAt(int i)
return mShopItems.at(i)->getDisplayName();
}
-void ShopItems::addItem(int inventoryIndex, short id, int amount, int price)
+void ShopItems::addItem(int inventoryIndex, int id, int quantity,
+ int price)
{
- ShopItem *item = new ShopItem(id, amount, price);
- item->setInvIndex(inventoryIndex);
- mShopItems.push_back(item);
+ ShopItem* item = 0;
+ if (mMergeDuplicates)
+ {
+ item = findItem(id);
+ }
+
+ if (item)
+ {
+ item->addDuplicate (inventoryIndex, quantity);
+ }
+ else
+ {
+ item = new ShopItem(inventoryIndex, id, quantity, price);
+ mShopItems.push_back(item);
+ }
}
-void ShopItems::addItem(short id, int price)
+void ShopItems::addItem(int id, int price)
{
- mShopItems.push_back(new ShopItem(id, 0, price));
+ addItem(-1, id, 0, price);
}
ShopItem* ShopItems::at(int i) const
@@ -55,13 +73,30 @@ ShopItem* ShopItems::at(int i) const
return mShopItems.at(i);
}
+void ShopItems::erase(int i)
+{
+ mShopItems.erase(mShopItems.begin() + i);
+}
+
void ShopItems::clear()
{
delete_all(mShopItems);
mShopItems.clear();
}
-std::vector<ShopItem*>* ShopItems::getShop()
+ShopItem* ShopItems::findItem(int id)
{
- return &mShopItems;
+ ShopItem *item;
+
+ std::vector<ShopItem*>::iterator it;
+ for(it = mShopItems.begin(); it != mShopItems.end(); it++)
+ {
+ item = *(it);
+ if (item->getId() == id)
+ {
+ return item;
+ }
+ }
+
+ return 0;
}