summaryrefslogtreecommitdiff
path: root/src/net/tmwa
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tmwa')
-rw-r--r--src/net/tmwa/npchandler.cpp132
-rw-r--r--src/net/tmwa/npchandler.h11
-rw-r--r--src/net/tmwa/playerhandler.cpp7
3 files changed, 63 insertions, 87 deletions
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index bd655fa6..485a8ff7 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -22,10 +22,9 @@
#include "net/tmwa/npchandler.h"
#include "actorspritemanager.h"
+#include "eventmanager.h"
#include "localplayer.h"
-#include "gui/npcdialog.h"
-
#include "net/messagein.h"
#include "net/messageout.h"
#include "net/net.h"
@@ -33,10 +32,27 @@
#include "net/tmwa/protocol.h"
+#include "utils/stringutils.h"
+
#include <SDL_types.h>
extern Net::NpcHandler *npcHandler;
+static void parseMenu(Mana::Event *event, const std::string &options)
+{
+ std::istringstream iss(options);
+
+ int count = 0;
+ std::string tmp;
+ while (getline(iss, tmp, ':'))
+ {
+ count++;
+ event->setString("choice" + toString(count), tmp);
+ }
+
+ event->setInt("choiceCount", count);
+}
+
namespace TmwAthena {
NpcHandler::NpcHandler()
@@ -62,67 +78,55 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
}
int npcId = msg.readInt32();
- NpcDialogs::iterator diag = mNpcDialogs.find(npcId);
- NpcDialog *dialog = 0;
-
- if (diag == mNpcDialogs.end())
- {
- // Empty dialogs don't help
- if (msg.getId() == SMSG_NPC_CLOSE)
- {
- closeDialog(npcId);
- return;
- }
- else if (msg.getId() == SMSG_NPC_NEXT)
- {
- nextDialog(npcId);
- return;
- }
- else
- {
- dialog = new NpcDialog(npcId);
- Wrapper wrap;
- wrap.dialog = dialog;
- mNpcDialogs[npcId] = wrap;
- }
- }
- else
- {
- dialog = diag->second.dialog;
- }
+ Mana::Event *event = 0;
switch (msg.getId())
{
- case SMSG_NPC_CHOICE:
- dialog->choiceRequest();
- dialog->parseListItems(msg.readString(msg.getLength() - 8));
- break;
-
- case SMSG_NPC_MESSAGE:
- dialog->addText(msg.readString(msg.getLength() - 8));
- break;
-
- case SMSG_NPC_CLOSE:
- // Show the close button
- dialog->showCloseButton();
- break;
-
- case SMSG_NPC_NEXT:
- // Show the next button
- dialog->showNextButton();
- break;
-
- case SMSG_NPC_INT_INPUT:
- // Request for an integer
- dialog->integerRequest(0);
- break;
-
- case SMSG_NPC_STR_INPUT:
- // Request for a string
- dialog->textRequest("");
- break;
+ case SMSG_NPC_CHOICE:
+ event = new Mana::Event("Menu");
+ event->setInt("id", npcId);
+ parseMenu(event, msg.readString(msg.getLength() - 8));
+ Mana::EventManager::trigger("NPC", *event);
+ break;
+
+ case SMSG_NPC_MESSAGE:
+ event = new Mana::Event("Message");
+ event->setInt("id", npcId);
+ event->setString("text", msg.readString(msg.getLength() - 8));
+ Mana::EventManager::trigger("NPC", *event);
+ break;
+
+ case SMSG_NPC_CLOSE:
+ // Show the close button
+ event = new Mana::Event("Close");
+ event->setInt("id", npcId);
+ Mana::EventManager::trigger("NPC", *event);
+ break;
+
+ case SMSG_NPC_NEXT:
+ // Show the next button
+ event = new Mana::Event("Next");
+ event->setInt("id", npcId);
+ Mana::EventManager::trigger("NPC", *event);
+ break;
+
+ case SMSG_NPC_INT_INPUT:
+ // Request for an integer
+ event = new Mana::Event("IntegerInput");
+ event->setInt("id", npcId);
+ Mana::EventManager::trigger("NPC", *event);
+ break;
+
+ case SMSG_NPC_STR_INPUT:
+ // Request for a string
+ event = new Mana::Event("StringInput");
+ event->setInt("id", npcId);
+ Mana::EventManager::trigger("NPC", *event);
+ break;
}
+ delete event;
+
if (player_node->getCurrentAction() != Being::SIT)
player_node->setAction(Being::STAND);
}
@@ -144,13 +148,6 @@ void NpcHandler::closeDialog(int npcId)
{
MessageOut outMsg(CMSG_NPC_CLOSE);
outMsg.writeInt32(npcId);
-
- NpcDialogs::iterator it = mNpcDialogs.find(npcId);
- if (it != mNpcDialogs.end())
- {
- (*it).second.dialog->close();
- mNpcDialogs.erase(it);
- }
}
void NpcHandler::listInput(int npcId, int value)
@@ -222,9 +219,4 @@ void NpcHandler::endShopping(int beingId)
// TODO
}
-void NpcHandler::clearDialogs()
-{
- mNpcDialogs.clear();
-}
-
} // namespace TmwAthena
diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h
index bd696bdd..515f62df 100644
--- a/src/net/tmwa/npchandler.h
+++ b/src/net/tmwa/npchandler.h
@@ -29,8 +29,6 @@
#include <map>
-class NpcDialog;
-
namespace TmwAthena {
class NpcHandler : public MessageHandler, public Net::NpcHandler
@@ -66,15 +64,6 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler
void sellItem(int beingId, int itemId, int amount);
void endShopping(int beingId);
-
- void clearDialogs();
-
- private:
- typedef struct {
- NpcDialog* dialog;
- } Wrapper;
- typedef std::map<int, Wrapper> NpcDialogs;
- NpcDialogs mNpcDialogs;
};
} // namespace TmwAthena
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index 733d4a88..98cbc8fb 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -31,7 +31,6 @@
#include "gui/buy.h"
#include "gui/buysell.h"
#include "gui/gui.h"
-#include "gui/npcdialog.h"
#include "gui/okdialog.h"
#include "gui/sell.h"
#include "gui/statuswindow.h"
@@ -41,7 +40,6 @@
#include "net/messageout.h"
#include "net/tmwa/protocol.h"
-#include "net/tmwa/npchandler.h"
#include "utils/stringutils.h"
#include "utils/gettext.h"
@@ -79,14 +77,11 @@ namespace {
BuyDialog::closeAll();
BuySellDialog::closeAll();
- NpcDialog::closeAll();
SellDialog::closeAll();
viewport->closePopupMenu();
- TmwAthena::NpcHandler *handler =
- static_cast<TmwAthena::NpcHandler*>(Net::getNpcHandler());
- handler->clearDialogs();
+ Mana::EventManager::trigger("NPC", Mana::Event("CloseAll"));
}
} deathListener;