Old borders now disappear when borders expand

This commit is contained in:
Yair Morgenstern 2018-03-21 19:07:05 +02:00
parent e496148e21
commit c8c1ecc4da
3 changed files with 12 additions and 15 deletions

View file

@ -2,7 +2,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.Container
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Align
@ -22,8 +21,9 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
private var improvementType: String? = null
var populationImage: Image? = null
private var roadImages = HashMap<String, Image>()
private var borderImages = ArrayList<Image>()
protected var cityButton: Container<TextButton>? = null
public var cityButton: TextButton? = null
init {
val groupSize = 50f
@ -158,10 +158,11 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
}
}
// Borders
if(tileInfo.owner!=null){
for(border in borderImages) border.remove()
for (neighbor in tileInfo.neighbors.filter { it.owner!=tileInfo.owner }){
val image = ImageGetter.getImage(ImageGetter.WhiteDot)
// roadImages[neighbor.position.toString()] = image
val relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position)
val relativeWorldPosition = HexMath.Hex2WorldCoords(relativeHexPosition)
@ -179,6 +180,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
image.setOrigin(image.width/2, image.height/2) // This is so that the rotation is calculated from the middle of the road and not the edge
image.rotation = (90 + 180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat()
addActor(image)
borderImages.add(image)
}
}

View file

@ -1,6 +1,5 @@
package com.unciv.ui.tilegroups
import com.badlogic.gdx.scenes.scene2d.ui.Container
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.logic.map.TileInfo
import com.unciv.ui.cityscreen.CityScreen
@ -32,23 +31,19 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
if (tileInfo.isCityCenter) {
val buttonScale = 0.7f
if (cityButton == null) {
cityButton = Container()
cityButton!!.actor = TextButton("", CameraStageBaseScreen.skin)
cityButton!!.actor.label.setFontScale(buttonScale)
cityButton = TextButton("", CameraStageBaseScreen.skin)
cityButton!!.label.setFontScale(buttonScale)
val game = worldScreen.game
cityButton!!.actor.addClickListener { game.screen = CityScreen(city!!)
}
cityButton!!.addClickListener { game.screen = CityScreen(city!!)}
addActor(cityButton!!)
addActor(cityButton)
zIndex = parent.children.size // so this tile is rendered over neighboring tiles
}
val cityButtonText = city!!.name + " (" + city.population.population + ")"
val button = cityButton!!.actor
button.setText(cityButtonText)
button.setSize(button.prefWidth, button.prefHeight)
cityButton!!.setText(cityButtonText)
cityButton!!.setSize(cityButton!!.prefWidth, cityButton!!.prefHeight)
cityButton!!.setPosition((width - cityButton!!.width) / 2,
height * 0.9f)

View file

@ -72,7 +72,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
lastInitialDistance = initialDistance
lastScale = scaleX
}
val scale = Math.sqrt((distance / initialDistance).toDouble()).toFloat() * lastScale
val scale: Float = Math.sqrt((distance / initialDistance).toDouble()).toFloat() * lastScale
if (scale < 1) return
setScale(scale)
}