From e15b8c360ac5171fe73b8b73fbe00eedba8970ff Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Mon, 23 Feb 2009 19:19:55 +0100 Subject: 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. --- src/gui/shop.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 7 deletions(-) (limited to 'src/gui/shop.h') diff --git a/src/gui/shop.h b/src/gui/shop.h index e0db4c59..faffe7e3 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -31,31 +31,62 @@ class ShopItem; +/** + * This class handles the list of items available in a shop. + * + * The addItem routine can automatically check, if an item already exists and + * only adds duplicates to the old item, if one is found. The original + * distribution of the duplicates can be retrieved from the item. + * + * This functionality can be enabled in the constructor. + */ class ShopItems : public gcn::ListModel { public: + /** + * Constructor. Creates a new ShopItems instance. + * + * @param mergeDuplicates lets the Shop look for duplicate entries and + * merges them to one item. + */ + ShopItems(bool mergeDuplicates = false); + /** * Destructor. */ ~ShopItems(); /** - * Adds an item to the list (used by sell dialog). + * Adds an item to the list (used by sell dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item */ - void addItem(int inventoryIndex, short id, int amount, int price); + void addItem(int inventoryIndex, int id, int amount, int price); /** - * Adds an item to the list (used by buy dialog). + * Adds an item to the list (used by buy dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param id the id of the item + * @param price price of the item */ - void addItem(short id, int price); + void addItem(int id, int price); /** * Returns the number of items in the shop. + * + * @return the number of items in the shop */ int getNumberOfElements(); /** * Returns the name of item number i in the shop. + * + * @param i the index to retrieve */ std::string getElementAt(int i); @@ -64,18 +95,32 @@ class ShopItems : public gcn::ListModel */ ShopItem* at(int i) const; + /** + * Removes an element from the shop. + * + * @param i index to remove + */ + void erase(int i); + /** * Clear the vector. */ void clear(); + private: /** - * Direct access to the vector. + * Searches the current items in the shop for the specified + * id and returns the item if found, or 0 else. + * + * @return the item found or 0 */ - std::vector* getShop(); + ShopItem* findItem(int id); - private: + /** the shop storage */ std::vector mShopItems; + + /** Look for duplicate entries on addition */ + bool mMergeDuplicates; }; #endif -- cgit v1.2.3-70-g09d2