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-2018 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_NPCDIALOG_H
24 #define GUI_WINDOWS_NPCDIALOG_H
25 
28 
31 
33 
34 #include "gui/widgets/window.h"
35 
37 
38 class Being;
39 class Button;
40 class BrowserBox;
41 class ComplexInventory;
42 class ComplexItem;
43 class Container;
44 class ExtendedListBox;
45 class Item;
46 class ItemLinkHandler;
47 class Inventory;
48 class IntTextField;
49 class ItemContainer;
50 class NpcDialog;
51 class PlayerBox;
52 class ScrollArea;
53 class TextField;
54 
56 
57 typedef std::map<BeingId, NpcDialog*> NpcDialogs;
58 
64 class NpcDialog final : public Window,
65  public ActionListener,
66  public ExtendedListModel,
67  public ConfigListener
68 {
69  public:
75  explicit NpcDialog(const BeingId npcId);
76 
78 
79  ~NpcDialog() override final;
80 
81  void postInit() override final;
82 
86  void action(const ActionEvent &event) override final;
87 
93 // void setText(const std::string &string);
94 
101  void addText(const std::string &string,
102  const bool save);
103 
107  void showNextButton();
108 
113  void showCloseButton();
114 
118  void nextDialog();
119 
123  void closeDialog();
124 
128  int getNumberOfElements() override final A_WARN_UNUSED;
129 
133  std::string getElementAt(int i) override final A_WARN_UNUSED;
134 
138  const Image *getImageAt(int i) override final A_WARN_UNUSED;
139 
143  void choiceRequest();
144 
148  void addChoice(const std::string &);
149 
155  void parseListItems(const std::string &itemString);
156 
160  void textRequest(const std::string &defaultText);
161 
162  bool isInputFocused() const A_WARN_UNUSED;
163 
164  bool isTextInputFocused() const A_WARN_UNUSED;
165 
166  static bool isAnyInputFocused() A_WARN_UNUSED;
167 
171  void integerRequest(const int defaultValue,
172  const int min,
173  const int max);
174 
175  void itemRequest(const int size);
176 
177  void itemIndexRequest(const int size);
178 
179  void itemCraftRequest(const int size);
180 
181  void move(const int amount);
182 
183  void setVisible(Visible visible) override final;
184 
185  void optionChanged(const std::string &name) override final;
186 
190  static bool isActive() A_WARN_UNUSED
191  { return !instances.empty(); }
192 
198 
202  static void closeAll();
203 
207  static void destroyAll();
208 
209  void saveCamera();
210 
211  void restoreCamera();
212 
213  void refocus();
214 
215  void showAvatar(const BeingTypeId avatarId);
216 
217  void setAvatarDirection(const uint8_t direction);
218 
219  void setAvatarAction(const int actionId);
220 
221  void logic() override final;
222 
223  void clearRows();
224 
225  void mousePressed(MouseEvent &event) override final;
226 
227  int isCloseState() const
228  { return static_cast<int>(mActionState == NpcActionState::CLOSE); }
229 
230  void setSkin(const std::string &skin);
231 
232  void addCraftItem(Item *const item,
233  const int amount,
234  const int slot);
235 
237  { return mInputState; }
238 
239  void copyToClipboard(const int x, const int y) const;
240 
242 
243  static void clearDialogs();
244 
245  private:
246  typedef std::list<NpcDialog*> DialogList;
247  static DialogList instances;
248 
249  void buildLayout();
250 
251  void placeNormalControls();
252 
253  void placeMenuControls();
254 
255  void placeSkinControls();
256 
257  void placeTextInputControls();
258 
259  void placeIntInputControls();
260 
261  void placeItemInputControls();
262 
263  void createSkinControls();
264 
265  void deleteSkinControls();
266 
267  void restoreVirtuals();
268 
269  std::string complexItemToStr(const ComplexItem *const item);
270 
272 
274  std::string mDefaultString;
275 
276  // Used for the main input area
279  std::string mText;
280  std::string mNewText;
281 
282  // Used for choice input
284  STD_VECTOR<Image *> mImages;
290 
291  // Used for string and integer input
297 
298  // Used for the button
302 
303  // Will reset the text and integer input to the provided default
305 
310 
313  STD_VECTOR<Widget*> mSkinControls;
314  std::string mSkinName;
320  int mCameraX;
321  int mCameraY;
324 };
325 
326 #endif // GUI_WINDOWS_NPCDIALOG_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
static bool isActive()
Definition: npcdialog.h:190
NpcActionState ::T NpcActionStateT
void optionChanged(const std::string &name)
Definition: npcdialog.cpp:845
void addChoice(const std::string &)
Definition: npcdialog.cpp:699
void deleteSkinControls()
Definition: npcdialog.cpp:1269
static void destroyAll()
void placeNormalControls()
Definition: npcdialog.cpp:874
void addText(const std::string &string, const bool save)
Definition: npcdialog.cpp:290
Button * mButton2
Definition: npcdialog.h:300
NpcActionStateT mActionState
Definition: npcdialog.h:312
#define A_NONNULLPOINTER
Definition: localconsts.h:257
void showNextButton()
Definition: npcdialog.cpp:306
NpcInputStateT getInputState()
Definition: npcdialog.h:236
void move(const int amount)
Definition: npcdialog.cpp:814
std::string complexItemToStr(const ComplexItem *const item)
Definition: npcdialog.cpp:1350
BeingId mNpcId
Definition: npcdialog.h:271
static NpcDialog * getActive()
Definition: npcdialog.cpp:851
int isCloseState() const
Definition: npcdialog.h:227
ComplexInventory * mComplexInventory
Definition: npcdialog.h:307
void restoreVirtuals()
Definition: npcdialog.cpp:1343
#define A_WARN_UNUSED
Definition: localconsts.h:152
std::string mDefaultString
Definition: npcdialog.h:274
Definition: window.h:98
StringVect mItems
Definition: npcdialog.h:283
ItemContainer * mItemContainer
Definition: npcdialog.h:308
Definition: button.h:96
#define final
Definition: localconsts.h:45
int BeingId
Definition: beingid.h:29
void choiceRequest()
Definition: npcdialog.cpp:685
void setVisible(Visible visible)
Definition: npcdialog.cpp:837
void integerRequest(const int defaultValue, const int min, const int max)
Definition: npcdialog.cpp:778
ScrollArea * mScrollArea
Definition: npcdialog.h:278
Button * mButton3
Definition: npcdialog.h:301
const Image * getImageAt(int i)
Definition: npcdialog.cpp:680
void placeTextInputControls()
Definition: npcdialog.cpp:947
void postInit()
Definition: npcdialog.cpp:223
std::vector< std::string > StringVect
Definition: stringvector.h:28
void setAvatarDirection(const uint8_t direction)
Definition: npcdialog.cpp:1176
void copyToClipboard(const int x, const int y) const
Definition: npcdialog.cpp:1244
void setSkin(const std::string &skin)
Definition: npcdialog.cpp:1250
Button * mResetButton
Definition: npcdialog.h:304
int getNumberOfElements()
Definition: npcdialog.cpp:670
std::list< NpcDialog * > DialogList
Definition: npcdialog.h:246
NpcInputState ::T NpcInputStateT
Definition: npcinputstate.h:38
void restoreCamera()
Definition: npcdialog.cpp:1114
IntTextField * mIntField
Definition: npcdialog.h:293
void itemCraftRequest(const int size)
Definition: npcdialog.cpp:806
std::map< BeingId, NpcDialog * > NpcDialogs
Definition: npcdialog.h:55
void buildLayout()
Definition: npcdialog.cpp:1051
void placeMenuControls()
Definition: npcdialog.cpp:891
void nextDialog()
Definition: npcdialog.cpp:659
void clearRows()
Definition: npcdialog.cpp:1211
void placeSkinControls()
Definition: npcdialog.cpp:912
int mCameraX
Definition: npcdialog.h:320
void logic()
Definition: npcdialog.cpp:1190
static NpcDialogs mNpcDialogs
Definition: npcdialog.h:241
std::string getElementAt(int i)
Definition: npcdialog.cpp:675
BrowserBox * mTextBox
Definition: npcdialog.h:277
const NpcDialogInfo * mDialogInfo
Definition: npcdialog.h:317
void closeDialog()
Definition: npcdialog.cpp:664
void createSkinControls()
Definition: npcdialog.cpp:1274
Definition: item.h:48
std::vector< Image * > mImages
Definition: npcdialog.h:284
static void closeAll()
Definition: npcdialog.cpp:865
void refocus()
Definition: npcdialog.cpp:740
Being * mAvatarBeing
Definition: npcdialog.h:316
void parseListItems(const std::string &itemString)
Definition: npcdialog.cpp:705
bool isTextInputFocused() const
Definition: npcdialog.cpp:756
std::string mSkinName
Definition: npcdialog.h:314
static bool isAnyInputFocused()
Definition: npcdialog.cpp:767
std::string mText
Definition: npcdialog.h:279
void showAvatar(const BeingTypeId avatarId)
Definition: npcdialog.cpp:1129
int mCameraY
Definition: npcdialog.h:321
int mLastNextTime
Definition: npcdialog.h:318
Button * mClearButton
Definition: npcdialog.h:296
Inventory * mInventory
Definition: npcdialog.h:306
ScrollArea * mSkinScrollArea
Definition: npcdialog.h:288
void saveCamera()
Definition: npcdialog.cpp:1104
int mDefaultInt
Definition: npcdialog.h:273
NpcInputStateT mInputState
Definition: npcdialog.h:311
static DialogList instances
Definition: npcdialog.h:247
ExtendedListBox * mItemList
Definition: npcdialog.h:285
static void clearDialogs()
Definition: npcdialog.cpp:1216
bool mShowAvatar
Definition: npcdialog.h:322
Container * mSkinContainer
Definition: npcdialog.h:287
void showCloseButton()
Definition: npcdialog.cpp:312
NpcDialog(const BeingId npcId)
Definition: npcdialog.cpp:97
std::string mNewText
Definition: npcdialog.h:280
int mCameraMode
Definition: npcdialog.h:319
ItemLinkHandler * mItemLinkHandler
Definition: npcdialog.h:289
ScrollArea * mItemScrollArea
Definition: npcdialog.h:309
void textRequest(const std::string &defaultText)
Definition: npcdialog.cpp:746
void placeIntInputControls()
Definition: npcdialog.cpp:968
Definition: image.h:61
void action(const ActionEvent &event)
Definition: npcdialog.cpp:318
void mousePressed(MouseEvent &event)
Definition: npcdialog.cpp:1228
std::vector< Widget * > mSkinControls
Definition: npcdialog.h:313
void setAvatarAction(const int actionId)
Definition: npcdialog.cpp:1183
void placeItemInputControls()
Definition: npcdialog.cpp:993
void itemIndexRequest(const int size)
Definition: npcdialog.cpp:798
Button * mMinusButton
Definition: npcdialog.h:295
Button * mButton
Definition: npcdialog.h:299
void addCraftItem(Item *const item, const int amount, const int slot)
Definition: npcdialog.cpp:1381
int BeingTypeId
Definition: beingtypeid.h:29
Definition: being.h:93
void itemRequest(const int size)
Definition: npcdialog.cpp:790
ScrollArea * mListScrollArea
Definition: npcdialog.h:286
PlayerBox * mPlayerBox
Definition: npcdialog.h:315
bool isInputFocused() const
Definition: npcdialog.cpp:761
TextField * mTextField
Definition: npcdialog.h:292
bool mLogInteraction
Definition: npcdialog.h:323
Button * mPlusButton
Definition: npcdialog.h:294