summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-10 22:31:49 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-10 22:34:57 +0200
commit77ff71350b0749470770e91268593397e36f8a87 (patch)
treefb348d641b5fa6f5170cb19f8741567ad7f0bd53 /src
parent2401f44a83bff8e2b4ffb1dab68cb8c20db4386f (diff)
downloadmana-77ff71350b0749470770e91268593397e36f8a87.tar.gz
mana-77ff71350b0749470770e91268593397e36f8a87.tar.bz2
mana-77ff71350b0749470770e91268593397e36f8a87.tar.xz
mana-77ff71350b0749470770e91268593397e36f8a87.zip
Removed the ???/??? for party members of which health isn't known
Not very useful. :P
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/avatar.cpp53
-rw-r--r--src/gui/widgets/avatar.h10
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 <stdio.h>
+#include <sstream>
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 <string>
-#include <sstream>
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;
};