From 8c0be488bc09481888fc18613a419c0e59989829 Mon Sep 17 00:00:00 2001 From: Jack Rainy Date: Sat, 23 Jan 2021 19:11:41 +0200 Subject: [PATCH] Avoid overflow of the health bar in the overkill situation (#3558) --- core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 0cc2b034d1..51b5b38287 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -309,8 +309,9 @@ class BattleTable(val worldScreen: WorldScreen): Table() { private fun getHealthBar(currentHealth: Int, maxHealth: Int, expectedDamage:Int): Table { val healthBar = Table() val totalWidth = 100f - fun addHealthToBar(image: Image, amount:Int){ - healthBar.add(image).size(amount*totalWidth/maxHealth,3f) + fun addHealthToBar(image: Image, amount:Int) { + val width = totalWidth * amount/maxHealth + healthBar.add(image).size(width.coerceIn(0f,totalWidth),3f) } addHealthToBar(ImageGetter.getDot(Color.BLACK), maxHealth-currentHealth)