diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-04-27 19:03:49 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-04-27 19:03:49 +0300 |
commit | c77f06f7b80a67c842abe837beb2f22e9ecf60cc (patch) | |
tree | 65da775f4830fde8ccbf7a6d7514e42169321486 | |
parent | 8836d01c806f7d7e99befb5036148e8ff7b0e24e (diff) | |
download | mv-c77f06f7b80a67c842abe837beb2f22e9ecf60cc.tar.gz mv-c77f06f7b80a67c842abe837beb2f22e9ecf60cc.tar.bz2 mv-c77f06f7b80a67c842abe837beb2f22e9ecf60cc.tar.xz mv-c77f06f7b80a67c842abe837beb2f22e9ecf60cc.zip |
Add ArrowsListener.
Also fix arrows amount update on arrows pickup.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gui/windows/ministatuswindow.cpp | 12 | ||||
-rw-r--r-- | src/gui/windows/ministatuswindow.h | 8 | ||||
-rw-r--r-- | src/listeners/arrowslistener.cpp | 36 | ||||
-rw-r--r-- | src/listeners/arrowslistener.h | 38 | ||||
-rw-r--r-- | src/net/ea/inventoryhandler.cpp | 15 |
7 files changed, 97 insertions, 16 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11e161a77..8a6774c8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -603,6 +603,8 @@ SET(SRCS being/actorsprite.cpp being/actorsprite.h listeners/actorspritelistener.h + listeners/arrowslistener.cpp + listeners/arrowslistener.h listeners/attributelistener.cpp listeners/attributelistener.h listeners/baselistener.hpp diff --git a/src/Makefile.am b/src/Makefile.am index 0caeee76b..2bc92424b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -687,6 +687,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ being/actorsprite.cpp \ being/actorsprite.h \ listeners/actorspritelistener.h \ + listeners/arrowslistener.cpp \ + listeners/arrowslistener.h \ listeners/attributelistener.cpp \ listeners/attributelistener.h \ listeners/baselistener.hpp \ diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index 804d52d5b..95948e776 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -56,6 +56,8 @@ MiniStatusWindow::MiniStatusWindow() : Window("MiniStatus", false, nullptr, "ministatus.xml"), InventoryListener(), AttributeListener(), + StatListener(), + ArrowsListener(), mBars(), mBarNames(), mIcons(), @@ -532,11 +534,6 @@ void MiniStatusWindow::slotsChanged(Inventory *const inventory) StatusWindow::updateInvSlotsBar(mInvSlotsBar); } -void MiniStatusWindow::updateArrows() -{ - StatusWindow::updateArrowsBar(mArrowsBar); -} - Rect MiniStatusWindow::getChildrenArea() { const int padding = mPadding; @@ -547,6 +544,11 @@ Rect MiniStatusWindow::getChildrenArea() rect.height - padding2); } +void MiniStatusWindow::arrowsChanged() +{ + StatusWindow::updateArrowsBar(mArrowsBar); +} + #ifdef USE_PROFILER void MiniStatusWindow::logicChildren() { diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h index 171e1fe2f..3b7138a23 100644 --- a/src/gui/windows/ministatuswindow.h +++ b/src/gui/windows/ministatuswindow.h @@ -25,6 +25,7 @@ #include "inventory.h" +#include "listeners/arrowslistener.h" #include "listeners/attributelistener.h" #include "listeners/statlistener.h" @@ -46,7 +47,8 @@ class TextPopup; class MiniStatusWindow final : public Window, public InventoryListener, public AttributeListener, - public StatListener + public StatListener, + public ArrowsListener { public: MiniStatusWindow(); @@ -80,8 +82,6 @@ class MiniStatusWindow final : public Window, void updateBars(); - void updateArrows(); - void slotsChanged(Inventory *const inventory) override final; std::vector <ProgressBar*> &getBars() A_WARN_UNUSED @@ -97,6 +97,8 @@ class MiniStatusWindow final : public Window, const int oldVal1, const int oldVal2) override final; + void arrowsChanged(); + #ifdef USE_PROFILER void logicChildren(); #endif diff --git a/src/listeners/arrowslistener.cpp b/src/listeners/arrowslistener.cpp new file mode 100644 index 000000000..d9d7b0006 --- /dev/null +++ b/src/listeners/arrowslistener.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/arrowslistener.h" + +#include "debug.h" + +defineListener(ArrowsListener) + +void ArrowsListener::distributeEvent() +{ + FOR_EACH (std::vector<ArrowsListener*>::iterator, + it, mListeners) + { + ArrowsListener *const listener = *it; + if (listener) + listener->arrowsChanged(); + } +} diff --git a/src/listeners/arrowslistener.h b/src/listeners/arrowslistener.h new file mode 100644 index 000000000..92811331b --- /dev/null +++ b/src/listeners/arrowslistener.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_ARROWSLISTENER_H +#define LISTENERS_ARROWSLISTENER_H + +#include "listeners/baselistener.hpp" + +#include "localconsts.h" + +class ArrowsListener +{ + public: + virtual void arrowsChanged() = 0; + + static void distributeEvent(); + + defineListenerHeader(ArrowsListener) +}; + +#endif // LISTENERS_ARROWSLISTENER_H diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index ea7390ccb..d1dd5cf7d 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -35,6 +35,8 @@ #include "utils/delete2.h" +#include "listeners/arrowslistener.h" + #include "debug.h" extern int serverVersion; @@ -336,6 +338,7 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) inventory->setItem(index, itemId, amount, refine, identified, equipType != 0); } + ArrowsListener::distributeEvent(); } } @@ -353,8 +356,7 @@ void InventoryHandler::processPlayerInventoryRemove(Net::MessageIn &msg) item->increaseQuantity(-amount); if (item->getQuantity() == 0) inventory->removeItemAt(index); - if (miniStatusWindow) - miniStatusWindow->updateArrows(); + ArrowsListener::distributeEvent(); } } } @@ -566,8 +568,8 @@ void InventoryHandler::processPlayerUnEquip(Net::MessageIn &msg) if (flag) mEquips.setEquipment(getSlot(equipType), -1); - if (miniStatusWindow && equipType & 0x8000) - miniStatusWindow->updateArrows(); + if (equipType & 0x8000) + ArrowsListener::distributeEvent(); } void InventoryHandler::processPlayerAttackRange(Net::MessageIn &msg) @@ -586,11 +588,8 @@ void InventoryHandler::processPlayerArrowEquip(Net::MessageIn &msg) return; index -= INVENTORY_OFFSET; - mEquips.setEquipment(Equipment::EQUIP_PROJECTILE_SLOT, index); - - if (miniStatusWindow) - miniStatusWindow->updateArrows(); + ArrowsListener::distributeEvent(); } void InventoryHandler::closeStorage() |