diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-08-12 19:43:51 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-12 20:07:04 -0600 |
commit | 2293b1c5ef0bb7378140bf73f1fef03a4504bdd2 (patch) | |
tree | b3df7512fd0e48e8b1b3a0ed3cbd6d5e9d149ad2 /src/gui/npcdialog.cpp | |
parent | 71595e5db41f503f06401c59090748b46e9731f0 (diff) | |
download | mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.tar.gz mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.tar.bz2 mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.tar.xz mana-2293b1c5ef0bb7378140bf73f1fef03a4504bdd2.zip |
Replace most of Net::NpcHandler with events
Reviewed-by: Chuck Miller
Diffstat (limited to 'src/gui/npcdialog.cpp')
-rw-r--r-- | src/gui/npcdialog.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index d76e8418..a14e88eb 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -22,6 +22,7 @@ #include "gui/npcdialog.h" #include "configuration.h" +#include "eventmanager.h" #include "listener.h" #include "playerinfo.h" @@ -36,9 +37,6 @@ #include "gui/widgets/textbox.h" #include "gui/widgets/textfield.h" -#include "net/net.h" -#include "net/npchandler.h" - #include "utils/gettext.h" #include "utils/stringutils.h" @@ -49,6 +47,13 @@ #define CAPTION_CLOSE _("Close") #define CAPTION_SUBMIT _("Submit") +#define NpcEvent(name) Mana::Event event(name);\ +event.setInt("npcId", mNpcId); + +#define FireEvent(event) Mana::EventManager::trigger("NPC", event); + +#define FireEvent2(name) NpcEvent(name) FireEvent(event) + typedef std::map<int, NpcDialog*> NpcDialogs; class NpcEventListener : public Mana::Listener @@ -217,27 +222,32 @@ void NpcDialog::action(const gcn::ActionEvent &event) if (mInputState == NPC_INPUT_LIST) { - int choice = 0; int selectedIndex = mItemList->getSelected(); if (selectedIndex >= (int) mItems.size() || selectedIndex < 0) - { return; - } - choice = selectedIndex + 1; + printText = mItems[selectedIndex]; - Net::getNpcHandler()->listInput(mNpcId, choice); + NpcEvent("doMenu") + event.setInt("choice", selectedIndex + 1); + FireEvent(event); } else if (mInputState == NPC_INPUT_STRING) { printText = mTextField->getText(); - Net::getNpcHandler()->stringInput(mNpcId, printText); + + NpcEvent("doStringInput") + event.setString("value", printText); + FireEvent(event); } else if (mInputState == NPC_INPUT_INTEGER) { printText = strprintf("%d", mIntField->getValue()); - Net::getNpcHandler()->integerInput(mNpcId, mIntField->getValue()); + + NpcEvent("doIntegerInput") + event.setInt("value", mIntField->getValue()); + FireEvent(event); } // addText will auto remove the input layout addText(strprintf("\n> \"%s\"\n", printText.c_str()), false); @@ -275,12 +285,12 @@ void NpcDialog::action(const gcn::ActionEvent &event) void NpcDialog::nextDialog() { - Net::getNpcHandler()->nextDialog(mNpcId); + FireEvent2("doNext") } void NpcDialog::closeDialog() { - Net::getNpcHandler()->closeDialog(mNpcId); + FireEvent2("doClose") close(); } @@ -550,7 +560,8 @@ void NpcEventListener::event(const std::string &channel, if (!dialog) { - Net::getNpcHandler()->nextDialog(id); + int mNpcId = id; + FireEvent2("doNext") return; } @@ -563,7 +574,8 @@ void NpcEventListener::event(const std::string &channel, if (!dialog) { - Net::getNpcHandler()->closeDialog(id); + int mNpcId = id; + FireEvent2("doClose") return; } |