From 1a6e4d30f809da540f6cb1b3f4e458e3050e2b0e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 6 May 2018 09:30:20 +0300 Subject: [PATCH] Can now see the units from within the city screen --- android/build.gradle | 4 +- .../com/unciv/ui/cityscreen/CityTileGroup.kt | 32 +++++++++----- core/src/com/unciv/ui/tilegroups/TileGroup.kt | 44 +++++++++++++++++++ .../com/unciv/ui/tilegroups/WorldTileGroup.kt | 40 +---------------- 4 files changed, 68 insertions(+), 52 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index e88caa2f..5661ae93 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 44 - versionName "2.0.1" + versionCode 45 + versionName "2.0.2" } buildTypes { release { diff --git a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt index 5fc30018..3e821674 100644 --- a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt +++ b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt @@ -23,6 +23,27 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup( fun update() { super.update(true) + updateUnitImage(true) + if(unitImage!=null) { + unitImage!!.setPosition(width / 2 - unitImage!!.width / 2 + 20, + height / 2 - unitImage!!.height / 2 + 20) // top + } + + updatePopulationImage() + if (improvementImage != null) improvementImage!!.setColor(1f, 1f, 1f, 0.5f) + if (resourceImage != null) resourceImage!!.setColor(1f, 1f, 1f, 0.5f) + updateYieldGroup() + } + + private fun updateYieldGroup() { + yieldGroup.setStats(tileInfo.getTileStats(city, city.civInfo.gameInfo.getPlayerCivilization())) + yieldGroup.setOrigin(Align.center) + yieldGroup.setScale(0.7f) + yieldGroup.toFront() + yieldGroup.setPosition(width / 2 - yieldGroup.width / 2, height * 0.25f - yieldGroup.height / 2) + } + + private fun updatePopulationImage() { if (populationImage != null) { populationImage!!.setSize(30f, 30f) populationImage!!.setPosition(width / 2 - populationImage!!.width / 2, @@ -33,17 +54,6 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup( else populationImage!!.color = Color.GRAY populationImage!!.toFront() } - - - if (improvementImage != null) improvementImage!!.setColor(1f, 1f, 1f, 0.5f) - if (resourceImage != null) resourceImage!!.setColor(1f, 1f, 1f, 0.5f) - - yieldGroup.setStats(tileInfo.getTileStats(city, city.civInfo.gameInfo.getPlayerCivilization())) - yieldGroup.setOrigin(Align.center) - yieldGroup.setScale(0.7f) - yieldGroup.toFront() - yieldGroup.setPosition(width / 2 - yieldGroup.width / 2, height * 0.25f - yieldGroup.height / 2) - } diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index 206a0779..3b64a624 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -20,6 +20,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { var populationImage: Image? = null private var roadImages = HashMap() private var borderImages = ArrayList() + protected var unitImage: Group? = null init { @@ -177,4 +178,47 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { addActor(resourceImage!!) } } + + + protected fun updateUnitImage(isViewable: Boolean) { + if (unitImage != null) { // The unit can change within one update - for instance, when attacking, the attacker replaces the defender! + unitImage!!.remove() + unitImage = null + } + + if (tileInfo.unit != null && isViewable) { // Tile is visible + val unit = tileInfo.unit!! + unitImage = getUnitImage(unit.name, unit.civInfo.getCivilization().getColor()) + addActor(unitImage!!) + unitImage!!.setSize(20f, 20f) + } + + + if (unitImage != null) { + if (!tileInfo.hasIdleUnit()) + unitImage!!.color = Color(1f, 1f, 1f, 0.5f) + else + unitImage!!.color = Color.WHITE + } + } + + + private fun getUnitImage(unitType:String, color:Color): Group { + val unitBaseImage = ImageGetter.getImage("UnitIcons/$unitType.png") + .apply { setSize(15f,15f) } + val background = ImageGetter.getImage("UnitIcons/Circle.png").apply { + this.color = color + setSize(20f,20f) + } + val group = Group().apply { + setSize(background.width,background.height) + addActor(background) + } + unitBaseImage.setPosition(group.width/2-unitBaseImage.width/2, + group.height/2-unitBaseImage.height/2) + group.addActor(unitBaseImage) + return group + } + + } \ No newline at end of file diff --git a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index d7acda15..99792e5b 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -1,7 +1,6 @@ package com.unciv.ui.tilegroups import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align @@ -16,7 +15,6 @@ import com.unciv.ui.utils.ImageGetter class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { var cityButton: Table? = null - private var unitImage: Group? = null private var circleImage = ImageGetter.getImage("UnitIcons/Circle.png") // for blue and red circles on the tile init{ @@ -58,30 +56,10 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { updateCityButton(city) updateUnitImage(isViewable) - } - - private fun updateUnitImage(isViewable: Boolean) { - if (unitImage != null) { // The unit can change within one update - for instance, when attacking, the attacker replaces the defender! - unitImage!!.remove() - unitImage = null - } - - if (tileInfo.unit != null && isViewable) { // Tile is visible - val unit = tileInfo.unit!! - unitImage = getUnitImage(unit.name, unit.civInfo.getCivilization().getColor()) - addActor(unitImage!!) - unitImage!!.setSize(20f, 20f) + if(unitImage!=null) { unitImage!!.setPosition(width / 2 - unitImage!!.width / 2, height / 2 - unitImage!!.height / 2 + 20) // top } - - - if (unitImage != null) { - if (!tileInfo.hasIdleUnit()) - unitImage!!.color = Color(1f, 1f, 1f, 0.5f) - else - unitImage!!.color = Color.WHITE - } } private fun updateCityButton(city: CityInfo?) { @@ -120,20 +98,4 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { } - private fun getUnitImage(unitType:String, color:Color): Group { - val unitBaseImage = ImageGetter.getImage("UnitIcons/$unitType.png") - .apply { setSize(15f,15f) } - val background = ImageGetter.getImage("UnitIcons/Circle.png").apply { - this.color = color - setSize(20f,20f) - } - val group = Group().apply { - setSize(background.width,background.height) - addActor(background) - } - unitBaseImage.setPosition(group.width/2-unitBaseImage.width/2, - group.height/2-unitBaseImage.height/2) - group.addActor(unitBaseImage) - return group - } }