diff --git a/core/src/com/unciv/ui/tilegroups/CityButton.kt b/core/src/com/unciv/ui/tilegroups/CityButton.kt index 59b018db35..5f8e1ebd6b 100644 --- a/core/src/com/unciv/ui/tilegroups/CityButton.kt +++ b/core/src/com/unciv/ui/tilegroups/CityButton.kt @@ -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) diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index fa61020f44..b065ad5401 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -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() private val borderImages = HashMap>() // 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() 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 diff --git a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index 4c61629c2d..1c7ab8dd3c 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -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) { } } - } \ No newline at end of file diff --git a/core/src/com/unciv/ui/utils/IconCircleGroup.kt b/core/src/com/unciv/ui/utils/IconCircleGroup.kt index f8a6bc919a..5241b9a756 100644 --- a/core/src/com/unciv/ui/utils/IconCircleGroup.kt +++ b/core/src/com/unciv/ui/utils/IconCircleGroup.kt @@ -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) diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index ef103614f7..0549dbe190 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -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") - } - } - - } \ No newline at end of file diff --git a/core/src/com/unciv/ui/utils/UnitGroup.kt b/core/src/com/unciv/ui/utils/UnitGroup.kt index 973aaa0ff6..0da0bea812 100644 --- a/core/src/com/unciv/ui/utils/UnitGroup.kt +++ b/core/src/com/unciv/ui/utils/UnitGroup.kt @@ -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 + } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt index ce1bf521ed..de6d382e69 100644 --- a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt +++ b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt @@ -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) diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index f5dd961a8e..ee6ec2edcb 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -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)) diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 4e8cc360c8..ae0dc42f7d 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -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() diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index e8cc98990c..710f8f1924 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -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)