Better battle menu (#13076)

* Better battle menu

* Cleaned the code

* More descriptive variable name

* Added animations to unit action menu

* Revert "Added animations to unit action menu"

This reverts commit 4d29699e1e2526e3ea0c0bcf81a3a4779320569d.

---------

Co-authored-by: K-OA <klishynoleh@gmail.com>
This commit is contained in:
k-oa 2025-03-25 11:37:46 +02:00 committed by GitHub
parent 1c03133fdc
commit f98995e718
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 16 deletions

View File

@ -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

View File

@ -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 maybeDamagedHealth = ImageGetter.getDot(Color.ORANGE)
val remainingHealthDot = ImageGetter.getWhiteDot()
remainingHealthDot.color = Color.GREEN
addHealthToBar(ImageGetter.getDot(ImageGetter.CHARCOAL), maxHealth - currentHealth)
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)
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
}