From 688872b5b1caf727061519cc6e6d0f58bd7872ae Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 4 Jun 2023 16:56:05 +0300 Subject: [PATCH] Resolved #9494 - Pillaged improvements have a visual indication on the icon --- .../components/tilegroups/layers/TileLayerMisc.kt | 14 +++++++++----- core/src/com/unciv/ui/images/ImageGetter.kt | 4 ++-- core/src/com/unciv/ui/images/Portrait.kt | 8 +++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt index 774e25a66e..d7c83664f8 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt @@ -88,7 +88,7 @@ class TileLayerMisc(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, si private var workedIcon: Actor? = null - private var improvementName: String? = null + private var improvementPlusPillagedID: String? = null var improvementIcon: Actor? = null private set // Getter public for BattleTable to display as City Combatant @@ -140,15 +140,19 @@ class TileLayerMisc(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, si private fun updateImprovementIcon(viewingCiv: Civilization?, show: Boolean) { // If improvement has changed, force new icon next time it is needed val improvementToShow = tile().getShownImprovement(viewingCiv) - if (improvementName != improvementToShow) { - improvementName = improvementToShow + val newImprovementPlusPillagedID = if (improvementToShow==null) null + else if (tile().improvementIsPillaged) "$improvementToShow-Pillaged" + else improvementToShow + + if (improvementPlusPillagedID != newImprovementPlusPillagedID) { + improvementPlusPillagedID = newImprovementPlusPillagedID improvementIcon?.remove() improvementIcon = null } // Get new icon when needed - if (improvementName != null && show && improvementIcon == null) { - val icon = ImageGetter.getImprovementPortrait(improvementName!!, dim = false) + if (improvementPlusPillagedID != null && show && improvementIcon == null) { + val icon = ImageGetter.getImprovementPortrait(improvementToShow!!, dim = false, isPillaged = tile().improvementIsPillaged) icon.center(tileGroup) icon.x -= 22 // left icon.y -= 12 // bottom diff --git a/core/src/com/unciv/ui/images/ImageGetter.kt b/core/src/com/unciv/ui/images/ImageGetter.kt index cb79db7dc3..9ee66c5873 100644 --- a/core/src/com/unciv/ui/images/ImageGetter.kt +++ b/core/src/com/unciv/ui/images/ImageGetter.kt @@ -264,8 +264,8 @@ object ImageGetter { return PortraitTech(techName, circleSize) } - fun getImprovementPortrait(improvementName: String, size: Float = 20f, dim: Boolean = false): Portrait { - return PortraitImprovement(improvementName, size, dim) + fun getImprovementPortrait(improvementName: String, size: Float = 20f, dim: Boolean = false, isPillaged: Boolean = false): Portrait { + return PortraitImprovement(improvementName, size, dim, isPillaged) } fun getUnitActionPortrait(actionName: String, size: Float = 20f): Portrait { diff --git a/core/src/com/unciv/ui/images/Portrait.kt b/core/src/com/unciv/ui/images/Portrait.kt index a6ebb2527b..0eba9d9fb0 100644 --- a/core/src/com/unciv/ui/images/Portrait.kt +++ b/core/src/com/unciv/ui/images/Portrait.kt @@ -195,13 +195,19 @@ class PortraitUnitAction(name: String, size: Float) : Portrait(Type.UnitAction, } } -class PortraitImprovement(name: String, size: Float, dim: Boolean = false) : Portrait(Type.Improvement, name, size) { +class PortraitImprovement(name: String, size: Float, dim: Boolean = false, isPillaged: Boolean = false) : Portrait(Type.Improvement, name, size) { init { if (dim) { image.color.a = 0.7f background.color.a = 0.7f } + if (isPillaged){ + val pillagedIcon = ImageGetter.getImage("OtherIcons/Fire") + pillagedIcon.setSize(width/2, height/2) + pillagedIcon.setPosition(width, 0f, Align.bottomRight) + addActor(pillagedIcon) + } } private fun getColorFromStats(stats: Stats): Color {