diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index 27d4090198..e4af480fd4 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -76,10 +76,10 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings, protected var cityImage: Image? = null private var naturalWonderImage: Image? = null - private var pixelMilitaryUnitImageLocation = "" - private var pixelMilitaryUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } - private var pixelCivilianUnitImageLocation = "" - private var pixelCivilianUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } + private var pixelMilitaryUnitImageLocation = "" + var pixelMilitaryUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } + private var pixelCivilianUnitImageLocation = "" + var pixelCivilianUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } class MiscLayerGroupClass:ActionlessGroup(){ override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha) diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index 009e9b4f6b..b656901908 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -38,7 +38,7 @@ import com.unciv.ui.utils.* class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap): ZoomableScrollPane() { internal var selectedTile: TileInfo? = null - private val tileGroups = HashMap>() + val tileGroups = HashMap>() //allWorldTileGroups exists to easily access all WordTileGroups //since tileGroup is a HashMap of Lists and getting all WordTileGroups diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 21e48ac168..c3adfe2b48 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -380,7 +380,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas // This is private so that we will set the shouldUpdate to true instead. // That way, not only do we save a lot of unnecessary updates, we also ensure that all updates are called from the main GL thread // and we don't get any silly concurrency problems! - private fun update() { + internal fun update() { displayTutorialsOnUpdate() diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 3e5d5fa729..ed06bc4034 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -1,8 +1,11 @@ package com.unciv.ui.worldscreen.bottombar import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.math.Interpolation +import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.actions.Actions +import com.badlogic.gdx.scenes.scene2d.actions.FloatAction import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Label @@ -246,7 +249,26 @@ class BattleTable(val worldScreen: WorldScreen): Table() { attackButton.onClick(attacker.getAttackSound()) { Battle.moveAndAttack(attacker, attackableTile) worldScreen.mapHolder.removeUnitActionOverlay() // the overlay was one of attacking - worldScreen.shouldUpdate = true + worldScreen.update() + + val actorsToFlashRed = arrayListOf() + + if (damageToDefender != 0) + actorsToFlashRed.addAll(getMapActorsForCombatant(defender)) + if (damageToAttacker != 0) + actorsToFlashRed.addAll(getMapActorsForCombatant(attacker)) + fun updateRedPercent(percent: Float) { + for (actor in actorsToFlashRed) + actor.color = Color.WHITE.cpy().lerp(Color.RED, percent) + } + worldScreen.stage.addAction(Actions.sequence( + object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) { + override fun update(percent: Float)=updateRedPercent(percent) + }, + object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) { + override fun update(percent: Float)=updateRedPercent(1-percent) + } + )) } } @@ -257,6 +279,28 @@ class BattleTable(val worldScreen: WorldScreen): Table() { setPosition(worldScreen.stage.width/2-width/2, 5f) } + + fun getMapActorsForCombatant(combatant: ICombatant):Sequence = + sequence { + val tilegroups = + worldScreen.mapHolder.tileGroups[combatant.getTile()]!! + when { + combatant.isCity() -> yieldAll(tilegroups.mapNotNull { it.icons.improvementIcon }) + combatant.isCivilian() -> { + for (tileGroup in tilegroups) { + tileGroup.icons.civilianUnitIcon?.let { yield(it) } + yieldAll(tileGroup.pixelCivilianUnitGroup.children) + } + } + else -> { + for (tileGroup in tilegroups) { + tileGroup.icons.militaryUnitIcon?.let { yield(it) } + yieldAll(tileGroup.pixelMilitaryUnitGroup.children) + } + } + } + } + private fun simulateNuke(attacker: MapUnitCombatant, targetTile: TileInfo){ clear()