mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 23:10:39 -04:00
Added health bar to injured units!
This commit is contained in:
parent
b983de9599
commit
6e2eaa20a8
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.HexMath
|
||||
@ -325,6 +326,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
addActor(newImage)
|
||||
newImage.center(this)
|
||||
newImage.y += yFromCenter
|
||||
|
||||
if (!unit.isIdle()) newImage.color = Color(1f, 1f, 1f, 0.5f)
|
||||
}
|
||||
return newImage
|
||||
@ -347,6 +349,12 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
}
|
||||
unitBaseImage.center(group)
|
||||
group.addActor(unitBaseImage)
|
||||
|
||||
|
||||
if (unit.health < 100) { // add health bar
|
||||
group.addActor(getHealthBar(unit.health.toFloat(),100f,size))
|
||||
}
|
||||
|
||||
return group
|
||||
}
|
||||
|
||||
@ -358,5 +366,25 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
circleImage.color = color
|
||||
}
|
||||
|
||||
fun hideCircle(){circleImage.isVisible=false}
|
||||
fun hideCircle() {
|
||||
circleImage.isVisible = false
|
||||
}
|
||||
|
||||
|
||||
protected fun getHealthBar(currentHealth: Float, maxHealth: Float, healthBarSize: Float): Table {
|
||||
val healthPercent = currentHealth / maxHealth
|
||||
val healthBar = Table()
|
||||
val healthPartOfBar = ImageGetter.getImage(ImageGetter.WhiteDot)
|
||||
healthPartOfBar.color = when {
|
||||
healthPercent > 2 / 3f -> Color.GREEN
|
||||
healthPercent > 1 / 3f -> Color.ORANGE
|
||||
else -> Color.RED
|
||||
}
|
||||
val emptyPartOfBar = ImageGetter.getImage(ImageGetter.WhiteDot).apply { color = Color.BLACK }
|
||||
healthBar.add(healthPartOfBar).width(healthBarSize * healthPercent).height(5f)
|
||||
healthBar.add(emptyPartOfBar).width(healthBarSize * (1 - healthPercent)).height(5f)
|
||||
healthBar.pack()
|
||||
return healthBar
|
||||
|
||||
}
|
||||
}
|
@ -90,18 +90,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
||||
cityButton!!.run {
|
||||
clear()
|
||||
if(viewable && city.health<city.getMaxHealth().toFloat()) {
|
||||
val healthBarSize = 100f
|
||||
val healthPercent = city.health / city.getMaxHealth().toFloat()
|
||||
val healthBar = Table()
|
||||
val healthPartOfBar = ImageGetter.getImage(ImageGetter.WhiteDot)
|
||||
healthPartOfBar.color = when {
|
||||
healthPercent > 2 / 3f -> Color.GREEN
|
||||
healthPercent > 1 / 3f -> Color.ORANGE
|
||||
else -> Color.RED
|
||||
}
|
||||
val emptyPartOfBar = ImageGetter.getImage(ImageGetter.WhiteDot).apply { color = Color.BLACK }
|
||||
healthBar.add(healthPartOfBar).width(healthBarSize * healthPercent).height(5f)
|
||||
healthBar.add(emptyPartOfBar).width(healthBarSize * (1 - healthPercent)).height(5f)
|
||||
val healthBar = getHealthBar(city.health.toFloat(),city.getMaxHealth().toFloat(),100f)
|
||||
add(healthBar).colspan(3).row()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user