ManaPlus
npcdialog.h
Go to the documentation of this file.
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_NPCDIALOG_H
25 #define GUI_WINDOWS_NPCDIALOG_H
26 
29 
32 
34 
35 #include "gui/widgets/window.h"
36 
38 
39 class Being;
40 class Button;
41 class BrowserBox;
42 class ComplexInventory;
43 class ComplexItem;
44 class Container;
45 class ExtendedListBox;
46 class Item;
47 class ItemLinkHandler;
48 class Inventory;
49 class IntTextField;
50 class ItemContainer;
51 class NpcDialog;
52 class PlayerBox;
53 class ScrollArea;
54 class TextField;
55 
56 struct NpcDialogInfo;
57 
58 typedef std::map<BeingId, NpcDialog*> NpcDialogs;
59 
65 class NpcDialog final : public Window,
66  public ActionListener,
67  public ExtendedListModel,
68  public ConfigListener
69 {
70  public:
76  explicit NpcDialog(const BeingId npcId);
77 
79 
80  ~NpcDialog() override final;
81 
82  void postInit() override final;
83 
87  void action(const ActionEvent &event) override final;
88 
94 // void setText(const std::string &string);
95 
102  void addText(const std::string &string,
103  const bool save);
104 
108  void showNextButton();
109 
114  void showCloseButton();
115 
119  void nextDialog();
120 
124  void closeDialog();
125 
129  int getNumberOfElements() override final A_WARN_UNUSED;
130 
134  std::string getElementAt(int i) override final A_WARN_UNUSED;
135 
139  const Image *getImageAt(int i) override final A_WARN_UNUSED;
140 
144  void choiceRequest();
145 
149  void addChoice(const std::string &);
150 
156  void parseListItems(const std::string &itemString);
157 
161  void textRequest(const std::string &defaultText);
162 
163  bool isInputFocused() const A_WARN_UNUSED;
164 
165  bool isTextInputFocused() const A_WARN_UNUSED;
166 
167  static bool isAnyInputFocused() A_WARN_UNUSED;
168 
172  void integerRequest(const int defaultValue,
173  const int min,
174  const int max);
175 
176  void itemRequest(const int size);
177 
178  void itemIndexRequest(const int size);
179 
180  void itemCraftRequest(const int size);
181 
182  void move(const int amount);
183 
184  void setVisible(Visible visible) override final;
185 
186  void optionChanged(const std::string &name) override final;
187 
191  static bool isActive() A_WARN_UNUSED
192  { return !instances.empty(); }
193 
199 
203  static void closeAll();
204 
208  static void destroyAll();
209 
210  void saveCamera();
211 
212  void restoreCamera();
213 
214  void refocus();
215 
216  void showAvatar(const BeingTypeId avatarId);
217 
218  void setAvatarDirection(const uint8_t direction);
219 
220  void setAvatarAction(const int actionId);
221 
222  void logic() override final;
223 
224  void clearRows();
225 
226  void mousePressed(MouseEvent &event) override final;
227 
228  int isCloseState() const
229  { return static_cast<int>(mActionState == NpcActionState::CLOSE); }
230 
231  void setSkin(const std::string &skin);
232 
233  void addCraftItem(Item *const item,
234  const int amount,
235  const int slot);
236 
238  { return mInputState; }
239 
240  void copyToClipboard(const int x, const int y) const;
241 
243 
244  static void clearDialogs();
245 
246  private:
247  typedef std::list<NpcDialog*> DialogList;
249 
250  void buildLayout();
251 
252  void placeNormalControls();
253 
254  void placeMenuControls();
255 
256  void placeSkinControls();
257 
258  void placeTextInputControls();
259 
260  void placeIntInputControls();
261 
262  void placeItemInputControls();
263 
264  void createSkinControls();
265 
266  void deleteSkinControls();
267 
268  static void restoreVirtuals();
269 
270  static std::string complexItemToStr(const ComplexItem *const item);
271 
273 
275  std::string mDefaultString;
276 
277  // Used for the main input area
280  std::string mText;
281  std::string mNewText;
282 
283  // Used for choice input
285  STD_VECTOR<Image *> mImages;
291 
292  // Used for string and integer input
298 
299  // Used for the button
303 
304  // Will reset the text and integer input to the provided default
306 
311 
314  STD_VECTOR<Widget*> mSkinControls;
315  std::string mSkinName;
321  int mCameraX;
322  int mCameraY;
325 };
326 
327 #endif // GUI_WINDOWS_NPCDIALOG_H
int BeingId
Definition: beingid.h:30
int BeingTypeId
Definition: beingtypeid.h:30
Definition: being.h:96
Definition: button.h:102
Definition: item.h:50
static bool isAnyInputFocused()
Definition: npcdialog.cpp:768
void postInit()
Definition: npcdialog.cpp:224
void itemRequest(const int size)
Definition: npcdialog.cpp:791
void logic()
Definition: npcdialog.cpp:1191
void placeIntInputControls()
Definition: npcdialog.cpp:969
void addChoice(const std::string &)
Definition: npcdialog.cpp:700
std::string getElementAt(int i)
Definition: npcdialog.cpp:676
void copyToClipboard(const int x, const int y) const
Definition: npcdialog.cpp:1245
void placeMenuControls()
Definition: npcdialog.cpp:892
ExtendedListBox * mItemList
Definition: npcdialog.h:286
static DialogList instances
Definition: npcdialog.h:248
std::string mSkinName
Definition: npcdialog.h:315
void textRequest(const std::string &defaultText)
Definition: npcdialog.cpp:747
void deleteSkinControls()
Definition: npcdialog.cpp:1270
bool mLogInteraction
Definition: npcdialog.h:324
std::string mNewText
Definition: npcdialog.h:281
void placeSkinControls()
Definition: npcdialog.cpp:913
BrowserBox * mTextBox
Definition: npcdialog.h:278
void placeNormalControls()
Definition: npcdialog.cpp:875
void nextDialog()
Definition: npcdialog.cpp:660
Button * mButton2
Definition: npcdialog.h:301
void setSkin(const std::string &skin)
Definition: npcdialog.cpp:1251
std::list< NpcDialog * > DialogList
Definition: npcdialog.h:247
Button * mMinusButton
Definition: npcdialog.h:296
void addText(const std::string &string, const bool save)
Definition: npcdialog.cpp:291
void createSkinControls()
Definition: npcdialog.cpp:1275
NpcInputStateT getInputState()
Definition: npcdialog.h:237
void placeTextInputControls()
Definition: npcdialog.cpp:948
bool isTextInputFocused() const
Definition: npcdialog.cpp:757
void itemCraftRequest(const int size)
Definition: npcdialog.cpp:807
void addCraftItem(Item *const item, const int amount, const int slot)
Definition: npcdialog.cpp:1382
ScrollArea * mItemScrollArea
Definition: npcdialog.h:310
void saveCamera()
Definition: npcdialog.cpp:1105
static std::string complexItemToStr(const ComplexItem *const item)
Definition: npcdialog.cpp:1351
void itemIndexRequest(const int size)
Definition: npcdialog.cpp:799
int mCameraX
Definition: npcdialog.h:321
ComplexInventory * mComplexInventory
Definition: npcdialog.h:308
const NpcDialogInfo * mDialogInfo
Definition: npcdialog.h:318
static NpcDialog * getActive()
Definition: npcdialog.cpp:852
TextField * mTextField
Definition: npcdialog.h:293
Inventory * mInventory
Definition: npcdialog.h:307
PlayerBox * mPlayerBox
Definition: npcdialog.h:316
void parseListItems(const std::string &itemString)
Definition: npcdialog.cpp:706
NpcDialog(const BeingId npcId)
Definition: npcdialog.cpp:98
IntTextField * mIntField
Definition: npcdialog.h:294
Button * mClearButton
Definition: npcdialog.h:297
Being * mAvatarBeing
Definition: npcdialog.h:317
int isCloseState() const
Definition: npcdialog.h:228
ItemLinkHandler * mItemLinkHandler
Definition: npcdialog.h:290
void mousePressed(MouseEvent &event)
Definition: npcdialog.cpp:1229
void placeItemInputControls()
Definition: npcdialog.cpp:994
void move(const int amount)
Definition: npcdialog.cpp:815
void buildLayout()
Definition: npcdialog.cpp:1052
void choiceRequest()
Definition: npcdialog.cpp:686
int mDefaultInt
Definition: npcdialog.h:274
Button * mButton
Definition: npcdialog.h:300
void setAvatarAction(const int actionId)
Definition: npcdialog.cpp:1184
void refocus()
Definition: npcdialog.cpp:741
void setVisible(Visible visible)
Definition: npcdialog.cpp:838
void showNextButton()
Definition: npcdialog.cpp:307
std::string mText
Definition: npcdialog.h:280
int mLastNextTime
Definition: npcdialog.h:319
ScrollArea * mListScrollArea
Definition: npcdialog.h:287
Button * mButton3
Definition: npcdialog.h:302
bool mShowAvatar
Definition: npcdialog.h:323
bool isInputFocused() const
Definition: npcdialog.cpp:762
static void destroyAll()
std::vector< Image * > mImages
Definition: npcdialog.h:285
Button * mResetButton
Definition: npcdialog.h:305
void showAvatar(const BeingTypeId avatarId)
Definition: npcdialog.cpp:1130
ScrollArea * mSkinScrollArea
Definition: npcdialog.h:289
NpcInputStateT mInputState
Definition: npcdialog.h:312
std::string mDefaultString
Definition: npcdialog.h:275
int getNumberOfElements()
Definition: npcdialog.cpp:671
static bool isActive()
Definition: npcdialog.h:191
void setAvatarDirection(const uint8_t direction)
Definition: npcdialog.cpp:1177
StringVect mItems
Definition: npcdialog.h:284
static NpcDialogs mNpcDialogs
Definition: npcdialog.h:242
void showCloseButton()
Definition: npcdialog.cpp:313
ScrollArea * mScrollArea
Definition: npcdialog.h:279
static void restoreVirtuals()
Definition: npcdialog.cpp:1344
void clearRows()
Definition: npcdialog.cpp:1212
NpcActionStateT mActionState
Definition: npcdialog.h:313
void restoreCamera()
Definition: npcdialog.cpp:1115
static void clearDialogs()
Definition: npcdialog.cpp:1217
static void closeAll()
Definition: npcdialog.cpp:866
Button * mPlusButton
Definition: npcdialog.h:295
void optionChanged(const std::string &name)
Definition: npcdialog.cpp:846
std::vector< Widget * > mSkinControls
Definition: npcdialog.h:314
int mCameraMode
Definition: npcdialog.h:320
BeingId mNpcId
Definition: npcdialog.h:272
void closeDialog()
Definition: npcdialog.cpp:665
ItemContainer * mItemContainer
Definition: npcdialog.h:309
Container * mSkinContainer
Definition: npcdialog.h:288
void action(const ActionEvent &event)
Definition: npcdialog.cpp:319
int mCameraY
Definition: npcdialog.h:322
const Image * getImageAt(int i)
Definition: npcdialog.cpp:681
void integerRequest(const int defaultValue, const int min, const int max)
Definition: npcdialog.cpp:779
Definition: window.h:102
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
int size()
Definition: emotedb.cpp:306
NpcActionState ::T NpcActionStateT
std::map< BeingId, NpcDialog * > NpcDialogs
Definition: npcdialog.h:56
NpcInputState ::T NpcInputStateT
Definition: npcinputstate.h:39
std::vector< std::string > StringVect
Definition: stringvector.h:29
bool Visible
Definition: visible.h:30