Mana
Loading...
Searching...
No Matches
npcdialog.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "gui/widgets/window.h"
25
26#include <guichan/actionlistener.hpp>
27#include <guichan/listmodel.hpp>
28
29#include <list>
30#include <memory>
31#include <string>
32#include <vector>
33
34class BrowserBox;
35class ListBox;
36class TextField;
37class IntTextField;
38class ItemLinkHandler;
39class Button;
40
46class NpcDialog final : public Window,
47 public gcn::ActionListener,
48 public gcn::ListModel
49{
50 public:
51 NpcDialog(int npcId);
52
53 ~NpcDialog() override;
54
58 void action(const gcn::ActionEvent &event) override;
59
65 void setText(const std::vector<std::string> &string);
66
73 void addText(const std::string &string, bool save = true);
74
78 void showNextButton();
79
84 void showCloseButton();
85
89 void nextDialog();
90
95 void close() override;
96
100 int getNumberOfElements() override;
101
105 std::string getElementAt(int i) override;
106
110 void choiceRequest();
111
115 void addChoice(const std::string &);
116
120 void initChoiceSelection();
121
125 void textRequest(const std::string &defaultText = std::string());
126
127 bool isInputFocused() const;
128
129 bool isTextInputFocused() const;
130
131 static bool isAnyInputFocused();
132
136 void integerRequest(int defaultValue, int min, int max);
137
138 void move(int amount);
139
140 void setVisible(bool visible) override;
141
142 void mouseClicked(gcn::MouseEvent &mouseEvent) override;
143
148 static NpcDialog *getActive();
149
151 { return mActionState == NPC_ACTION_WAIT; }
152
156 static void closeAll();
157
158 static void setup();
159
160 private:
161 using DialogList = std::list<NpcDialog *>;
163
164 void buildLayout();
165
167
168 int mDefaultInt = 0;
169 std::string mDefaultString;
170
171 // Used for the main input area
172 gcn::ScrollArea *mScrollArea;
174 std::vector<std::string> mNewText;
175
176 std::unique_ptr<ItemLinkHandler> mItemLinkHandler;
177
178 // Used for choice input
180 gcn::ScrollArea *mListScrollArea;
181 std::vector<std::string> mItems;
182
183 // Used for string and integer input
188
190
191 // Used for the button
193
194 // Will reset the text and integer input to the provided default
196
204
212
215};
A simple browser box able to handle links and forward events to the parent conteiner.
Definition browserbox.h:74
Button widget.
Definition button.h:38
TextBox which only accepts numbers as input.
A list box, meant to be used inside a scroll area.
Definition listbox.h:36
The npc dialog.
Definition npcdialog.h:49
static bool isAnyInputFocused()
void initChoiceSelection()
Put focus on the first choice.
void addChoice(const std::string &)
Adds a choice to the list box.
gcn::ScrollArea * mScrollArea
Definition npcdialog.h:172
static DialogList instances
Definition npcdialog.h:162
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
void setVisible(bool visible) override
Overloads window setVisible by Guichan to allow sticky window handling.
~NpcDialog() override
void integerRequest(int defaultValue, int min, int max)
Requests an integer from the user.
BrowserBox * mTextBox
Definition npcdialog.h:173
void nextDialog()
Notifies the server that client has performed a next action.
Button * mMinusButton
Definition npcdialog.h:187
bool isWaitingForTheServer() const
Definition npcdialog.h:150
bool isTextInputFocused() const
void move(int amount)
static NpcDialog * getActive()
Returns the first active instance.
TextField * mTextField
Definition npcdialog.h:184
static void setup()
std::unique_ptr< ItemLinkHandler > mItemLinkHandler
Definition npcdialog.h:176
std::vector< std::string > mNewText
Definition npcdialog.h:174
IntTextField * mIntField
Definition npcdialog.h:185
Button * mClearButton
Definition npcdialog.h:189
void buildLayout()
void choiceRequest()
Makes this dialog request a choice selection from the user.
int mDefaultInt
Definition npcdialog.h:168
std::list< NpcDialog * > DialogList
Definition npcdialog.h:161
NpcActionState mActionState
Definition npcdialog.h:214
void showNextButton()
When called, the widget will show a "Next" button.
@ NPC_INPUT_LIST
Definition npcdialog.h:200
@ NPC_INPUT_NONE
Definition npcdialog.h:199
@ NPC_INPUT_STRING
Definition npcdialog.h:201
@ NPC_INPUT_INTEGER
Definition npcdialog.h:202
bool isInputFocused() const
Button * mResetButton
Definition npcdialog.h:195
std::vector< std::string > mItems
Definition npcdialog.h:181
ListBox * mItemList
Definition npcdialog.h:179
std::string mDefaultString
Definition npcdialog.h:169
Button * mNextButton
Definition npcdialog.h:192
@ NPC_ACTION_NEXT
Definition npcdialog.h:208
@ NPC_ACTION_CLOSE
Definition npcdialog.h:210
@ NPC_ACTION_WAIT
Definition npcdialog.h:207
@ NPC_ACTION_INPUT
Definition npcdialog.h:209
void setText(const std::vector< std::string > &string)
Sets the text shows in the dialog.
void showCloseButton()
When called, the widget will show a "Close" button and will close the dialog when clicked.
std::string getElementAt(int i) override
Returns the name of item number i of the choices list.
void mouseClicked(gcn::MouseEvent &mouseEvent) override
void textRequest(const std::string &defaultText=std::string())
Requests a text string from the user.
void addText(const std::string &string, bool save=true)
Adds the text to the text shows in the dialog.
static void closeAll()
Closes all instances.
Button * mPlusButton
Definition npcdialog.h:186
void close() override
Notifies the server that the client has performed a close action.
gcn::ScrollArea * mListScrollArea
Definition npcdialog.h:180
NpcInputState mInputState
Definition npcdialog.h:213
int getNumberOfElements() override
Returns the number of items in the choices list.
A text field.
Definition textfield.h:72
A window.
Definition window.h:59