diff --git a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt index cbd61fa965..486d37f901 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt @@ -230,7 +230,7 @@ class BattleTable(val worldScreen: WorldScreen) : Table() { val maxRemainingLifeDefender = max(defenderHealth-minDamageToDefender, 0) add(getHealthBar(attacker.getMaxHealth(), attacker.getHealth(), maxRemainingLifeAttacker, minRemainingLifeAttacker)) - add(getHealthBar(defender.getMaxHealth(), defender.getHealth(), maxRemainingLifeDefender, minRemainingLifeDefender)).row() + add(getHealthBar(defender.getMaxHealth(), defender.getHealth(), maxRemainingLifeDefender, minRemainingLifeDefender, true)).row() fun avg(vararg values: Int) = values.average().roundToInt() // Don't use original damage estimates - they're raw, before clamping to 0..max diff --git a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt index 7ce258974e..9c141c2e3b 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt @@ -226,32 +226,55 @@ object BattleTableHelpers { container.addAction(DamageLabelAnimation(container)) } - fun getHealthBar(maxHealth: Int, currentHealth: Int, maxRemainingHealth: Int, minRemainingHealth: Int): Table { + fun getHealthBar(maxHealth: Int, currentHealth: Int, maxRemainingHealth: Int, minRemainingHealth: Int, forDefender: Boolean = false): Table { val healthBar = Table() - val totalWidth = 100f + val totalWidth = 120f fun addHealthToBar(image: Image, amount: Int) { val width = totalWidth * amount / maxHealth - healthBar.add(image).size(width.coerceIn(0f, totalWidth),3f) + healthBar.add(image).size(width.coerceIn(0f, totalWidth),4f) } + fun animateHealth(health: Image, healthDecreaseWidth: Float, move: Float) { + health.addAction(Actions.sequence( + Actions.sizeBy(healthDecreaseWidth, 0f), + Actions.sizeBy(-healthDecreaseWidth, 0f, 0.5f) + )) + health.addAction(Actions.sequence( + Actions.moveBy(-move, 0f), + Actions.moveBy(move, 0f, 0.5f) + )) + } + val damagedHealth = ImageGetter.getDot(Color.FIREBRICK) + val remainingHealthDot = ImageGetter.getDot(Color.GREEN) + val maybeDamagedHealth = ImageGetter.getDot(Color.ORANGE) + val missingHealth = ImageGetter.getDot(ImageGetter.CHARCOAL) if (UncivGame.Current.settings.continuousRendering) { - damagedHealth.addAction(Actions.forever(Actions.sequence( - Actions.color(ImageGetter.CHARCOAL, 0.7f), - Actions.color(Color.FIREBRICK, 0.7f) + maybeDamagedHealth.addAction(Actions.forever(Actions.sequence( + Actions.color(Color.FIREBRICK, 0.7f), + Actions.color(Color.ORANGE, 0.7f) ))) } + + val healthDecreaseWidth = (currentHealth - minRemainingHealth) * totalWidth / 100 // Used for animation only + if (forDefender) { + addHealthToBar(missingHealth, maxHealth - currentHealth) + addHealthToBar(damagedHealth, currentHealth - maxRemainingHealth) + addHealthToBar(maybeDamagedHealth, maxRemainingHealth - minRemainingHealth) + addHealthToBar(remainingHealthDot, minRemainingHealth) - val maybeDamagedHealth = ImageGetter.getDot(Color.ORANGE) - - val remainingHealthDot = ImageGetter.getWhiteDot() - remainingHealthDot.color = Color.GREEN - - addHealthToBar(ImageGetter.getDot(ImageGetter.CHARCOAL), maxHealth - currentHealth) - addHealthToBar(damagedHealth, currentHealth - maxRemainingHealth) - addHealthToBar(maybeDamagedHealth, maxRemainingHealth - minRemainingHealth) - addHealthToBar(remainingHealthDot, minRemainingHealth) + remainingHealthDot.toFront() + animateHealth(remainingHealthDot, healthDecreaseWidth, healthDecreaseWidth) + } + else { + addHealthToBar(remainingHealthDot, minRemainingHealth) + addHealthToBar(maybeDamagedHealth, maxRemainingHealth - minRemainingHealth) + addHealthToBar(damagedHealth, currentHealth - maxRemainingHealth) + addHealthToBar(missingHealth, maxHealth - currentHealth) + remainingHealthDot.toFront() + animateHealth(remainingHealthDot, healthDecreaseWidth, 0f) + } healthBar.pack() return healthBar }