Mana
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ShopItems Class Reference

This class handles the list of items available in a shop. More...

#include <shopitems.h>

Inheritance diagram for ShopItems:

Public Member Functions

 ShopItems (bool mergeDuplicates=false)
 Constructor.
 
 ~ShopItems () override
 
void addItem (int id, int amount, int price)
 Adds an item to the list.
 
void addItem (int inventoryIndex, int id, int amount, int price)
 Adds an item to the list (used by sell dialog).
 
int getNumberOfElements () override
 Returns the number of items in the shop.
 
std::string getElementAt (int i) override
 Returns the name of item number i in the shop.
 
ShopItemat (int i) const
 Returns the item number i in the shop.
 
void erase (int i)
 Removes an element from the shop.
 
void clear ()
 Clears the list of items in the shop.
 

Private Member Functions

ShopItemfindItem (int id)
 Searches the current items in the shop for the specified id and returns the item if found, or 0 else.
 

Private Attributes

std::vector< ShopItem * > mShopItems
 The list of items in the shop.
 
bool mMergeDuplicates
 Look for duplicate entries on addition.
 

Detailed Description

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.

Definition at line 40 of file shopitems.h.

Constructor & Destructor Documentation

◆ ShopItems()

ShopItems::ShopItems ( bool  mergeDuplicates = false)

Constructor.

Parameters
mergeDuplicateslets the Shop look for duplicate entries and merges them to one item.

Definition at line 28 of file shopitems.cpp.

◆ ~ShopItems()

ShopItems::~ShopItems ( )
override

Definition at line 33 of file shopitems.cpp.

Member Function Documentation

◆ addItem() [1/2]

void ShopItems::addItem ( int  id,
int  amount,
int  price 
)

Adds an item to the list.

Definition at line 48 of file shopitems.cpp.

◆ addItem() [2/2]

void ShopItems::addItem ( int  inventoryIndex,
int  id,
int  amount,
int  price 
)

Adds an item to the list (used by sell dialog).

Looks for duplicate entries, if mergeDuplicates was turned on.

Parameters
inventoryIndexthe inventory index of the item
idthe id of the item
amountnumber of available copies of the item
priceprice of the item

Definition at line 53 of file shopitems.cpp.

◆ at()

ShopItem * ShopItems::at ( int  i) const

Returns the item number i in the shop.

Definition at line 72 of file shopitems.cpp.

◆ clear()

void ShopItems::clear ( )

Clears the list of items in the shop.

Definition at line 82 of file shopitems.cpp.

◆ erase()

void ShopItems::erase ( int  i)

Removes an element from the shop.

Parameters
iindex to remove

Definition at line 77 of file shopitems.cpp.

◆ findItem()

ShopItem * ShopItems::findItem ( int  id)
private

Searches the current items in the shop for the specified id and returns the item if found, or 0 else.

Returns
the item found or 0

Definition at line 88 of file shopitems.cpp.

◆ getElementAt()

std::string ShopItems::getElementAt ( int  i)
override

Returns the name of item number i in the shop.

Parameters
ithe index to retrieve

Definition at line 43 of file shopitems.cpp.

◆ getNumberOfElements()

int ShopItems::getNumberOfElements ( )
override

Returns the number of items in the shop.

Definition at line 38 of file shopitems.cpp.

Member Data Documentation

◆ mMergeDuplicates

bool ShopItems::mMergeDuplicates
private

Look for duplicate entries on addition.

Definition at line 111 of file shopitems.h.

◆ mShopItems

std::vector<ShopItem*> ShopItems::mShopItems
private

The list of items in the shop.

Definition at line 108 of file shopitems.h.


The documentation for this class was generated from the following files: