From c90a79363de913f85e590c8472169ea9fafe0e66 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 28 May 2021 14:34:24 +0300 Subject: [PATCH] Added city strength label to city button --- core/src/com/unciv/ui/tilegroups/CityButton.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/ui/tilegroups/CityButton.kt b/core/src/com/unciv/ui/tilegroups/CityButton.kt index e055902f14..6b54de3ffe 100644 --- a/core/src/com/unciv/ui/tilegroups/CityButton.kt +++ b/core/src/com/unciv/ui/tilegroups/CityButton.kt @@ -10,6 +10,7 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align +import com.unciv.logic.battle.CityCombatant import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.CityInfo import com.unciv.logic.city.PerpetualConstruction @@ -39,7 +40,6 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab clear() setButtonActions() addAirUnitTable() - if (showAdditionalInfoTags && city.health < city.getMaxHealth().toFloat()) { val healthBar = ImageGetter.getHealthBar(city.health.toFloat(), city.getMaxHealth().toFloat(), 100f) add(healthBar).row() @@ -54,6 +54,8 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab add(influenceBar).row() } + + pack() setOrigin(Align.center) centerX(tileGroup) @@ -228,6 +230,12 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab label.toBack() // this is so the label is rendered right before the population group, // so we save the font texture and avoid another texture switch + // City strength is added NOT inside the table, but rather - top-center to it + val cityStrength = CityCombatant(city).getCityStrength() + val cityStrengthLabel = "${Fonts.strength}$cityStrength".toLabel(city.civInfo.nation.getInnerColor(), 10) + iconTable.addActor(cityStrengthLabel) // We create this here to we can .toBack() it as well. + cityStrengthLabel.toBack() + if (uncivGame.viewEntireMapForDebug || belongsToViewingCiv() || worldScreen.viewingCiv.isSpectator()) { val constructionGroup = getConstructionGroup(city.cityConstructions) iconTable.add(constructionGroup) @@ -243,6 +251,10 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab nationIcon.color = secondaryColor iconTable.add(nationIcon).size(20f) } + + iconTable.pack() + cityStrengthLabel.x = label.x // so it'll be aligned right above the city name + cityStrengthLabel.setY(iconTable.height, Align.top) return iconTable }