GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/shortcut/itemshortcut.h Lines: 0 7 0.0 %
Date: 2021-03-17 Branches: 0 2 0.0 %

Line Branch Exec Source
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
29
#include "enums/simpletypes/itemcolor.h"
30
31
#include <string>
32
33
#include "localconsts.h"
34
35
class Item;
36
37
/**
38
 * The class which keeps track of the item shortcuts.
39
 */
40
class ItemShortcut final
41
{
42
    public:
43
        /**
44
         * Constructor.
45
         */
46
        explicit ItemShortcut(const size_t number);
47
48
        A_DELETE_COPY(ItemShortcut)
49
50
        /**
51
         * Destructor.
52
         */
53
        ~ItemShortcut();
54
55
        /**
56
         * Load the configuration information.
57
         */
58
        void load();
59
60
        /**
61
         * Save the configuration information.
62
         */
63
        void save() const;
64
65
        /**
66
         * Returns the shortcut item ID specified by the index.
67
         *
68
         * @param index Index of the shortcut item.
69
         */
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
83
        /**
84
         * Returns the amount of shortcut items.
85
         */
86
        constexpr static int getItemCount() A_WARN_UNUSED
87
        { return SHORTCUT_ITEMS; }
88
89
        /**
90
         * Returns the item ID that is currently selected.
91
         */
92
        int getItemSelected() const noexcept2 A_WARN_UNUSED
93
        { return mItemSelected; }
94
95
        /**
96
         * Adds the selected item ID to the items specified by the index.
97
         *
98
         * @param index Index of the items.
99
         */
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
110
        /**
111
         * Adds an item to the items store specified by the index.
112
         *
113
         * @param index Index of the item.
114
         * @param itemId ID of the item.
115
         */
116
        void setItems(const size_t index,
117
                      const int itemId,
118
                      const ItemColor color)
119
        { mItems[index] = itemId; mItemColors[index] = color; save(); }
120
121
        /**
122
         * Set the item that is selected.
123
         *
124
         * @param itemId The ID of the item that is to be assigned.
125
         */
126
        void setItemSelected(const int itemId)
127
        { mItemSelected = itemId; }
128
129
        void setItemSelected(const Item *const item);
130
131
        /**
132
         * Returns selected shortcut item ID.
133
         */
134
        int getSelectedItem() const noexcept2 A_WARN_UNUSED
135
        { return mItemSelected; }
136
137
        /**
138
         * A flag to check if the item is selected.
139
         */
140
        bool isItemSelected() const noexcept2 A_WARN_UNUSED
141
        { return mItemSelected > -1; }
142
143
        /**
144
         * Remove a item from the shortcut.
145
         */
146
        void removeItem(const size_t index)
147
        { mItems[index] = -1;  save(); }
148
149
        /**
150
         * Try to use the item specified by the index.
151
         *
152
         * @param index Index of the item shortcut.
153
         */
154
        void useItem(const size_t index) const;
155
156
        /**
157
         * Equip a item from the shortcut.
158
         */
159
        void equipItem(const size_t index) const;
160
161
        /**
162
         * UnEquip a item from the shortcut.
163
         */
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:
174
        int mItems[SHORTCUT_ITEMS];             /**< The items. */
175
        ItemColor mItemColors[SHORTCUT_ITEMS];  /**< The item colors. */
176
        std::string mItemData[SHORTCUT_ITEMS];
177
        size_t mNumber;
178
        int mItemSelected;
179
        ItemColor mItemColorSelected;
180
};
181
182
extern ItemShortcut *itemShortcut[SHORTCUT_TABS];
183
184
#endif  // GUI_SHORTCUT_ITEMSHORTCUT_H