diff options
45 files changed, 167 insertions, 152 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index ff12822c..6120ef08 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -63,7 +63,7 @@ ActorSprite::~ActorSprite() // Notify listeners of the destruction. Mana::Event event("Destroyed"); event.setActor("source", this); - event.trigger("ActorSprite"); + event.trigger(CHANNEL_ACTORSPRITE); } bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const @@ -260,7 +260,7 @@ void ActorSprite::updateStunMode(int oldMode, int newMode) Mana::Event event("Stun"); event.setInt("oldMode", oldMode); event.setInt("newMode", newMode); - event.trigger("ActorSprite"); + event.trigger(CHANNEL_ACTORSPRITE); } handleStatusEffect(StatusEffect::getStatusEffect(oldMode, false), -1); @@ -274,7 +274,7 @@ void ActorSprite::updateStatusEffect(int index, bool newStatus) Mana::Event event("UpdateStatusEffect"); event.setInt("index", index); event.setBool("newStatus", newStatus); - event.trigger("ActorSprite"); + event.trigger(CHANNEL_ACTORSPRITE); } handleStatusEffect(StatusEffect::getStatusEffect(index, newStatus), index); diff --git a/src/being.cpp b/src/being.cpp index 95f2ecdd..c749d8ce 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -115,7 +115,7 @@ Being::Being(int id, Type type, int subtype, Map *map): setShowName(true); updateColors(); - listen("Chat"); + listen(CHANNEL_CHAT); } Being::~Being() @@ -1210,12 +1210,12 @@ void Being::talkTo() { Mana::Event event("doTalk"); event.setInt("npcId", mId); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } -void Being::event(const std::string &channel, const Mana::Event &event) +void Being::event(Channels channel, const Mana::Event &event) { - if (channel == "Chat" && + if (channel == CHANNEL_CHAT && (event.getName() == "Being" || event.getName() == "Player") && event.getInt("permissions") & PlayerRelation::SPEECH_FLOAT) { diff --git a/src/being.h b/src/being.h index 94790f5f..60dca323 100644 --- a/src/being.h +++ b/src/being.h @@ -485,7 +485,7 @@ class Being : public ActorSprite, public ConfigListener, public Mana::Listener void talkTo(); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); protected: /** diff --git a/src/client.cpp b/src/client.cpp index 975e3e05..4c8d1102 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -612,7 +612,7 @@ int Client::exec() Mana::Event event("StateChange"); event.setInt("oldState", mOldState); event.setInt("newState", mState); - event.trigger("Client"); + event.trigger(CHANNEL_CLIENT); } if (mOldState == STATE_GAME) @@ -772,7 +772,7 @@ int Client::exec() paths.init("paths.xml", true); paths.setDefaultValues(getPathsDefaults()); - Mana::Event::trigger("Client", "DBsLoading"); + Mana::Event::trigger(CHANNEL_CLIENT, "DBsLoading"); // Load XML databases ColorDB::load(); diff --git a/src/event.cpp b/src/event.cpp index 3ca4c5e2..c8de2ffd 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -215,7 +215,7 @@ bool Event::hasActor(const std::string &key) const // Triggers -void Event::trigger(const std::string &channel, const Event &event) +void Event::trigger(Channels channel, const Event &event) { ListenMap::iterator it = mBindings.find(channel); @@ -232,12 +232,12 @@ void Event::trigger(const std::string &channel, const Event &event) } } -void Event::bind(Listener *listener, const std::string &channel) +void Event::bind(Listener *listener, Channels channel) { mBindings[channel].insert(listener); } -void Event::unbind(Listener *listener, const std::string &channel) +void Event::unbind(Listener *listener, Channels channel) { mBindings[channel].erase(listener); } diff --git a/src/event.h b/src/event.h index c7382fc1..42f4d068 100644 --- a/src/event.h +++ b/src/event.h @@ -28,6 +28,21 @@ class ActorSprite; class Item; +enum Channels +{ + CHANNEL_ACTORSPRITE, + CHANNEL_ATTRIBUTES, + CHANNEL_BUYSELL, + CHANNEL_CHAT, + CHANNEL_CLIENT, + CHANNEL_GAME, + CHANNEL_ITEM, + CHANNEL_NOTICES, + CHANNEL_NPC, + CHANNEL_STATUS, + CHANNEL_STORAGE +}; + namespace Mana { @@ -41,7 +56,7 @@ enum BadEvent { class Listener; typedef std::set<Listener *> ListenerSet; -typedef std::map<std::string, ListenerSet > ListenMap; +typedef std::map<Channels, ListenerSet > ListenMap; class VariableData; typedef std::map<std::string, VariableData *> VariableMap; @@ -49,7 +64,7 @@ typedef std::map<std::string, VariableData *> VariableMap; #define SERVER_NOTICE(message) { \ Mana::Event event("ServerNotice"); \ event.setString("message", message); \ -event.trigger("Notices", event); } +event.trigger(CHANNEL_NOTICES, event); } class Event { @@ -220,19 +235,19 @@ public: /** * Sends this event to all classes listening to the given channel. */ - inline void trigger(const std::string &channel) const + inline void trigger(Channels channel) const { trigger(channel, *this); } /** * Sends the given event to all classes listening to the given channel. */ - static void trigger(const std::string &channel, const Event &event); + static void trigger(Channels channel, const Event &event); /** * Sends an empty event with the given name to all classes listening to the * given channel. */ - static inline void trigger(const std::string& channel, + static inline void trigger(Channels channel, const std::string& name) { trigger(channel, Mana::Event(name)); } @@ -243,13 +258,13 @@ protected: * Binds the given listener to the given channel. The listener will receive * all events triggered on the channel. */ - static void bind(Listener *listener, const std::string &channel); + static void bind(Listener *listener, Channels channel); /** * Unbinds the given listener from the given channel. The listener will no * longer receive any events from the channel. */ - static void unbind(Listener *listener, const std::string &channel); + static void unbind(Listener *listener, Channels channel); /** * Unbinds the given listener from all channels. diff --git a/src/game.cpp b/src/game.cpp index 2322d61e..4f2e1430 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -129,7 +129,7 @@ ChatTab *localChatTab = NULL; */ static void initEngines() { - Mana::Event::trigger("Game", "EnginesInitalizing"); + Mana::Event::trigger(CHANNEL_GAME, "EnginesInitalizing"); actorSpriteManager = new ActorSpriteManager; commandHandler = new CommandHandler; @@ -139,7 +139,7 @@ static void initEngines() particleEngine = new Particle(NULL); particleEngine->setupEngine(); - Mana::Event::trigger("Game", "EnginesInitalized"); + Mana::Event::trigger(CHANNEL_GAME, "EnginesInitalized"); } /** @@ -147,7 +147,7 @@ static void initEngines() */ static void createGuiWindows() { - Mana::Event::trigger("Game", "GuiWindowsLoading"); + Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsLoading"); setupWindow->clearWindowsForReset(); @@ -174,7 +174,7 @@ static void createGuiWindows() NpcDialog::setup(); - Mana::Event::trigger("Game", "GuiWindowsLoaded"); + Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsLoaded"); } #define del_0(X) { delete X; X = 0; } @@ -184,7 +184,7 @@ static void createGuiWindows() */ static void destroyGuiWindows() { - Mana::Event::trigger("Game", "GuiWindowsUnloading"); + Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsUnloading"); del_0(localChatTab) // Need to do this first, so it can remove itself del_0(chatWindow) @@ -203,9 +203,9 @@ static void destroyGuiWindows() del_0(specialsWindow) del_0(socialWindow) - Mana::Event::trigger("NPC", "CloseAll"); // Cleanup remaining NPC dialogs + Mana::Event::trigger(CHANNEL_NPC, "CloseAll"); // Cleanup remaining NPC dialogs - Mana::Event::trigger("Game", "GuiWindowsUnloaded"); + Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsUnloaded"); } Game *Game::mInstance = 0; @@ -257,12 +257,12 @@ Game::Game(): setupWindow->setInGame(true); - Mana::Event::trigger("Game", "Constructed"); + Mana::Event::trigger(CHANNEL_GAME, "Constructed"); } Game::~Game() { - Mana::Event::trigger("Game", "Destructing"); + Mana::Event::trigger(CHANNEL_GAME, "Destructing"); delete mWindowMenu; @@ -280,7 +280,7 @@ Game::~Game() mInstance = 0; - Mana::Event::trigger("Game", "Destructed"); + Mana::Event::trigger(CHANNEL_GAME, "Destructed"); } static bool saveScreenshot() @@ -982,5 +982,5 @@ void Game::changeMap(const std::string &mapPath) Mana::Event event("MapLoaded"); event.setString("mapPath", mapPath); - event.trigger("Game"); + event.trigger(CHANNEL_GAME); } diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 36125e60..280d4d15 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -90,8 +90,8 @@ ChatWindow::ChatWindow(): mAutoComplete(new ChatAutoComplete), mTmpVisible(false) { - listen("Chat"); - listen("Notices"); + listen(CHANNEL_CHAT); + listen(CHANNEL_NOTICES); setWindowName("Chat"); @@ -375,14 +375,14 @@ void ChatWindow::mouseDragged(gcn::MouseEvent &event) } } -void ChatWindow::event(const std::string &channel, const Mana::Event &event) +void ChatWindow::event(Channels channel, const Mana::Event &event) { - if (channel == "Notices") + if (channel == CHANNEL_NOTICES) { if (event.getName() == "ServerNotice") localChatTab->chatLog(event.getString("message"), BY_SERVER); } - else if (channel == "Chat") + else if (channel == CHANNEL_CHAT) { if (event.getName() == "Whisper") { diff --git a/src/gui/chat.h b/src/gui/chat.h index 3a001432..f546502c 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -158,7 +158,7 @@ class ChatWindow : public Window, void mousePressed(gcn::MouseEvent &event); void mouseDragged(gcn::MouseEvent &event); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); /** * Scrolls the chat window diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 62b63f24..fab87844 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -60,7 +60,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory): mInventory(inventory), mSplit(false) { - listen("Attributes"); + listen(CHANNEL_ATTRIBUTES); setWindowName(isMainInventory() ? "Inventory" : "Storage"); setupWindow->registerWindowForReset(this); @@ -261,7 +261,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) event.setInt("amount", item->getQuantity()); event.setInt("source", Inventory::INVENTORY); event.setInt("destination", Inventory::STORAGE); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); } else { @@ -270,7 +270,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) event.setInt("amount", item->getQuantity()); event.setInt("source", Inventory::STORAGE); event.setInt("destination", Inventory::INVENTORY); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); } } } @@ -370,12 +370,12 @@ void InventoryWindow::close() { Mana::Event event("doCloseInventory"); event.setInt("type", mInventory->getType()); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); scheduleDelete(); } } -void InventoryWindow::event(const std::string &channel, const Mana::Event &event) +void InventoryWindow::event(Channels channel, const Mana::Event &event) { if (event.getName() == "UpdateAttribute") { diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 99fc1c03..4ae80309 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -112,7 +112,7 @@ class InventoryWindow : public Window, bool isMainInventory() { return mInventory->isMainInventory(); } - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); private: /** diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp index aed8d11d..bb8f95d0 100644 --- a/src/gui/itemamount.cpp +++ b/src/gui/itemamount.cpp @@ -59,7 +59,7 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage) event.setInt("amount", amount); event.setInt("source", Inventory::INVENTORY); event.setInt("destination", Inventory::STORAGE); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); } break; case StoreRemove: @@ -69,7 +69,7 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage) event.setInt("amount", amount); event.setInt("source", Inventory::STORAGE); event.setInt("destination", Inventory::INVENTORY); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); } break; default: diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 1642d1b0..ab01dbbd 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -47,7 +47,7 @@ extern volatile int tick_time; MiniStatusWindow::MiniStatusWindow(): Popup("MiniStatus") { - listen("Attributes"); + listen(CHANNEL_ATTRIBUTES); mHpBar = new ProgressBar(0, 100, 20, Theme::PROG_HP); StatusWindow::updateHPBar(mHpBar); @@ -119,9 +119,9 @@ void MiniStatusWindow::drawIcons(Graphics *graphics) } } -void MiniStatusWindow::event(const std::string &channel, const Mana::Event &event) +void MiniStatusWindow::event(Channels channel, const Mana::Event &event) { - if (channel == "Attributes") + if (channel == CHANNEL_ATTRIBUTES) { if (event.getName() == "UpdateAttribute") { @@ -140,7 +140,7 @@ void MiniStatusWindow::event(const std::string &channel, const Mana::Event &even } } } - else if (channel == "ActorSprite") + else if (channel == CHANNEL_ACTORSPRITE) { if (event.getName() == "UpdateStatusEffect") { diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 077eedeb..9dfcaeae 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -45,7 +45,7 @@ class MiniStatusWindow : public Popup, public Mana::Listener void drawIcons(Graphics *graphics); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); void logic(); // Updates icons diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 935962a0..f565a13f 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -55,7 +55,7 @@ typedef std::map<int, NpcDialog*> NpcDialogs; class NpcEventListener : public Mana::Listener { public: - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); NpcDialog *getDialog(int id, bool make = true); @@ -227,7 +227,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) NpcEvent("doMenu") event.setInt("choice", selectedIndex + 1); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } else if (mInputState == NPC_INPUT_STRING) { @@ -235,7 +235,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) NpcEvent("doStringInput") event.setString("value", printText); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } else if (mInputState == NPC_INPUT_INTEGER) { @@ -243,7 +243,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) NpcEvent("doIntegerInput") event.setInt("value", mIntField->getValue()); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } // addText will auto remove the input layout addText(strprintf("\n> \"%s\"\n", printText.c_str()), false); @@ -282,13 +282,13 @@ void NpcDialog::action(const gcn::ActionEvent &event) void NpcDialog::nextDialog() { NpcEvent("doNext"); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } void NpcDialog::closeDialog() { NpcEvent("doClose"); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); close(); } @@ -436,7 +436,7 @@ void NpcDialog::setup() npcListener = new NpcEventListener(); - npcListener->listen("NPC"); + npcListener->listen(CHANNEL_NPC); } void NpcDialog::buildLayout() @@ -506,10 +506,10 @@ void NpcDialog::buildLayout() mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); } -void NpcEventListener::event(const std::string &channel, +void NpcEventListener::event(Channels channel, const Mana::Event &event) { - if (channel != "NPC") + if (channel != CHANNEL_NPC) return; if (event.getName() == "Message") @@ -560,7 +560,7 @@ void NpcEventListener::event(const std::string &channel, { int mNpcId = id; NpcEvent("doNext"); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); return; } @@ -575,7 +575,7 @@ void NpcEventListener::event(const std::string &channel, { int mNpcId = id; NpcEvent("doClose"); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); return; } diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp index 0662515e..a4740027 100644 --- a/src/gui/npcpostdialog.cpp +++ b/src/gui/npcpostdialog.cpp @@ -101,7 +101,7 @@ void NpcPostDialog::action(const gcn::ActionEvent &event) event.setInt("npcId", mNpcId); event.setString("recipient", mSender->getText()); event.setString("text", mText->getText()); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } setVisible(false); } diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 022a97c7..654d2bf3 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -96,7 +96,7 @@ class ChangeDisplay : public AttrDisplay, gcn::ActionListener StatusWindow::StatusWindow(): Window(player_node->getName()) { - listen("Attributes"); + listen(CHANNEL_ATTRIBUTES); setWindowName("Status"); setupWindow->registerWindowForReset(this); @@ -217,7 +217,7 @@ StatusWindow::StatusWindow(): mLvlLabel->adjustSize(); } -void StatusWindow::event(const std::string &channel, const Mana::Event &event) +void StatusWindow::event(Channels channel, const Mana::Event &event) { if (event.getName() == "UpdateAttribute") { diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index fd8c6319..275dd8c9 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -49,7 +49,7 @@ class StatusWindow : public Window, public Mana::Listener */ StatusWindow(); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); void updateAttrs(); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 06dbd43e..6cef33a1 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -72,7 +72,7 @@ Viewport::Viewport(): setFocusable(true); - listen("ActorSprite"); + listen(CHANNEL_ACTORSPRITE); } Viewport::~Viewport() @@ -556,9 +556,9 @@ void Viewport::hideBeingPopup() mBeingPopup->setVisible(false); } -void Viewport::event(const std::string &channel, const Mana::Event &event) +void Viewport::event(Channels channel, const Mana::Event &event) { - if (channel == "ActorSprite" && event.getName() == "Destroyed") + if (channel == CHANNEL_ACTORSPRITE && event.getName() == "Destroyed") { ActorSprite *actor = event.getActor("source"); diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 55db3676..9fbdf496 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -160,7 +160,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void hideBeingPopup(); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); private: /** diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index d448c3c2..bf0272ee 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -311,7 +311,7 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event) Mana::Event event("doMove"); event.setItem("item", item); event.setInt("newIndex", index); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); } selectNone(); } @@ -383,7 +383,7 @@ void ItemContainer::keyAction() Mana::Event event("doMove"); event.setItem("item", item); event.setInt("newIndex", mHighlightedIndex); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); setSelectedIndex(mHighlightedIndex); } // If the highlight is on an item then select it. @@ -399,7 +399,7 @@ void ItemContainer::keyAction() Mana::Event event("doMove"); event.setItem("item", item); event.setInt("newIndex", mHighlightedIndex); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); selectNone(); } } diff --git a/src/item.cpp b/src/item.cpp index a2a1d443..7357d35f 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -76,7 +76,7 @@ void Item::doEvent(const std::string &eventName) { Mana::Event event(eventName); event.setItem("item", this); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); } void Item::doEvent(const std::string &eventName, int amount) @@ -84,7 +84,7 @@ void Item::doEvent(const std::string &eventName, int amount) Mana::Event event(eventName); event.setItem("item", this); event.setInt("amount", amount); - event.trigger("Item"); + event.trigger(CHANNEL_ITEM); } bool Item::isEquippable() const diff --git a/src/listener.cpp b/src/listener.cpp index a9182c42..f9acac95 100644 --- a/src/listener.cpp +++ b/src/listener.cpp @@ -30,12 +30,12 @@ Listener::~Listener() Event::remove(this); } -void Listener::listen(const std::string &channel) +void Listener::listen(Channels channel) { Event::bind(this, channel); } -void Listener::ignore(const std::string &channel) +void Listener::ignore(Channels channel) { Event::unbind(this, channel); } diff --git a/src/listener.h b/src/listener.h index db7b3221..84b613eb 100644 --- a/src/listener.h +++ b/src/listener.h @@ -33,11 +33,11 @@ class Listener public: virtual ~Listener(); - void listen(const std::string &channel); + void listen(Channels channel); - void ignore(const std::string &channel); + void ignore(Channels channel); - virtual void event(const std::string &channel, const Event &event) = 0; + virtual void event(Channels channel, const Event &event) = 0; }; } // namespace Mana diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b60ee6f7..a0e7184d 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -87,14 +87,14 @@ LocalPlayer::LocalPlayer(int id, int subtype): mMessageTime(0), mShowIp(false) { - listen("Attributes"); + listen(CHANNEL_ATTRIBUTES); mUpdateName = true; config.addListener("showownname", this); setShowName(config.getValue("showownname", 1)); - listen("ActorSprite"); + listen(CHANNEL_ACTORSPRITE); } LocalPlayer::~LocalPlayer() @@ -1084,9 +1084,9 @@ void LocalPlayer::optionChanged(const std::string &value) } } -void LocalPlayer::event(const std::string &channel, const Mana::Event &event) +void LocalPlayer::event(Channels channel, const Mana::Event &event) { - if (channel == "ActorSprite") + if (channel == CHANNEL_ACTORSPRITE) { if (event.getName() == "Destroyed") { @@ -1099,7 +1099,7 @@ void LocalPlayer::event(const std::string &channel, const Mana::Event &event) mTarget = 0; } } - else if (channel == "Attributes") + else if (channel == CHANNEL_ATTRIBUTES) { if (event.getName() == "UpdateAttribute") { diff --git a/src/localplayer.h b/src/localplayer.h index 0580ef89..984e3c75 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -186,7 +186,7 @@ class LocalPlayer : public Being */ void optionChanged(const std::string &value); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); /** * Tells the engine wether to check diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index 147bab0a..70910cf6 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -171,7 +171,7 @@ void ChatHandler::handleGameChatMessage(Net::MessageIn &msg) event.setInt("permissions", player_relations .checkPermissionSilently(being->getName(), PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT)); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); } void ChatHandler::handleEnterChannelResponse(Net::MessageIn &msg) @@ -234,7 +234,7 @@ void ChatHandler::handlePrivateMessage(Net::MessageIn &msg) Mana::Event event("Whisper"); event.setString("nick", userNick); event.setString("message", chatMsg); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); } void ChatHandler::handleAnnouncement(Net::MessageIn &msg) @@ -242,7 +242,7 @@ void ChatHandler::handleAnnouncement(Net::MessageIn &msg) std::string chatMsg = msg.readString(); Mana::Event event("Announcement"); event.setString("message", chatMsg); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); } void ChatHandler::handleChatMessage(Net::MessageIn &msg) diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index 7bff8a30..178e0c48 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -91,8 +91,8 @@ GeneralHandler::GeneralHandler(): generalHandler = this; - listen("Client"); - listen("Game"); + listen(CHANNEL_CLIENT); + listen(CHANNEL_GAME); } void GeneralHandler::load() @@ -171,10 +171,10 @@ void GeneralHandler::clearHandlers() clearNetworkHandlers(); } -void GeneralHandler::event(const std::string &channel, +void GeneralHandler::event(Channels channel, const Mana::Event &event) { - if (channel == "Client") + if (channel == CHANNEL_CLIENT) { if (event.getName() == "StateChange") { @@ -192,7 +192,7 @@ void GeneralHandler::event(const std::string &channel, Attributes::informItemDB(); } } - else if (channel == "Game") + else if (channel == CHANNEL_GAME) { if (event.getName() == "GuiWindowsLoaded") { diff --git a/src/net/manaserv/generalhandler.h b/src/net/manaserv/generalhandler.h index 2a203e8c..c8671ec1 100644 --- a/src/net/manaserv/generalhandler.h +++ b/src/net/manaserv/generalhandler.h @@ -46,7 +46,7 @@ class GeneralHandler : public Net::GeneralHandler, public Mana::Listener void clearHandlers(); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); protected: MessageHandlerPtr mBeingHandler; diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index da1abab5..45ab1ebd 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -52,7 +52,7 @@ InventoryHandler::InventoryHandler() handledMessages = _messages; inventoryHandler = this; - listen("Item"); + listen(CHANNEL_ITEM); } void InventoryHandler::handleMessage(Net::MessageIn &msg) @@ -108,10 +108,10 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) } } -void InventoryHandler::event(const std::string &channel, +void InventoryHandler::event(Channels channel, const Mana::Event &event) { - if (channel == "Item") + if (channel == CHANNEL_ITEM) { Item *item = event.getItem("item"); diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index aa44f2ee..bb68ceeb 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -66,7 +66,7 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler, void handleMessage(Net::MessageIn &msg); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); bool canSplit(const Item *item); diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index f7e04c1b..64162cc5 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -52,7 +52,7 @@ NpcHandler::NpcHandler() handledMessages = _messages; npcHandler = this; - listen("NPC"); + listen(CHANNEL_NPC); } void NpcHandler::handleMessage(Net::MessageIn &msg) @@ -77,7 +77,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) event->setString("choice" + toString(count), msg.readString()); } event->setInt("choiceCount", count); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_NUMBER: @@ -86,52 +86,52 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) event->setInt("min", msg.readInt32()); event->setInt("max", msg.readInt32()); event->setInt("default", msg.readInt32()); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_STRING: event = new Mana::Event("StringInput"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_POST: event = new Mana::Event("Post"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_ERROR: event = new Mana::Event("End"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_MESSAGE: event = new Mana::Event("Message"); event->setInt("id", npcId); event->setString("text", msg.readString(msg.getUnreadLength())); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); delete event; event = new Mana::Event("Next"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_CLOSE: event = new Mana::Event("Close"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; } delete event; } -void NpcHandler::event(const std::string &channel, const Mana::Event &event) +void NpcHandler::event(Channels channel, const Mana::Event &event) { - if (channel == "NPC") + if (channel == CHANNEL_NPC) { if (event.getName() == "doTalk") { diff --git a/src/net/manaserv/npchandler.h b/src/net/manaserv/npchandler.h index 14e8a50a..397d3569 100644 --- a/src/net/manaserv/npchandler.h +++ b/src/net/manaserv/npchandler.h @@ -40,7 +40,7 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler, void handleMessage(Net::MessageIn &msg); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); void startShopping(int beingId); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index a579517f..d9bfb2b6 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -65,7 +65,7 @@ void RespawnRequestListener::action(const gcn::ActionEvent &event) { Net::getPlayerHandler()->respawn(); - Mana::Event::trigger("NPC", "CloseAll"); + Mana::Event::trigger(CHANNEL_NPC, "CloseAll"); } PlayerHandler::PlayerHandler() diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 2b647f68..9529a386 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -86,7 +86,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) event.setString("nick", nick); event.setString("error", strprintf(_("Whisper could " "not be sent, %s is offline."), nick.c_str())); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); } break; case 0x02: @@ -95,7 +95,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) event.setString("nick", nick); event.setString("error", strprintf(_("Whisper could " "not be sent, ignored by %s."), nick.c_str())); - event.Event::trigger("Chat"); + event.Event::trigger(CHANNEL_CHAT); } break; } @@ -118,7 +118,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) Mana::Event event("Whisper"); event.setString("nick", nick); event.setString("message", chatMsg); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); } } else @@ -180,7 +180,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) event.setString("nick", sender_name); event.setInt("beingId", beingId); event.setInt("permissions", perms); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); break; } @@ -213,13 +213,13 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) event.setInt("permissions", player_relations.getDefault() & (PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT)); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); } else { Mana::Event event("Announcement"); event.setString("message", chatMsg); - event.trigger("Chat"); + event.trigger(CHANNEL_CHAT); } break; } diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index 334a2e37..d98daa64 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -58,7 +58,7 @@ GameHandler::GameHandler() handledMessages = _messages; gameHandler = this; - listen("Game"); + listen(CHANNEL_GAME); } void GameHandler::handleMessage(Net::MessageIn &msg) @@ -105,9 +105,9 @@ void GameHandler::handleMessage(Net::MessageIn &msg) } } -void GameHandler::event(const std::string &channel, const Mana::Event &event) +void GameHandler::event(Channels channel, const Mana::Event &event) { - if (channel == "Game") + if (channel == CHANNEL_GAME) { if (event.getName() == "EnginesInitalized") { diff --git a/src/net/tmwa/gamehandler.h b/src/net/tmwa/gamehandler.h index 6bdcbaef..18317445 100644 --- a/src/net/tmwa/gamehandler.h +++ b/src/net/tmwa/gamehandler.h @@ -41,7 +41,7 @@ class GameHandler : public MessageHandler, public Net::GameHandler, void handleMessage(Net::MessageIn &msg); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); void connect(); diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 79362a6d..f9ed97b0 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -108,7 +108,7 @@ GeneralHandler::GeneralHandler(): itemDb->setStatsList(stats); - listen("Game"); + listen(CHANNEL_GAME); } GeneralHandler::~GeneralHandler() @@ -217,10 +217,10 @@ void GeneralHandler::clearHandlers() mNetwork->clearHandlers(); } -void GeneralHandler::event(const std::string &channel, +void GeneralHandler::event(Channels channel, const Mana::Event &event) { - if (channel == "Game") + if (channel == CHANNEL_GAME) { if (event.getName() == "GuiWindowsLoaded") { diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index f7f78759..722c3215 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -51,7 +51,7 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler, void clearHandlers(); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); protected: MessageHandlerPtr mAdminHandler; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 9fac8e8c..ae79ab09 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -110,7 +110,7 @@ InventoryHandler::InventoryHandler() mStorage = 0; mStorageWindow = 0; - listen("Item"); + listen(CHANNEL_ITEM); } InventoryHandler::~InventoryHandler() @@ -430,10 +430,10 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) } } -void InventoryHandler::event(const std::string &channel, +void InventoryHandler::event(Channels channel, const Mana::Event &event) { - if (channel == "Item") + if (channel == CHANNEL_ITEM) { if (event.getName() == "doCloseInventory") { diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 79d3bc65..dfbefaa8 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -133,7 +133,7 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler, void handleMessage(Net::MessageIn &msg); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); bool canSplit(const Item *item); diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index e1615fec..1f85e9a6 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -69,7 +69,7 @@ NpcHandler::NpcHandler() handledMessages = _messages; npcHandler = this; - listen("NPC"); + listen(CHANNEL_NPC); } void NpcHandler::handleMessage(Net::MessageIn &msg) @@ -88,42 +88,42 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) event = new Mana::Event("Menu"); event->setInt("id", npcId); parseMenu(event, msg.readString(msg.getLength() - 8)); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case SMSG_NPC_MESSAGE: event = new Mana::Event("Message"); event->setInt("id", npcId); event->setString("text", msg.readString(msg.getLength() - 8)); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case SMSG_NPC_CLOSE: // Show the close button event = new Mana::Event("Close"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case SMSG_NPC_NEXT: // Show the next button event = new Mana::Event("Next"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case SMSG_NPC_INT_INPUT: // Request for an integer event = new Mana::Event("IntegerInput"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; case SMSG_NPC_STR_INPUT: // Request for a string event = new Mana::Event("StringInput"); event->setInt("id", npcId); - event->trigger("NPC"); + event->trigger(CHANNEL_NPC); break; } @@ -133,9 +133,9 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) player_node->setAction(Being::STAND); } -void NpcHandler::event(const std::string &channel, const Mana::Event &event) +void NpcHandler::event(Channels channel, const Mana::Event &event) { - if (channel == "NPC") + if (channel == CHANNEL_NPC) { if (event.getName() == "doTalk") { diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index 93c9f6ec..9fcb0041 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -40,7 +40,7 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler, void handleMessage(Net::MessageIn &msg); - void event(const std::string &channel, const Mana::Event &event); + void event(Channels channel, const Mana::Event &event); void startShopping(int beingId); diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 970d1ecd..eeba7ae7 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -81,7 +81,7 @@ namespace { viewport->closePopupMenu(); - Mana::Event::trigger("NPC", "CloseAll"); + Mana::Event::trigger(CHANNEL_NPC, "CloseAll"); } } deathListener; diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index beb3942e..8757053c 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -62,7 +62,7 @@ void triggerAttr(int id, int old) event.setInt("id", id); event.setInt("oldValue", old); event.setInt("newValue", mData.mAttributes.find(id)->second); - event.trigger("Attributes"); + event.trigger(CHANNEL_ATTRIBUTES); } void triggerStat(int id, const std::string &changed, int old1, int old2 = 0) @@ -77,7 +77,7 @@ void triggerStat(int id, const std::string &changed, int old1, int old2 = 0) event.setString("changed", changed); event.setInt("oldValue1", old1); event.setInt("oldValue2", old2); - event.trigger("Attributes"); + event.trigger(CHANNEL_ATTRIBUTES); } // --- Attributes ------------------------------------------------------------- @@ -219,7 +219,7 @@ void setStorageCount(int count) Mana::Event event("StorageCount"); event.setInt("oldCount", old); event.setInt("newCount", count); - event.trigger("Storage"); + event.trigger(CHANNEL_STORAGE); } } @@ -240,7 +240,7 @@ void setNPCInteractionCount(int count) Mana::Event event("NPCCount"); event.setInt("oldCount", old); event.setInt("newCount", count); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } } @@ -259,7 +259,7 @@ void setNPCPostCount(int count) Mana::Event event("PostCount"); event.setInt("oldCount", old); event.setInt("newCount", count); - event.trigger("NPC"); + event.trigger(CHANNEL_NPC); } } @@ -280,7 +280,7 @@ void setBuySellState(BuySellState buySellState) Mana::Event event("StateChange"); event.setInt("oldState", old); event.setInt("newState", buySellState); - event.trigger("BuySell"); + event.trigger(CHANNEL_BUYSELL); } } @@ -298,7 +298,7 @@ void setTrading(bool trading) { Mana::Event event("Trading"); event.setBool("trading", trading); - event.trigger("Status"); + event.trigger(CHANNEL_STATUS); } } @@ -354,13 +354,13 @@ class PlayerLogic : Mana::Listener public: PlayerLogic() { - listen("Client"); - listen("Game"); + listen(CHANNEL_CLIENT); + listen(CHANNEL_GAME); } - void event(const std::string &channel, const Mana::Event &event) + void event(Channels channel, const Mana::Event &event) { - if (channel == "Client") + if (channel == CHANNEL_CLIENT) { if (event.getName() == "StateChange") { @@ -376,7 +376,7 @@ public: } } } - else if (channel == "Game") + else if (channel == CHANNEL_GAME) { if (event.getName() == "Destructed") { |