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 /src/gui | |
parent | 6a0e5f20c9faf7623a465daa4a8b350d3a52e5e6 (diff) | |
download | mana-client-42f6993e0deacc857302f48004031dd45b739874.tar.gz mana-client-42f6993e0deacc857302f48004031dd45b739874.tar.bz2 mana-client-42f6993e0deacc857302f48004031dd45b739874.tar.xz mana-client-42f6993e0deacc857302f48004031dd45b739874.zip |
Remove non-GUI references to MiniStatusWindow
Reviewed-by: Freeyorp
Diffstat (limited to 'src/gui')
-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 |
4 files changed, 88 insertions, 28 deletions
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: /** |