mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Added unit action icons on map units, so it'll be immediately visible what each unit is doing
This commit is contained in:
parent
cf2be25c73
commit
c7334a461f
@ -92,8 +92,10 @@ class TileGroupIcons(val tileGroup: TileGroup) {
|
||||
|
||||
// Instead of fading out the entire unit with its background, we just fade out its central icon,
|
||||
// that way it remains much more visible on the map
|
||||
if (!unit.isIdle() && unit.civInfo == viewingCiv)
|
||||
if (!unit.isIdle() && unit.civInfo == viewingCiv) {
|
||||
newImage.unitBaseImage.color.a = 0.5f
|
||||
newImage.actionGroup?.color?.a = 0.5f
|
||||
}
|
||||
}
|
||||
return newImage
|
||||
}
|
||||
|
@ -5,17 +5,18 @@ import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.map.MapUnit
|
||||
|
||||
class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
var blackSpinningCircle:Image?=null
|
||||
var blackSpinningCircle: Image? = null
|
||||
var actionGroup :Group? = null
|
||||
val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.nation.getInnerColor())
|
||||
.apply { setSize(size * 0.75f, size * 0.75f) }
|
||||
.apply { setSize(size * 0.75f, size * 0.75f) }
|
||||
|
||||
init {
|
||||
|
||||
val background = getBackgroundImageForUnit(unit)
|
||||
val background = getBackgroundImageForUnit()
|
||||
background.apply {
|
||||
this.color = unit.civInfo.nation.getOuterColor()
|
||||
setSize(size, size)
|
||||
@ -25,15 +26,24 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
unitBaseImage.center(this)
|
||||
addActor(unitBaseImage)
|
||||
|
||||
val actionImage = getActionImage()
|
||||
if (actionImage != null) {
|
||||
actionImage.color = Color.BLACK
|
||||
val actionCircle = actionImage.surroundWithCircle(size / 2 * 0.9f)
|
||||
.surroundWithCircle(size / 2, false, Color.BLACK)
|
||||
actionCircle.setPosition(size / 2, 0f)
|
||||
addActor(actionCircle)
|
||||
actionGroup = actionCircle
|
||||
}
|
||||
|
||||
if (unit.health < 100) { // add health bar
|
||||
addActor(ImageGetter.getHealthBar(unit.health.toFloat(), 100f, size))
|
||||
}
|
||||
|
||||
isTransform=false // performance helper - nothing here is rotated or scaled
|
||||
isTransform = false // performance helper - nothing here is rotated or scaled
|
||||
}
|
||||
|
||||
fun getBackgroundImageForUnit(unit: MapUnit): Image {
|
||||
fun getBackgroundImageForUnit(): Image {
|
||||
return when {
|
||||
unit.isEmbarked() -> ImageGetter.getImage("OtherIcons/Banner")
|
||||
unit.isFortified() -> ImageGetter.getImage("OtherIcons/Shield")
|
||||
@ -41,9 +51,21 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getActionImage(): Image? {
|
||||
return when {
|
||||
unit.isFortified() -> ImageGetter.getImage("OtherIcons/Shield")
|
||||
unit.isSleeping() -> ImageGetter.getImage("OtherIcons/Sleep")
|
||||
unit.isMoving() -> ImageGetter.getStatIcon("Movement")
|
||||
unit.action == Constants.unitActionExplore -> ImageGetter.getUnitIcon("Scout")
|
||||
unit.action == Constants.unitActionAutomation -> ImageGetter.getUnitIcon("Great Engineer")
|
||||
unit.action == Constants.unitActionSetUp -> ImageGetter.getUnitIcon("Catapult")
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun selectUnit() {
|
||||
val whiteHalo = getBackgroundImageForUnit(unit)
|
||||
val whiteHalo = getBackgroundImageForUnit()
|
||||
val whiteHaloSize = 30f
|
||||
whiteHalo.setSize(whiteHaloSize, whiteHaloSize)
|
||||
whiteHalo.center(this)
|
||||
@ -57,9 +79,17 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
spinningCircle.color = Color.BLACK
|
||||
spinningCircle.center(this)
|
||||
spinningCircle.x += whiteHaloSize / 2 // to edge of white halo
|
||||
spinningCircle.setOrigin(spinningCircle.width / 2 - whiteHaloSize / 2, spinningCircle.height / 2)
|
||||
spinningCircle.setOrigin(
|
||||
spinningCircle.width / 2 - whiteHaloSize / 2,
|
||||
spinningCircle.height / 2
|
||||
)
|
||||
addActor(spinningCircle)
|
||||
spinningCircle.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(90f, 1f)))
|
||||
spinningCircle.addAction(
|
||||
Actions.repeat(
|
||||
RepeatAction.FOREVER,
|
||||
Actions.rotateBy(90f, 1f)
|
||||
)
|
||||
)
|
||||
blackSpinningCircle = spinningCircle
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user