From 9e6a349f2a5b64855f88ac3c6b1d554dfda53a12 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 17 Sep 2020 23:21:05 -0400 Subject: [PATCH] v0.9.0: added a HP count to the main health bar --- .../java/com/watabou/noosa/BitmapText.java | 6 ++-- .../shatteredpixeldungeon/ui/StatusPane.java | 34 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java b/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java index 09ef45768..9f1dd3c06 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java @@ -209,8 +209,10 @@ public class BitmapText extends Visual { } public synchronized void text( String str ) { - text = str; - dirty = true; + if (str == null || !str.equals(text)) { + text = str; + dirty = true; + } } public static class Font extends TextureFilm { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 3f26d40c3..e5fbaf4ca 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -57,6 +57,8 @@ public class StatusPane extends Component { private Image rawShielding; private Image shieldedHP; private Image hp; + private BitmapText hpText; + private Image exp; private BossHealthBar bossHP; @@ -120,6 +122,10 @@ public class StatusPane extends Component { hp = new Image( Assets.Interfaces.HP_BAR ); add( hp ); + hpText = new BitmapText(PixelScene.pixelFont); + hpText.alpha(0.6f); + add(hpText); + exp = new Image( Assets.Interfaces.XP_BAR ); add( exp ); @@ -166,6 +172,12 @@ public class StatusPane extends Component { hp.x = shieldedHP.x = rawShielding.x = 30; hp.y = shieldedHP.y = rawShielding.y = 3; + hpText.scale.set(PixelScene.align(0.5f)); + hpText.x = hp.x + 1; + hpText.y = hp.y + (hp.height - (hpText.baseLine()+hpText.scale.y))/2f; + hpText.y -= 0.001f; //prefer to be slightly higher + PixelScene.align(hpText); + bossHP.setPos( 6 + (width - bossHP.width())/2, 20); depth.x = width - 35.5f - depth.width() / 2f; @@ -193,14 +205,14 @@ public class StatusPane extends Component { public void update() { super.update(); - float health = Dungeon.hero.HP; - float shield = Dungeon.hero.shielding(); - float max = Dungeon.hero.HT; + int health = Dungeon.hero.HP; + int shield = Dungeon.hero.shielding(); + int max = Dungeon.hero.HT; if (!Dungeon.hero.isAlive()) { avatar.tint(0x000000, 0.5f); - } else if ((health/max) < 0.3f) { - warning += Game.elapsed * 5f *(0.4f - (health/max)); + } else if ((health/(float)max) < 0.3f) { + warning += Game.elapsed * 5f *(0.4f - (health/(float)max)); warning %= 1f; avatar.tint(ColorMath.interpolate(warning, warningColors), 0.5f ); } else if (talentBlink > 0){ @@ -210,9 +222,15 @@ public class StatusPane extends Component { avatar.resetColor(); } - hp.scale.x = Math.max( 0, (health-shield)/max); - shieldedHP.scale.x = health/max; - rawShielding.scale.x = shield/max; + hp.scale.x = Math.max( 0, (health-shield)/(float)max); + shieldedHP.scale.x = health/(float)max; + rawShielding.scale.x = shield/(float)max; + + if (shield <= 0){ + hpText.text(health + "/" + max); + } else { + hpText.text(health + "+" + shield + "/" + max); + } exp.scale.x = (width / exp.width) * Dungeon.hero.exp / Dungeon.hero.maxExp();