diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-03-12 22:36:18 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-03-12 23:53:55 -0700 |
commit | f80e8769ff5c78255bd5e09a991ada83b7ed1aa2 (patch) | |
tree | a104ffd960173e7232a70a5d78b4551751ad303c | |
parent | ef3685ef63999b7132fa7b6f8ebc9a3387972e53 (diff) | |
download | mana-f80e8769ff5c78255bd5e09a991ada83b7ed1aa2.tar.gz mana-f80e8769ff5c78255bd5e09a991ada83b7ed1aa2.tar.bz2 mana-f80e8769ff5c78255bd5e09a991ada83b7ed1aa2.tar.xz mana-f80e8769ff5c78255bd5e09a991ada83b7ed1aa2.zip |
Fix some issues with Being deletion
Clear the Viewport's hover being when it gets removed and make sure
LocalPlayer's target pointer get's cleared.
Reviewed-by: Freeyorp
-rw-r--r-- | src/beingmanager.cpp | 3 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 6 | ||||
-rw-r--r-- | src/gui/viewport.h | 7 | ||||
-rw-r--r-- | src/localplayer.cpp | 9 |
4 files changed, 21 insertions, 4 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index c7ed9d86..26672de0 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -26,6 +26,8 @@ #include "npc.h" #include "player.h" +#include "gui/viewport.h" + #include "net/gamehandler.h" #include "net/net.h" @@ -102,6 +104,7 @@ Being *BeingManager::createBeing(int id, Being::Type type, int subtype) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); + viewport->clearHoverBeing(being); delete being; } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 1451b935..9befac9d 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -509,3 +509,9 @@ void Viewport::hideBeingPopup() { mBeingPopup->setVisible(false); } + +void Viewport::clearHoverBeing(Being *being) +{ + if (mHoverBeing == being) + mHoverBeing = 0; +} diff --git a/src/gui/viewport.h b/src/gui/viewport.h index e4944cd6..e67cc6d3 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -22,6 +22,7 @@ #ifndef VIEWPORT_H #define VIEWPORT_H +#include "beingmanager.h" #include "configlistener.h" #include "position.h" @@ -157,6 +158,12 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void hideBeingPopup(); + protected: + friend class BeingManager; + + /// Clears the hovered being if it matches + void clearHoverBeing(Being *being); + private: /** * Finds a path from the player to the mouse, and draws it. This is for diff --git a/src/localplayer.cpp b/src/localplayer.cpp index dfee7cdc..6d53cac3 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -422,10 +422,11 @@ Being *LocalPlayer::getTarget() const void LocalPlayer::setTarget(Being *target) { - if (mLastTarget != -1 || target == this) + if ((mLastTarget != -1 || target == this) && target) return; - mLastTarget = tick_time; + if (target) + mLastTarget = tick_time; if (target == mTarget) return; @@ -444,12 +445,12 @@ void LocalPlayer::setTarget(Being *target) mTarget->untarget(); if (mTarget && mTarget->getType() == Being::MONSTER) - static_cast<Monster *>(mTarget)->setShowName(false); + mTarget->setShowName(false); mTarget = target; if (target && target->getType() == Being::MONSTER) - static_cast<Monster *>(target)->setShowName(true); + target->setShowName(true); } void LocalPlayer::setDestination(int x, int y) |