diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-04-09 19:49:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-04-09 19:49:14 +0300 |
commit | 7e3bd20e9675202e30fac741f3d3acb4f19b109d (patch) | |
tree | 9e12ab198b68e8f6ed0dd2121a72066c7b7053ba | |
parent | b9d66c41246fef56e41f600b5523a5ff1a29a1c8 (diff) | |
download | mv-7e3bd20e9675202e30fac741f3d3acb4f19b109d.tar.gz mv-7e3bd20e9675202e30fac741f3d3acb4f19b109d.tar.bz2 mv-7e3bd20e9675202e30fac741f3d3acb4f19b109d.tar.xz mv-7e3bd20e9675202e30fac741f3d3acb4f19b109d.zip |
Small refactoring based on idea from mana commit 30d4b0adf4f17f05d1d62fc3428c896ef1079b6b
-rw-r--r-- | src/event.h | 11 | ||||
-rw-r--r-- | src/gui/chatwindow.cpp | 14 | ||||
-rw-r--r-- | src/gui/chatwindow.h | 2 | ||||
-rw-r--r-- | src/gui/inventorywindow.cpp | 6 | ||||
-rw-r--r-- | src/gui/inventorywindow.h | 2 | ||||
-rw-r--r-- | src/gui/killstats.cpp | 6 | ||||
-rw-r--r-- | src/gui/killstats.h | 2 | ||||
-rw-r--r-- | src/gui/ministatus.cpp | 8 | ||||
-rw-r--r-- | src/gui/ministatus.h | 2 | ||||
-rw-r--r-- | src/gui/statuswindow.cpp | 8 | ||||
-rw-r--r-- | src/gui/statuswindow.h | 2 | ||||
-rw-r--r-- | src/localplayer.cpp | 10 | ||||
-rw-r--r-- | src/localplayer.h | 2 | ||||
-rw-r--r-- | src/net/manaserv/generalhandler.cpp | 12 | ||||
-rw-r--r-- | src/net/manaserv/generalhandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/gamehandler.cpp | 10 | ||||
-rw-r--r-- | src/net/tmwa/gamehandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.cpp | 8 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.h | 2 | ||||
-rw-r--r-- | src/playerinfo.cpp | 26 |
20 files changed, 69 insertions, 68 deletions
diff --git a/src/event.h b/src/event.h index 7c5863ec8..8634a654c 100644 --- a/src/event.h +++ b/src/event.h @@ -26,6 +26,10 @@ #include <set> #include <string> + +namespace Mana +{ + enum Channels { CHANNEL_ACTORSPRITE = 0, @@ -95,9 +99,6 @@ enum Events EVENT_WHISPERERROR }; -namespace Mana -{ - // Possible exception that can be thrown enum BadEvent { @@ -114,9 +115,9 @@ typedef std::set<Listener *> ListenerSet; typedef std::map<Channels, ListenerSet > ListenMap; #define SERVER_NOTICE(message) { \ -Mana::Event event(EVENT_SERVERNOTICE); \ +Mana::Event event(Mana::EVENT_SERVERNOTICE); \ event.setString("message", message); \ -Mana::Event::trigger(CHANNEL_NOTICES, event); } +Mana::Event::trigger(Mana::CHANNEL_NOTICES, event); } class Event { diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 47db83c75..372461b29 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -154,7 +154,7 @@ ChatWindow::ChatWindow(): mChatHistoryIndex(0) { listen(CHANNEL_NOTICES); - listen(CHANNEL_ATTRIBUTES); + listen(Mana::CHANNEL_ATTRIBUTES); setWindowName("Chat"); @@ -798,19 +798,19 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) addInputText(Temp, false); } -void ChatWindow::event(Channels channel, const Mana::Event &event) +void ChatWindow::event(Mana::Channels channel, const Mana::Event &event) { - if (channel == CHANNEL_NOTICES) + if (channel == Mana::CHANNEL_NOTICES) { - if (event.getName() == EVENT_SERVERNOTICE && localChatTab) + if (event.getName() == Mana::EVENT_SERVERNOTICE && localChatTab) localChatTab->chatLog(event.getString("message"), BY_SERVER); } - else if (channel == CHANNEL_ATTRIBUTES) + else if (channel == Mana::CHANNEL_ATTRIBUTES) { if (!config.getBoolValue("showBattleEvents")) return; - if (event.getName() == EVENT_UPDATEATTRIBUTE) + if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) { switch (event.getInt("id")) { @@ -834,7 +834,7 @@ void ChatWindow::event(Channels channel, const Mana::Event &event) break; }; } - else if (event.getName() == EVENT_UPDATESTAT) + else if (event.getName() == Mana::EVENT_UPDATESTAT) { if (!config.getBoolValue("showJobExp")) return; diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index d8457d691..d22aea64c 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -191,7 +191,7 @@ class ChatWindow : public Window, */ void mousePressed(gcn::MouseEvent &event); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); /** * Scrolls the chat window diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index b897ad4b8..403868cd1 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -78,7 +78,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory): setWindowName("Inventory"); } - listen(CHANNEL_ATTRIBUTES); + listen(Mana::CHANNEL_ATTRIBUTES); if (setupWindow) setupWindow->registerWindowForReset(this); @@ -493,10 +493,10 @@ void InventoryWindow::close() } } -void InventoryWindow::event(Channels channel _UNUSED_, +void InventoryWindow::event(Mana::Channels channel _UNUSED_, const Mana::Event &event) { - if (event.getName() == EVENT_UPDATEATTRIBUTE) + if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == TOTAL_WEIGHT || id == MAX_WEIGHT) diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index de899afb8..63da97173 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -124,7 +124,7 @@ class InventoryWindow : public Window, void updateDropButton(); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); private: /** diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp index e373153e6..1486fdd64 100644 --- a/src/gui/killstats.cpp +++ b/src/gui/killstats.cpp @@ -54,7 +54,7 @@ KillStats::KillStats(): setResizable(true); setDefaultSize(250, 250, 350, 300); - listen(CHANNEL_ATTRIBUTES); + listen(Mana::CHANNEL_ATTRIBUTES); int xp(PlayerInfo::getAttribute(EXP)); int xpNextLevel(PlayerInfo::getAttribute(EXP_NEEDED)); @@ -409,10 +409,10 @@ void KillStats::validateJacko() } } -void KillStats::event(Channels channel _UNUSED_, +void KillStats::event(Mana::Channels channel _UNUSED_, const Mana::Event &event) { - if (event.getName() == EVENT_UPDATEATTRIBUTE) + if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == EXP || id == EXP_NEEDED) diff --git a/src/gui/killstats.h b/src/gui/killstats.h index df53aa319..59b1ff653 100644 --- a/src/gui/killstats.h +++ b/src/gui/killstats.h @@ -77,7 +77,7 @@ class KillStats : public Window, gcn::ActionListener, public Mana::Listener void addLog(std::string str); - void event(Channels channel _UNUSED_, + void event(Mana::Channels channel _UNUSED_, const Mana::Event &event); private: diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index e0103f080..213693e0a 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -51,7 +51,7 @@ extern volatile int tick_time; MiniStatusWindow::MiniStatusWindow(): Popup("MiniStatus") { - listen(CHANNEL_ATTRIBUTES); + listen(Mana::CHANNEL_ATTRIBUTES); mHpBar = createBar(0, 100, 20, Theme::PROG_HP, "hp bar", _("health bar")); StatusWindow::updateHPBar(mHpBar); @@ -209,10 +209,10 @@ void MiniStatusWindow::drawIcons(Graphics *graphics) } } -void MiniStatusWindow::event(Channels channel _UNUSED_, +void MiniStatusWindow::event(Mana::Channels channel _UNUSED_, const Mana::Event &event) { - if (event.getName() == EVENT_UPDATEATTRIBUTE) + if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == HP || id == MAX_HP) @@ -226,7 +226,7 @@ void MiniStatusWindow::event(Channels channel _UNUSED_, else if (id == MONEY) StatusWindow::updateMoneyBar(mMoneyBar); } - else if (event.getName() == EVENT_UPDATESTAT) + else if (event.getName() == Mana::EVENT_UPDATESTAT) { StatusWindow::updateMPBar(mMpBar); StatusWindow::updateJobBar(mJobBar); diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 9a88a3d7d..a2648d44b 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -66,7 +66,7 @@ class MiniStatusWindow : public Popup, void drawIcons(Graphics *graphics); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); void updateStatus(); diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 19ec14a50..82c97ff43 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -114,7 +114,7 @@ class ChangeDisplay : public AttrDisplay, gcn::ActionListener StatusWindow::StatusWindow(): Window(player_node ? player_node->getName() : "?") { - listen(CHANNEL_ATTRIBUTES); + listen(Mana::CHANNEL_ATTRIBUTES); setWindowName("Status"); setupWindow->registerWindowForReset(this); @@ -260,14 +260,14 @@ StatusWindow::StatusWindow(): mLvlLabel->adjustSize(); } -void StatusWindow::event(Channels channel _UNUSED_, +void StatusWindow::event(Mana::Channels channel _UNUSED_, const Mana::Event &event) { static bool blocked = false; if (blocked) return; - if (event.getName() == EVENT_UPDATEATTRIBUTE) + if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) { switch(event.getInt("id")) { @@ -326,7 +326,7 @@ void StatusWindow::event(Channels channel _UNUSED_, break; } } - else if (event.getName() == EVENT_UPDATESTAT) + else if (event.getName() == Mana::EVENT_UPDATESTAT) { int id = event.getInt("id"); if (id == Net::getPlayerHandler()->getJobLocation()) diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index f9837ba26..79126a095 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -56,7 +56,7 @@ class StatusWindow : public Window, public Mana::Listener */ StatusWindow(); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); void setPointsNeeded(int id, int needed); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 7cf26cd44..2497e09f9 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -124,7 +124,7 @@ LocalPlayer::LocalPlayer(int id, int subtype): { logger->log1("LocalPlayer::LocalPlayer"); - listen(CHANNEL_ATTRIBUTES); + listen(Mana::CHANNEL_ATTRIBUTES); mLevel = 1; mAwayListener = new AwayListener(); @@ -1547,11 +1547,11 @@ void LocalPlayer::optionChanged(const std::string &value) mShowJobExp = config.getBoolValue("showJobExp"); } -void LocalPlayer::event(Channels channel, const Mana::Event &event) +void LocalPlayer::event(Mana::Channels channel, const Mana::Event &event) { - if (channel == CHANNEL_ATTRIBUTES) + if (channel == Mana::CHANNEL_ATTRIBUTES) { - if (event.getName() == EVENT_UPDATEATTRIBUTE) + if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) { switch (event.getInt("id")) { @@ -1574,7 +1574,7 @@ void LocalPlayer::event(Channels channel, const Mana::Event &event) break; }; } - else if (event.getName() == EVENT_UPDATESTAT) + else if (event.getName() == Mana::EVENT_UPDATESTAT) { if (!mShowJobExp) return; diff --git a/src/localplayer.h b/src/localplayer.h index 4d177a23b..10c5b945e 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -384,7 +384,7 @@ class LocalPlayer : public Being, public ActorSpriteListener, */ void optionChanged(const std::string &value); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); /** * set a following player. diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index 3683187fe..8b38deb21 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -176,28 +176,28 @@ void GeneralHandler::clearHandlers() clearNetworkHandlers(); } -void GeneralHandler::event(Channels channel, +void GeneralHandler::event(Mana::Channels channel, const Mana::Event &event) { - if (channel == CHANNEL_CLIENT) + if (channel == Mana::CHANNEL_CLIENT) { int newState = event.getInt("newState"); - if (newState == STATE_GAME) + if (newState == Mana::STATE_GAME) { GameHandler *game = static_cast<GameHandler*>( Net::getGameHandler()); game->gameLoading(); } - else if (newState == STATE_LOAD_DATA) + else if (newState == Mana::STATE_LOAD_DATA) { Attributes::load(); Attributes::informItemDB(); } } - else if (channel == CHANNEL_GAME) + else if (channel == Mana::CHANNEL_GAME) { - if (event.getName() == EVENT_GUIWINDOWSLOADED) + if (event.getName() == Mana::EVENT_GUIWINDOWSLOADED) { inventoryWindow->setSplitAllowed(true); skillDialog->loadSkills("mana-skills.xml"); diff --git a/src/net/manaserv/generalhandler.h b/src/net/manaserv/generalhandler.h index d5636127f..946f7d631 100644 --- a/src/net/manaserv/generalhandler.h +++ b/src/net/manaserv/generalhandler.h @@ -54,7 +54,7 @@ class GeneralHandler : public Net::GeneralHandler, public Mana::Listener void clearHandlers(); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); protected: MessageHandlerPtr mBeingHandler; diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index 3e22e94bb..b1f72a834 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -62,7 +62,7 @@ GameHandler::GameHandler() gameHandler = this; mCharID = 0; - listen(CHANNEL_GAME); + listen(Mana::CHANNEL_GAME); } void GameHandler::handleMessage(Net::MessageIn &msg) @@ -109,13 +109,13 @@ void GameHandler::handleMessage(Net::MessageIn &msg) } } -void GameHandler::event(Channels channel, const Mana::Event &event) +void GameHandler::event(Mana::Channels channel, const Mana::Event &event) { - if (channel == CHANNEL_GAME) + if (channel == Mana::CHANNEL_GAME) { - if (event.getName() == EVENT_ENGINESINITALIZED) + if (event.getName() == Mana::EVENT_ENGINESINITALIZED) Game::instance()->changeMap(mMap); - else if (event.getName() == EVENT_MAPLOADED) + else if (event.getName() == Mana::EVENT_MAPLOADED) MessageOut outMsg(CMSG_MAP_LOADED); } } diff --git a/src/net/tmwa/gamehandler.h b/src/net/tmwa/gamehandler.h index 7616ae878..fbb623409 100644 --- a/src/net/tmwa/gamehandler.h +++ b/src/net/tmwa/gamehandler.h @@ -49,7 +49,7 @@ class GameHandler : public MessageHandler, public Net::GameHandler, void handleMessage(Net::MessageIn &msg); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); void connect(); diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index a246d0d8f..26f6983d7 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -230,12 +230,12 @@ void GeneralHandler::clearHandlers() mNetwork->clearHandlers(); } -void GeneralHandler::event(Channels channel, +void GeneralHandler::event(Mana::Channels channel, const Mana::Event &event) { - if (channel == CHANNEL_GAME) + if (channel == Mana::CHANNEL_GAME) { - if (event.getName() == EVENT_GUIWINDOWSLOADED) + if (event.getName() == Mana::EVENT_GUIWINDOWSLOADED) { if (inventoryWindow) inventoryWindow->setSplitAllowed(false); @@ -266,7 +266,7 @@ void GeneralHandler::event(Channels channel, statusWindow->addAttribute(ATTACK_RANGE, _("Attack Range"), false, ""); } - else if (event.getName() == EVENT_GUIWINDOWSUNLOADING) + else if (event.getName() == Mana::EVENT_GUIWINDOWSUNLOADING) { if (socialWindow) { diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index 6dadb01ed..516db76c5 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -59,7 +59,7 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler, void clearHandlers(); - void event(Channels channel, const Mana::Event &event); + void event(Mana::Channels channel, const Mana::Event &event); protected: MessageHandlerPtr mAdminHandler; diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 61c34d54a..ab2596f32 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -54,17 +54,17 @@ int mLevelProgress = 0; void triggerAttr(int id, int old) { - Mana::Event event(EVENT_UPDATEATTRIBUTE); + Mana::Event event(Mana::EVENT_UPDATEATTRIBUTE); event.setInt("id", id); event.setInt("oldValue", old); event.setInt("newValue", mData.mAttributes.find(id)->second); - Mana::Event::trigger(CHANNEL_ATTRIBUTES, event); + Mana::Event::trigger(Mana::CHANNEL_ATTRIBUTES, event); } void triggerStat(int id, const std::string &changed, int old1, int old2) { StatMap::iterator it = mData.mStats.find(id); - Mana::Event event(EVENT_UPDATESTAT); + Mana::Event event(Mana::EVENT_UPDATESTAT); event.setInt("id", id); event.setInt("base", it->second.base); event.setInt("mod", it->second.mod); @@ -73,7 +73,7 @@ void triggerStat(int id, const std::string &changed, int old1, int old2) event.setString("changed", changed); event.setInt("oldValue1", old1); event.setInt("oldValue2", old2); - Mana::Event::trigger(CHANNEL_ATTRIBUTES, event); + Mana::Event::trigger(Mana::CHANNEL_ATTRIBUTES, event); } // --- Attributes ------------------------------------------------------------- @@ -272,9 +272,9 @@ void setTrading(bool trading) if (notify) { - Mana::Event event(EVENT_TRADING); + Mana::Event event(Mana::EVENT_TRADING); event.setInt("trading", trading); - Mana::Event::trigger(CHANNEL_STATUS, event); + Mana::Event::trigger(Mana::CHANNEL_STATUS, event); } } @@ -283,15 +283,15 @@ class PlayerInfoListener : Mana::Listener public: PlayerInfoListener() { - listen(CHANNEL_CLIENT); - listen(CHANNEL_GAME); + listen(Mana::CHANNEL_CLIENT); + listen(Mana::CHANNEL_GAME); } - void event(Channels channel, const Mana::Event &event) + void event(Mana::Channels channel, const Mana::Event &event) { - if (channel == CHANNEL_CLIENT) + if (channel == Mana::CHANNEL_CLIENT) { - if (event.getName() == EVENT_STATECHANGE) + if (event.getName() == Mana::EVENT_STATECHANGE) { int newState = event.getInt("newState"); @@ -305,9 +305,9 @@ public: } } } - else if (channel == CHANNEL_GAME) + else if (channel == Mana::CHANNEL_GAME) { - if (event.getName() == EVENT_DESTRUCTED) + if (event.getName() == Mana::EVENT_DESTRUCTED) { delete mInventory; delete mEquipment; |