mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +07:00
chore: Battle animation readability
This commit is contained in:
@ -28,7 +28,7 @@ import com.unciv.ui.components.extensions.toTextButton
|
|||||||
import com.unciv.ui.images.ImageGetter
|
import com.unciv.ui.images.ImageGetter
|
||||||
import com.unciv.ui.screens.basescreen.BaseScreen
|
import com.unciv.ui.screens.basescreen.BaseScreen
|
||||||
import com.unciv.ui.screens.worldscreen.WorldScreen
|
import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||||
import com.unciv.ui.screens.worldscreen.bottombar.BattleTableHelpers.flashWoundedCombatants
|
import com.unciv.ui.screens.worldscreen.bottombar.BattleTableHelpers.battleAnimation
|
||||||
import com.unciv.ui.screens.worldscreen.bottombar.BattleTableHelpers.getHealthBar
|
import com.unciv.ui.screens.worldscreen.bottombar.BattleTableHelpers.getHealthBar
|
||||||
import com.unciv.utils.DebugUtils
|
import com.unciv.utils.DebugUtils
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
@ -311,7 +311,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||||||
SoundPlayer.play(attacker.getAttackSound())
|
SoundPlayer.play(attacker.getAttackSound())
|
||||||
Battle.attackOrNuke(attacker, attackableTile)
|
Battle.attackOrNuke(attacker, attackableTile)
|
||||||
|
|
||||||
worldScreen.flashWoundedCombatants(attacker, damageToAttacker, defender, damageToDefender)
|
worldScreen.battleAnimation(attacker, damageToAttacker, defender, damageToDefender)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.unciv.ui.screens.worldscreen.bottombar
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.math.Interpolation
|
import com.badlogic.gdx.math.Interpolation
|
||||||
|
import com.badlogic.gdx.math.Vector2
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||||
import com.badlogic.gdx.scenes.scene2d.Group
|
import com.badlogic.gdx.scenes.scene2d.Group
|
||||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||||
@ -18,23 +19,42 @@ import com.unciv.ui.screens.worldscreen.WorldScreen
|
|||||||
|
|
||||||
object BattleTableHelpers {
|
object BattleTableHelpers {
|
||||||
|
|
||||||
fun WorldScreen.flashWoundedCombatants(
|
class FlashRedAction(start:Float, end:Float, private val actorsToOriginalColors:Map<Actor, Color>) : FloatAction(start, end, 0.2f, Interpolation.sine){
|
||||||
|
private fun updateRedPercent(percent: Float) {
|
||||||
|
for ((actor, color) in actorsToOriginalColors)
|
||||||
|
actor.color = color.cpy().lerp(Color.RED, start+percent*(end-start))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun update(percent: Float) = updateRedPercent(percent)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MoveActorsAction(private val actorsToMove:List<Actor>, private val movementVector: Vector2) : RelativeTemporalAction(){
|
||||||
|
init {
|
||||||
|
duration = 0.3f
|
||||||
|
interpolation = Interpolation.sine
|
||||||
|
}
|
||||||
|
override fun updateRelative(percentDelta: Float) {
|
||||||
|
for (actor in actorsToMove){
|
||||||
|
actor.moveBy(movementVector.x * percentDelta, movementVector.y * percentDelta)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun WorldScreen.battleAnimation(
|
||||||
attacker: ICombatant, damageToAttacker: Int,
|
attacker: ICombatant, damageToAttacker: Int,
|
||||||
defender: ICombatant, damageToDefender: Int
|
defender: ICombatant, damageToDefender: Int
|
||||||
) {
|
) {
|
||||||
fun getMapActorsForCombatant(combatant: ICombatant):Sequence<Actor> =
|
fun getMapActorsForCombatant(combatant: ICombatant):Sequence<Actor> =
|
||||||
sequence {
|
sequence {
|
||||||
val tileGroup = mapHolder.tileGroups[combatant.getTile()]!!
|
val tileGroup = mapHolder.tileGroups[combatant.getTile()]!!
|
||||||
when {
|
if (combatant.isCity()) {
|
||||||
combatant.isCity() -> {
|
val icon = tileGroup.layerMisc.improvementIcon
|
||||||
val icon = tileGroup.layerMisc.improvementIcon
|
if (icon != null) yield(icon)
|
||||||
if (icon != null)
|
}
|
||||||
yield(icon)
|
else {
|
||||||
}
|
val slot = if (combatant.isCivilian()) 0 else 1
|
||||||
else -> {
|
yieldAll((tileGroup.layerUnitArt.getChild(slot) as Group).children)
|
||||||
val slot = if (combatant.isCivilian()) 0 else 1
|
|
||||||
yieldAll((tileGroup.layerUnitArt.getChild(slot) as Group).children)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +62,7 @@ object BattleTableHelpers {
|
|||||||
sequence {
|
sequence {
|
||||||
if (damageToDefender != 0) yieldAll(getMapActorsForCombatant(defender))
|
if (damageToDefender != 0) yieldAll(getMapActorsForCombatant(defender))
|
||||||
if (damageToAttacker != 0) yieldAll(getMapActorsForCombatant(attacker))
|
if (damageToAttacker != 0) yieldAll(getMapActorsForCombatant(attacker))
|
||||||
}.mapTo(arrayListOf()) { it to it.color.cpy() }
|
}.mapTo(arrayListOf()) { it to it.color.cpy() }.toMap()
|
||||||
|
|
||||||
fun updateRedPercent(percent: Float) {
|
|
||||||
for ((actor, color) in actorsToFlashRed)
|
|
||||||
actor.color = color.cpy().lerp(Color.RED, percent)
|
|
||||||
}
|
|
||||||
|
|
||||||
val actorsToMove = getMapActorsForCombatant(attacker).toList()
|
val actorsToMove = getMapActorsForCombatant(attacker).toList()
|
||||||
|
|
||||||
@ -58,36 +73,12 @@ object BattleTableHelpers {
|
|||||||
|
|
||||||
stage.addAction(
|
stage.addAction(
|
||||||
Actions.sequence(
|
Actions.sequence(
|
||||||
object : RelativeTemporalAction(){
|
MoveActorsAction(actorsToMove, attackVectorWorldCoords),
|
||||||
init {
|
|
||||||
duration = 0.3f
|
|
||||||
interpolation = Interpolation.sine
|
|
||||||
}
|
|
||||||
override fun updateRelative(percentDelta: Float) {
|
|
||||||
for (actor in actorsToMove){
|
|
||||||
actor.moveBy(attackVectorWorldCoords.x * percentDelta, attackVectorWorldCoords.y * percentDelta)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Actions.parallel( // While the unit is moving back to its normal position, we flash the damages on both units
|
Actions.parallel( // While the unit is moving back to its normal position, we flash the damages on both units
|
||||||
object : RelativeTemporalAction(){
|
MoveActorsAction(actorsToMove, attackVectorWorldCoords.cpy().scl(-1f)),
|
||||||
init {
|
|
||||||
duration = 0.3f
|
|
||||||
interpolation = Interpolation.sine
|
|
||||||
}
|
|
||||||
override fun updateRelative(percentDelta: Float) {
|
|
||||||
for (actor in actorsToMove){
|
|
||||||
actor.moveBy(attackVectorWorldCoords.x * -percentDelta, attackVectorWorldCoords.y * -percentDelta)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Actions.sequence(
|
Actions.sequence(
|
||||||
object : FloatAction(0f, 1f, 0.2f, Interpolation.sine) {
|
FlashRedAction(0f,1f, actorsToFlashRed),
|
||||||
override fun update(percent: Float) = updateRedPercent(percent)
|
FlashRedAction(1f,0f, actorsToFlashRed)
|
||||||
},
|
|
||||||
object : FloatAction(0f, 1f, 0.2f, Interpolation.sine) {
|
|
||||||
override fun update(percent: Float) = updateRedPercent(1 - percent)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
Reference in New Issue
Block a user