Added small black spinning circle around selected unit, so it will be more noticable

This commit is contained in:
Yair Morgenstern
2018-12-05 15:01:42 +02:00
parent 67625321b8
commit ed1753d4ad
10 changed files with 64 additions and 75 deletions

View File

@ -72,7 +72,7 @@ class CityButton(val city: CityInfo, skin: Skin): Table(skin){
val groupHeight = 25f
group.setSize(40f,groupHeight)
val circle = ImageGetter.getImage("OtherIcons/Circle")
val circle = ImageGetter.getCircle()
circle.setSize(25f,25f)
val image = ImageGetter.getConstructionImage(cityConstructions.currentConstruction)
image.setSize(18f,18f)

View File

@ -13,6 +13,7 @@ import com.unciv.logic.map.RoadStatus
import com.unciv.logic.map.TileInfo
import com.unciv.ui.cityscreen.YieldGroup
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.UnitGroup
import com.unciv.ui.utils.center
open class TileGroup(var tileInfo: TileInfo) : Group() {
@ -26,10 +27,10 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
var populationImage: Image? = null //reuse for acquire icon
private val roadImages = HashMap<TileInfo, RoadImage>()
private val borderImages = HashMap<TileInfo, List<Image>>() // map of neighboring tile to border images
protected var civilianUnitImage: Group? = null
protected var militaryUnitImage: Group? = null
private val circleImage = ImageGetter.getImage("OtherIcons/Circle.png") // for blue and red circles on the tile
private val crosshairImage = ImageGetter.getImage("OtherIcons/Crosshair.png") // for blue and red circles on the tile
protected var civilianUnitImage: UnitGroup? = null
protected var militaryUnitImage: UnitGroup? = null
private val circleImage = ImageGetter.getCircle() // for blue and red circles on the tile
private val crosshairImage = ImageGetter.getImage("OtherIcons/Crosshair.png") // for when a unit is targeted
protected val fogImage = ImageGetter.getImage("TerrainIcons/CrosshatchHexagon")
var yieldGroup = YieldGroup()
@ -210,7 +211,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
val images = mutableListOf<Image>()
borderImages[neighbor] = images
for (i in -2..2) {
val image = ImageGetter.getImage("OtherIcons/Circle.png")
val image = ImageGetter.getCircle()
image.setSize(5f, 5f)
image.center(this)
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50
@ -340,13 +341,17 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
}
protected fun newUnitImage(unit: MapUnit?, currentImage: Group?, isViewable: Boolean, yFromCenter: Float): Group? {
var newImage: Group? = null
protected fun newUnitImage(unit: MapUnit?, oldUnitGroup: UnitGroup?, isViewable: Boolean, yFromCenter: Float): UnitGroup? {
var newImage: UnitGroup? = null
// The unit can change within one update - for instance, when attacking, the attacker replaces the defender!
currentImage?.remove()
oldUnitGroup?.remove()
if (unit != null && isViewable) { // Tile is visible
newImage = ImageGetter.getUnitImage(unit, 25f)
newImage = UnitGroup(unit, 25f)
if(oldUnitGroup?.blackSpinningCircle != null){
newImage.blackSpinningCircle = ImageGetter.getCircle()
.apply { rotation= oldUnitGroup.blackSpinningCircle!!.rotation}
}
addActor(newImage)
newImage.center(this)
newImage.y += yFromCenter

View File

@ -5,28 +5,21 @@ import com.unciv.logic.city.CityInfo
import com.unciv.logic.map.MapUnit
import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.center
class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
var cityButton: CityButton? = null
fun addWhiteHaloAroundUnit(unit: MapUnit) {
val whiteHalo = ImageGetter.getBackgroundImageForUnit(unit)
whiteHalo.setSize(30f,30f)
val unitImage = if(unit.type.isCivilian()) civilianUnitImage
else militaryUnitImage
if(unitImage==null) //Stuff has changed since we requested this, the unit is no longer here...
return
whiteHalo.center(unitImage)
unitImage.addActor(whiteHalo)
whiteHalo.toBack()
fun selectUnit(unit: MapUnit) {
val unitImage = if (unit.type.isCivilian()) civilianUnitImage
else militaryUnitImage
unitImage?.selectUnit()
}
init{
init {
yieldGroup.center(this)
yieldGroup.moveBy(-22f,0f)
yieldGroup.moveBy(-22f, 0f)
}
@ -46,7 +39,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
UnCivGame.Current.settings.showResourcesAndImprovements)
yieldGroup.isVisible = !UnCivGame.Current.settings.showResourcesAndImprovements
if(yieldGroup.isVisible)
if (yieldGroup.isVisible)
yieldGroup.setStats(tileInfo.getTileStats(UnCivGame.Current.gameInfo.getPlayerCivilization()))
// order by z index!
@ -63,14 +56,14 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
private fun updateCityButton(city: CityInfo?, viewable: Boolean) {
if(city==null && cityButton!=null)// there used to be a city here but it was razed
if (city == null && cityButton != null)// there used to be a city here but it was razed
{
cityButton!!.remove()
cityButton=null
cityButton = null
}
if (city != null && tileInfo.isCityCenter()) {
if (cityButton == null) {
cityButton = CityButton(city,CameraStageBaseScreen.skin)
cityButton = CityButton(city, CameraStageBaseScreen.skin)
addActor(cityButton)
toFront() // so this tile is rendered over neighboring tiles
}
@ -80,5 +73,4 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
}
}
}

View File

@ -4,7 +4,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group
class IconCircleGroup(size:Float, val image: Actor): Group(){
val circle = ImageGetter.getImage("OtherIcons/Circle").apply { setSize(size, size) }
val circle = ImageGetter.getCircle().apply { setSize(size, size) }
init {
setSize(size, size)
addActor(circle)

View File

@ -10,7 +10,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import com.unciv.logic.map.MapUnit
import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.tile.ResourceType
@ -102,6 +101,8 @@ object ImageGetter {
fun getBlue() = Color(0x004085bf)
fun getCircle() = getImage("OtherIcons/Circle") // This is used, like, everywhere
fun getBackground(color:Color): Drawable {
return getDrawable(whiteDotLocation).tint(color)
}
@ -162,39 +163,4 @@ object ImageGetter {
healthBar.pack()
return healthBar
}
fun getUnitImage(unit: MapUnit, size: Float): Group {
val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.getNation().getSecondaryColor())
.apply { setSize(size*0.75f, size*0.75f) }
val background = getBackgroundImageForUnit(unit)
background.apply {
this.color = unit.civInfo.getNation().getColor()
setSize(size, size)
}
val group = Group().apply {
setSize(size, size)
addActor(background)
}
unitBaseImage.center(group)
group.addActor(unitBaseImage)
if (unit.health < 100) { // add health bar
group.addActor(ImageGetter.getHealthBar(unit.health.toFloat(),100f,size))
}
return group
}
fun getBackgroundImageForUnit(unit: MapUnit):Image{
return when {
unit.isEmbarked() -> ImageGetter.getImage("OtherIcons/Banner")
unit.isFortified() -> ImageGetter.getImage("OtherIcons/Shield.png")
else -> ImageGetter.getImage("OtherIcons/Circle.png")
}
}
}

View File

@ -1,10 +1,15 @@
package com.unciv.ui.utils
import com.badlogic.gdx.graphics.Color
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.logic.map.MapUnit
class UnitImage(val unit: MapUnit, val size: Float): Group() {
class UnitGroup(val unit: MapUnit, val size: Float): Group() {
var blackSpinningCircle:Image?=null
init {
val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.getNation().getSecondaryColor())
.apply { setSize(size * 0.75f, size * 0.75f) }
@ -32,4 +37,26 @@ class UnitImage(val unit: MapUnit, val size: Float): Group() {
else -> ImageGetter.getCircle()
}
}
fun selectUnit() {
val whiteHalo = getBackgroundImageForUnit(unit)
val whiteHaloSize = 30f
whiteHalo.setSize(whiteHaloSize, whiteHaloSize)
whiteHalo.center(this)
addActor(whiteHalo)
whiteHalo.toBack()
val spinningCircle = if (blackSpinningCircle != null) blackSpinningCircle!!
else ImageGetter.getCircle()
spinningCircle.setSize(5f, 5f)
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)
addActor(spinningCircle)
spinningCircle.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(90f, 1f)))
blackSpinningCircle = spinningCircle
}
}

View File

@ -22,7 +22,7 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu
.setFontSize(14)
val minitable = Table()
minitable.add(ImageGetter.getImage("OtherIcons/Circle.png")
minitable.add(ImageGetter.getCircle()
.apply { color=notification.color }).size(10f).pad(5f)
minitable.background(ImageGetter.getDrawable("OtherIcons/civTableBackground.png"))
minitable.add(label).pad(3f).padRight(10f)

View File

@ -108,16 +108,16 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
private fun addMoveHereButtonToTile(selectedUnit: MapUnit, tileInfo: TileInfo, tileGroup: WorldTileGroup) {
val size = 60f
val moveHereButton = Group().apply { width = size;height = size; }
moveHereButton.addActor(ImageGetter.getImage("OtherIcons/Circle").apply { width = size; height = size })
moveHereButton.addActor(ImageGetter.getCircle().apply { width = size; height = size })
moveHereButton.addActor(ImageGetter.getStatIcon("Movement").apply { width = size / 2; height = size / 2; center(moveHereButton) })
val turnsToGetThere = selectedUnit.movementAlgs().getShortestPath(tileInfo).size
val numberCircle = ImageGetter.getImage("OtherIcons/Circle").apply { width = size / 2; height = size / 2;color = Color.BLUE }
val numberCircle = ImageGetter.getCircle().apply { width = size / 2; height = size / 2;color = Color.BLUE }
moveHereButton.addActor(numberCircle)
moveHereButton.addActor(Label(turnsToGetThere.toString(), CameraStageBaseScreen.skin)
.apply { center(numberCircle); setFontColor(Color.WHITE) })
val unitIcon = ImageGetter.getUnitImage(selectedUnit, size / 2)
val unitIcon = UnitGroup(selectedUnit, size / 2)
unitIcon.y = size - unitIcon.height
moveHereButton.addActor(unitIcon)
@ -176,7 +176,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
if(worldScreen.bottomBar.unitTable.selectedUnit!=null){
val unit = worldScreen.bottomBar.unitTable.selectedUnit!!
tileGroups[unit.getTile()]!!.addWhiteHaloAroundUnit(unit)
tileGroups[unit.getTile()]!!.selectUnit(unit)
for(tile: TileInfo in unit.getDistanceToTiles().keys)
if(unit.canMoveTo(tile))

View File

@ -59,15 +59,14 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
val attackerNameWrapper = Table()
val attackerLabel = Label(attacker.getName(), skin)
attackerNameWrapper.add(ImageGetter.getUnitImage(attacker.unit,25f)).padRight(5f)
attackerNameWrapper.add(UnitGroup(attacker.unit,25f)).padRight(5f)
attackerNameWrapper.add(attackerLabel)
add(attackerNameWrapper)
val defenderNameWrapper = Table()
val defenderLabel = Label(defender.getName(), skin)
// .setFontColor(defender.getCivilization().getNation().getColor())
if(defender is MapUnitCombatant)
defenderNameWrapper.add(ImageGetter.getUnitImage(defender.unit,25f)).padRight(5f)
defenderNameWrapper.add(UnitGroup(defender.unit,25f)).padRight(5f)
defenderNameWrapper.add(defenderLabel)
add(defenderNameWrapper).row()

View File

@ -109,7 +109,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
unitDescriptionTable.clearListeners()
if(selectedUnit!=null) {
unitIconHolder.add(ImageGetter.getUnitImage(selectedUnit!!,30f)).pad(5f)
unitIconHolder.add(UnitGroup(selectedUnit!!,30f)).pad(5f)
for(promotion in selectedUnit!!.promotions.promotions)
promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f)