mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +07:00
Changed terrain visualization - is now plain color awith overlays for terrain feature, looks really good!
This commit is contained in:
@ -5,27 +5,32 @@ import com.unciv.models.stats.NamedStats
|
||||
class Terrain : NamedStats(), ICivilopedia {
|
||||
override val description: String
|
||||
get() = this.clone().toString()
|
||||
@JvmField var type: TerrainType? = null // BaseTerrain or TerrainFeature
|
||||
lateinit var type: TerrainType
|
||||
|
||||
@JvmField var overrideStats = false
|
||||
var overrideStats = false
|
||||
|
||||
/***
|
||||
* If true, other terrain layers can come over this one. For mountains, lakes etc. this is false
|
||||
*/
|
||||
|
||||
@JvmField var canHaveOverlay = true
|
||||
var canHaveOverlay = true
|
||||
|
||||
/***
|
||||
* If true, nothing can be built here - not even resource improvements
|
||||
*/
|
||||
@JvmField var unbuildable = false
|
||||
var unbuildable = false
|
||||
|
||||
/***
|
||||
* For terrain features
|
||||
*/
|
||||
@JvmField var occursOn: Collection<String>? = null
|
||||
var occursOn: Collection<String>? = null
|
||||
|
||||
@JvmField var movementCost = 1
|
||||
/**
|
||||
* RGB color of base terrain
|
||||
*/
|
||||
var RGB: List<Int>? = null
|
||||
|
||||
var movementCost = 1
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,42 +5,47 @@ 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
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.ui.utils.HexMath
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
|
||||
open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
protected var terrainImage: Image
|
||||
private var terrainType: String
|
||||
|
||||
protected var hexagon: Image
|
||||
protected var terrainFeatureImage:Image?=null
|
||||
|
||||
protected var resourceImage: Image? = null
|
||||
protected var unitImage: Image? = null
|
||||
protected var improvementImage: Image? =null
|
||||
private var improvementType: String? = null
|
||||
var populationImage: Image? = null
|
||||
private var roadImages = HashMap<String, Image>()
|
||||
protected var hexagon: Image? = null
|
||||
|
||||
protected var cityButton: Container<TextButton>? = null
|
||||
|
||||
init {
|
||||
|
||||
terrainType = tileInfo.lastTerrain.name
|
||||
val terrainFileName = "TerrainIcons/" + terrainType.replace(' ', '_') + "_(Civ5).png"
|
||||
terrainImage = ImageGetter.getImage(terrainFileName)
|
||||
val groupSize = 50
|
||||
terrainImage.setSize(groupSize.toFloat(), groupSize.toFloat())
|
||||
this.setSize(groupSize.toFloat(), groupSize.toFloat())
|
||||
this.addActor(terrainImage)
|
||||
val groupSize = 50f
|
||||
this.setSize(groupSize,groupSize)
|
||||
hexagon = ImageGetter.getImage("TerrainIcons/Hexagon.png")
|
||||
val imageScale = groupSize * 1.3f / 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
|
||||
}
|
||||
|
||||
fun addPopulationIcon() {
|
||||
populationImage = ImageGetter.getImage("StatIcons/populationGreen.png")
|
||||
populationImage!!.run {
|
||||
setSize(20f, 20f)
|
||||
moveBy(0f, terrainImage.height - populationImage!!.height)
|
||||
setPosition(this@TileGroup.width/2 - width/2,
|
||||
this@TileGroup.height/2 - height/2 - 15)
|
||||
} // top left
|
||||
addActor(populationImage!!)
|
||||
addActor(populationImage)
|
||||
}
|
||||
|
||||
protected fun removePopulationIcon() {
|
||||
@ -51,30 +56,45 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
|
||||
open fun update() {
|
||||
if (!tileInfo.explored) {
|
||||
terrainImage.color = Color.BLACK
|
||||
hexagon.color = Color.BLACK
|
||||
return
|
||||
}
|
||||
|
||||
terrainImage.color = Color.WHITE
|
||||
if(terrainFeatureImage==null && tileInfo.terrainFeature!=null){
|
||||
terrainFeatureImage = ImageGetter.getImage("TerrainIcons/${tileInfo.terrainFeature}.png")
|
||||
addActor(terrainFeatureImage)
|
||||
terrainFeatureImage!!.run {
|
||||
setSize(30f,30f)
|
||||
setColor(1f,1f,1f,0.5f)
|
||||
setPosition(this@TileGroup.width /2-width/2,
|
||||
this@TileGroup.height/2-height/2)
|
||||
}
|
||||
|
||||
if (terrainType != tileInfo.lastTerrain.name) {
|
||||
terrainType = tileInfo.lastTerrain.name
|
||||
val terrainFileName = "TerrainIcons/" + terrainType.replace(' ', '_') + "_(Civ5).png"
|
||||
terrainImage.drawable = ImageGetter.getDrawable(terrainFileName) // In case we e.g. removed a jungle
|
||||
}
|
||||
|
||||
if(terrainFeatureImage!=null && tileInfo.terrainFeature==null){
|
||||
terrainFeatureImage!!.remove()
|
||||
terrainFeatureImage=null
|
||||
}
|
||||
|
||||
val RGB= tileInfo.getBaseTerrain().RGB!!
|
||||
hexagon.color = Color(RGB[0]/255f,RGB[1]/255f,RGB[2]/255f,1f)
|
||||
|
||||
if (tileInfo.hasViewableResource(tileInfo.tileMap!!.gameInfo!!.getPlayerCivilization()) && resourceImage == null) { // Need to add the resource image!
|
||||
val fileName = "ResourceIcons/" + tileInfo.resource + "_(Civ5).png"
|
||||
resourceImage = ImageGetter.getImage(fileName)
|
||||
resourceImage!!.setSize(20f, 20f)
|
||||
resourceImage!!.moveBy(terrainImage.width - resourceImage!!.width, 0f) // bottom right
|
||||
resourceImage!!.setPosition(width/2 - resourceImage!!.width/2-20f,
|
||||
height/2 - resourceImage!!.height/2) // left
|
||||
addActor(resourceImage!!)
|
||||
}
|
||||
|
||||
if (tileInfo.unit != null && unitImage == null) {
|
||||
unitImage = ImageGetter.getImage("UnitIcons/" + tileInfo.unit!!.name!!.replace(" ", "_") + "_(Civ5).png")
|
||||
addActor(unitImage!!)
|
||||
unitImage!!.setSize(20f, 20f) // not moved - is at bottom left
|
||||
unitImage!!.setSize(20f, 20f)
|
||||
unitImage!!.setPosition(width/2 - unitImage!!.width/2,
|
||||
height/2 - unitImage!!.height/2 +15) // top
|
||||
}
|
||||
|
||||
if (tileInfo.unit == null && unitImage != null) {
|
||||
@ -95,9 +115,10 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
addActor(improvementImage)
|
||||
improvementImage!!.run {
|
||||
setSize(20f, 20f)
|
||||
moveBy(terrainImage.width - width,
|
||||
terrainImage.height - height)
|
||||
} // top right
|
||||
|
||||
setPosition(this@TileGroup.width/2 - width/2+20f,
|
||||
this@TileGroup.height/2 - height/2) // right
|
||||
}
|
||||
improvementType = tileInfo.improvement
|
||||
}
|
||||
|
||||
@ -154,7 +175,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
// Here, we want to have the roads start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25.
|
||||
image.moveBy(-relativeWorldPosition.x * 0.8f * 25f, -relativeWorldPosition.y * 0.8f * 25f)
|
||||
|
||||
image.setColor(Color.RED)
|
||||
image.color = Color.RED
|
||||
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)
|
||||
|
@ -6,7 +6,6 @@ import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.ui.cityscreen.CityScreen
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
|
||||
|
||||
@ -29,17 +28,6 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
||||
if (tileInfo.workingCity == null && populationImage != null) removePopulationIcon()
|
||||
|
||||
|
||||
if (tileInfo.owner != null && hexagon == null) {
|
||||
hexagon = ImageGetter.getImage("TerrainIcons/Hexagon.png")
|
||||
val imageScale = terrainImage.width * 1.3f / hexagon!!.width
|
||||
hexagon!!.setScale(imageScale)
|
||||
hexagon!!.setPosition((width - hexagon!!.width * imageScale) / 2,
|
||||
(height - hexagon!!.height * imageScale) / 2)
|
||||
addActor(hexagon!!)
|
||||
hexagon!!.zIndex = 0
|
||||
}
|
||||
|
||||
|
||||
val city = tileInfo.city
|
||||
if (tileInfo.isCityCenter) {
|
||||
val buttonScale = 0.7f
|
||||
|
Reference in New Issue
Block a user