Added very basic "flash red on attack" battle animations

This commit is contained in:
Yair Morgenstern 2022-04-19 12:39:14 +03:00
parent dbaf4edb2f
commit 5ad258ca47
4 changed files with 51 additions and 7 deletions

View File

@ -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)

View File

@ -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<TileInfo, List<WorldTileGroup>>()
val tileGroups = HashMap<TileInfo, List<WorldTileGroup>>()
//allWorldTileGroups exists to easily access all WordTileGroups
//since tileGroup is a HashMap of Lists and getting all WordTileGroups

View File

@ -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()

View File

@ -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<Actor>()
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<Actor> =
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()