Mana
Loading...
Searching...
No Matches
npcpostdialog.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-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#include "gui/npcpostdialog.h"
23
24#include "event.h"
25#include "playerinfo.h"
26
27#include "gui/widgets/button.h"
28#include "gui/widgets/label.h"
29#include "gui/widgets/textbox.h"
32
33#include "net/net.h"
34#include "net/npchandler.h"
35
36#include "utils/gettext.h"
37
39
41 Window(_("NPC")),
42 mNpcId(npcId)
43{
44 setContentSize(400, 180);
45
46 // create text field for receiver
47 gcn::Label *senderText = new Label(_("To:"));
48 senderText->setPosition(5, 5);
49 mSender = new TextField;
50 mSender->setPosition(senderText->getWidth() + 5, 5);
51 mSender->setWidth(65);
52
53 // create button for sending
54 auto *sendButton = new Button(_("Send"), "send", this);
55 sendButton->setPosition(400 - sendButton->getWidth(),
56 170 - sendButton->getHeight());
57 auto *cancelButton = new Button(_("Cancel"), "cancel", this);
58 cancelButton->setPosition(sendButton->getX() - (cancelButton->getWidth() + 2),
59 sendButton->getY());
60
61 // create textfield for letter
62 mText = new TextBox;
63 mText->setHeight(400 - (mSender->getHeight() + sendButton->getHeight()));
64 mText->setEditable(true);
65
66 // create scroll box for letter text
67 auto *scrollArea = new ScrollArea(mText);
68 scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
69 scrollArea->setDimension(gcn::Rectangle(
70 5, mSender->getHeight() + 5,
71 380, 140 - (mSender->getHeight() + sendButton->getHeight())));
72
73 add(senderText);
74 add(mSender);
75 add(scrollArea);
76 add(sendButton);
77 add(cancelButton);
78
79 center();
80
81 instances.push_back(this);
82 setVisible(true);
83
85}
86
92
93void NpcPostDialog::action(const gcn::ActionEvent &event)
94{
95 if (event.getId() == "send")
96 {
97 if (mSender->getText().empty() || mText->getText().empty())
98 {
99 serverNotice(_("Failed to send as sender or letter invalid."));
100 }
101 else
102 {
104 mSender->getText(),
105 mText->getText());
106 }
107 setVisible(false);
108 }
109 else if (event.getId() == "cancel")
110 {
111 setVisible(false);
112 }
113}
114
116{
117 Window::setVisible(visible);
118
119 if (!visible)
120 {
122 }
123}
124
126{
127 for (auto &instance : instances)
128 instance->close();
129}
Button widget.
Definition button.h:38
Label widget.
Definition label.h:34
virtual void sendLetter(int npcId, const std::string &recipient, const std::string &text)=0
static void closeAll()
Closes all instances.
TextField * mSender
TextBox * mText
static DialogList instances
NpcPostDialog(int npcId)
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
~NpcPostDialog() override
void setVisible(bool visible) override
Overloads window setVisible by Guichan to allow sticky window handling.
std::list< NpcPostDialog * > DialogList
A scroll area.
Definition scrollarea.h:38
A text box, meant to be used inside a scroll area.
Definition textbox.h:36
A text field.
Definition textfield.h:72
A window.
Definition window.h:59
void center()
Positions the window in the center of it's parent.
Definition window.cpp:768
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Definition window.cpp:282
void setContentSize(int width, int height)
Sets the size of this window.
Definition window.cpp:151
void scheduleDelete()
Schedule this window for deletion.
Definition window.cpp:299
void serverNotice(const std::string &message)
Definition event.h:319
#define _(s)
Definition gettext.h:38
NpcHandler * getNpcHandler()
Definition net.cpp:100
void setNPCPostCount(int count)
Sets the number of currently open NPC post windows.
int getNPCPostCount()
Returns the number of currently open NPC post windows.