GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/npcdialog.h Lines: 0 1 0.0 %
Date: 2021-03-17 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-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
27
#include "enums/simpletypes/beingid.h"
28
#include "enums/simpletypes/beingtypeid.h"
29
30
#include "enums/gui/npcactionstate.h"
31
#include "enums/gui/npcinputstate.h"
32
33
#include "gui/models/extendedlistmodel.h"
34
35
#include "gui/widgets/window.h"
36
37
#include "listeners/actionlistener.h"
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
60
/**
61
 * The npc dialog.
62
 *
63
 * \ingroup Interface
64
 */
65
class NpcDialog final : public Window,
66
                        public ActionListener,
67
                        public ExtendedListModel,
68
                        public ConfigListener
69
{
70
    public:
71
        /**
72
         * Constructor.
73
         *
74
         * @see Window::Window
75
         */
76
        explicit NpcDialog(const BeingId npcId);
77
78
        A_DELETE_COPY(NpcDialog)
79
80
        ~NpcDialog() override final;
81
82
        void postInit() override final;
83
84
        /**
85
         * Called when receiving actions from the widgets.
86
         */
87
        void action(const ActionEvent &event) override final;
88
89
        /**
90
        * Sets the text shows in the dialog.
91
        *
92
        * @param string The new text.
93
        */
94
//        void setText(const std::string &string);
95
96
        /**
97
         * Adds the text to the text shows in the dialog. Also adds a newline
98
         * to the end.
99
         *
100
         * @param string The text to add.
101
         */
102
        void addText(const std::string &string,
103
                     const bool save);
104
105
        /**
106
         * When called, the widget will show a "Next" button.
107
         */
108
        void showNextButton();
109
110
        /**
111
         * When called, the widget will show a "Close" button and will close
112
         * the dialog when clicked.
113
         */
114
        void showCloseButton();
115
116
        /**
117
         * Notifies the server that client has performed a next action.
118
         */
119
        void nextDialog();
120
121
        /**
122
         * Notifies the server that the client has performed a close action.
123
         */
124
        void closeDialog();
125
126
        /**
127
         * Returns the number of items in the choices list.
128
         */
129
        int getNumberOfElements() override final A_WARN_UNUSED;
130
131
        /**
132
         * Returns the name of item number i of the choices list.
133
         */
134
        std::string getElementAt(int i) override final A_WARN_UNUSED;
135
136
        /**
137
         * Returns the image of item number i of the choices list.
138
         */
139
        const Image *getImageAt(int i) override final A_WARN_UNUSED;
140
141
        /**
142
         * Makes this dialog request a choice selection from the user.
143
         */
144
        void choiceRequest();
145
146
        /**
147
         * Adds a choice to the list box.
148
         */
149
        void addChoice(const std::string &);
150
151
        /**
152
          * Fills the options list for an NPC dialog.
153
          *
154
          * @param itemString A string with the options separated with colons.
155
          */
156
        void parseListItems(const std::string &itemString);
157
158
        /**
159
         * Requests a text string from the user.
160
         */
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
169
        /**
170
         * Requests a interger from the user.
171
         */
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
188
        /**
189
         * Returns true if any instances exist.
190
         */
191
        static bool isActive() A_WARN_UNUSED
192
        { return !instances.empty(); }
193
194
        /**
195
         * Returns the first active instance. Useful for pushing user
196
         * interaction.
197
         */
198
        static NpcDialog *getActive() A_WARN_UNUSED;
199
200
        /**
201
         * Closes all instances.
202
         */
203
        static void closeAll();
204
205
        /**
206
         * Closes all instances and destroy also net handler dialogs.
207
         */
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
237
        NpcInputStateT getInputState()
238
        { return mInputState; }
239
240
        void copyToClipboard(const int x, const int y) const;
241
242
        static NpcDialogs mNpcDialogs;
243
244
        static void clearDialogs();
245
246
    private:
247
        typedef std::list<NpcDialog*> DialogList;
248
        static DialogList instances;
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
272
        BeingId mNpcId;
273
274
        int mDefaultInt;
275
        std::string mDefaultString;
276
277
        // Used for the main input area
278
        BrowserBox *mTextBox A_NONNULLPOINTER;
279
        ScrollArea *mScrollArea A_NONNULLPOINTER;
280
        std::string mText;
281
        std::string mNewText;
282
283
        // Used for choice input
284
        StringVect mItems;
285
        STD_VECTOR<Image *> mImages;
286
        ExtendedListBox *mItemList A_NONNULLPOINTER;
287
        ScrollArea *mListScrollArea A_NONNULLPOINTER;
288
        Container *mSkinContainer A_NONNULLPOINTER;
289
        ScrollArea *mSkinScrollArea A_NONNULLPOINTER;
290
        ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
291
292
        // Used for string and integer input
293
        TextField *mTextField A_NONNULLPOINTER;
294
        IntTextField *mIntField A_NONNULLPOINTER;
295
        Button *mPlusButton A_NONNULLPOINTER;
296
        Button *mMinusButton A_NONNULLPOINTER;
297
        Button *mClearButton A_NONNULLPOINTER;
298
299
        // Used for the button
300
        Button *mButton A_NONNULLPOINTER;
301
        Button *mButton2 A_NONNULLPOINTER;
302
        Button *mButton3 A_NONNULLPOINTER;
303
304
        // Will reset the text and integer input to the provided default
305
        Button *mResetButton A_NONNULLPOINTER;
306
307
        Inventory *mInventory A_NONNULLPOINTER;
308
        ComplexInventory *mComplexInventory A_NONNULLPOINTER;
309
        ItemContainer *mItemContainer A_NONNULLPOINTER;
310
        ScrollArea *mItemScrollArea A_NONNULLPOINTER;
311
312
        NpcInputStateT mInputState;
313
        NpcActionStateT mActionState;
314
        STD_VECTOR<Widget*> mSkinControls;
315
        std::string mSkinName;
316
        PlayerBox *mPlayerBox A_NONNULLPOINTER;
317
        Being *mAvatarBeing;
318
        const NpcDialogInfo *mDialogInfo;
319
        int mLastNextTime;
320
        int mCameraMode;
321
        int mCameraX;
322
        int mCameraY;
323
        bool mShowAvatar;
324
        bool mLogInteraction;
325
};
326
327
#endif  // GUI_WINDOWS_NPCDIALOG_H