diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-04-27 19:37:59 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-04-27 19:37:59 +0300 |
commit | 03418ce78766b062ce5af7aaf99f7f2c62152b6b (patch) | |
tree | eb0127126e8d9506ca4aeee639c896bc561fa6ca | |
parent | c77f06f7b80a67c842abe837beb2f22e9ecf60cc (diff) | |
download | manaplus-03418ce78766b062ce5af7aaf99f7f2c62152b6b.tar.gz manaplus-03418ce78766b062ce5af7aaf99f7f2c62152b6b.tar.bz2 manaplus-03418ce78766b062ce5af7aaf99f7f2c62152b6b.tar.xz manaplus-03418ce78766b062ce5af7aaf99f7f2c62152b6b.zip |
Add UpdateStatusListener.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/actionmanager.cpp | 6 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 19 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 5 | ||||
-rw-r--r-- | src/gui/windows/ministatuswindow.cpp | 1 | ||||
-rw-r--r-- | src/gui/windows/ministatuswindow.h | 4 | ||||
-rw-r--r-- | src/listeners/updatestatuslistener.cpp | 36 | ||||
-rw-r--r-- | src/listeners/updatestatuslistener.h | 38 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/ea/playerhandler.cpp | 6 |
11 files changed, 100 insertions, 22 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a6774c8a..8cbfca3ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -815,6 +815,8 @@ SET(SRCS listeners/selectionlistener.h listeners/statlistener.cpp listeners/statlistener.h + listeners/updatestatuslistener.cpp + listeners/updatestatuslistener.h utils/sdlpixel.h gui/widgets/widget.h listeners/widgetlistener.h diff --git a/src/Makefile.am b/src/Makefile.am index 2bc92424b..ef8c6da8e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -173,6 +173,8 @@ manaplus_SOURCES += events/actionevent.h \ listeners/selectionlistener.h \ listeners/statlistener.cpp \ listeners/statlistener.h \ + listeners/updatestatuslistener.cpp \ + listeners/updatestatuslistener.h \ utils/sdlpixel.h \ gui/widgets/widget.h \ listeners/widgetlistener.h \ diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index 381244799..464403eb2 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -54,7 +54,6 @@ #include "gui/windows/inventorywindow.h" #include "gui/windows/killstats.h" #include "gui/windows/minimap.h" -#include "gui/windows/ministatuswindow.h" #include "gui/windows/npcdialog.h" #include "gui/windows/outfitwindow.h" #include "gui/windows/setupwindow.h" @@ -69,6 +68,8 @@ #include "net/playerhandler.h" #include "net/tradehandler.h" +#include "listeners/updatestatuslistener.h" + #include "utils/gettext.h" #ifdef ANDROID @@ -863,8 +864,7 @@ impHandler0(changeMapMode) { if (viewport) viewport->toggleDebugPath(); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); if (Game::instance()) { if (Map *const map = Game::instance()->getCurrentMap()) diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 08dce56ad..b7747464d 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -69,6 +69,8 @@ #include "resources/db/emotedb.h" #include "resources/db/weaponsdb.h" +#include "listeners/updatestatuslistener.h" + #include "utils/delete2.h" #include "utils/gettext.h" #include "utils/timer.h" @@ -1252,8 +1254,7 @@ void LocalPlayer::changeMode(unsigned *restrict const var, *var = def; if (save) config.setValue(conf, *var); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); const std::string str = (this->*func)(); if (str.size() > 4) debugMsg(str.substr(4)); @@ -1467,8 +1468,7 @@ void LocalPlayer::setQuickDropCounter(const int n) return; mQuickDropCounter = n; config.setValue("quickDropCounter", mQuickDropCounter); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); } const unsigned pickUpTypeSize = 7; @@ -1619,8 +1619,7 @@ void LocalPlayer::changeAwayMode() mAfkTime = 0; mInactive = false; updateName(); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); if (mAwayMode) { if (chatWindow) @@ -1691,7 +1690,7 @@ void LocalPlayer::switchGameModifiers() { mDisableGameModifiers = !mDisableGameModifiers; config.setValue("disableGameModifiers", mDisableGameModifiers); - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); const std::string str = getGameModifiersString(); if (str.size() > 4) @@ -3680,8 +3679,7 @@ void LocalPlayer::resetYellowBar() mImitationMode = config.resetIntValue("imitationMode"); mDisableGameModifiers = config.resetBoolValue("disableGameModifiers"); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); } unsigned char LocalPlayer::getWalkMask() const @@ -3782,7 +3780,6 @@ void AwayListener::action(const ActionEvent &event) player_node->updateStatus(); if (outfitWindow) outfitWindow->unwearAwayOutfit(); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); } } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index c7e2b31df..061b07adc 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -43,6 +43,8 @@ #include "gui/windows/ministatuswindow.h" +#include "listeners/updatestatuslistener.h" + #include "utils/delete2.h" #include "debug.h" @@ -997,8 +999,7 @@ void Viewport::toggleCameraMode() mCameraRelativeX = 0; mCameraRelativeY = 0; } - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); } void Viewport::hideBeingPopup() diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index 95948e776..720c1375c 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -58,6 +58,7 @@ MiniStatusWindow::MiniStatusWindow() : AttributeListener(), StatListener(), ArrowsListener(), + UpdateStatusListener(), mBars(), mBarNames(), mIcons(), diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h index 3b7138a23..7c16bb132 100644 --- a/src/gui/windows/ministatuswindow.h +++ b/src/gui/windows/ministatuswindow.h @@ -28,6 +28,7 @@ #include "listeners/arrowslistener.h" #include "listeners/attributelistener.h" #include "listeners/statlistener.h" +#include "listeners/updatestatuslistener.h" #include "gui/widgets/window.h" @@ -48,7 +49,8 @@ class MiniStatusWindow final : public Window, public InventoryListener, public AttributeListener, public StatListener, - public ArrowsListener + public ArrowsListener, + public UpdateStatusListener { public: MiniStatusWindow(); diff --git a/src/listeners/updatestatuslistener.cpp b/src/listeners/updatestatuslistener.cpp new file mode 100644 index 000000000..12673f3a7 --- /dev/null +++ b/src/listeners/updatestatuslistener.cpp @@ -0,0 +1,36 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "listeners/updatestatuslistener.h" + +#include "debug.h" + +defineListener(UpdateStatusListener) + +void UpdateStatusListener::distributeEvent() +{ + FOR_EACH (std::vector<UpdateStatusListener*>::iterator, + it, mListeners) + { + UpdateStatusListener *const listener = *it; + if (listener) + listener->updateStatus(); + } +} diff --git a/src/listeners/updatestatuslistener.h b/src/listeners/updatestatuslistener.h new file mode 100644 index 000000000..8671687c6 --- /dev/null +++ b/src/listeners/updatestatuslistener.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef LISTENERS_UPDATESTATUSLISTENER_H +#define LISTENERS_UPDATESTATUSLISTENER_H + +#include "listeners/baselistener.hpp" + +#include "localconsts.h" + +class UpdateStatusListener +{ + public: + virtual void updateStatus() = 0; + + static void distributeEvent(); + + defineListenerHeader(UpdateStatusListener) +}; + +#endif // LISTENERS_UPDATESTATUSLISTENER_H diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index d1dd5cf7d..1daafc2d5 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -27,8 +27,6 @@ #include "being/localplayer.h" -#include "gui/windows/ministatuswindow.h" - #include "net/messagein.h" #include "net/ea/eaprotocol.h" @@ -36,6 +34,7 @@ #include "utils/delete2.h" #include "listeners/arrowslistener.h" +#include "listeners/updatestatuslistener.h" #include "debug.h" diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index de376cead..475df2db0 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -33,7 +33,6 @@ #include "gui/viewport.h" -#include "gui/windows/ministatuswindow.h" #include "gui/windows/okdialog.h" #include "gui/windows/npcdialog.h" #include "gui/windows/skilldialog.h" @@ -41,6 +40,8 @@ #include "resources/db/deaddb.h" +#include "listeners/updatestatuslistener.h" + #include "net/messagein.h" #include "net/net.h" @@ -210,8 +211,7 @@ void PlayerHandler::processPlayerWarp(Net::MessageIn &msg) if (viewport) { viewport->returnCamera(); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + UpdateStatusListener::distributeEvent(); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } BLOCK_END("PlayerHandler::processPlayerWarp") |