GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/shortcut/itemshortcut.h Lines: 0 7 0.0 %
Date: 2017-11-29 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-2017  The ManaPlus Developers
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_ITEMSHORTCUT_H
24
#define GUI_SHORTCUT_ITEMSHORTCUT_H
25
26
#include "const/itemshortcut.h"
27
28
#include "enums/simpletypes/itemcolor.h"
29
30
#include <string>
31
32
#include "localconsts.h"
33
34
class Item;
35
36
/**
37
 * The class which keeps track of the item shortcuts.
38
 */
39
class ItemShortcut final
40
{
41
    public:
42
        /**
43
         * Constructor.
44
         */
45
        explicit ItemShortcut(const size_t number);
46
47
        A_DELETE_COPY(ItemShortcut)
48
49
        /**
50
         * Destructor.
51
         */
52
        ~ItemShortcut();
53
54
        /**
55
         * Load the configuration information.
56
         */
57
        void load();
58
59
        /**
60
         * Save the configuration information.
61
         */
62
        void save() const;
63
64
        /**
65
         * Returns the shortcut item ID specified by the index.
66
         *
67
         * @param index Index of the shortcut item.
68
         */
69
        int getItem(const size_t index) const A_WARN_UNUSED
70
        { return mItems[index]; }
71
72
        ItemColor getItemColor(const size_t index) const A_WARN_UNUSED
73
        { return mItemColors[index]; }
74
75
        void setItemData(const size_t index,
76
                         const std::string &data)
77
        { mItemData[index] = data; }
78
79
        std::string getItemData(const size_t index) const A_WARN_UNUSED
80
        { return mItemData[index]; }
81
82
        /**
83
         * Returns the amount of shortcut items.
84
         */
85
        constexpr static int getItemCount() A_WARN_UNUSED
86
        { return SHORTCUT_ITEMS; }
87
88
        /**
89
         * Returns the item ID that is currently selected.
90
         */
91
        int getItemSelected() const noexcept2 A_WARN_UNUSED
92
        { return mItemSelected; }
93
94
        /**
95
         * Adds the selected item ID to the items specified by the index.
96
         *
97
         * @param index Index of the items.
98
         */
99
        void setItem(const size_t index);
100
101
        void setItem(const size_t index,
102
                     const int item,
103
                     const ItemColor color);
104
105
        void setItemFast(const size_t index,
106
                         const int item,
107
                         const ItemColor color);
108
109
        /**
110
         * Adds an item to the items store specified by the index.
111
         *
112
         * @param index Index of the item.
113
         * @param itemId ID of the item.
114
         */
115
        void setItems(const size_t index,
116
                      const int itemId,
117
                      const ItemColor color)
118
        { mItems[index] = itemId; mItemColors[index] = color; save(); }
119
120
        /**
121
         * Set the item that is selected.
122
         *
123
         * @param itemId The ID of the item that is to be assigned.
124
         */
125
        void setItemSelected(const int itemId)
126
        { mItemSelected = itemId; }
127
128
        void setItemSelected(const Item *const item);
129
130
        /**
131
         * Returns selected shortcut item ID.
132
         */
133
        int getSelectedItem() const noexcept2 A_WARN_UNUSED
134
        { return mItemSelected; }
135
136
        /**
137
         * A flag to check if the item is selected.
138
         */
139
        bool isItemSelected() const noexcept2 A_WARN_UNUSED
140
        { return mItemSelected > -1; }
141
142
        /**
143
         * Remove a item from the shortcut.
144
         */
145
        void removeItem(const size_t index)
146
        { mItems[index] = -1;  save(); }
147
148
        /**
149
         * Try to use the item specified by the index.
150
         *
151
         * @param index Index of the item shortcut.
152
         */
153
        void useItem(const size_t index) const;
154
155
        /**
156
         * Equip a item from the shortcut.
157
         */
158
        void equipItem(const size_t index) const;
159
160
        /**
161
         * UnEquip a item from the shortcut.
162
         */
163
        void unequipItem(const size_t index) const;
164
165
        void swap(const size_t index1,
166
                  const size_t index2);
167
168
        void clear();
169
170
        size_t getFreeIndex() const A_WARN_UNUSED;
171
172
    private:
173
        int mItems[SHORTCUT_ITEMS];             /**< The items. */
174
        ItemColor mItemColors[SHORTCUT_ITEMS];  /**< The item colors. */
175
        std::string mItemData[SHORTCUT_ITEMS];
176
        size_t mNumber;
177
        int mItemSelected;
178
        ItemColor mItemColorSelected;
179
};
180
181
extern ItemShortcut *itemShortcut[SHORTCUT_TABS];
182
183
#endif  // GUI_SHORTCUT_ITEMSHORTCUT_H