GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/npcdialog.h Lines: 0 1 0.0 %
Date: 2018-09-20 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-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
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() override final;
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,
102
                     const bool save);
103
104
        /**
105
         * When called, the widget will show a "Next" button.
106
         */
107
        void showNextButton();
108
109
        /**
110
         * When called, the widget will show a "Close" button and will close
111
         * the dialog when clicked.
112
         */
113
        void showCloseButton();
114
115
        /**
116
         * Notifies the server that client has performed a next action.
117
         */
118
        void nextDialog();
119
120
        /**
121
         * Notifies the server that the client has performed a close action.
122
         */
123
        void closeDialog();
124
125
        /**
126
         * Returns the number of items in the choices list.
127
         */
128
        int getNumberOfElements() override final A_WARN_UNUSED;
129
130
        /**
131
         * Returns the name of item number i of the choices list.
132
         */
133
        std::string getElementAt(int i) override final A_WARN_UNUSED;
134
135
        /**
136
         * Returns the image of item number i of the choices list.
137
         */
138
        const Image *getImageAt(int i) override final A_WARN_UNUSED;
139
140
        /**
141
         * Makes this dialog request a choice selection from the user.
142
         */
143
        void choiceRequest();
144
145
        /**
146
         * Adds a choice to the list box.
147
         */
148
        void addChoice(const std::string &);
149
150
        /**
151
          * Fills the options list for an NPC dialog.
152
          *
153
          * @param itemString A string with the options separated with colons.
154
          */
155
        void parseListItems(const std::string &itemString);
156
157
        /**
158
         * Requests a text string from the user.
159
         */
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
168
        /**
169
         * Requests a interger from the user.
170
         */
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
187
        /**
188
         * Returns true if any instances exist.
189
         */
190
        static bool isActive() A_WARN_UNUSED
191
        { return !instances.empty(); }
192
193
        /**
194
         * Returns the first active instance. Useful for pushing user
195
         * interaction.
196
         */
197
        static NpcDialog *getActive() A_WARN_UNUSED;
198
199
        /**
200
         * Closes all instances.
201
         */
202
        static void closeAll();
203
204
        /**
205
         * Closes all instances and destroy also net handler dialogs.
206
         */
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
236
        NpcInputStateT getInputState()
237
        { return mInputState; }
238
239
        void copyToClipboard(const int x, const int y) const;
240
241
        static NpcDialogs mNpcDialogs;
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
271
        BeingId mNpcId;
272
273
        int mDefaultInt;
274
        std::string mDefaultString;
275
276
        // Used for the main input area
277
        BrowserBox *mTextBox A_NONNULLPOINTER;
278
        ScrollArea *mScrollArea A_NONNULLPOINTER;
279
        std::string mText;
280
        std::string mNewText;
281
282
        // Used for choice input
283
        StringVect mItems;
284
        STD_VECTOR<Image *> mImages;
285
        ExtendedListBox *mItemList A_NONNULLPOINTER;
286
        ScrollArea *mListScrollArea A_NONNULLPOINTER;
287
        Container *mSkinContainer A_NONNULLPOINTER;
288
        ScrollArea *mSkinScrollArea A_NONNULLPOINTER;
289
        ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
290
291
        // Used for string and integer input
292
        TextField *mTextField A_NONNULLPOINTER;
293
        IntTextField *mIntField A_NONNULLPOINTER;
294
        Button *mPlusButton A_NONNULLPOINTER;
295
        Button *mMinusButton A_NONNULLPOINTER;
296
        Button *mClearButton A_NONNULLPOINTER;
297
298
        // Used for the button
299
        Button *mButton A_NONNULLPOINTER;
300
        Button *mButton2 A_NONNULLPOINTER;
301
        Button *mButton3 A_NONNULLPOINTER;
302
303
        // Will reset the text and integer input to the provided default
304
        Button *mResetButton A_NONNULLPOINTER;
305
306
        Inventory *mInventory A_NONNULLPOINTER;
307
        ComplexInventory *mComplexInventory A_NONNULLPOINTER;
308
        ItemContainer *mItemContainer A_NONNULLPOINTER;
309
        ScrollArea *mItemScrollArea A_NONNULLPOINTER;
310
311
        NpcInputStateT mInputState;
312
        NpcActionStateT mActionState;
313
        STD_VECTOR<Widget*> mSkinControls;
314
        std::string mSkinName;
315
        PlayerBox *mPlayerBox A_NONNULLPOINTER;
316
        Being *mAvatarBeing;
317
        const NpcDialogInfo *mDialogInfo;
318
        int mLastNextTime;
319
        int mCameraMode;
320
        int mCameraX;
321
        int mCameraY;
322
        bool mShowAvatar;
323
        bool mLogInteraction;
324
};
325
326
#endif  // GUI_WINDOWS_NPCDIALOG_H