summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-01-05 22:56:42 +0200
committerAndrei Karas <akaras@inbox.ru>2011-01-05 22:56:42 +0200
commit1c49a83df05dbf6837687e1bfc5b142a680144ed (patch)
tree5e1ae2d371ca8ec6aa5caa95cf8e4bee00f726ee
parent6941cbc58099ee54ba326382eaf4de805d933e0e (diff)
downloadplus-1c49a83df05dbf6837687e1bfc5b142a680144ed.tar.gz
plus-1c49a83df05dbf6837687e1bfc5b142a680144ed.tar.bz2
plus-1c49a83df05dbf6837687e1bfc5b142a680144ed.tar.xz
plus-1c49a83df05dbf6837687e1bfc5b142a680144ed.zip
Add hp bar to local player.
-rw-r--r--src/being.cpp46
-rw-r--r--src/being.h3
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/gui/setup_colors.cpp2
-rw-r--r--src/gui/setup_other.cpp17
-rw-r--r--src/gui/setup_other.h3
-rw-r--r--src/gui/userpalette.cpp5
-rw-r--r--src/gui/userpalette.h2
8 files changed, 57 insertions, 22 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 3a9285750..2372cfe1b 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -169,6 +169,7 @@ bool Being::mLowTraffic = true;
bool Being::mDrawHotKeys = true;
bool Being::mShowBattleEvents = false;
bool Being::mShowMobHP = false;
+bool Being::mShowOwnHP = false;
std::list<BeingCacheEntry*> beingInfoCache;
@@ -1551,6 +1552,7 @@ void Being::reReadConfig()
mDrawHotKeys = config.getBoolValue("drawHotKeys");
mShowBattleEvents = config.getBoolValue("showBattleEvents");
mShowMobHP = config.getBoolValue("showMobHP");
+ mShowOwnHP = config.getBoolValue("showOwnHP");
mUpdateConfigTime = cur_time;
}
@@ -1745,42 +1747,48 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const
2 * attackRange + 32, 2 * attackRange + 32));
}
- if (mShowMobHP && player_node && player_node->getTarget() == this
+ if (mShowMobHP && mInfo && player_node && player_node->getTarget() == this
&& getType() == MONSTER)
{
// show hp bar here
- drawHpBar(graphics, x - 50 + 16, y + 32 - 6, 2 * 50, 4);
+ int maxHP = mMaxHP;
+ if (!maxHP)
+ maxHP = mInfo->getMaxHP();
+
+ drawHpBar(graphics, maxHP, mHP, mDamageTaken,
+ UserPalette::MONSTER_HP, UserPalette::MONSTER_HP2,
+ x - 50 + 16, y + 32 - 6, 2 * 50, 4);
+ }
+ if (mShowOwnHP && player_node == this)
+ {
+ drawHpBar(graphics, PlayerInfo::getAttribute(MAX_HP),
+ PlayerInfo::getAttribute(HP), 0,
+ UserPalette::PLAYER_HP, UserPalette::PLAYER_HP2,
+ x - 50 + 16, y + 32 - 6, 2 * 50, 4);
}
return res;
}
-void Being::drawHpBar(Graphics *graphics, int x, int y,
+void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage,
+ int color1, int color2, int x, int y,
int width, int height) const
{
- if (!mInfo)
- return;
-
- int maxHP = mMaxHP;
-
- if (!maxHP)
- maxHP = mInfo->getMaxHP();
-
if (maxHP <= 0)
return;
- if (!mHP && maxHP < mHP)
+ if (!hp && maxHP < hp)
return;
float p;
- if (mHP)
+ if (hp)
{
- p = static_cast<float>(maxHP) / static_cast<float>(mHP);
+ p = static_cast<float>(maxHP) / static_cast<float>(hp);
}
- else if (maxHP != mDamageTaken)
+ else if (maxHP != damage)
{
p = static_cast<float>(maxHP)
- / static_cast<float>(maxHP - mDamageTaken);
+ / static_cast<float>(maxHP - damage);
}
else
{
@@ -1792,8 +1800,7 @@ void Being::drawHpBar(Graphics *graphics, int x, int y,
int dx = width / p;
- graphics->setColor(userPalette->getColorWithAlpha(
- UserPalette::MONSTER_HP));
+ graphics->setColor(userPalette->getColorWithAlpha(color1));
graphics->fillRectangle(gcn::Rectangle(
x, y, dx, height));
@@ -1801,8 +1808,7 @@ void Being::drawHpBar(Graphics *graphics, int x, int y,
if (width - dx <= 0)
return;
- graphics->setColor(userPalette->getColorWithAlpha(
- UserPalette::MONSTER_HP2));
+ graphics->setColor(userPalette->getColorWithAlpha(color2));
graphics->fillRectangle(gcn::Rectangle(
x + dx, y, width - dx, height));
diff --git a/src/being.h b/src/being.h
index 09466f5af..f9731366a 100644
--- a/src/being.h
+++ b/src/being.h
@@ -520,6 +520,7 @@ class Being : public ActorSprite, public ConfigListener
int posX, int posY) const;
void drawHpBar(Graphics *graphics, int x, int y,
+ int maxHP, int hp, int damage, int color1, int color2,
int width, int height) const;
static void load();
@@ -751,7 +752,7 @@ class Being : public ActorSprite, public ConfigListener
static bool mDrawHotKeys;
static bool mShowBattleEvents;
static bool mShowMobHP;
-// std::string mDisplayName;
+ static bool mShowOwnHP;
unsigned int mMoveTime;
unsigned int mAttackTime;
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 916c20398..190c1816c 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -189,6 +189,7 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "enableBattleTab", false);
AddDEF(configData, "showBattleEvents", false);
AddDEF(configData, "showMobHP", true);
+ AddDEF(configData, "showOwnHP", true);
return configData;
}
diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp
index 76510a283..68d517cae 100644
--- a/src/gui/setup_colors.cpp
+++ b/src/gui/setup_colors.cpp
@@ -302,6 +302,8 @@ void Setup_Colors::valueChanged(const gcn::SelectionEvent &event _UNUSED_)
case UserPalette::ROAD_POINT:
case UserPalette::MONSTER_HP:
case UserPalette::MONSTER_HP2:
+ case UserPalette::PLAYER_HP:
+ case UserPalette::PLAYER_HP2:
mGradDelayLabel->setCaption(_("Alpha:"));
mGradDelayText->setRange(0, 255);
mGradDelaySlider->setScale(0, 255);
diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp
index 54ec1c65d..5a2b77a81 100644
--- a/src/gui/setup_other.cpp
+++ b/src/gui/setup_other.cpp
@@ -63,6 +63,7 @@
#define ACTION_WARP_PARTICLE "warp particle"
#define ACTION_AUTO_SHOP "auto shop"
#define ACTION_SHOW_MOB_HP "show mob hp"
+#define ACTION_SHOW_OWN_HP "show own hp"
Setup_Other::Setup_Other():
mShowMonstersTakedDamage(config.getBoolValue("showMonstersTakedDamage")),
@@ -87,7 +88,8 @@ Setup_Other::Setup_Other():
mQuickStats(config.getBoolValue("quickStats")),
mWarpParticle(config.getBoolValue("warpParticle")),
mAutoShop(config.getBoolValue("autoShop")),
- mShowMobHP(config.getBoolValue("showMobHP"))
+ mShowMobHP(config.getBoolValue("showMobHP")),
+ mShowOwnHP(config.getBoolValue("showOwnHP"))
{
setName(_("Misc"));
@@ -178,6 +180,10 @@ Setup_Other::Setup_Other():
mShowMobHP,
this, ACTION_SHOW_MOB_HP);
+ mShowOwnHPCheckBox = new CheckBox(_("Show own hp bar"),
+ mShowOwnHP,
+ this, ACTION_SHOW_OWN_HP);
+
// Do the layout
LayoutHelper h(this);
ContainerPlacer place = h.getPlacer(0, 0);
@@ -192,6 +198,7 @@ Setup_Other::Setup_Other():
place(12, 4, mWarpParticleCheckBox, 10);
place(12, 5, mAutoShopCheckBox, 10);
place(12, 6, mShowMobHPCheckBox, 10);
+ place(12, 7, mShowOwnHPCheckBox, 10);
place(0, 3, mFloorItemsHighlightCheckBox, 12);
place(0, 4, mHighlightAttackRangeCheckBox, 12);
place(0, 5, mHighlightMonsterAttackRangeCheckBox, 12);
@@ -320,6 +327,10 @@ void Setup_Other::action(const gcn::ActionEvent &event)
{
mShowMobHP = mShowMobHPCheckBox->isSelected();
}
+ else if (event.getId() == ACTION_SHOW_OWN_HP)
+ {
+ mShowOwnHP = mShowOwnHPCheckBox->isSelected();
+ }
}
void Setup_Other::cancel()
@@ -389,6 +400,9 @@ void Setup_Other::cancel()
mShowMobHP = config.getBoolValue("showMobHP");
mShowMobHPCheckBox->setSelected(mShowMobHP);
+
+ mShowOwnHP = config.getBoolValue("showOwnHP");
+ mShowOwnHPCheckBox->setSelected(mShowOwnHP);
}
void Setup_Other::apply()
@@ -416,6 +430,7 @@ void Setup_Other::apply()
config.setValue("warpParticle", mWarpParticle);
config.setValue("autoShop", mAutoShop);
config.setValue("showMobHP", mShowMobHP);
+ config.setValue("showOwnHP", mShowOwnHP);
logger->setDebugLog(mDebugLog);
}
diff --git a/src/gui/setup_other.h b/src/gui/setup_other.h
index b20401be5..6a092e93f 100644
--- a/src/gui/setup_other.h
+++ b/src/gui/setup_other.h
@@ -119,6 +119,9 @@ class Setup_Other : public SetupTab, public gcn::ActionListener
gcn::CheckBox *mShowMobHPCheckBox;
bool mShowMobHP;
+ gcn::CheckBox *mShowOwnHPCheckBox;
+ bool mShowOwnHP;
+
EditDialog *mEditDialog;
};
diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp
index 03e5c1eed..46f1b72b3 100644
--- a/src/gui/userpalette.cpp
+++ b/src/gui/userpalette.cpp
@@ -52,6 +52,8 @@ const std::string ColorTypeNames[] =
"ColorParticle",
"ColorPickupInfo",
"ColorExpInfo",
+ "ColorPlayerHp",
+ "ColorPlayerHp2",
"ColorHitPlayerMonster",
"ColorHitMonsterPlayer",
"ColorHitPlayerPlayer",
@@ -124,6 +126,9 @@ UserPalette::UserPalette():
addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"));
addColor(PICKUP_INFO, 0x28dc28, STATIC, _("Pickup Notification"));
addColor(EXP_INFO, 0xffff00, STATIC, _("Exp Notification"));
+ addColor(PLAYER_HP, 0x00ff00, STATIC, _("Player HP bar"), 50);
+ addColor(PLAYER_HP2, 0xff0000, STATIC,
+ _("Player HP bar (second color)"), 50);
addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, _("Player Hits Monster"));
addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, _("Monster Hits Player"));
addColor(HIT_PLAYER_PLAYER, 0xff5050, STATIC,
diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h
index 057d47113..db2463e20 100644
--- a/src/gui/userpalette.h
+++ b/src/gui/userpalette.h
@@ -53,6 +53,8 @@ class UserPalette : public Palette, public gcn::ListModel
PARTICLE,
PICKUP_INFO,
EXP_INFO,
+ PLAYER_HP,
+ PLAYER_HP2,
HIT_PLAYER_MONSTER,
HIT_MONSTER_PLAYER,
HIT_PLAYER_PLAYER,