diff options
Diffstat (limited to 'src')
34 files changed, 204 insertions, 148 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 6120ef08..df568d72 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -61,7 +61,7 @@ ActorSprite::~ActorSprite() mUsedTargetCursor = NULL; // Notify listeners of the destruction. - Mana::Event event("Destroyed"); + Mana::Event event(EVENT_DESTROYED); event.setActor("source", this); event.trigger(CHANNEL_ACTORSPRITE); } @@ -257,7 +257,7 @@ void ActorSprite::updateStunMode(int oldMode, int newMode) { if (this == player_node) { - Mana::Event event("Stun"); + Mana::Event event(EVENT_STUN); event.setInt("oldMode", oldMode); event.setInt("newMode", newMode); event.trigger(CHANNEL_ACTORSPRITE); @@ -271,7 +271,7 @@ void ActorSprite::updateStatusEffect(int index, bool newStatus) { if (this == player_node) { - Mana::Event event("UpdateStatusEffect"); + Mana::Event event(EVENT_UPDATESTATUSEFFECT); event.setInt("index", index); event.setBool("newStatus", newStatus); event.trigger(CHANNEL_ACTORSPRITE); diff --git a/src/being.cpp b/src/being.cpp index c749d8ce..a9790246 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -1208,7 +1208,7 @@ bool Being::canTalk() void Being::talkTo() { - Mana::Event event("doTalk"); + Mana::Event event(EVENT_DOTALK); event.setInt("npcId", mId); event.trigger(CHANNEL_NPC); } @@ -1216,7 +1216,7 @@ void Being::talkTo() void Being::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_CHAT && - (event.getName() == "Being" || event.getName() == "Player") && + (event.getName() == EVENT_BEING || event.getName() == EVENT_PLAYER) && event.getInt("permissions") & PlayerRelation::SPEECH_FLOAT) { try diff --git a/src/client.cpp b/src/client.cpp index 4c8d1102..d584d168 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -609,7 +609,7 @@ int Client::exec() if (mState != mOldState) { { - Mana::Event event("StateChange"); + Mana::Event event(EVENT_STATECHANGE); event.setInt("oldState", mOldState); event.setInt("newState", mState); event.trigger(CHANNEL_CLIENT); @@ -772,7 +772,7 @@ int Client::exec() paths.init("paths.xml", true); paths.setDefaultValues(getPathsDefaults()); - Mana::Event::trigger(CHANNEL_CLIENT, "DBsLoading"); + Mana::Event::trigger(CHANNEL_CLIENT, EVENT_DBSLOADING); // Load XML databases ColorDB::load(); diff --git a/src/event.h b/src/event.h index 42f4d068..99bd6fcb 100644 --- a/src/event.h +++ b/src/event.h @@ -43,6 +43,60 @@ enum Channels CHANNEL_STORAGE }; +enum Events +{ + EVENT_ANNOUNCEMENT, + EVENT_BEING, + EVENT_CLOSE, + EVENT_CLOSEALL, + EVENT_CONSTRUCTED, + EVENT_DBSLOADING, + EVENT_DESTROYED, + EVENT_DESTRUCTED, + EVENT_DESTRUCTING, + EVENT_DOCLOSE, + EVENT_DOCLOSEINVENTORY, + EVENT_DODROP, + EVENT_DOEQUIP, + EVENT_DOINTEGERINPUT, + EVENT_DOMENU, + EVENT_DOMOVE, + EVENT_DONEXT, + EVENT_DOSENDLETTER, + EVENT_DOSPLIT, + EVENT_DOSTRINGINPUT, + EVENT_DOTALK, + EVENT_DOUNEQUIP, + EVENT_DOUSE, + EVENT_END, + EVENT_ENGINESINITALIZED, + EVENT_ENGINESINITALIZING, + EVENT_GUIWINDOWSLOADED, + EVENT_GUIWINDOWSLOADING, + EVENT_GUIWINDOWSUNLOADED, + EVENT_GUIWINDOWSUNLOADING, + EVENT_INTEGERINPUT, + EVENT_MAPLOADED, + EVENT_MENU, + EVENT_MESSAGE, + EVENT_NEXT, + EVENT_NPCCOUNT, + EVENT_PLAYER, + EVENT_POST, + EVENT_POSTCOUNT, + EVENT_SERVERNOTICE, + EVENT_STATECHANGE, + EVENT_STORAGECOUNT, + EVENT_STRINGINPUT, + EVENT_STUN, + EVENT_TRADING, + EVENT_UPDATEATTRIBUTE, + EVENT_UPDATESTAT, + EVENT_UPDATESTATUSEFFECT, + EVENT_WHISPER, + EVENT_WHISPERERROR +}; + namespace Mana { @@ -62,7 +116,7 @@ class VariableData; typedef std::map<std::string, VariableData *> VariableMap; #define SERVER_NOTICE(message) { \ -Mana::Event event("ServerNotice"); \ +Mana::Event event(EVENT_SERVERNOTICE); \ event.setString("message", message); \ event.trigger(CHANNEL_NOTICES, event); } @@ -72,7 +126,7 @@ public: /** * Makes an event with the given name. */ - Event(const std::string &name) + Event(Events name) { mEventName = name; } ~Event(); @@ -80,7 +134,7 @@ public: /** * Returns the name of the event. */ - const std::string &getName() const + Events getName() const { return mEventName; } // Integers @@ -247,8 +301,7 @@ public: * Sends an empty event with the given name to all classes listening to the * given channel. */ - static inline void trigger(Channels channel, - const std::string& name) + static inline void trigger(Channels channel, Events name) { trigger(channel, Mana::Event(name)); } protected: @@ -274,7 +327,7 @@ protected: private: static ListenMap mBindings; - std::string mEventName; + Events mEventName; VariableMap mData; }; diff --git a/src/game.cpp b/src/game.cpp index 4f2e1430..cb754701 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -129,7 +129,7 @@ ChatTab *localChatTab = NULL; */ static void initEngines() { - Mana::Event::trigger(CHANNEL_GAME, "EnginesInitalizing"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_ENGINESINITALIZING); actorSpriteManager = new ActorSpriteManager; commandHandler = new CommandHandler; @@ -139,7 +139,7 @@ static void initEngines() particleEngine = new Particle(NULL); particleEngine->setupEngine(); - Mana::Event::trigger(CHANNEL_GAME, "EnginesInitalized"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_ENGINESINITALIZED); } /** @@ -147,7 +147,7 @@ static void initEngines() */ static void createGuiWindows() { - Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsLoading"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_GUIWINDOWSLOADING); setupWindow->clearWindowsForReset(); @@ -174,7 +174,7 @@ static void createGuiWindows() NpcDialog::setup(); - Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsLoaded"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_GUIWINDOWSLOADED); } #define del_0(X) { delete X; X = 0; } @@ -184,7 +184,7 @@ static void createGuiWindows() */ static void destroyGuiWindows() { - Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsUnloading"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_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(CHANNEL_NPC, "CloseAll"); // Cleanup remaining NPC dialogs + Mana::Event::trigger(CHANNEL_NPC, EVENT_CLOSEALL); // Cleanup remaining NPC dialogs - Mana::Event::trigger(CHANNEL_GAME, "GuiWindowsUnloaded"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_GUIWINDOWSUNLOADED); } Game *Game::mInstance = 0; @@ -257,12 +257,12 @@ Game::Game(): setupWindow->setInGame(true); - Mana::Event::trigger(CHANNEL_GAME, "Constructed"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_CONSTRUCTED); } Game::~Game() { - Mana::Event::trigger(CHANNEL_GAME, "Destructing"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_DESTRUCTING); delete mWindowMenu; @@ -280,7 +280,7 @@ Game::~Game() mInstance = 0; - Mana::Event::trigger(CHANNEL_GAME, "Destructed"); + Mana::Event::trigger(CHANNEL_GAME, EVENT_DESTRUCTED); } static bool saveScreenshot() @@ -980,7 +980,7 @@ void Game::changeMap(const std::string &mapPath) delete mCurrentMap; mCurrentMap = newMap; - Mana::Event event("MapLoaded"); + Mana::Event event(EVENT_MAPLOADED); event.setString("mapPath", mapPath); event.trigger(CHANNEL_GAME); } diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 280d4d15..7acb7de8 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -379,29 +379,29 @@ void ChatWindow::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_NOTICES) { - if (event.getName() == "ServerNotice") + if (event.getName() == EVENT_SERVERNOTICE) localChatTab->chatLog(event.getString("message"), BY_SERVER); } else if (channel == CHANNEL_CHAT) { - if (event.getName() == "Whisper") + if (event.getName() == EVENT_WHISPER) { whisper(event.getString("nick"), event.getString("message")); } - else if (event.getName() == "WhisperError") + else if (event.getName() == EVENT_WHISPERERROR) { whisper(event.getString("nick"), event.getString("error"), BY_SERVER); } - else if (event.getName() == "Player") + else if (event.getName() == EVENT_PLAYER) { localChatTab->chatLog(event.getString("message"), BY_PLAYER); } - else if (event.getName() == "Announcement") + else if (event.getName() == EVENT_ANNOUNCEMENT) { localChatTab->chatLog(event.getString("message"), BY_GM); } - else if (event.getName() == "Being") + else if (event.getName() == EVENT_BEING) { if (event.getInt("permissions") & PlayerRelation::SPEECH_LOG) localChatTab->chatLog(event.getString("message"), BY_OTHER); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 474a9cb6..aeeaf223 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -158,7 +158,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) if (event.getId() == "unequip" && mSelected > -1) { Item *item = mEquipment->getEquipment(mSelected); - item->doEvent("doUnequip"); + item->doEvent(EVENT_DOUNEQUIP); setSelected(-1); } } diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index fab87844..31743c57 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -186,19 +186,19 @@ void InventoryWindow::action(const gcn::ActionEvent &event) return; if (event.getId() == "activate") - item->doEvent("doUse"); + item->doEvent(EVENT_DOUSE); else if (event.getId() == "equip") { if (item->isEquippable()) { if (item->isEquipped()) - item->doEvent("doUnequip"); + item->doEvent(EVENT_DOUNEQUIP); else - item->doEvent("doEquip"); + item->doEvent(EVENT_DOEQUIP); } else { - item->doEvent("doUse"); + item->doEvent(EVENT_DOUSE); } } else if (event.getId() == "drop") @@ -256,7 +256,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) return; if (mInventory->isMainInventory()) { - Mana::Event event("doMove"); + Mana::Event event(EVENT_DOMOVE); event.setItem("item", item); event.setInt("amount", item->getQuantity()); event.setInt("source", Inventory::INVENTORY); @@ -265,7 +265,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) } else { - Mana::Event event("doMove"); + Mana::Event event(EVENT_DOMOVE); event.setItem("item", item); event.setInt("amount", item->getQuantity()); event.setInt("source", Inventory::STORAGE); @@ -368,7 +368,7 @@ void InventoryWindow::close() } else { - Mana::Event event("doCloseInventory"); + Mana::Event event(EVENT_DOCLOSEINVENTORY); event.setInt("type", mInventory->getType()); event.trigger(CHANNEL_ITEM); scheduleDelete(); @@ -377,7 +377,7 @@ void InventoryWindow::close() void InventoryWindow::event(Channels channel, const Mana::Event &event) { - if (event.getName() == "UpdateAttribute") + if (event.getName() == EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == TOTAL_WEIGHT || diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp index bb8f95d0..85325c66 100644 --- a/src/gui/itemamount.cpp +++ b/src/gui/itemamount.cpp @@ -47,14 +47,14 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage) tradeWindow->tradeItem(item, amount); break; case ItemDrop: - item->doEvent("doDrop", amount); + item->doEvent(EVENT_DODROP, amount); break; case ItemSplit: - item->doEvent("doSplit", amount); + item->doEvent(EVENT_DOSPLIT, amount); break; case StoreAdd: { - Mana::Event event("doMove"); + Mana::Event event(EVENT_DOMOVE); event.setItem("item", item); event.setInt("amount", amount); event.setInt("source", Inventory::INVENTORY); @@ -64,7 +64,7 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage) break; case StoreRemove: { - Mana::Event event("doMove"); + Mana::Event event(EVENT_DOMOVE); event.setItem("item", item); event.setInt("amount", amount); event.setInt("source", Inventory::STORAGE); diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index ab01dbbd..fae40d03 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -123,7 +123,7 @@ void MiniStatusWindow::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_ATTRIBUTES) { - if (event.getName() == "UpdateAttribute") + if (event.getName() == EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == HP || id == MAX_HP) @@ -142,7 +142,7 @@ void MiniStatusWindow::event(Channels channel, const Mana::Event &event) } else if (channel == CHANNEL_ACTORSPRITE) { - if (event.getName() == "UpdateStatusEffect") + if (event.getName() == EVENT_UPDATESTATUSEFFECT) { int index = event.getInt("index"); bool newStatus = event.getBool("newStatus"); diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index f565a13f..33c18eca 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -225,7 +225,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) printText = mItems[selectedIndex]; - NpcEvent("doMenu") + NpcEvent(EVENT_DOMENU) event.setInt("choice", selectedIndex + 1); event.trigger(CHANNEL_NPC); } @@ -233,7 +233,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) { printText = mTextField->getText(); - NpcEvent("doStringInput") + NpcEvent(EVENT_DOSTRINGINPUT) event.setString("value", printText); event.trigger(CHANNEL_NPC); } @@ -241,7 +241,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) { printText = strprintf("%d", mIntField->getValue()); - NpcEvent("doIntegerInput") + NpcEvent(EVENT_DOINTEGERINPUT) event.setInt("value", mIntField->getValue()); event.trigger(CHANNEL_NPC); } @@ -281,13 +281,13 @@ void NpcDialog::action(const gcn::ActionEvent &event) void NpcDialog::nextDialog() { - NpcEvent("doNext"); + NpcEvent(EVENT_DONEXT); event.trigger(CHANNEL_NPC); } void NpcDialog::closeDialog() { - NpcEvent("doClose"); + NpcEvent(EVENT_DOCLOSE); event.trigger(CHANNEL_NPC); close(); } @@ -512,13 +512,13 @@ void NpcEventListener::event(Channels channel, if (channel != CHANNEL_NPC) return; - if (event.getName() == "Message") + if (event.getName() == EVENT_MESSAGE) { NpcDialog *dialog = getDialog(event.getInt("id")); dialog->addText(event.getString("text")); } - else if (event.getName() == "Menu") + else if (event.getName() == EVENT_MENU) { NpcDialog *dialog = getDialog(event.getInt("id")); @@ -528,7 +528,7 @@ void NpcEventListener::event(Channels channel, for (int i = 1; i <= count; i++) dialog->addChoice(event.getString("choice" + toString(i))); } - else if (event.getName() == "IntegerInput") + else if (event.getName() == EVENT_INTEGERINPUT) { NpcDialog *dialog = getDialog(event.getInt("id")); @@ -538,7 +538,7 @@ void NpcEventListener::event(Channels channel, dialog->integerRequest(defaultValue, min, max); } - else if (event.getName() == "StringInput") + else if (event.getName() == EVENT_STRINGINPUT) { NpcDialog *dialog = getDialog(event.getInt("id")); @@ -551,7 +551,7 @@ void NpcEventListener::event(Channels channel, dialog->textRequest(""); } } - else if (event.getName() == "Next") + else if (event.getName() == EVENT_NEXT) { int id = event.getInt("id"); NpcDialog *dialog = getDialog(id, false); @@ -559,14 +559,14 @@ void NpcEventListener::event(Channels channel, if (!dialog) { int mNpcId = id; - NpcEvent("doNext"); + NpcEvent(EVENT_DONEXT); event.trigger(CHANNEL_NPC); return; } dialog->showNextButton(); } - else if (event.getName() == "Close") + else if (event.getName() == EVENT_CLOSE) { int id = event.getInt("id"); NpcDialog *dialog = getDialog(id, false); @@ -574,18 +574,18 @@ void NpcEventListener::event(Channels channel, if (!dialog) { int mNpcId = id; - NpcEvent("doClose"); + NpcEvent(EVENT_DOCLOSE); event.trigger(CHANNEL_NPC); return; } dialog->showCloseButton(); } - else if (event.getName() == "CloseAll") + else if (event.getName() == EVENT_CLOSEALL) { NpcDialog::closeAll(); } - else if (event.getName() == "End") + else if (event.getName() == EVENT_END) { int id = event.getInt("id"); NpcDialog *dialog = getDialog(id, false); @@ -593,7 +593,7 @@ void NpcEventListener::event(Channels channel, if (dialog) dialog->close(); } - else if (event.getName() == "Post") + else if (event.getName() == EVENT_POST) { new NpcPostDialog(event.getInt("id")); } diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp index a4740027..7a85dda5 100644 --- a/src/gui/npcpostdialog.cpp +++ b/src/gui/npcpostdialog.cpp @@ -97,7 +97,7 @@ void NpcPostDialog::action(const gcn::ActionEvent &event) } else { - Mana::Event event("doSendLetter"); + Mana::Event event(EVENT_DOSENDLETTER); event.setInt("npcId", mNpcId); event.setString("recipient", mSender->getText()); event.setString("text", mText->getText()); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 7e126dc8..8da8914a 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -172,7 +172,7 @@ void OutfitWindow::wearOutfit(int outfit) if (item && !item->isEquipped() && item->getQuantity()) { if (item->isEquippable()) - item->doEvent("doEquip"); + item->doEvent(EVENT_DOEQUIP); } } } @@ -341,7 +341,7 @@ void OutfitWindow::unequipNotInOutfit(int outfit) Item *item = inventory->getItem(i); if (item) - item->doEvent("doUnequip"); + item->doEvent(EVENT_DOUNEQUIP); } } } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 3d389374..8ff638c2 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -269,13 +269,13 @@ void PopupMenu::handleLink(const std::string &link) if (mItem->isEquippable()) { if (mItem->isEquipped()) - mItem->doEvent("doUnequip"); + mItem->doEvent(EVENT_DOUNEQUIP); else - mItem->doEvent("doEquip"); + mItem->doEvent(EVENT_DOEQUIP); } else { - mItem->doEvent("doUse"); + mItem->doEvent(EVENT_DOUSE); } } else if (link == "chat") diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 654d2bf3..a3420f06 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -219,7 +219,7 @@ StatusWindow::StatusWindow(): void StatusWindow::event(Channels channel, const Mana::Event &event) { - if (event.getName() == "UpdateAttribute") + if (event.getName() == EVENT_UPDATEATTRIBUTE) { switch(event.getInt("id")) { @@ -265,7 +265,7 @@ void StatusWindow::event(Channels channel, const Mana::Event &event) break; } } - else if (event.getName() == "UpdateStat") + else if (event.getName() == EVENT_UPDATESTAT) { int id = event.getInt("id"); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 6cef33a1..4152bd95 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -558,7 +558,7 @@ void Viewport::hideBeingPopup() void Viewport::event(Channels channel, const Mana::Event &event) { - if (channel == CHANNEL_ACTORSPRITE && event.getName() == "Destroyed") + if (channel == CHANNEL_ACTORSPRITE && event.getName() == EVENT_DESTROYED) { ActorSprite *actor = event.getActor("source"); diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index bf0272ee..2e9b698d 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -308,7 +308,7 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event) Item *item = getSelectedItem(); { - Mana::Event event("doMove"); + Mana::Event event(EVENT_DOMOVE); event.setItem("item", item); event.setInt("newIndex", index); event.trigger(CHANNEL_ITEM); @@ -380,7 +380,7 @@ void ItemContainer::keyAction() mHighlightedIndex != -1) { Item *item = getSelectedItem(); - Mana::Event event("doMove"); + Mana::Event event(EVENT_DOMOVE); event.setItem("item", item); event.setInt("newIndex", mHighlightedIndex); event.trigger(CHANNEL_ITEM); @@ -396,7 +396,7 @@ void ItemContainer::keyAction() else if (mSelectedIndex != -1) { Item *item = getSelectedItem(); - Mana::Event event("doMove"); + Mana::Event event(EVENT_DOMOVE); event.setItem("item", item); event.setInt("newIndex", mHighlightedIndex); event.trigger(CHANNEL_ITEM); diff --git a/src/item.cpp b/src/item.cpp index 7357d35f..fee7e86f 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -72,14 +72,14 @@ void Item::setId(int id) "unknown-item.png")); } -void Item::doEvent(const std::string &eventName) +void Item::doEvent(Events eventName) { Mana::Event event(eventName); event.setItem("item", this); event.trigger(CHANNEL_ITEM); } -void Item::doEvent(const std::string &eventName, int amount) +void Item::doEvent(Events eventName, int amount) { Mana::Event event(eventName); event.setItem("item", this); @@ -22,6 +22,8 @@ #ifndef ITEM_H #define ITEM_H +#include "event.h" + #include "resources/itemdb.h" class Image; @@ -112,9 +114,9 @@ class Item */ int getInvIndex() const { return mInvIndex; } - void doEvent(const std::string &eventName); + void doEvent(Events eventName); - void doEvent(const std::string &eventName, int amount); + void doEvent(Events eventName, int amount); /** * Returns information about this item type. diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index ef4f6387..2d65c7e9 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -75,13 +75,13 @@ void ItemShortcut::useItem(int index) if (item->getInfo().getEquippable()) { if (item->isEquipped()) - item->doEvent("doUnequip"); + item->doEvent(EVENT_DOUNEQUIP); else - item->doEvent("doEquip"); + item->doEvent(EVENT_DOEQUIP); } else { - item->doEvent("doUse"); + item->doEvent(EVENT_DOUSE); } } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index a0e7184d..79f814a3 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -1088,7 +1088,7 @@ void LocalPlayer::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_ACTORSPRITE) { - if (event.getName() == "Destroyed") + if (event.getName() == EVENT_DESTROYED) { ActorSprite *actor = event.getActor("source"); @@ -1101,7 +1101,7 @@ void LocalPlayer::event(Channels channel, const Mana::Event &event) } else if (channel == CHANNEL_ATTRIBUTES) { - if (event.getName() == "UpdateAttribute") + if (event.getName() == EVENT_UPDATEATTRIBUTE) { if (event.getInt("id") == EXP) { diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index 70910cf6..db0e1084 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -163,7 +163,7 @@ void ChatHandler::handleGameChatMessage(Net::MessageIn &msg) else mes = "Unknown : " + chatMsg; - Mana::Event event(being == player_node ? "Player" : "Being"); + Mana::Event event(being == player_node ? EVENT_PLAYER : EVENT_BEING); event.setString("message", mes); event.setString("text", chatMsg); event.setString("nick", being->getName()); @@ -231,7 +231,7 @@ void ChatHandler::handlePrivateMessage(Net::MessageIn &msg) std::string userNick = msg.readString(); std::string chatMsg = msg.readString(); - Mana::Event event("Whisper"); + Mana::Event event(EVENT_WHISPER); event.setString("nick", userNick); event.setString("message", chatMsg); event.trigger(CHANNEL_CHAT); @@ -240,7 +240,7 @@ void ChatHandler::handlePrivateMessage(Net::MessageIn &msg) void ChatHandler::handleAnnouncement(Net::MessageIn &msg) { std::string chatMsg = msg.readString(); - Mana::Event event("Announcement"); + Mana::Event event(EVENT_ANNOUNCEMENT); event.setString("message", chatMsg); event.trigger(CHANNEL_CHAT); } diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index 178e0c48..d2151307 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -176,7 +176,7 @@ void GeneralHandler::event(Channels channel, { if (channel == CHANNEL_CLIENT) { - if (event.getName() == "StateChange") + if (event.getName() == EVENT_STATECHANGE) { int newState = event.getInt("newState"); @@ -186,7 +186,7 @@ void GeneralHandler::event(Channels channel, game->gameLoading(); } } - else if (event.getName() == "DBsLoading") + else if (event.getName() == EVENT_DBSLOADING) { Attributes::load(); Attributes::informItemDB(); @@ -194,7 +194,7 @@ void GeneralHandler::event(Channels channel, } else if (channel == CHANNEL_GAME) { - if (event.getName() == "GuiWindowsLoaded") + if (event.getName() == EVENT_GUIWINDOWSLOADED) { inventoryWindow->setSplitAllowed(true); skillDialog->loadSkills("mana-skills.xml"); diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 45ab1ebd..9d2fdfeb 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -120,13 +120,13 @@ void InventoryHandler::event(Channels channel, int index = item->getInvIndex(); - if (event.getName() == "doEquip") + if (event.getName() == EVENT_DOEQUIP) { MessageOut msg(PGMSG_EQUIP); msg.writeInt8(index); gameServerConnection->send(msg); } - else if (event.getName() == "doUnequip") + else if (event.getName() == EVENT_DOUNEQUIP) { MessageOut msg(PGMSG_UNEQUIP); msg.writeInt8(index); @@ -136,13 +136,13 @@ void InventoryHandler::event(Channels channel, // for instance. mEquips.setEquipment(index, 0, 0); } - else if (event.getName() == "doUse") + else if (event.getName() == EVENT_DOUSE) { MessageOut msg(PGMSG_USE_ITEM); msg.writeInt8(index); gameServerConnection->send(msg); } - else if (event.getName() == "doDrop") + else if (event.getName() == EVENT_DODROP) { int amount = event.getInt("amount", 1); @@ -151,7 +151,7 @@ void InventoryHandler::event(Channels channel, msg.writeInt8(amount); gameServerConnection->send(msg); } - else if (event.getName() == "doSplit") + else if (event.getName() == EVENT_DOSPLIT) { int amount = event.getInt("amount", 1); @@ -165,7 +165,7 @@ void InventoryHandler::event(Channels channel, gameServerConnection->send(msg); } } - else if (event.getName() == "doMove") + else if (event.getName() == EVENT_DOMOVE) { int newIndex = event.getInt("newIndex", -1); diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index 64162cc5..403dedb6 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -69,7 +69,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case GPMSG_NPC_CHOICE: - event = new Mana::Event("Menu"); + event = new Mana::Event(EVENT_MENU); event->setInt("id", npcId); while (msg.getUnreadLength()) { @@ -81,7 +81,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) break; case GPMSG_NPC_NUMBER: - event = new Mana::Event("IntegerInput"); + event = new Mana::Event(EVENT_INTEGERINPUT); event->setInt("id", npcId); event->setInt("min", msg.readInt32()); event->setInt("max", msg.readInt32()); @@ -90,37 +90,37 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) break; case GPMSG_NPC_STRING: - event = new Mana::Event("StringInput"); + event = new Mana::Event(EVENT_STRINGINPUT); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_POST: - event = new Mana::Event("Post"); + event = new Mana::Event(EVENT_POST); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_ERROR: - event = new Mana::Event("End"); + event = new Mana::Event(EVENT_END); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_MESSAGE: - event = new Mana::Event("Message"); + event = new Mana::Event(EVENT_MESSAGE); event->setInt("id", npcId); event->setString("text", msg.readString(msg.getUnreadLength())); event->trigger(CHANNEL_NPC); delete event; - event = new Mana::Event("Next"); + event = new Mana::Event(EVENT_NEXT); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; case GPMSG_NPC_CLOSE: - event = new Mana::Event("Close"); + event = new Mana::Event(EVENT_CLOSE); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; @@ -133,40 +133,41 @@ void NpcHandler::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_NPC) { - if (event.getName() == "doTalk") + if (event.getName() == EVENT_DOTALK) { MessageOut msg(PGMSG_NPC_TALK); msg.writeInt16(event.getInt("npcId")); gameServerConnection->send(msg); } - else if (event.getName() == "doNext" || event.getName() == "doClose") + else if (event.getName() == EVENT_DONEXT || + event.getName() == EVENT_DOCLOSE) { MessageOut msg(PGMSG_NPC_TALK_NEXT); msg.writeInt16(event.getInt("npcId")); gameServerConnection->send(msg); } - else if (event.getName() == "doMenu") + else if (event.getName() == EVENT_DOMENU) { MessageOut msg(PGMSG_NPC_SELECT); msg.writeInt16(event.getInt("npcId")); msg.writeInt8(event.getInt("choice")); gameServerConnection->send(msg); } - else if (event.getName() == "doIntegerInput") + else if (event.getName() == EVENT_DOINTEGERINPUT) { MessageOut msg(PGMSG_NPC_NUMBER); msg.writeInt16(event.getInt("npcId")); msg.writeInt32(event.getInt("value")); gameServerConnection->send(msg); } - else if (event.getName() == "doStringInput") + else if (event.getName() == EVENT_DOSTRINGINPUT) { MessageOut msg(PGMSG_NPC_STRING); msg.writeInt16(event.getInt("npcId")); msg.writeString(event.getString("value")); gameServerConnection->send(msg); } - else if (event.getName() == "doSendLetter") + else if (event.getName() == EVENT_DOSENDLETTER) { MessageOut msg(PGMSG_NPC_POST_SEND); msg.writeString(event.getString("recipient")); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index d9bfb2b6..be09ff69 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(CHANNEL_NPC, "CloseAll"); + Mana::Event::trigger(CHANNEL_NPC, EVENT_CLOSEALL); } PlayerHandler::PlayerHandler() diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 9529a386..33826762 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -82,7 +82,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) break; case 0x01: { - Mana::Event event("WhisperError"); + Mana::Event event(EVENT_WHISPERERROR); event.setString("nick", nick); event.setString("error", strprintf(_("Whisper could " "not be sent, %s is offline."), nick.c_str())); @@ -91,7 +91,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) break; case 0x02: { - Mana::Event event("WhisperError"); + Mana::Event event(EVENT_WHISPERERROR); event.setString("nick", nick); event.setString("error", strprintf(_("Whisper could " "not be sent, ignored by %s."), nick.c_str())); @@ -115,7 +115,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) { if (player_relations.hasPermission(nick, PlayerRelation::WHISPER)) { - Mana::Event event("Whisper"); + Mana::Event event(EVENT_WHISPER); event.setString("nick", nick); event.setString("message", chatMsg); event.trigger(CHANNEL_CHAT); @@ -174,7 +174,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) std::string reducedMessage = chatMsg; chatMsg = removeColors(sender_name) + " : " + reducedMessage; - Mana::Event event("Being"); + Mana::Event event(EVENT_BEING); event.setString("message", chatMsg); event.setString("text", reducedMessage); event.setString("nick", sender_name); @@ -205,7 +205,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) trim(chatMsg); - Mana::Event event("Player"); + Mana::Event event(EVENT_PLAYER); event.setString("message", mes); event.setString("text", chatMsg); event.setString("nick", player_node->getName()); @@ -217,7 +217,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) } else { - Mana::Event event("Announcement"); + Mana::Event event(EVENT_ANNOUNCEMENT); event.setString("message", chatMsg); event.trigger(CHANNEL_CHAT); } diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index d98daa64..63f5fcec 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -109,11 +109,11 @@ void GameHandler::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_GAME) { - if (event.getName() == "EnginesInitalized") + if (event.getName() == EVENT_ENGINESINITALIZED) { Game::instance()->changeMap(mMap); } - else if (event.getName() == "MapLoaded") + else if (event.getName() == EVENT_MAPLOADED) { MessageOut outMsg(CMSG_MAP_LOADED); } diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index f9ed97b0..b4327d47 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -222,7 +222,7 @@ void GeneralHandler::event(Channels channel, { if (channel == CHANNEL_GAME) { - if (event.getName() == "GuiWindowsLoaded") + if (event.getName() == EVENT_GUIWINDOWSLOADED) { inventoryWindow->setSplitAllowed(false); skillDialog->loadSkills("ea-skills.xml"); @@ -242,7 +242,7 @@ void GeneralHandler::event(Channels channel, statusWindow->addAttribute(FLEE, _("% Evade"), false, ""); statusWindow->addAttribute(CRIT, _("% Critical"), false, ""); } - else if (event.getName() == "GuiWindowsUnloading") + else if (event.getName() == EVENT_GUIWINDOWSUNLOADING) { socialWindow->removeTab(taGuild); socialWindow->removeTab(taParty); diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index ae79ab09..3a0a93e3 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -435,7 +435,7 @@ void InventoryHandler::event(Channels channel, { if (channel == CHANNEL_ITEM) { - if (event.getName() == "doCloseInventory") + if (event.getName() == EVENT_DOCLOSEINVENTORY) { // No need to worry about type MessageOut outMsg(CMSG_CLOSE_STORAGE); @@ -449,24 +449,24 @@ void InventoryHandler::event(Channels channel, int index = item->getInvIndex() + INVENTORY_OFFSET; - if (event.getName() == "doEquip") + if (event.getName() == EVENT_DOEQUIP) { MessageOut outMsg(CMSG_PLAYER_EQUIP); outMsg.writeInt16(index); outMsg.writeInt16(0); } - else if (event.getName() == "doUnequip") + else if (event.getName() == EVENT_DOUNEQUIP) { MessageOut outMsg(CMSG_PLAYER_UNEQUIP); outMsg.writeInt16(index); } - else if (event.getName() == "doUse") + else if (event.getName() == EVENT_DOUSE) { MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE); outMsg.writeInt16(index); outMsg.writeInt32(item->getId()); // unused } - else if (event.getName() == "doDrop") + else if (event.getName() == EVENT_DODROP) { int amount = event.getInt("amount", 1); @@ -476,7 +476,7 @@ void InventoryHandler::event(Channels channel, outMsg.writeInt16(index); outMsg.writeInt16(amount); } - else if (event.getName() == "doMove") + else if (event.getName() == EVENT_DOMOVE) { int newIndex = event.getInt("newIndex", -1); diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 1f85e9a6..1b12b63f 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -85,14 +85,14 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case SMSG_NPC_CHOICE: - event = new Mana::Event("Menu"); + event = new Mana::Event(EVENT_MENU); event->setInt("id", npcId); parseMenu(event, msg.readString(msg.getLength() - 8)); event->trigger(CHANNEL_NPC); break; case SMSG_NPC_MESSAGE: - event = new Mana::Event("Message"); + event = new Mana::Event(EVENT_MESSAGE); event->setInt("id", npcId); event->setString("text", msg.readString(msg.getLength() - 8)); event->trigger(CHANNEL_NPC); @@ -100,28 +100,28 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) case SMSG_NPC_CLOSE: // Show the close button - event = new Mana::Event("Close"); + event = new Mana::Event(EVENT_CLOSE); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; case SMSG_NPC_NEXT: // Show the next button - event = new Mana::Event("Next"); + event = new Mana::Event(EVENT_NEXT); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; case SMSG_NPC_INT_INPUT: // Request for an integer - event = new Mana::Event("IntegerInput"); + event = new Mana::Event(EVENT_INTEGERINPUT); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; case SMSG_NPC_STR_INPUT: // Request for a string - event = new Mana::Event("StringInput"); + event = new Mana::Event(EVENT_STRINGINPUT); event->setInt("id", npcId); event->trigger(CHANNEL_NPC); break; @@ -137,35 +137,35 @@ void NpcHandler::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_NPC) { - if (event.getName() == "doTalk") + if (event.getName() == EVENT_DOTALK) { MessageOut outMsg(CMSG_NPC_TALK); outMsg.writeInt32(event.getInt("npcId")); outMsg.writeInt8(0); // Unused } - else if (event.getName() == "doNext") + else if (event.getName() == EVENT_DONEXT) { MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(event.getInt("npcId")); } - else if (event.getName() == "doClose") + else if (event.getName() == EVENT_DOCLOSE) { MessageOut outMsg(CMSG_NPC_CLOSE); outMsg.writeInt32(event.getInt("npcId")); } - else if (event.getName() == "doMenu") + else if (event.getName() == EVENT_DOMENU) { MessageOut outMsg(CMSG_NPC_LIST_CHOICE); outMsg.writeInt32(event.getInt("npcId")); outMsg.writeInt8(event.getInt("choice")); } - else if (event.getName() == "doIntegerInput") + else if (event.getName() == EVENT_DOINTEGERINPUT) { MessageOut outMsg(CMSG_NPC_INT_RESPONSE); outMsg.writeInt32(event.getInt("npcId")); outMsg.writeInt32(event.getInt("value")); } - else if (event.getName() == "doStringInput") + else if (event.getName() == EVENT_DOSTRINGINPUT) { const std::string &value = event.getString("value"); MessageOut outMsg(CMSG_NPC_STR_RESPONSE); diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index eeba7ae7..b82968a3 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -81,7 +81,7 @@ namespace { viewport->closePopupMenu(); - Mana::Event::trigger(CHANNEL_NPC, "CloseAll"); + Mana::Event::trigger(CHANNEL_NPC, EVENT_CLOSEALL); } } deathListener; diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index c8615485..034b959d 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -191,7 +191,7 @@ void TradeHandler::handleMessage(Net::MessageIn &msg) // Successfully added item if (item->isEquippable() && item->isEquipped()) { - item->doEvent("doUnequip"); + item->doEvent(EVENT_DOUNEQUIP); } tradeWindow->addItem(item->getId(), true, quantity); diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 8757053c..a8e2bebb 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -58,7 +58,7 @@ int mLevelProgress = 0; void triggerAttr(int id, int old) { - Mana::Event event("UpdateAttribute"); + Mana::Event event(EVENT_UPDATEATTRIBUTE); event.setInt("id", id); event.setInt("oldValue", old); event.setInt("newValue", mData.mAttributes.find(id)->second); @@ -68,7 +68,7 @@ void triggerAttr(int id, int old) void triggerStat(int id, const std::string &changed, int old1, int old2 = 0) { StatMap::iterator it = mData.mStats.find(id); - Mana::Event event("UpdateStat"); + Mana::Event event(EVENT_UPDATESTAT); event.setInt("id", id); event.setInt("base", it->second.base); event.setInt("mod", it->second.mod); @@ -216,7 +216,7 @@ void setStorageCount(int count) if (count != old) { - Mana::Event event("StorageCount"); + Mana::Event event(EVENT_STORAGECOUNT); event.setInt("oldCount", old); event.setInt("newCount", count); event.trigger(CHANNEL_STORAGE); @@ -237,7 +237,7 @@ void setNPCInteractionCount(int count) if (count != old) { - Mana::Event event("NPCCount"); + Mana::Event event(EVENT_NPCCOUNT); event.setInt("oldCount", old); event.setInt("newCount", count); event.trigger(CHANNEL_NPC); @@ -256,7 +256,7 @@ void setNPCPostCount(int count) if (count != old) { - Mana::Event event("PostCount"); + Mana::Event event(EVENT_POSTCOUNT); event.setInt("oldCount", old); event.setInt("newCount", count); event.trigger(CHANNEL_NPC); @@ -277,7 +277,7 @@ void setBuySellState(BuySellState buySellState) if (buySellState != old) { - Mana::Event event("StateChange"); + Mana::Event event(EVENT_STATECHANGE); event.setInt("oldState", old); event.setInt("newState", buySellState); event.trigger(CHANNEL_BUYSELL); @@ -296,7 +296,7 @@ void setTrading(bool trading) if (notify) { - Mana::Event event("Trading"); + Mana::Event event(EVENT_TRADING); event.setBool("trading", trading); event.trigger(CHANNEL_STATUS); } @@ -362,7 +362,7 @@ public: { if (channel == CHANNEL_CLIENT) { - if (event.getName() == "StateChange") + if (event.getName() == EVENT_STATECHANGE) { int newState = event.getInt("newState"); @@ -378,7 +378,7 @@ public: } else if (channel == CHANNEL_GAME) { - if (event.getName() == "Destructed") + if (event.getName() == EVENT_DESTRUCTED) { delete mInventory; delete mEquipment; |