00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/npcpostdialog.h"
00023
00024 #include "gui/widgets/button.h"
00025 #include "gui/widgets/chattab.h"
00026 #include "gui/widgets/label.h"
00027 #include "gui/widgets/textbox.h"
00028 #include "gui/widgets/textfield.h"
00029 #include "gui/widgets/scrollarea.h"
00030
00031 #include "npc.h"
00032
00033 #include "net/net.h"
00034 #include "net/npchandler.h"
00035
00036 #include "utils/gettext.h"
00037
00038 NpcPostDialog::NpcPostDialog():
00039 Window(_("NPC"))
00040 {
00041 setContentSize(400, 180);
00042
00043
00044 gcn::Label *senderText = new Label("To:");
00045 senderText->setPosition(5, 5);
00046 mSender = new TextField;
00047 mSender->setPosition(senderText->getWidth() + 5, 5);
00048 mSender->setWidth(65);
00049
00050
00051 Button *sendButton = new Button(_("Send"), "send", this);
00052 sendButton->setPosition(400-sendButton->getWidth(),
00053 170-sendButton->getHeight());
00054 Button *cancelButton = new Button(_("Cancel"), "cancel", this);
00055 cancelButton->setPosition(sendButton->getX() - (cancelButton->getWidth() + 2),
00056 sendButton->getY());
00057
00058
00059 mText = new TextBox;
00060 mText->setHeight(400 - (mSender->getHeight() + sendButton->getHeight()));
00061 mText->setEditable(true);
00062
00063
00064 ScrollArea *scrollArea = new ScrollArea(mText);
00065 scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
00066 scrollArea->setDimension(gcn::Rectangle(
00067 5, mSender->getHeight() + 5,
00068 380, 140 - (mSender->getHeight() + sendButton->getHeight())));
00069
00070 add(senderText);
00071 add(mSender);
00072 add(scrollArea);
00073 add(sendButton);
00074 add(cancelButton);
00075
00076 setLocationRelativeTo(getParent());
00077 }
00078
00079 void NpcPostDialog::action(const gcn::ActionEvent &event)
00080 {
00081 if (event.getId() == "send")
00082 {
00083 if (mSender->getText().empty() || mText->getText().empty())
00084 {
00085 localChatTab->chatLog("Failed to send as sender or letter invalid");
00086 }
00087 else
00088 {
00089 Net::getNpcHandler()->sendLetter(current_npc, mSender->getText(),
00090 mText->getText());
00091 }
00092 setVisible(false);
00093 clear();
00094 }
00095 else if (event.getId() == "cancel")
00096 {
00097 setVisible(false);
00098 clear();
00099 }
00100 }
00101
00102 void NpcPostDialog::clear()
00103 {
00104 mSender->setText("");
00105 mText->setText("");
00106 }