ManaPlus
shortcutbase.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009 The Mana World Development Team
4  * Copyright (C) 2011-2019 The ManaPlus Developers
5  * Copyright (C) 2009-2021 Andrei Karas
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef GUI_SHORTCUT_SHORTCUTBASE_H
24 #define GUI_SHORTCUT_SHORTCUTBASE_H
25 
27 
28 #include "utils/cast.h"
29 
30 #include <string>
31 
32 #include "localconsts.h"
33 
34 class Item;
35 
40 {
41  public:
45  ShortcutBase(const std::string &itemName,
46  const std::string &colorName,
47  const int maxSize);
48 
50 
51 
54  virtual ~ShortcutBase();
55 
59  void load();
60 
64  void save() const;
65 
71  int getItem(const size_t index) const A_WARN_UNUSED
72  { return mItems[index]; }
73 
74  ItemColor getItemColor(const size_t index) const A_WARN_UNUSED
75  { return mItemColors[index]; }
76 
81  { return CAST_S32(mMaxSize); }
82 
87  { return mItemSelected; }
88 
94  void setItem(const size_t index);
95 
102  void setItems(const size_t index,
103  const int itemId,
104  const ItemColor color)
105  { mItems[index] = itemId; mItemColors[index] = color; save(); }
106 
112  void setItemSelected(const int itemId)
113  { mItemSelected = itemId; }
114 
115  void setItemSelected(const Item *const item);
116 
121  { return mItemSelected > -1; }
122 
126  void removeItem(const size_t index)
127  { mItems[index] = -1; save(); }
128 
129  void clear(const bool isSave);
130 
131  private:
134  std::string mItemName;
135  std::string mColorName;
136  size_t mMaxSize;
139 };
140 
141 #endif // GUI_SHORTCUT_SHORTCUTBASE_H
#define CAST_S32
Definition: cast.h:30
Definition: item.h:50
ShortcutBase(const std::string &itemName, const std::string &colorName, const int maxSize)
void setItemSelected(const int itemId)
Definition: shortcutbase.h:112
ItemColor * mItemColors
Definition: shortcutbase.h:133
void clear(const bool isSave)
bool isItemSelected() const
Definition: shortcutbase.h:120
std::string mItemName
Definition: shortcutbase.h:134
virtual ~ShortcutBase()
void save() const
ItemColor mItemColorSelected
Definition: shortcutbase.h:138
int getItemSelected() const
Definition: shortcutbase.h:86
size_t mMaxSize
Definition: shortcutbase.h:136
int getItem(const size_t index) const
Definition: shortcutbase.h:71
void setItem(const size_t index)
int getItemCount() const
Definition: shortcutbase.h:80
ItemColor getItemColor(const size_t index) const
Definition: shortcutbase.h:74
std::string mColorName
Definition: shortcutbase.h:135
void setItems(const size_t index, const int itemId, const ItemColor color)
Definition: shortcutbase.h:102
void removeItem(const size_t index)
Definition: shortcutbase.h:126
uint16_t ItemColor
Definition: itemcolor.h:30
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define A_DELETE_COPY(func)
Definition: localconsts.h:53