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