mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-05 07:49:17 +07:00
City labels are colored according to civ, and scale down when zooming in
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 35
|
versionCode 36
|
||||||
versionName "1.4.2"
|
versionName "1.4.3"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -2,7 +2,9 @@ package com.unciv.ui.tilegroups
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.Group
|
import com.badlogic.gdx.scenes.scene2d.Group
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.ui.UnCivGame
|
import com.unciv.ui.UnCivGame
|
||||||
import com.unciv.ui.cityscreen.CityScreen
|
import com.unciv.ui.cityscreen.CityScreen
|
||||||
@ -12,7 +14,7 @@ import com.unciv.ui.utils.ImageGetter
|
|||||||
|
|
||||||
|
|
||||||
class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
||||||
private var cityButton: TextButton? = null
|
var cityButton: Table? = null
|
||||||
private var unitImage: Group? = null
|
private var unitImage: Group? = null
|
||||||
|
|
||||||
fun setIsViewable(isViewable: Boolean) {
|
fun setIsViewable(isViewable: Boolean) {
|
||||||
@ -29,30 +31,41 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||||||
override fun update() {
|
override fun update() {
|
||||||
super.update()
|
super.update()
|
||||||
|
|
||||||
if (tileInfo.workingCity != null && populationImage == null) addPopulationIcon()
|
if (populationImage != null) removePopulationIcon()
|
||||||
if (tileInfo.workingCity == null && populationImage != null) removePopulationIcon()
|
if (tileInfo.workingCity != null && !tileInfo.isCityCenter && populationImage == null) addPopulationIcon()
|
||||||
|
|
||||||
|
|
||||||
val city = tileInfo.city
|
val city = tileInfo.city
|
||||||
if (tileInfo.isCityCenter) {
|
if (city != null && tileInfo.isCityCenter) {
|
||||||
val buttonScale = 0.7f
|
|
||||||
if (cityButton == null) {
|
if (cityButton == null) {
|
||||||
cityButton = TextButton("", CameraStageBaseScreen.skin)
|
cityButton = Table()
|
||||||
cityButton!!.label.setFontScale(buttonScale)
|
cityButton!!.background = ImageGetter.getDrawable("skin/civTableBackground.png")
|
||||||
|
cityButton!!.isTransform=true
|
||||||
cityButton!!.addClickListener { UnCivGame.Current.screen = CityScreen(city!!)}
|
|
||||||
|
|
||||||
addActor(cityButton)
|
addActor(cityButton)
|
||||||
zIndex = parent.children.size // so this tile is rendered over neighboring tiles
|
zIndex = parent.children.size // so this tile is rendered over neighboring tiles
|
||||||
}
|
}
|
||||||
|
|
||||||
val cityButtonText = city!!.name + " (" + city.population.population + ")"
|
val cityButtonText = city.name + " (" + city.population.population + ")"
|
||||||
cityButton!!.setText(cityButtonText)
|
val label = Label(cityButtonText, CameraStageBaseScreen.skin)
|
||||||
cityButton!!.setSize(cityButton!!.prefWidth, cityButton!!.prefHeight)
|
val labelStyle = Label.LabelStyle(label.style)
|
||||||
|
labelStyle.fontColor= city.civInfo.getCivilization().getColor()
|
||||||
|
label.style=labelStyle
|
||||||
|
label.addClickListener {
|
||||||
|
UnCivGame.Current.screen = CityScreen(city)
|
||||||
|
}
|
||||||
|
|
||||||
|
cityButton!!.run {
|
||||||
|
clear()
|
||||||
|
add(label).pad(5f)
|
||||||
|
pack()
|
||||||
|
setOrigin(Align.center)
|
||||||
|
toFront()
|
||||||
|
}
|
||||||
|
|
||||||
|
cityButton!!.setPosition(width/2 - cityButton!!.width / 2,
|
||||||
|
height/2 - cityButton!!.height/2)
|
||||||
|
|
||||||
cityButton!!.setPosition((width - cityButton!!.width) / 2,
|
|
||||||
height * 0.9f)
|
|
||||||
cityButton!!.zIndex = cityButton!!.parent.children.size // so city button is rendered over everything else in this tile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,6 +74,8 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||||||
val scale: Float = Math.sqrt((distance / initialDistance).toDouble()).toFloat() * lastScale
|
val scale: Float = Math.sqrt((distance / initialDistance).toDouble()).toFloat() * lastScale
|
||||||
if (scale < 1) return
|
if (scale < 1) return
|
||||||
setScale(scale)
|
setScale(scale)
|
||||||
|
for(tilegroup in tileGroups.values.filter { it.cityButton!=null })
|
||||||
|
tilegroup.cityButton!!.setScale(1/scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user