mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 05:41:11 +07:00
Added very basic "flash red on attack" battle animations
This commit is contained in:
@ -76,10 +76,10 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
|||||||
protected var cityImage: Image? = null
|
protected var cityImage: Image? = null
|
||||||
private var naturalWonderImage: Image? = null
|
private var naturalWonderImage: Image? = null
|
||||||
|
|
||||||
private var pixelMilitaryUnitImageLocation = ""
|
private var pixelMilitaryUnitImageLocation = ""
|
||||||
private var pixelMilitaryUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
var pixelMilitaryUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||||
private var pixelCivilianUnitImageLocation = ""
|
private var pixelCivilianUnitImageLocation = ""
|
||||||
private var pixelCivilianUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
var pixelCivilianUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||||
|
|
||||||
class MiscLayerGroupClass:ActionlessGroup(){
|
class MiscLayerGroupClass:ActionlessGroup(){
|
||||||
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
|
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
|
||||||
|
@ -38,7 +38,7 @@ import com.unciv.ui.utils.*
|
|||||||
|
|
||||||
class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap): ZoomableScrollPane() {
|
class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap): ZoomableScrollPane() {
|
||||||
internal var selectedTile: TileInfo? = null
|
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
|
//allWorldTileGroups exists to easily access all WordTileGroups
|
||||||
//since tileGroup is a HashMap of Lists and getting all WordTileGroups
|
//since tileGroup is a HashMap of Lists and getting all WordTileGroups
|
||||||
|
@ -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.
|
// 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
|
// 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!
|
// and we don't get any silly concurrency problems!
|
||||||
private fun update() {
|
internal fun update() {
|
||||||
|
|
||||||
displayTutorialsOnUpdate()
|
displayTutorialsOnUpdate()
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package com.unciv.ui.worldscreen.bottombar
|
package com.unciv.ui.worldscreen.bottombar
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
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.actions.RepeatAction
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
@ -246,7 +249,26 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||||||
attackButton.onClick(attacker.getAttackSound()) {
|
attackButton.onClick(attacker.getAttackSound()) {
|
||||||
Battle.moveAndAttack(attacker, attackableTile)
|
Battle.moveAndAttack(attacker, attackableTile)
|
||||||
worldScreen.mapHolder.removeUnitActionOverlay() // the overlay was one of attacking
|
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)
|
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){
|
private fun simulateNuke(attacker: MapUnitCombatant, targetTile: TileInfo){
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user