User:Freeyorp/Patches/Add support for viewing the health and maximum health of other nearby members of your party/
From The Mana World
Pushed as 7f15330d969e5c973429d03ca767551e7b67c3c3
From 32c3ee5194393bc5de772e7dd730ed352d437aa7 Mon Sep 17 00:00:00 2001 From: Freeyorp <Freeyorp101@[email protected]> Date: Mon, 11 May 2009 00:45:17 +1200 Subject: [PATCH] Add support for viewing the health and maximum health of other nearby members of your party. --- src/gui/partywindow.cpp | 14 +++++++++--- src/gui/partywindow.h | 7 ++++- src/gui/widgets/avatar.cpp | 46 ++++++++++++++++++++++++++++++++++++++++-- src/gui/widgets/avatar.h | 10 +++++++++ src/net/ea/partyhandler.cpp | 7 +++-- 5 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp index b3c6c74..5172f4b 100644 --- a/src/gui/partywindow.cpp +++ b/src/gui/partywindow.cpp @@ -34,12 +34,12 @@ PartyWindow::PartyWindow() : Window(_("Party")) { setWindowName("Party"); setVisible(false); - setResizable(false); + setResizable(true); setSaveVisible(true); setCloseButton(true); - setMinWidth(110); + setMinWidth(200); setMinHeight(200); - setDefaultSize(620, 300, 110, 200); + setDefaultSize(620, 300, 200, 200); loadWindowState(); setVisible(false); // Do not start out visible @@ -58,7 +58,6 @@ void PartyWindow::draw(gcn::Graphics *graphics) PartyMember *PartyWindow::findMember(int id) const { PartyList::const_iterator it = mMembers.find(id); - if (it == mMembers.end()) return NULL; else @@ -114,6 +113,13 @@ void PartyWindow::updateMember(int id, const std::string &memberName, } } +void PartyWindow::updateMemberHP(int id, int hp, int maxhp) +{ + PartyMember *player = findOrCreateMember(id); + player->avatar->setHp(hp); + player->avatar->setMaxHp(maxhp); +} + void PartyWindow::removeMember(int id) { mMembers.erase(id); diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h index c915d9c..6a8cc4f 100644 --- a/src/gui/partywindow.h +++ b/src/gui/partywindow.h @@ -40,8 +40,6 @@ struct PartyMember { std::string name; - int health; - int healthMax; bool leader; bool online; Avatar *avatar; @@ -85,6 +83,11 @@ class PartyWindow : public Window, gcn::ActionListener bool leader = false, bool online = true); /** + * Update a member's HP and Max HP + */ + void updateMemberHP(int id, int hp, int maxhp); + + /** * Remove party member with the given id. */ void removeMember(int id); diff --git a/src/gui/widgets/avatar.cpp b/src/gui/widgets/avatar.cpp index 8cb23a3..4391010 100644 --- a/src/gui/widgets/avatar.cpp +++ b/src/gui/widgets/avatar.cpp @@ -19,6 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "localplayer.h" + #include "gui/widgets/avatar.h" #include "gui/widgets/icon.h" @@ -27,6 +29,11 @@ #include "resources/image.h" #include "resources/resourcemanager.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include <stdio.h> + namespace { Image *avatarStatusOffline; Image *avatarStatusOnline; @@ -38,6 +45,8 @@ Avatar::Avatar(const std::string &name): { setOpaque(false); setSize(200, 12); + mHpState = "???"; + mMaxHpState = "???"; if (avatarCount == 0) { @@ -52,8 +61,12 @@ Avatar::Avatar(const std::string &name): mStatus = new Icon(avatarStatusOffline); mStatus->setSize(12, 12); add(mStatus, 1, 0); - - mLabel = new Label(name); + mAvatarLabel.str(""); + if (mName != player_node->getName()) + mAvatarLabel << mName << " " << mHpState << "/" + mMaxHpState; + else + mAvatarLabel << mName << " " << player_node->getHp() << "/" << player_node->getMaxHp(); + mLabel = new Label(mAvatarLabel.str()); mLabel->setSize(174, 12); add(mLabel, 16, 0); } @@ -69,10 +82,37 @@ Avatar::~Avatar() void Avatar::setName(const std::string &name) { mName = name; - mLabel->setCaption(name); + updateAvatarLabel(); } void Avatar::setOnline(bool online) { mStatus->setImage(online ? avatarStatusOnline : avatarStatusOffline); } + +void Avatar::setHp(int hp) +{ + if (hp) + mHpState = strprintf("%i", hp); + else + mHpState = "???"; + updateAvatarLabel(); +} + +void Avatar::setMaxHp(int maxhp) +{ + if (maxhp) + mMaxHpState = strprintf("%i", maxhp); + else + mMaxHpState = "???"; + 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()); +} diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h index 550e43b..69f7ed3 100644 --- a/src/gui/widgets/avatar.h +++ b/src/gui/widgets/avatar.h @@ -27,6 +27,7 @@ #include "gui/widgets/container.h" #include <string> +#include <sstream> class Image; class Icon; @@ -52,8 +53,17 @@ public: */ void setOnline(bool online); + void setHp(int hp); + + void setMaxHp(int maxhp); + + void updateAvatarLabel(); + private: std::string mName; + std::string mHpState; + std::string mMaxHpState; + std::stringstream mAvatarLabel; Icon *mStatus; gcn::Label *mLabel; }; diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index 1a0a9e3..cb42ec7 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -239,9 +239,10 @@ void PartyHandler::handleMessage(MessageIn &msg) } case SMSG_PARTY_UPDATE_HP: { - msg.readInt32(); // id - msg.readInt16(); // hp - msg.readInt16(); // hpMax + int id = msg.readInt32(); + int hp = msg.readInt16(); + int maxhp = msg.readInt16(); + partyWindow->updateMemberHP(id, hp, maxhp); } break; case SMSG_PARTY_UPDATE_COORDS: -- 1.6.0.4