ManaPlus
itemshortcut.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2007-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_SHORTCUT_ITEMSHORTCUT_H
25 #define GUI_SHORTCUT_ITEMSHORTCUT_H
26 
27 #include "const/itemshortcut.h"
28 
30 
31 #include <string>
32 
33 #include "localconsts.h"
34 
35 class Item;
36 
41 {
42  public:
46  explicit ItemShortcut(const size_t number);
47 
49 
50 
53  ~ItemShortcut();
54 
58  void load();
59 
63  void save() const;
64 
70  int getItem(const size_t index) const A_WARN_UNUSED
71  { return mItems[index]; }
72 
73  ItemColor getItemColor(const size_t index) const A_WARN_UNUSED
74  { return mItemColors[index]; }
75 
76  void setItemData(const size_t index,
77  const std::string &data)
78  { mItemData[index] = data; }
79 
80  std::string getItemData(const size_t index) const A_WARN_UNUSED
81  { return mItemData[index]; }
82 
87  { return SHORTCUT_ITEMS; }
88 
93  { return mItemSelected; }
94 
100  void setItem(const size_t index);
101 
102  void setItem(const size_t index,
103  const int item,
104  const ItemColor color);
105 
106  void setItemFast(const size_t index,
107  const int item,
108  const ItemColor color);
109 
116  void setItems(const size_t index,
117  const int itemId,
118  const ItemColor color)
119  { mItems[index] = itemId; mItemColors[index] = color; save(); }
120 
126  void setItemSelected(const int itemId)
127  { mItemSelected = itemId; }
128 
129  void setItemSelected(const Item *const item);
130 
135  { return mItemSelected; }
136 
141  { return mItemSelected > -1; }
142 
146  void removeItem(const size_t index)
147  { mItems[index] = -1; save(); }
148 
154  void useItem(const size_t index) const;
155 
159  void equipItem(const size_t index) const;
160 
164  void unequipItem(const size_t index) const;
165 
166  void swap(const size_t index1,
167  const size_t index2);
168 
169  void clear();
170 
171  size_t getFreeIndex() const A_WARN_UNUSED;
172 
173  private:
177  size_t mNumber;
180 };
181 
183 
184 #endif // GUI_SHORTCUT_ITEMSHORTCUT_H
size_t getFreeIndex() const
int getSelectedItem() const
Definition: itemshortcut.h:134
void save() const
ItemColor getItemColor(const size_t index) const
Definition: itemshortcut.h:73
void setItemFast(const size_t index, const int item, const ItemColor color)
void setItemSelected(const int itemId)
Definition: itemshortcut.h:126
void setItemData(const size_t index, const std::string &data)
Definition: itemshortcut.h:76
int getItem(const size_t index) const
Definition: itemshortcut.h:70
size_t mNumber
Definition: itemshortcut.h:177
static int getItemCount()
Definition: itemshortcut.h:86
ItemShortcut(const size_t number)
int mItems[SHORTCUT_ITEMS]
Definition: itemshortcut.h:174
void equipItem(const size_t index) const
ItemColor mItemColors[SHORTCUT_ITEMS]
Definition: itemshortcut.h:175
ItemColor mItemColorSelected
Definition: itemshortcut.h:179
bool isItemSelected() const
Definition: itemshortcut.h:140
int getItemSelected() const
Definition: itemshortcut.h:92
void removeItem(const size_t index)
Definition: itemshortcut.h:146
void swap(const size_t index1, const size_t index2)
void setItem(const size_t index)
void useItem(const size_t index) const
std::string mItemData[SHORTCUT_ITEMS]
Definition: itemshortcut.h:176
std::string getItemData(const size_t index) const
Definition: itemshortcut.h:80
void setItems(const size_t index, const int itemId, const ItemColor color)
Definition: itemshortcut.h:116
void unequipItem(const size_t index) const
Definition: item.h:50
const unsigned int SHORTCUT_ITEMS
Definition: itemshortcut.h:27
const unsigned int SHORTCUT_TABS
Definition: itemshortcut.h:28
ItemShortcut * itemShortcut[SHORTCUT_TABS]
uint16_t ItemColor
Definition: itemcolor.h:30
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define constexpr
Definition: localconsts.h:48
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
uint32_t data