GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/buydialog.h Lines: 0 1 0.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_BUYDIALOG_H
24
#define GUI_WINDOWS_BUYDIALOG_H
25
26
#include "enums/resources/item/itemtype.h"
27
28
#include "enums/simpletypes/beingid.h"
29
#include "enums/simpletypes/itemcolor.h"
30
31
#include "gui/widgets/window.h"
32
33
#include "listeners/actionlistener.h"
34
#include "listeners/selectionlistener.h"
35
36
class Being;
37
class Button;
38
class DropDown;
39
class ShopItem;
40
class ShopItems;
41
class ShopListBox;
42
class SortListModelBuy;
43
class IntTextField;
44
class Label;
45
class ScrollArea;
46
class Slider;
47
class TextField;
48
49
/**
50
 * The buy dialog.
51
 *
52
 * \ingroup Interface
53
 */
54
class BuyDialog final : public Window,
55
                        public ActionListener,
56
                        public SelectionListener
57
{
58
    public:
59
        /**
60
         * Constructor.
61
         *
62
         * @see Window::Window
63
         */
64
        BuyDialog();
65
66
        /**
67
         * Constructor.
68
         *
69
         * @see Window::Window
70
         */
71
        BuyDialog(const BeingId npcId,
72
                  const std::string &currency);
73
74
#ifdef TMWA_SUPPORT
75
        /**
76
         * Constructor.
77
         *
78
         * @see Window::Window
79
         */
80
        BuyDialog(const std::string &nick,
81
                  const std::string &currency);
82
#endif  // TMWA_SUPPORT
83
84
        /**
85
         * Constructor.
86
         *
87
         * @see Window::Window
88
         */
89
        BuyDialog(const Being *const being,
90
                  const std::string &currency);
91
92
        A_DELETE_COPY(BuyDialog)
93
94
        /**
95
         * Destructor
96
         */
97
        ~BuyDialog();
98
99
        enum
100
        {
101
#ifdef TMWA_SUPPORT
102
            Nick    = -1,
103
#endif  // TMWA_SUPPORT
104
            Items   = -2,
105
            Market  = -3,
106
            Cash    = -4,
107
            Vending = -5
108
        };
109
110
        void init();
111
112
        /**
113
         * Resets the dialog, clearing shop inventory.
114
         */
115
        void reset();
116
117
        /**
118
         * Sets the amount of available money.
119
         */
120
        void setMoney(const int amount);
121
122
        /**
123
         * Adds an item to the shop inventory.
124
         */
125
        ShopItem *addItem(const int id,
126
                          const ItemTypeT type,
127
                          const ItemColor color,
128
                          const int amount,
129
                          const int price);
130
131
        /**
132
         * Called when receiving actions from the widgets.
133
         */
134
        void action(const ActionEvent &event) override final;
135
136
        /**
137
         * Returns the number of items in the shop inventory.
138
         */
139
        int getNumberOfElements() A_WARN_UNUSED;
140
141
        /**
142
         * Updates the labels according to the selected item.
143
         */
144
        void valueChanged(const SelectionEvent &event) override final;
145
146
        /**
147
         * Updates the state of buttons and labels.
148
         */
149
        void updateButtonsAndLabels();
150
151
        /**
152
         * Sets the visibility of this window.
153
         */
154
        void setVisible(Visible visible) override final;
155
156
        void sort();
157
158
        void close() override final;
159
160
        /**
161
         * Returns true if any instances exist.
162
         */
163
        static bool isActive() A_WARN_UNUSED
164
        { return !instances.empty(); }
165
166
        /**
167
         * Closes all instances.
168
         */
169
        static void closeAll();
170
171
    private:
172
        void updateSlider(const int selectedItem);
173
174
        void applyNameFilter(const std::string &filter);
175
176
        typedef std::list<BuyDialog*> DialogList;
177
        static DialogList instances;
178
179
        Button *mBuyButton A_NONNULLPOINTER;
180
        Button *mConfirmButton A_NONNULLPOINTER;
181
        Button *mQuitButton A_NONNULLPOINTER;
182
        Button *mAddMaxButton A_NONNULLPOINTER;
183
        Button *mIncreaseButton A_NONNULLPOINTER;
184
        Button *mDecreaseButton A_NONNULLPOINTER;
185
        ShopListBox *mShopItemList A_NONNULLPOINTER;
186
        ScrollArea *mScrollArea A_NONNULLPOINTER;
187
        Label *mMoneyLabel A_NONNULLPOINTER;
188
        Label *mQuantityLabel A_NONNULLPOINTER;
189
        Slider *mSlider A_NONNULLPOINTER;
190
        Label *mAmountLabel A_NONNULLPOINTER;
191
        IntTextField *mAmountField A_NONNULLPOINTER;
192
        ShopItems *mShopItems A_NONNULLPOINTER;
193
        SortListModelBuy *mSortModel;
194
        DropDown *mSortDropDown;
195
        TextField *mFilterTextField A_NONNULLPOINTER;
196
        Label *mFilterLabel;
197
198
        std::string mNick;
199
        std::string mCurrency;
200
        BeingId mNpcId;
201
        int mMoney;
202
        int mAmountItems;
203
        int mMaxItems;
204
        bool mAdvanced;
205
};
206
207
#endif  // GUI_WINDOWS_BUYDIALOG_H