diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-08-02 02:32:18 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-02 02:48:03 -0600 |
commit | 42f6993e0deacc857302f48004031dd45b739874 (patch) | |
tree | f8a25e94b32257c1364864824fcf61c83b834d6d | |
parent | 6a0e5f20c9faf7623a465daa4a8b350d3a52e5e6 (diff) | |
download | mana-42f6993e0deacc857302f48004031dd45b739874.tar.gz mana-42f6993e0deacc857302f48004031dd45b739874.tar.bz2 mana-42f6993e0deacc857302f48004031dd45b739874.tar.xz mana-42f6993e0deacc857302f48004031dd45b739874.zip |
Remove non-GUI references to MiniStatusWindow
Reviewed-by: Freeyorp
-rw-r--r-- | src/actorsprite.cpp | 21 | ||||
-rw-r--r-- | src/actorspritemanager.cpp | 4 | ||||
-rw-r--r-- | src/gui/ministatus.cpp | 82 | ||||
-rw-r--r-- | src/gui/ministatus.h | 15 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 10 | ||||
-rw-r--r-- | src/gui/viewport.h | 9 | ||||
-rw-r--r-- | src/localplayer.cpp | 51 | ||||
-rw-r--r-- | src/localplayer.h | 4 | ||||
-rw-r--r-- | src/playerinfo.cpp | 3 |
9 files changed, 106 insertions, 93 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 6a1dcbc7..3d0e7d54 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -23,6 +23,7 @@ #include "client.h" #include "effectmanager.h" +#include "eventmanager.h" #include "imagesprite.h" #include "localplayer.h" #include "log.h" @@ -53,9 +54,7 @@ ActorSprite::ActorSprite(int id): mChildParticleEffects(&mStatusParticleEffects, false), mMustResetParticles(false), mUsedTargetCursor(NULL) -{ - // -} +{} ActorSprite::~ActorSprite() { @@ -261,12 +260,28 @@ void ActorSprite::internalTriggerEffect(int effectId, bool sfx, bool gfx) void ActorSprite::updateStunMode(int oldMode, int newMode) { + if (this == player_node) + { + Mana::Event event("Stun"); + event.setInt("oldMode", oldMode); + event.setInt("newMode", newMode); + Mana::EventManager::trigger("ActorSprite", event); + } + handleStatusEffect(StatusEffect::getStatusEffect(oldMode, false), -1); handleStatusEffect(StatusEffect::getStatusEffect(newMode, true), -1); } void ActorSprite::updateStatusEffect(int index, bool newStatus) { + if (this == player_node) + { + Mana::Event event("UpdateStatusEffect"); + event.setInt("index", index); + event.setBool("newStatus", newStatus); + Mana::EventManager::trigger("ActorSprite", event); + } + handleStatusEffect(StatusEffect::getStatusEffect(index, newStatus), index); } diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index a6c82420..2a57c21a 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -206,11 +206,7 @@ void ActorSpriteManager::logic() for (it = mDeleteActors.begin(), it_end = mDeleteActors.end(); it != it_end; ++it) - { - viewport->clearHover(*it); - mActors.erase(*it); delete *it; - } mDeleteActors.clear(); } diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index eb7c0756..620754ef 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -25,6 +25,7 @@ #include "configuration.h" #include "graphics.h" #include "playerinfo.h" +#include "statuseffect.h" #include "gui/gui.h" #include "gui/statuswindow.h" @@ -119,20 +120,79 @@ void MiniStatusWindow::drawIcons(Graphics *graphics) void MiniStatusWindow::event(const std::string &channel, const Mana::Event &event) { - if (event.getName() == "UpdateAttribute") + if (channel == "Attributes") { - int id = event.getInt("id"); - if (id == HP || id == MAX_HP) + if (event.getName() == "UpdateAttribute") { - StatusWindow::updateHPBar(mHpBar); + int id = event.getInt("id"); + if (id == HP || id == MAX_HP) + { + StatusWindow::updateHPBar(mHpBar); + } + else if (id == MP || id == MAX_MP) + { + StatusWindow::updateMPBar(mMpBar); + } + else if (id == EXP || id == EXP_NEEDED) + { + StatusWindow::updateXPBar(mXpBar); + } } - else if (id == MP || id == MAX_MP) - { - StatusWindow::updateMPBar(mMpBar); - } - else if (id == EXP || id == EXP_NEEDED) + } + else if (channel == "ActorSprite") + { + if (event.getName() == "UpdateStatusEffect") { - StatusWindow::updateXPBar(mXpBar); + int index = event.getInt("index"); + bool newStatus = event.getBool("newStatus"); + + StatusEffect *effect = StatusEffect::getStatusEffect(index, + newStatus); + + if (effect) + { + effect->deliverMessage(); + effect->playSFX(); + + AnimatedSprite *sprite = effect->getIcon(); + + typedef std::vector<int> IntMap; + + if (!sprite) + { + // delete sprite, if necessary + for (unsigned int i = 0; i < mStatusEffectIcons.size();) + if (mStatusEffectIcons[i] == index) + { + mStatusEffectIcons.erase(mStatusEffectIcons.begin() + + i); + miniStatusWindow->eraseIcon(i); + } + else + i++; + } + else + { + // replace sprite or append + bool found = false; + + for (unsigned int i = 0; i < mStatusEffectIcons.size(); + i++) + if (mStatusEffectIcons[i] == index) + { + miniStatusWindow->setIcon(i, sprite); + found = true; + break; + } + + if (!found) + { // add new + int offset = mStatusEffectIcons.size(); + miniStatusWindow->setIcon(offset, sprite); + mStatusEffectIcons.push_back(index); + } + } + } } } } @@ -199,5 +259,3 @@ void MiniStatusWindow::mouseExited(gcn::MouseEvent &event) mTextPopup->setVisible(false); } - - diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 1c772850..077eedeb 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -43,13 +43,6 @@ class MiniStatusWindow : public Popup, public Mana::Listener public: MiniStatusWindow(); - /** - * Sets one of the icons. - */ - void setIcon(int index, AnimatedSprite *sprite); - - void eraseIcon(int index); - void drawIcons(Graphics *graphics); void event(const std::string &channel, const Mana::Event &event); @@ -65,6 +58,13 @@ class MiniStatusWindow : public Popup, public Mana::Listener private: bool isInBar(ProgressBar *bar, int x, int y) const; + /** + * Sets one of the icons. + */ + void setIcon(int index, AnimatedSprite *sprite); + + void eraseIcon(int index); + /* * Mini Status Bars */ @@ -73,6 +73,7 @@ class MiniStatusWindow : public Popup, public Mana::Listener ProgressBar *mXpBar; TextPopup *mTextPopup; + std::vector<int> mStatusEffectIcons; std::vector<AnimatedSprite *> mIcons; }; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index fc9adab1..b6e4f71d 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -495,14 +495,17 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) const int x = (event.getX() + (int) mPixelViewX); const int y = (event.getY() + (int) mPixelViewY); + mHoverBeing->removeActorSpriteListener(this); mHoverBeing = actorSpriteManager->findBeingByPixel(x, y); mBeingPopup->show(getMouseX(), getMouseY(), mHoverBeing); + mHoverItem->removeActorSpriteListener(this); mHoverItem = actorSpriteManager->findItem(x / mMap->getTileWidth(), y / mMap->getTileHeight()); if (mHoverBeing) { + mHoverBeing->addActorSpriteListener(this); switch (mHoverBeing->getType()) { // NPCs @@ -522,6 +525,7 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) } else if (mHoverItem) { + mHoverItem->addActorSpriteListener(this); gui->setCursorType(Gui::CURSOR_PICKUP); } else @@ -546,11 +550,11 @@ void Viewport::hideBeingPopup() mBeingPopup->setVisible(false); } -void Viewport::clearHover(ActorSprite *actor) +void Viewport::actorSpriteDestroyed(const ActorSprite &actorSprite) { - if (mHoverBeing == actor) + if (&actorSprite == mHoverBeing) mHoverBeing = 0; - if (mHoverItem == actor) + if (&actorSprite == mHoverItem) mHoverItem = 0; } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index f91504f2..eaf23085 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -22,6 +22,7 @@ #ifndef VIEWPORT_H #define VIEWPORT_H +#include "actorspritelistener.h" #include "actorspritemanager.h" #include "configlistener.h" #include "position.h" @@ -53,7 +54,7 @@ const int walkingMouseDelay = 500; * coordinates. */ class Viewport : public WindowContainer, public gcn::MouseListener, - public ConfigListener + public ConfigListener, public ActorSpriteListener { public: /** @@ -159,11 +160,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void hideBeingPopup(); - protected: - friend class ActorSpriteManager; - - /// Clears any matching hovers - void clearHover(ActorSprite *actor); + void actorSpriteDestroyed(const ActorSprite &actorSprite); private: /** diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 11fdf44c..2d17cf90 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -35,13 +35,10 @@ #include "playerinfo.h" #include "simpleanimation.h" #include "sound.h" -#include "statuseffect.h" #include "text.h" #include "gui/gui.h" -#include "gui/ministatus.h" #include "gui/okdialog.h" -#include "gui/skilldialog.h" #include "gui/theme.h" #include "gui/userpalette.h" @@ -1084,54 +1081,6 @@ void LocalPlayer::setGotoTarget(Being *target) } } -extern MiniStatusWindow *miniStatusWindow; - -void LocalPlayer::handleStatusEffect(StatusEffect *effect, int effectId) -{ - Being::handleStatusEffect(effect, effectId); - - if (effect) - { - effect->deliverMessage(); - effect->playSFX(); - - AnimatedSprite *sprite = effect->getIcon(); - - if (!sprite) - { - // delete sprite, if necessary - for (unsigned int i = 0; i < mStatusEffectIcons.size();) - if (mStatusEffectIcons[i] == effectId) - { - mStatusEffectIcons.erase(mStatusEffectIcons.begin() + i); - miniStatusWindow->eraseIcon(i); - } - else - i++; - } - else - { - // replace sprite or append - bool found = false; - - for (unsigned int i = 0; i < mStatusEffectIcons.size(); i++) - if (mStatusEffectIcons[i] == effectId) - { - miniStatusWindow->setIcon(i, sprite); - found = true; - break; - } - - if (!found) - { // add new - int offset = mStatusEffectIcons.size(); - miniStatusWindow->setIcon(offset, sprite); - mStatusEffectIcons.push_back(effectId); - } - } - } -} - void LocalPlayer::addMessageToQueue(const std::string &message, int color) { mMessages.push_back(MessagePair(message, color)); diff --git a/src/localplayer.h b/src/localplayer.h index 99c3acf5..64ff6e30 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -245,8 +245,6 @@ class LocalPlayer : public Being, public ActorSpriteListener, /** Whether or not the name settings have changed */ bool mUpdateName; - virtual void handleStatusEffect(StatusEffect *effect, int effectId); - void startWalking(unsigned char dir); int mAttackRange; @@ -271,8 +269,6 @@ class LocalPlayer : public Being, public ActorSpriteListener, int mWalkingDir; /**< The direction the player is walking in. */ bool mPathSetByMouse; /**< Tells if the path was set using mouse */ - std::vector<int> mStatusEffectIcons; - int mLocalWalkTime; /**< Timestamp used to control keyboard walk messages flooding */ diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index a9f40974..a6cc60e6 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -27,9 +27,6 @@ #include "listener.h" #include "log.h" -#include "gui/npcdialog.h" -#include "gui/npcpostdialog.h" - #include "resources/itemdb.h" #include "resources/iteminfo.h" |