GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/inventorywindow.h Lines: 1 1 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
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-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_WINDOWS_INVENTORYWINDOW_H
24
#define GUI_WINDOWS_INVENTORYWINDOW_H
25
26
#include "resources/inventory/inventory.h"
27
28
#include "gui/widgets/window.h"
29
30
#include "listeners/actionlistener.h"
31
#include "listeners/attributelistener.h"
32
#include "listeners/inventorylistener.h"
33
#include "listeners/keylistener.h"
34
#include "listeners/selectionlistener.h"
35
36
class Button;
37
class DropDown;
38
class InventoryWindow;
39
class Item;
40
class ItemContainer;
41
class LayoutCell;
42
class ProgressBar;
43
class SortListModelInv;
44
class TabStrip;
45
class TextField;
46
47
extern InventoryWindow *inventoryWindow;
48
extern InventoryWindow *storageWindow;
49
extern InventoryWindow *cartWindow;
50
51
/**
52
 * Inventory dialog.
53
 *
54
 * \ingroup Interface
55
 */
56
class InventoryWindow final : public Window,
57
                              public ActionListener,
58
                              public KeyListener,
59
                              public SelectionListener,
60
                              public InventoryListener,
61
                              public AttributeListener
62
{
63
    public:
64
        /**
65
         * Constructor.
66
         */
67
        explicit InventoryWindow(Inventory *const inventory);
68
69
        A_DELETE_COPY(InventoryWindow)
70
71
        /**
72
         * Destructor.
73
         */
74
        ~InventoryWindow();
75
76
        void postInit() override final;
77
78
        void storeSortOrder() const;
79
80
        /**
81
         * Called when receiving actions from the widgets.
82
         */
83
        void action(const ActionEvent &event) override final;
84
85
        /**
86
         * Returns the selected item.
87
         */
88
        Item* getSelectedItem() const A_WARN_UNUSED;
89
90
        /**
91
         * Unselect item
92
         */
93
        void unselectItem();
94
95
        /**
96
         * Handles closing of the window
97
         */
98
        void widgetHidden(const Event &event) override final;
99
100
        /**
101
         * Handles the mouse clicks.
102
         */
103
        void mouseClicked(MouseEvent &event) override final;
104
105
        /**
106
         * Handles the key presses.
107
         */
108
        void keyPressed(KeyEvent &event) override final;
109
110
        /**
111
         * Handles the key releases.
112
         */
113
        void keyReleased(KeyEvent &event) override final;
114
115
        /**
116
         * Updates labels to currently selected item.
117
         */
118
        void valueChanged(const SelectionEvent &event) override final;
119
120
        /**
121
         * Closes the Storage Window, as well as telling the server that the
122
         * window has been closed.
123
         */
124
        void close() override final;
125
126
        void slotsChanged(const Inventory *const inventory) override final;
127
128
        bool isMainInventory() const A_WARN_UNUSED
129
        {
130
            return mInventory != nullptr ?
131
                mInventory->isMainInventory() : false;
132
        }
133
134
        /**
135
         * Returns true if any instances exist.
136
         */
137
        static bool isStorageActive() A_WARN_UNUSED
138
2
        { return storageWindow != nullptr; }
139
140
        void updateDropButton();
141
142
        void updateButtons(const Item *item = nullptr);
143
144
        bool isInputFocused() const A_WARN_UNUSED;
145
146
        void widgetResized(const Event &event) override final;
147
148
        void mouseMoved(MouseEvent &event) override final;
149
150
        void mouseExited(MouseEvent &event) override final;
151
152
        void setVisible(Visible visible) override final;
153
154
        void unsetInventory();
155
156
        void attributeChanged(const AttributesT id,
157
                              const int64_t oldVal,
158
                              const int64_t newVal) override final;
159
160
        void combineItems(const int index1,
161
                          const int index2);
162
163
        void moveItemToCraft(const int craftSlot);
164
165
        static bool isAnyInputFocused();
166
167
        static InventoryWindow *getFirstVisible();
168
169
        static void nextTab();
170
171
        static void prevTab();
172
173
    private:
174
        /**
175
         * Updates the weight bar.
176
         */
177
        void updateWeight();
178
179
        typedef std::list<InventoryWindow*> WindowList;
180
        static WindowList invInstances;
181
182
        Inventory *mInventory;
183
        ItemContainer *mItems A_NONNULLPOINTER;
184
185
        Button *mUseButton;
186
        Button *mDropButton;
187
        Button *mOutfitButton;
188
        Button *mShopButton;
189
        Button *mCartButton;
190
        Button *mEquipmentButton;
191
        Button *mStoreButton;
192
        Button *mRetrieveButton;
193
        Button *mInvCloseButton;
194
195
        ProgressBar *mWeightBar;
196
        ProgressBar *mSlotsBar A_NONNULLPOINTER;
197
        TabStrip *mFilter;
198
        SortListModelInv *mSortModel A_NONNULLPOINTER;
199
        DropDown *mSortDropDown A_NONNULLPOINTER;
200
        TextField *mNameFilter A_NONNULLPOINTER;
201
        LayoutCell *mSortDropDownCell;
202
        LayoutCell *mNameFilterCell;
203
        LayoutCell *mFilterCell;
204
        LayoutCell *mSlotsBarCell;
205
206
        bool mSplit;
207
        bool mCompactMode;
208
};
209
210
#endif  // GUI_WINDOWS_INVENTORYWINDOW_H