diff --git a/core/src/com/unciv/logic/battle/CityCombatant.kt b/core/src/com/unciv/logic/battle/CityCombatant.kt index 7c5d7084ba..2d394a8278 100644 --- a/core/src/com/unciv/logic/battle/CityCombatant.kt +++ b/core/src/com/unciv/logic/battle/CityCombatant.kt @@ -7,6 +7,10 @@ import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.unit.UnitType class CityCombatant(val city: CityInfo) : ICombatant { + override fun getMaxHealth(): Int { + return city.getMaxHealth() + } + override fun getHealth(): Int = city.health override fun getCivilization(): CivilizationInfo = city.civInfo override fun getTile(): TileInfo = city.getCenterTile() diff --git a/core/src/com/unciv/logic/battle/ICombatant.kt b/core/src/com/unciv/logic/battle/ICombatant.kt index 3b942c607b..9a547a3dee 100644 --- a/core/src/com/unciv/logic/battle/ICombatant.kt +++ b/core/src/com/unciv/logic/battle/ICombatant.kt @@ -1,13 +1,13 @@ package com.unciv.logic.battle import com.unciv.logic.civilization.CivilizationInfo -import com.unciv.logic.map.MapUnit import com.unciv.logic.map.TileInfo import com.unciv.models.gamebasics.unit.UnitType interface ICombatant{ fun getName(): String fun getHealth():Int + fun getMaxHealth():Int fun getUnitType(): UnitType fun getAttackingStrength(): Int fun getDefendingStrength(): Int diff --git a/core/src/com/unciv/logic/battle/MapUnitCombatant.kt b/core/src/com/unciv/logic/battle/MapUnitCombatant.kt index 23bcf13a34..c95fee24ac 100644 --- a/core/src/com/unciv/logic/battle/MapUnitCombatant.kt +++ b/core/src/com/unciv/logic/battle/MapUnitCombatant.kt @@ -7,6 +7,7 @@ import com.unciv.models.gamebasics.unit.UnitType class MapUnitCombatant(val unit: MapUnit) : ICombatant { override fun getHealth(): Int = unit.health + override fun getMaxHealth() = 100 override fun getCivilization(): CivilizationInfo = unit.civInfo override fun getTile(): TileInfo = unit.getTile() override fun getName(): String = unit.name diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index 8dc290cd72..6f7dfe29de 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -267,7 +267,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { } if (roadStatus == RoadStatus.None) continue // no road image - val image = if (roadStatus == RoadStatus.Road) ImageGetter.getWhiteDot().apply { color = Color.BROWN } + val image = if (roadStatus == RoadStatus.Road) ImageGetter.getDot(Color.BROWN) else ImageGetter.getImage("OtherIcons/Railroad.png") roadImage.image = image diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index d6f6062a04..4297afc106 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -24,7 +24,7 @@ object ImageGetter { // and the atlas is what tells us what was packed where. var atlas = TextureAtlas("game.atlas") fun getWhiteDot() = getImage(whiteDotLocation) - + fun getDot(dotColor: Color) = getWhiteDot().apply { color = dotColor} fun getExternalImage(fileName:String): Image { return Image(TextureRegion(Texture("ExtraImages/$fileName.png"))) @@ -158,7 +158,7 @@ object ImageGetter { healthPercent > 1 / 3f -> Color.ORANGE else -> Color.RED } - val emptyPartOfBar = ImageGetter.getWhiteDot().apply { color = Color.BLACK } + val emptyPartOfBar = ImageGetter.getDot(Color.BLACK) healthBar.add(healthPartOfBar).width(healthBarSize * healthPercent).height(5f) healthBar.add(emptyPartOfBar).width(healthBarSize * (1 - healthPercent)).height(5f) healthBar.pack() diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 21af698822..eba5ba3406 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -1,6 +1,9 @@ package com.unciv.ui.worldscreen.bottombar import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.scenes.scene2d.actions.Actions +import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction +import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton @@ -118,12 +121,10 @@ class BattleTable(val worldScreen: WorldScreen): Table() { add("{Captured!}".tr()) } - else { - add("{Health}: ".tr() + attacker.getHealth().toString() + " -> " - + (attacker.getHealth() - damageToAttacker)) - add("{Health}: ".tr() + defender.getHealth().toString() + " -> " - + (defender.getHealth() - damageToDefender)) + else { + add(getHealthBar(attacker.getHealth(), attacker.getMaxHealth(), damageToAttacker)) + add(getHealthBar(defender.getHealth(), defender.getMaxHealth(), damageToDefender)) } row().pad(5f) @@ -171,4 +172,32 @@ class BattleTable(val worldScreen: WorldScreen): Table() { setPosition(worldScreen.stage.width/2-width/2, 5f) } + 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) + } + addHealthToBar(ImageGetter.getDot(Color.BLACK), maxHealth-currentHealth) + + val damagedHealth = ImageGetter.getDot(Color.RED) + damagedHealth.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.sequence( + Actions.color(Color.BLACK,0.7f), + Actions.color(Color.RED,0.7f) + ))) + addHealthToBar(damagedHealth,expectedDamage) + + val remainingHealth = currentHealth-expectedDamage + val remainingHealthDot = ImageGetter.getWhiteDot() + remainingHealthDot.color = when { + remainingHealth / maxHealth.toFloat() > 2 / 3f -> Color.GREEN + remainingHealth / maxHealth.toFloat() > 1 / 3f -> Color.ORANGE + else -> Color.RED + } + addHealthToBar(remainingHealthDot ,remainingHealth) + + healthBar.pack() + return healthBar + } + } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt b/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt index 5e40e966e3..2e12cca0cb 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt @@ -1,6 +1,5 @@ package com.unciv.ui.worldscreen.bottombar -import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table import com.unciv.logic.map.TileInfo import com.unciv.ui.worldscreen.WorldScreen @@ -11,7 +10,6 @@ class WorldScreenBottomBar(val worldScreen: WorldScreen) : Table(){ val tileInfoTable = TileInfoTable(worldScreen) init { - touchable= Touchable.enabled add(unitTable).width(worldScreen.stage.width/3).fill() add().width(worldScreen.stage.width/3) // empty space for the battle table add(tileInfoTable).width(worldScreen.stage.width/3).fill()