From 77ff71350b0749470770e91268593397e36f8a87 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 10 May 2009 22:31:49 +0200 Subject: Removed the ???/??? for party members of which health isn't known Not very useful. :P --- src/gui/widgets/avatar.cpp | 53 +++++++++++++++++++++++++--------------------- src/gui/widgets/avatar.h | 10 ++++----- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/gui/widgets/avatar.cpp b/src/gui/widgets/avatar.cpp index a6434f2e..116640d8 100644 --- a/src/gui/widgets/avatar.cpp +++ b/src/gui/widgets/avatar.cpp @@ -19,20 +19,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "localplayer.h" - #include "gui/widgets/avatar.h" +#include "localplayer.h" + #include "gui/widgets/icon.h" #include "gui/widgets/label.h" #include "resources/image.h" #include "resources/resourcemanager.h" -#include "utils/gettext.h" -#include "utils/stringutils.h" - -#include +#include namespace { Image *avatarStatusOffline; @@ -41,8 +38,8 @@ namespace { } Avatar::Avatar(): - mHpState("???"), - mMaxHpState("???") + mHp(0), + mMaxHp(0) { setOpaque(false); setSize(200, 12); @@ -86,27 +83,35 @@ void Avatar::setOnline(bool online) void Avatar::setHp(int hp) { - if (hp) - mHpState = strprintf("%i", hp); - else - mHpState = "???"; + if (hp == mHp) + return; + + mHp = hp; updateAvatarLabel(); } -void Avatar::setMaxHp(int maxhp) +void Avatar::setMaxHp(int maxHp) { - if (maxhp) - mMaxHpState = strprintf("%i", maxhp); - else - mMaxHpState = "???"; + if (maxHp == mMaxHp) + return; + + mMaxHp = maxHp; updateAvatarLabel(); } -void Avatar::updateAvatarLabel() { - mAvatarLabel.str(""); - if (mName != player_node->getName()) - mAvatarLabel << mName << " " << mHpState << "/" << mMaxHpState; - else - mAvatarLabel << mName << " " << player_node->getHp() << "/" << player_node->getMaxHp(); - mLabel->setCaption(mAvatarLabel.str()); +void Avatar::updateAvatarLabel() +{ + std::ostringstream ss; + ss << mName; + + if (mName == player_node->getName()) + { + mHp = player_node->getHp(); + mMaxHp = player_node->getMaxHp(); + } + + if (mMaxHp != 0) + ss << " (" << mHp << "/" << mMaxHp << ")"; + + mLabel->setCaption(ss.str()); } diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h index ff718cc6..32586668 100644 --- a/src/gui/widgets/avatar.h +++ b/src/gui/widgets/avatar.h @@ -27,7 +27,6 @@ #include "gui/widgets/container.h" #include -#include class Image; class Icon; @@ -50,15 +49,14 @@ public: void setHp(int hp); - void setMaxHp(int maxhp); + void setMaxHp(int maxHp); +private: void updateAvatarLabel(); -private: std::string mName; - std::string mHpState; - std::string mMaxHpState; - std::stringstream mAvatarLabel; + int mHp; + int mMaxHp; Icon *mStatus; gcn::Label *mLabel; }; -- cgit v1.2.3-70-g09d2