GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/npcdialog.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_NPCDIALOG_H
24
#define GUI_WINDOWS_NPCDIALOG_H
25
26
#include "enums/simpletypes/beingid.h"
27
#include "enums/simpletypes/beingtypeid.h"
28
29
#include "enums/gui/npcactionstate.h"
30
#include "enums/gui/npcinputstate.h"
31
32
#include "gui/models/extendedlistmodel.h"
33
34
#include "gui/widgets/window.h"
35
36
#include "listeners/actionlistener.h"
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
55
struct NpcDialogInfo;
56
57
typedef std::map<BeingId, NpcDialog*> NpcDialogs;
58
59
/**
60
 * The npc dialog.
61
 *
62
 * \ingroup Interface
63
 */
64
class NpcDialog final : public Window,
65
                        public ActionListener,
66
                        public ExtendedListModel,
67
                        public ConfigListener
68
{
69
    public:
70
        /**
71
         * Constructor.
72
         *
73
         * @see Window::Window
74
         */
75
        explicit NpcDialog(const BeingId npcId);
76
77
        A_DELETE_COPY(NpcDialog)
78
79
        ~NpcDialog();
80
81
        void postInit() override final;
82
83
        /**
84
         * Called when receiving actions from the widgets.
85
         */
86
        void action(const ActionEvent &event) override final;
87
88
        /**
89
        * Sets the text shows in the dialog.
90
        *
91
        * @param string The new text.
92
        */
93
//        void setText(const std::string &string);
94
95
        /**
96
         * Adds the text to the text shows in the dialog. Also adds a newline
97
         * to the end.
98
         *
99
         * @param string The text to add.
100
         */
101
        void addText(const std::string &string, const bool save = true);
102
103
        /**
104
         * When called, the widget will show a "Next" button.
105
         */
106
        void showNextButton();
107
108
        /**
109
         * When called, the widget will show a "Close" button and will close
110
         * the dialog when clicked.
111
         */
112
        void showCloseButton();
113
114
        /**
115
         * Notifies the server that client has performed a next action.
116
         */
117
        void nextDialog();
118
119
        /**
120
         * Notifies the server that the client has performed a close action.
121
         */
122
        void closeDialog();
123
124
        /**
125
         * Returns the number of items in the choices list.
126
         */
127
        int getNumberOfElements() override final A_WARN_UNUSED;
128
129
        /**
130
         * Returns the name of item number i of the choices list.
131
         */
132
        std::string getElementAt(int i) override final A_WARN_UNUSED;
133
134
        /**
135
         * Returns the image of item number i of the choices list.
136
         */
137
        const Image *getImageAt(int i) override final A_WARN_UNUSED;
138
139
        /**
140
         * Makes this dialog request a choice selection from the user.
141
         */
142
        void choiceRequest();
143
144
        /**
145
         * Adds a choice to the list box.
146
         */
147
        void addChoice(const std::string &);
148
149
        /**
150
          * Fills the options list for an NPC dialog.
151
          *
152
          * @param itemString A string with the options separated with colons.
153
          */
154
        void parseListItems(const std::string &itemString);
155
156
        /**
157
         * Requests a text string from the user.
158
         */
159
        void textRequest(const std::string &defaultText = "");
160
161
        bool isInputFocused() const A_WARN_UNUSED;
162
163
        bool isTextInputFocused() const A_WARN_UNUSED;
164
165
        static bool isAnyInputFocused() A_WARN_UNUSED;
166
167
        /**
168
         * Requests a interger from the user.
169
         */
170
        void integerRequest(const int defaultValue = 0, const int min = 0,
171
                            const int max = 2147483647);
172
173
        void itemRequest(const int size);
174
175
        void itemIndexRequest(const int size);
176
177
        void itemCraftRequest(const int size);
178
179
        void move(const int amount);
180
181
        void setVisible(Visible visible) override final;
182
183
        void optionChanged(const std::string &name) override final;
184
185
        /**
186
         * Returns true if any instances exist.
187
         */
188
        static bool isActive() A_WARN_UNUSED
189
        { return !instances.empty(); }
190
191
        /**
192
         * Returns the first active instance. Useful for pushing user
193
         * interaction.
194
         */
195
        static NpcDialog *getActive() A_WARN_UNUSED;
196
197
        /**
198
         * Closes all instances.
199
         */
200
        static void closeAll();
201
202
        /**
203
         * Closes all instances and destroy also net handler dialogs.
204
         */
205
        static void destroyAll();
206
207
        void saveCamera();
208
209
        void restoreCamera();
210
211
        void refocus();
212
213
        void showAvatar(const BeingTypeId avatarId);
214
215
        void setAvatarDirection(const uint8_t direction);
216
217
        void setAvatarAction(const int actionId);
218
219
        void logic() override final;
220
221
        void clearRows();
222
223
        void mousePressed(MouseEvent &event) override final;
224
225
        int isCloseState() const
226
        { return static_cast<int>(mActionState == NpcActionState::CLOSE); }
227
228
        void setSkin(const std::string &skin);
229
230
        void addCraftItem(Item *const item,
231
                          const int amount,
232
                          const int slot);
233
234
        NpcInputStateT getInputState()
235
        { return mInputState; }
236
237
        void copyToClipboard(const int x, const int y) const;
238
239
        static NpcDialogs mNpcDialogs;
240
241
        static void clearDialogs();
242
243
    private:
244
        typedef std::list<NpcDialog*> DialogList;
245
        static DialogList instances;
246
247
        void buildLayout();
248
249
        void placeNormalControls();
250
251
        void placeMenuControls();
252
253
        void placeSkinControls();
254
255
        void placeTextInputControls();
256
257
        void placeIntInputControls();
258
259
        void placeItemInputControls();
260
261
        void createSkinControls();
262
263
        void deleteSkinControls();
264
265
        void restoreVirtuals();
266
267
        std::string complexItemToStr(const ComplexItem *const item);
268
269
        BeingId mNpcId;
270
271
        int mDefaultInt;
272
        std::string mDefaultString;
273
274
        // Used for the main input area
275
        BrowserBox *mTextBox A_NONNULLPOINTER;
276
        ScrollArea *mScrollArea A_NONNULLPOINTER;
277
        std::string mText;
278
        std::string mNewText;
279
280
        // Used for choice input
281
        StringVect mItems;
282
        STD_VECTOR<Image *> mImages;
283
        ExtendedListBox *mItemList A_NONNULLPOINTER;
284
        ScrollArea *mListScrollArea A_NONNULLPOINTER;
285
        Container *mSkinContainer A_NONNULLPOINTER;
286
        ScrollArea *mSkinScrollArea A_NONNULLPOINTER;
287
        ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
288
289
        // Used for string and integer input
290
        TextField *mTextField A_NONNULLPOINTER;
291
        IntTextField *mIntField A_NONNULLPOINTER;
292
        Button *mPlusButton A_NONNULLPOINTER;
293
        Button *mMinusButton A_NONNULLPOINTER;
294
        Button *mClearButton A_NONNULLPOINTER;
295
296
        // Used for the button
297
        Button *mButton A_NONNULLPOINTER;
298
        Button *mButton2 A_NONNULLPOINTER;
299
        Button *mButton3 A_NONNULLPOINTER;
300
301
        // Will reset the text and integer input to the provided default
302
        Button *mResetButton A_NONNULLPOINTER;
303
304
        Inventory *mInventory A_NONNULLPOINTER;
305
        ComplexInventory *mComplexInventory A_NONNULLPOINTER;
306
        ItemContainer *mItemContainer A_NONNULLPOINTER;
307
        ScrollArea *mItemScrollArea A_NONNULLPOINTER;
308
309
        NpcInputStateT mInputState;
310
        NpcActionStateT mActionState;
311
        STD_VECTOR<Widget*> mSkinControls;
312
        std::string mSkinName;
313
        PlayerBox *mPlayerBox A_NONNULLPOINTER;
314
        Being *mAvatarBeing;
315
        const NpcDialogInfo *mDialogInfo;
316
        int mLastNextTime;
317
        int mCameraMode;
318
        int mCameraX;
319
        int mCameraY;
320
        bool mShowAvatar;
321
        bool mLogInteraction;
322
};
323
324
#endif  // GUI_WINDOWS_NPCDIALOG_H