summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/commandhandler.cpp20
-rw-r--r--src/game.cpp27
-rw-r--r--src/gui/npcpostdialog.cpp101
-rw-r--r--src/gui/npcpostdialog.h (renamed from src/net/posthandler.h)33
-rw-r--r--src/net/gameserver/player.cpp8
-rw-r--r--src/net/gameserver/player.h1
-rw-r--r--src/net/npchandler.cpp10
-rw-r--r--src/net/posthandler.cpp80
-rw-r--r--src/net/protocol.h9
11 files changed, 167 insertions, 130 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dc190f25..20e615a4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -140,6 +140,8 @@ SET(SRCS
gui/newskill.h
gui/npclistdialog.cpp
gui/npclistdialog.h
+ gui/npcpostdialog.cpp
+ gui/npcpostdialog.h
gui/npc_text.cpp
gui/npc_text.h
gui/ok_dialog.cpp
@@ -249,8 +251,6 @@ SET(SRCS
net/partyhandler.h
net/playerhandler.cpp
net/playerhandler.h
- net/posthandler.cpp
- net/posthandler.h
net/protocol.h
net/tradehandler.cpp
net/tradehandler.h
diff --git a/src/Makefile.am b/src/Makefile.am
index de028f8e..aca42e7e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -92,6 +92,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
gui/newskill.h \
gui/npclistdialog.cpp \
gui/npclistdialog.h \
+ gui/npcpostdialog.cpp \
+ gui/npcpostdialog.h \
gui/npc_text.cpp \
gui/npc_text.h \
gui/ok_dialog.cpp \
@@ -201,8 +203,6 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
net/partyhandler.h \
net/playerhandler.cpp \
net/playerhandler.h \
- net/posthandler.cpp \
- net/posthandler.h \
net/protocol.h \
net/tradehandler.cpp \
net/tradehandler.h \
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index f142af36..5c7b5e52 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -89,26 +89,6 @@ void CommandHandler::handleCommand(const std::string &command)
{
handleOp(args);
}
- else if (type == "post")
- {
- std::string::size_type pos = args.find(' ');
- if (pos == std::string::npos)
- {
- chatWindow->chatLog("Please include the user and message");
- return;
- }
- std::string recipient(args, 0, pos);
- if (recipient == "")
- {
- chatWindow->chatLog("Invalid user");
- }
- std::string text(args, pos+1);
- if (text == "")
- {
- chatWindow->chatLog("Invalid message");
- }
- Net::GameServer::Player::sendLetter(recipient, text);
- }
else
{
chatWindow->chatLog("Unknown command");
diff --git a/src/game.cpp b/src/game.cpp
index 690cf727..421c8aac 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -63,6 +63,7 @@
#include "gui/minimap.h"
#include "gui/ministatus.h"
#include "gui/npclistdialog.h"
+#include "gui/npcpostdialog.h"
#include "gui/npc_text.h"
#include "gui/ok_dialog.h"
#include "gui/partywindow.h"
@@ -84,7 +85,6 @@
#include "net/network.h"
#include "net/npchandler.h"
#include "net/partyhandler.h"
-#include "net/posthandler.h"
#include "net/playerhandler.h"
#include "net/tradehandler.h"
#include "net/effecthandler.h"
@@ -118,6 +118,7 @@ BuySellDialog *buySellDialog;
InventoryWindow *inventoryWindow;
NpcListDialog *npcListDialog;
NpcTextDialog *npcTextDialog;
+NpcPostDialog *npcPostDialog;
SkillDialog *skillDialog;
MagicDialog *magicDialog;
//NewSkillDialog *newSkillWindow;
@@ -205,6 +206,7 @@ void createGuiWindows()
inventoryWindow = new InventoryWindow();
npcTextDialog = new NpcTextDialog();
npcListDialog = new NpcListDialog();
+ npcPostDialog = new NpcPostDialog();
skillDialog = new SkillDialog();
magicDialog = new MagicDialog();
//newSkillWindow = new NewSkillDialog();
@@ -254,6 +256,7 @@ void destroyGuiWindows()
delete inventoryWindow;
delete npcListDialog;
delete npcTextDialog;
+ delete npcPostDialog;
delete skillDialog;
delete magicDialog;
delete setupWindow;
@@ -280,7 +283,6 @@ Game::Game():
mNpcHandler(new NPCHandler()),
mPartyHandler(new PartyHandler()),
mPlayerHandler(new PlayerHandler()),
- mPostHandler(new PostHandler()),
mTradeHandler(new TradeHandler()),
mEffectHandler(new EffectHandler()),
mLogicCounterId(0), mSecondsCounterId(0)
@@ -328,7 +330,6 @@ Game::Game():
Net::registerHandler(mNpcHandler.get());
Net::registerHandler(mPartyHandler.get());
Net::registerHandler(mPlayerHandler.get());
- Net::registerHandler(mPostHandler.get());
Net::registerHandler(mTradeHandler.get());
Net::registerHandler(mEffectHandler.get());
}
@@ -498,6 +499,22 @@ void Game::handleInput()
keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE);
return;
}
+
+ // send straight to gui for certain windows
+ if (npcPostDialog->isVisible())
+ {
+ try
+ {
+ guiInput->pushInput(event);
+ }
+ catch (gcn::Exception e)
+ {
+ const char* err = e.getMessage().c_str();
+ logger->log("Warning: guichan input exception: %s", err);
+ }
+ return;
+ }
+
switch (event.key.keysym.sym)
{
case SDLK_F1:
@@ -535,8 +552,8 @@ void Game::handleInput()
}
// Don not focus chat input when quit dialog is active
- if(quitDialog != NULL && quitDialog->isVisible())
- break;
+ if(quitDialog != NULL && quitDialog->isVisible())
+ break;
// Close the Browser if opened
if (helpWindow->isVisible())
diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp
new file mode 100644
index 00000000..b50154a8
--- /dev/null
+++ b/src/gui/npcpostdialog.cpp
@@ -0,0 +1,101 @@
+/*
+ * The Mana World
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "npcpostdialog.h"
+#include "textfield.h"
+#include "button.h"
+#include "scrollarea.h"
+#include "chat.h"
+
+#include "../net/gameserver/player.h"
+#include "../utils/gettext.h"
+
+#include <guichan/widgets/label.hpp>
+
+NpcPostDialog::NpcPostDialog():
+ Window(_("NPC"))
+{
+ setContentSize(400, 180);
+
+ // create text field for receiver
+ gcn::Label *senderText = new gcn::Label("To:");
+ senderText->setPosition(5, 5);
+ mSender = new TextField();
+ mSender->setPosition(senderText->getWidth() + 5, 5);
+ mSender->setWidth(65);
+
+ // create button for sending
+ Button *sendButton = new Button(_("Send"), "send", this);
+ sendButton->setPosition(400-sendButton->getWidth(),
+ 170-sendButton->getHeight());
+ Button *cancelButton = new Button(_("Cancel"), "cancel", this);
+ cancelButton->setPosition(sendButton->getX() - (cancelButton->getWidth() + 2),
+ sendButton->getY());
+
+ // create textfield for letter
+ mText = new TextField();
+ mText->setHeight(400 - (mSender->getHeight() + sendButton->getHeight()));
+
+ // create scroll box for letter text
+ ScrollArea *scrollArea = new ScrollArea(mText);
+ scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ scrollArea->setDimension(gcn::Rectangle(
+ 5, mSender->getHeight() + 5,
+ 380, 140 - (mSender->getHeight() + sendButton->getHeight())));
+
+ add(senderText);
+ add(mSender);
+ add(scrollArea);
+ add(sendButton);
+ add(cancelButton);
+
+ setLocationRelativeTo(getParent());
+}
+
+void NpcPostDialog::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "send")
+ {
+ if (mSender->getText().empty() || mText->getText().empty())
+ {
+ chatWindow->chatLog("Failed to send as sender or letter invalid");
+ }
+ else
+ {
+ Net::GameServer::Player::sendLetter(mSender->getText(), mText->getText());
+ }
+ setVisible(false);
+ clear();
+ }
+ else if (event.getId() == "cancel")
+ {
+ setVisible(false);
+ clear();
+ }
+}
+
+void NpcPostDialog::clear()
+{
+ mSender->setText("");
+ mText->setText("");
+}
diff --git a/src/net/posthandler.h b/src/gui/npcpostdialog.h
index d46b8bce..33a3a8f7 100644
--- a/src/net/posthandler.h
+++ b/src/gui/npcpostdialog.h
@@ -1,6 +1,6 @@
/*
* The Mana World
- * Copyright 2009 The Mana World Development Team
+ * Copyright 2008 The Mana World Development Team
*
* This file is part of The Mana World.
*
@@ -21,17 +21,36 @@
* $Id$
*/
-#ifndef _TMW_NET_POSTHANDLER_H
-#define _TMW_NET_POSTHANDLER_H
+#ifndef _TMW_GUI_NPCPOSTDIALOG_H
+#define _TMW_GUI_NPCPOSTDIALOG_H
-#include "messagehandler.h"
+#include <guichan/actionlistener.hpp>
-class PostHandler : public MessageHandler
+#include "window.h"
+
+class TextField;
+
+class NpcPostDialog : public Window, public gcn::ActionListener
{
public:
- PostHandler();
+ /**
+ * Constructor
+ */
+ NpcPostDialog();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ /**
+ * Clear the contents of the dialog
+ */
+ void clear();
- void handleMessage(MessageIn &msg);
+private:
+ TextField *mText;
+ TextField *mSender;
};
#endif
diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp
index 79ada480..cd85447c 100644
--- a/src/net/gameserver/player.cpp
+++ b/src/net/gameserver/player.cpp
@@ -170,18 +170,12 @@ void Net::GameServer::Player::tradeWithNPC(int item, int amount)
void Net::GameServer::Player::sendLetter(const std::string &player,
const std::string &text)
{
- MessageOut msg(PGMSG_SEND_POST);
+ MessageOut msg(PGMSG_NPC_POST_SEND);
msg.writeString(player);
msg.writeString(text);
Net::GameServer::connection->send(msg);
}
-void Net::GameServer::Player::getLetters()
-{
- MessageOut msg(PGMSG_GET_POST);
- Net::GameServer::connection->send(msg);
-}
-
void Net::GameServer::Player::raiseAttribute(int attribute)
{
MessageOut msg(PGMSG_RAISE_ATTRIBUTE);
diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h
index 3eba8a13..75e28270 100644
--- a/src/net/gameserver/player.h
+++ b/src/net/gameserver/player.h
@@ -61,7 +61,6 @@ namespace Net
void tradeMoney(int amount);
void tradeWithNPC(int item, int amount);
void sendLetter(const std::string &player, const std::string &text);
- void getLetters();
void raiseAttribute(int attribute);
void lowerAttribute(int attribute);
void respawn();
diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp
index 58c2c9ed..4b08ed8d 100644
--- a/src/net/npchandler.cpp
+++ b/src/net/npchandler.cpp
@@ -30,15 +30,18 @@
#include "../npc.h"
#include "../gui/npclistdialog.h"
+#include "../gui/npcpostdialog.h"
#include "../gui/npc_text.h"
extern NpcListDialog *npcListDialog;
extern NpcTextDialog *npcTextDialog;
+extern NpcPostDialog *npcPostDialog;
NPCHandler::NPCHandler()
{
static const Uint16 _messages[] = {
GPMSG_NPC_CHOICE,
+ GPMSG_NPC_POST,
GPMSG_NPC_MESSAGE,
GPMSG_NPC_ERROR,
0
@@ -67,12 +70,19 @@ void NPCHandler::handleMessage(MessageIn &msg)
npcListDialog->setVisible(true);
break;
+ case GPMSG_NPC_POST:
+ npcTextDialog->setVisible(false);
+ npcPostDialog->clear();
+ npcPostDialog->setVisible(true);
+ break;
+
case GPMSG_NPC_ERROR:
current_npc = NULL;
case GPMSG_NPC_MESSAGE:
npcTextDialog->addText(msg.readString(msg.getUnreadLength()));
npcListDialog->setVisible(false);
npcTextDialog->setVisible(true);
+ npcPostDialog->setVisible(false);
break;
}
}
diff --git a/src/net/posthandler.cpp b/src/net/posthandler.cpp
deleted file mode 100644
index 673d8611..00000000
--- a/src/net/posthandler.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * The Mana World
- * Copyright 2009 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#include "posthandler.h"
-
-#include <string>
-#include <sstream>
-
-#include "messagein.h"
-#include "protocol.h"
-
-#include "../gui/chat.h"
-
-PostHandler::PostHandler()
-{
- static const Uint16 _messages[] = {
- GPMSG_SEND_POST_RESPONSE,
- GPMSG_GET_POST_RESPONSE,
- 0
- };
- handledMessages = _messages;
-}
-
-void PostHandler::handleMessage(MessageIn &msg)
-{
- switch (msg.getId())
- {
- case GPMSG_SEND_POST_RESPONSE:
- {
- if (msg.readInt8() == ERRMSG_OK)
- {
- chatWindow->chatLog("Post sent successfully");
- }
- else
- {
- chatWindow->chatLog("Unable to send post");
- }
- } break;
-
- case GPMSG_GET_POST_RESPONSE:
- {
- std::stringstream str;
- // get the name of the sender
- std::string sender = msg.readString();
-
- if (sender == "")
- {
- chatWindow->chatLog("No post found");
- break;
- }
-
- // get the message
- std::string letter = msg.readString();
-
- // put message together
- str << "Message from " << sender << " says: " << letter;
- chatWindow->chatLog(str.str());
- } break;
- }
-}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index bbc7d2d2..c0bffb50 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -117,6 +117,9 @@ enum {
GPMSG_NPC_SELL = 0x02B6, // W being id, { W item id, W amount, W cost }*
PGMSG_NPC_BUYSELL = 0x02B7, // W item id, W amount
GPMSG_NPC_ERROR = 0x02B8, // B error
+ GPMSG_NPC_POST = 0x02D0, // W being id
+ PGMSG_NPC_POST_SEND = 0x02D1, // S name, S text, W item id
+ GPMSG_NPC_POST_GET = 0x02D2, // W being id, { S name, S text, W item id }
PGMSG_TRADE_REQUEST = 0x02C0, // W being id
GPMSG_TRADE_REQUEST = 0x02C1, // W being id
GPMSG_TRADE_START = 0x02C2, // -
@@ -184,12 +187,6 @@ enum {
PCMSG_USER_MODE = 0x0465, // W channel id, S name, B mode
PCMSG_KICK_USER = 0x0466, // W channel id, S name
- // Post
- PGMSG_SEND_POST = 0x04A0, // S player, S letter, { W attachment id }
- GPMSG_SEND_POST_RESPONSE = 0x04A1, // B error
- PGMSG_GET_POST = 0x04A2, //
- GPMSG_GET_POST_RESPONSE = 0x04A3, // { S sender name, S letter, { W attachment id } }
-
XXMSG_INVALID = 0x7FFF
};