Now shows which tile the city will next expand to

This commit is contained in:
Yair Morgenstern 2018-05-06 11:08:00 +03:00
parent 75f4301004
commit fd5aaaeee1
5 changed files with 43 additions and 30 deletions

View file

@ -1,6 +1,7 @@
package com.unciv.logic.city
import com.unciv.logic.Automation
import com.unciv.logic.map.TileInfo
class CityExpansionManager {
@ -29,13 +30,18 @@ class CityExpansionManager {
private fun addNewTileWithCulture() {
cultureStored -= getCultureToNextTile()
for (i in 2..3) {
val chosenTile = getNewTile()
cityInfo.tiles.add(chosenTile!!.position)
}
fun getNewTile(): TileInfo? {
for (i in 2..5) {
val tiles = cityInfo.getCenterTile().getTilesInDistance(i).filter { it.getOwner() == null }
if (tiles.isEmpty()) continue
val chosenTile = tiles.maxBy { Automation().rankTile(it,cityInfo.civInfo) }
cityInfo.tiles.add(chosenTile!!.position)
return
return chosenTile
}
return null
}
fun nextTurn(culture: Float) {

View file

@ -95,9 +95,15 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
private fun updateTileGroups() {
val nextTile = city.expansion.getNewTile()
for (HG in tileGroups) {
HG.update()
if(HG.tileInfo == nextTile){
HG.showCircle(Color.PURPLE)
HG.setColor(0f,0f,0f,0.7f)
}
}
}
private fun updateCityPickerTable() {

View file

@ -11,29 +11,42 @@ import com.unciv.ui.utils.ImageGetter
open class TileGroup(var tileInfo: TileInfo) : Group() {
protected var hexagon: Image
protected val hexagon = ImageGetter.getImage("TerrainIcons/Hexagon.png")
protected var terrainFeatureImage:Image?=null
protected var resourceImage: Image? = null
protected var improvementImage: Image? =null
private var improvementType: String? = null
var populationImage: Image? = null
private var roadImages = HashMap<String, Image>()
private var borderImages = ArrayList<Image>()
private val roadImages = HashMap<String, Image>()
private val borderImages = ArrayList<Image>()
protected var unitImage: Group? = null
private val circleImage = ImageGetter.getImage("UnitIcons/Circle.png") // for blue and red circles on the tile
init {
val groupSize = 50f
this.setSize(groupSize,groupSize)
hexagon = ImageGetter.getImage("TerrainIcons/Hexagon.png")
addHexagon(groupSize)
addCircleImage()
}
private fun addCircleImage() {
circleImage.width = 50f
circleImage.height = 50f
circleImage.setPosition(width / 2 - circleImage.width / 2,
height / 2 - circleImage.height / 2)
addActor(circleImage)
circleImage.isVisible = false
}
private fun addHexagon(groupSize: Float) {
val imageScale = groupSize * 1.5f / hexagon.width
hexagon.setScale(imageScale)
hexagon.setOrigin(Align.center)
hexagon.setPosition((width - hexagon.width) / 2,
(height - hexagon.height) / 2)
this.addActor(hexagon)
hexagon.zIndex = 0
addActor(hexagon)
}
fun addPopulationIcon() {
@ -58,6 +71,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
return
}
hideCircle()
updateTerrainFeatureImage()
updateTileColor(isViewable)
updateResourceImage()
@ -69,7 +83,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
private fun updateBorderImages() {
for (border in borderImages) border.remove() //clear
borderImages = arrayListOf()
borderImages.clear()
if (tileInfo.getOwner() != null) {
for (neighbor in tileInfo.neighbors.filter { it.getOwner() != tileInfo.getOwner() }) {
@ -221,4 +235,11 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
}
fun showCircle(color:Color){
circleImage.isVisible = true
color.a = 0.3f
circleImage.color = color
}
fun hideCircle(){circleImage.isVisible=false}
}

View file

@ -1,6 +1,5 @@
package com.unciv.ui.tilegroups
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
@ -15,16 +14,6 @@ import com.unciv.ui.utils.ImageGetter
class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
var cityButton: Table? = null
private var circleImage = ImageGetter.getImage("UnitIcons/Circle.png") // for blue and red circles on the tile
init{
circleImage.width = 50f
circleImage.height = 50f
circleImage.setPosition(width/2-circleImage.width/2,
height/2-circleImage.height/2)
addActor(circleImage)
circleImage.isVisible = false
}
fun addWhiteCircleAroundUnit(){
val whiteCircle = ImageGetter.getImage("UnitIcons/Circle.png")
@ -35,14 +24,6 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
whiteCircle.toBack()
}
fun showCircle(color:Color){
circleImage.isVisible = true
color.a = 0.3f
circleImage.color = color
}
fun hideCircle(){circleImage.isVisible=false}
override fun update(isViewable: Boolean) {
super.update(isViewable)

View file

@ -85,7 +85,6 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
internal fun updateTiles() {
for (WG in tileGroups.values){
WG.hideCircle()
WG.update(false)
}