diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-08-10 18:06:20 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-10 18:10:17 -0600 |
commit | f983b7381a298be8639e007f835d2aad30a768e2 (patch) | |
tree | 6d82253211e6bde52507f2de091c002f4a948553 /src/net/manaserv/npchandler.cpp | |
parent | 96187972ff9ac50a2a7fa280abbb21bd3c7f0737 (diff) | |
download | mana-client-f983b7381a298be8639e007f835d2aad30a768e2.tar.gz mana-client-f983b7381a298be8639e007f835d2aad30a768e2.tar.bz2 mana-client-f983b7381a298be8639e007f835d2aad30a768e2.tar.xz mana-client-f983b7381a298be8639e007f835d2aad30a768e2.zip |
Remove NpcDialog references from netcode
Reviewed-by: Chuck Miller
Diffstat (limited to 'src/net/manaserv/npchandler.cpp')
-rw-r--r-- | src/net/manaserv/npchandler.cpp | 134 |
1 files changed, 61 insertions, 73 deletions
diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index 509f26e1..09dccffe 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -22,15 +22,15 @@ #include "net/manaserv/npchandler.h" #include "actorspritemanager.h" - -#include "gui/npcdialog.h" -#include "gui/npcpostdialog.h" +#include "eventmanager.h" #include "net/manaserv/connection.h" #include "net/manaserv/messagein.h" #include "net/manaserv/messageout.h" #include "net/manaserv/protocol.h" +#include "utils/stringutils.h" + extern Net::NpcHandler *npcHandler; namespace ManaServ { @@ -61,70 +61,70 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) return; } - int npcId = being->getId(); - NpcDialogs::iterator diag = mNpcDialogs.find(npcId); - NpcDialog *dialog; - - if (diag == mNpcDialogs.end()) - { - if (msg.getId() == GPMSG_NPC_ERROR || msg.getId() == GPMSG_NPC_CLOSE) - return; // Dialog is pointless in these cases - - dialog = new NpcDialog(npcId); - Wrapper wrap; - wrap.dialog = dialog; - mNpcDialogs[npcId] = wrap; - } - else - { - dialog = diag->second.dialog; - } + int npcId = being->getId(), count = 0; + Mana::Event *event = 0; switch (msg.getId()) { - case GPMSG_NPC_CHOICE: - dialog->choiceRequest(); - while (msg.getUnreadLength()) - { - dialog->addChoice(msg.readString()); - } - break; - - case GPMSG_NPC_NUMBER: - { - int min_num = msg.readInt32(); - int max_num = msg.readInt32(); - dialog->integerRequest(msg.readInt32(), min_num, max_num); - break; - } - - case GPMSG_NPC_STRING: - dialog->textRequest(""); - break; - - case GPMSG_NPC_POST: + case GPMSG_NPC_CHOICE: + event = new Mana::Event("Menu"); + event->setInt("id", npcId); + while (msg.getUnreadLength()) { - new NpcPostDialog(npcId); - break; + count++; + event->setString("choice" + toString(count), msg.readString()); } - - case GPMSG_NPC_ERROR: - dialog->close(); - if (diag != mNpcDialogs.end()) - { - mNpcDialogs.erase(diag); - } - break; - - case GPMSG_NPC_MESSAGE: - dialog->addText(msg.readString(msg.getUnreadLength())); - dialog->showNextButton(); - break; - - case GPMSG_NPC_CLOSE: - dialog->showCloseButton(); - break; + event->setInt("choiceCount", count); + Mana::EventManager::trigger("NPC", *event); + break; + + case GPMSG_NPC_NUMBER: + event = new Mana::Event("IntegerInput"); + event->setInt("id", npcId); + event->setInt("min", msg.readInt32()); + event->setInt("max", msg.readInt32()); + event->setInt("default", msg.readInt32()); + Mana::EventManager::trigger("NPC", *event); + break; + + case GPMSG_NPC_STRING: + event = new Mana::Event("StringInput"); + event->setInt("id", npcId); + Mana::EventManager::trigger("NPC", *event); + break; + + case GPMSG_NPC_POST: + event = new Mana::Event("Post"); + event->setInt("id", npcId); + Mana::EventManager::trigger("NPC", *event); + break; + + case GPMSG_NPC_ERROR: + event = new Mana::Event("End"); + event->setInt("id", npcId); + Mana::EventManager::trigger("NPC", *event); + break; + + case GPMSG_NPC_MESSAGE: + event = new Mana::Event("Message"); + event->setInt("id", npcId); + event->setString("text", msg.readString(msg.getUnreadLength())); + Mana::EventManager::trigger("NPC", *event); + delete event; + + event = new Mana::Event("Next"); + event->setInt("id", npcId); + Mana::EventManager::trigger("NPC", *event); + break; + + case GPMSG_NPC_CLOSE: + event = new Mana::Event("Close"); + event->setInt("id", npcId); + Mana::EventManager::trigger("NPC", *event); + break; } + + delete event; } void NpcHandler::talk(int npcId) @@ -146,13 +146,6 @@ void NpcHandler::closeDialog(int npcId) MessageOut msg(PGMSG_NPC_TALK_NEXT); msg.writeInt16(npcId); gameServerConnection->send(msg); - - NpcDialogs::iterator it = mNpcDialogs.find(npcId); - if (it != mNpcDialogs.end()) - { - (*it).second.dialog->close(); - mNpcDialogs.erase(it); - } } void NpcHandler::listInput(int npcId, int value) @@ -224,9 +217,4 @@ void NpcHandler::endShopping(int beingId) // TODO } -void NpcHandler::clearDialogs() -{ - mNpcDialogs.clear(); -} - } // namespace ManaServ |