Can now see the units from within the city screen

This commit is contained in:
Yair Morgenstern 2018-05-06 09:30:20 +03:00
parent fc7b6529f0
commit 1a6e4d30f8
4 changed files with 68 additions and 52 deletions

View file

@ -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 {

View file

@ -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)
}

View file

@ -20,6 +20,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
var populationImage: Image? = null
private var roadImages = HashMap<String, Image>()
private var borderImages = ArrayList<Image>()
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
}
}

View file

@ -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
}
}