ManaPlus
shopitems.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_MODELS_SHOPITEMS_H
25 #define GUI_MODELS_SHOPITEMS_H
26 
28 
30 
31 #include "gui/models/listmodel.h"
32 
33 #include "utils/cast.h"
34 #include "utils/vector.h"
35 
36 #include "localconsts.h"
37 
38 class ShopItem;
39 
49 class ShopItems final : public ListModel
50 {
51  public:
58  ShopItems(const bool mergeDuplicates,
59  const std::string &currency);
60 
62 
63  ~ShopItems() override final;
64 
68  ShopItem *addItem(const int id,
69  const ItemTypeT type,
70  const ItemColor color,
71  const int amount,
72  const int price);
73 
83  ShopItem *addItem2(const int inventoryIndex,
84  const int id,
85  const ItemTypeT type,
86  const ItemColor color,
87  const int amount,
88  const int price);
89 
90  ShopItem *addItemNoDup(const int id,
91  const ItemTypeT type,
92  const ItemColor color,
93  const int amount,
94  const int price);
95 
100  { return CAST_S32(mShopItems.size()); }
101 
103  { return mShopItems.empty(); }
104 
110  std::string getElementAt(int i) override final A_WARN_UNUSED;
111 
115  ShopItem *at(const size_t i) const A_WARN_UNUSED;
116 
122  void erase(const unsigned int i);
123 
129  void del(const unsigned int i);
130 
134  void clear();
135 
136  STD_VECTOR<ShopItem*> &items() A_WARN_UNUSED
137  { return mShopItems; }
138 
139  STD_VECTOR<ShopItem*> &allItems() A_WARN_UNUSED
140  { return mAllShopItems; }
141 
142  void setMergeDuplicates(const bool b)
143  { mMergeDuplicates = b; }
144 
145  void updateList();
146 
147  private:
154  ShopItem *findItem(const int id,
155  const ItemColor color) const A_WARN_UNUSED;
156 
157  bool findInAllItems(STD_VECTOR<ShopItem*>::iterator &it,
158  const ShopItem *const item);
159 
161  STD_VECTOR<ShopItem*> mAllShopItems;
162 
163  STD_VECTOR<ShopItem*> mShopItems;
164 
165  std::string mCurrency;
166 
169 };
170 
171 #endif // GUI_MODELS_SHOPITEMS_H
#define CAST_S32
Definition: cast.h:30
ShopItems(const bool mergeDuplicates, const std::string &currency)
Definition: shopitems.cpp:33
bool mMergeDuplicates
Definition: shopitems.h:168
std::vector< ShopItem * > mAllShopItems
Definition: shopitems.h:161
ShopItem * addItemNoDup(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:77
std::vector< ShopItem * > & allItems()
Definition: shopitems.h:139
std::string getElementAt(int i)
Definition: shopitems.cpp:48
std::vector< ShopItem * > & items()
Definition: shopitems.h:136
void del(const unsigned int i)
Definition: shopitems.cpp:161
ShopItem * addItem2(const int inventoryIndex, const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:99
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:59
void erase(const unsigned int i)
Definition: shopitems.cpp:149
bool empty() const
Definition: shopitems.h:102
std::string mCurrency
Definition: shopitems.h:165
int getNumberOfElements()
Definition: shopitems.h:99
std::vector< ShopItem * > mShopItems
Definition: shopitems.h:163
void updateList()
Definition: shopitems.cpp:198
void setMergeDuplicates(const bool b)
Definition: shopitems.h:142
bool findInAllItems(std::vector< ShopItem * >::iterator &it, const ShopItem *const item)
Definition: shopitems.cpp:137
ShopItem * findItem(const int id, const ItemColor color) const
Definition: shopitems.cpp:181
void clear()
Definition: shopitems.cpp:174
ShopItem * at(const size_t i) const
Definition: shopitems.cpp:129
uint16_t ItemColor
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53