Changed terrain visualization - is now plain color awith overlays for terrain feature, looks really good!

This commit is contained in:
Yair Morgenstern 2018-03-16 13:09:43 +02:00
parent eadf7b01db
commit 66f900e4ec
9 changed files with 67 additions and 48 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -4,25 +4,29 @@
name:"Grassland", name:"Grassland",
type:"BaseTerrain", type:"BaseTerrain",
food:2, food:2,
movementCost:1 movementCost:1,
RGB: [109,139,53]
}, },
{ {
name:"Plains", name:"Plains",
type:"BaseTerrain", type:"BaseTerrain",
food:1, food:1,
production:1, production:1,
movementCost:1 movementCost:1,
RGB: [200,208,161]
}, },
{ {
name:"Tundra", name:"Tundra",
type:"BaseTerrain", type:"BaseTerrain",
food:1, food:1,
movementCost:1 movementCost:1,
RGB: [125,122,113]
}, },
{ {
name:"Desert", name:"Desert",
type:"BaseTerrain", type:"BaseTerrain",
movementCost:1 movementCost:1,
RGB: [188,189,145]
}, },
{ {
name:"Lakes", name:"Lakes",
@ -35,7 +39,8 @@
name:"Hill", name:"Hill",
type:"BaseTerrain", type:"BaseTerrain",
production:2, production:2,
movementCost:2 movementCost:2,
RGB: [74,81,40]
}, },
// Terrain features // Terrain features

View File

@ -5,27 +5,32 @@ import com.unciv.models.stats.NamedStats
class Terrain : NamedStats(), ICivilopedia { class Terrain : NamedStats(), ICivilopedia {
override val description: String override val description: String
get() = this.clone().toString() 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 * 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 * If true, nothing can be built here - not even resource improvements
*/ */
@JvmField var unbuildable = false var unbuildable = false
/*** /***
* For terrain features * 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
} }

View File

@ -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.Container
import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.TextButton 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.RoadStatus
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.HexMath import com.unciv.ui.utils.HexMath
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
open class TileGroup(var tileInfo: TileInfo) : Group() { 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 resourceImage: Image? = null
protected var unitImage: Image? = null protected var unitImage: Image? = null
protected var improvementImage: Image? =null protected var improvementImage: Image? =null
private var improvementType: String? = null private var improvementType: String? = null
var populationImage: Image? = null var populationImage: Image? = null
private var roadImages = HashMap<String, Image>() private var roadImages = HashMap<String, Image>()
protected var hexagon: Image? = null
protected var cityButton: Container<TextButton>? = null protected var cityButton: Container<TextButton>? = null
init { init {
val groupSize = 50f
terrainType = tileInfo.lastTerrain.name this.setSize(groupSize,groupSize)
val terrainFileName = "TerrainIcons/" + terrainType.replace(' ', '_') + "_(Civ5).png" hexagon = ImageGetter.getImage("TerrainIcons/Hexagon.png")
terrainImage = ImageGetter.getImage(terrainFileName) val imageScale = groupSize * 1.3f / hexagon.width
val groupSize = 50 hexagon.setScale(imageScale)
terrainImage.setSize(groupSize.toFloat(), groupSize.toFloat()) hexagon.setOrigin(Align.center)
this.setSize(groupSize.toFloat(), groupSize.toFloat()) hexagon.setPosition((width - hexagon.width) / 2,
this.addActor(terrainImage) (height - hexagon.height) / 2)
this.addActor(hexagon)
hexagon.zIndex = 0
} }
fun addPopulationIcon() { fun addPopulationIcon() {
populationImage = ImageGetter.getImage("StatIcons/populationGreen.png") populationImage = ImageGetter.getImage("StatIcons/populationGreen.png")
populationImage!!.run { populationImage!!.run {
setSize(20f, 20f) 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 } // top left
addActor(populationImage!!) addActor(populationImage)
} }
protected fun removePopulationIcon() { protected fun removePopulationIcon() {
@ -51,30 +56,45 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
open fun update() { open fun update() {
if (!tileInfo.explored) { if (!tileInfo.explored) {
terrainImage.color = Color.BLACK hexagon.color = Color.BLACK
return return
} }
terrainImage.color = Color.WHITE if(terrainFeatureImage==null && tileInfo.terrainFeature!=null){
terrainFeatureImage = ImageGetter.getImage("TerrainIcons/${tileInfo.terrainFeature}.png")
if (terrainType != tileInfo.lastTerrain.name) { addActor(terrainFeatureImage)
terrainType = tileInfo.lastTerrain.name terrainFeatureImage!!.run {
val terrainFileName = "TerrainIcons/" + terrainType.replace(' ', '_') + "_(Civ5).png" setSize(30f,30f)
terrainImage.drawable = ImageGetter.getDrawable(terrainFileName) // In case we e.g. removed a jungle setColor(1f,1f,1f,0.5f)
setPosition(this@TileGroup.width /2-width/2,
this@TileGroup.height/2-height/2)
} }
}
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! if (tileInfo.hasViewableResource(tileInfo.tileMap!!.gameInfo!!.getPlayerCivilization()) && resourceImage == null) { // Need to add the resource image!
val fileName = "ResourceIcons/" + tileInfo.resource + "_(Civ5).png" val fileName = "ResourceIcons/" + tileInfo.resource + "_(Civ5).png"
resourceImage = ImageGetter.getImage(fileName) resourceImage = ImageGetter.getImage(fileName)
resourceImage!!.setSize(20f, 20f) 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!!) addActor(resourceImage!!)
} }
if (tileInfo.unit != null && unitImage == null) { if (tileInfo.unit != null && unitImage == null) {
unitImage = ImageGetter.getImage("UnitIcons/" + tileInfo.unit!!.name!!.replace(" ", "_") + "_(Civ5).png") unitImage = ImageGetter.getImage("UnitIcons/" + tileInfo.unit!!.name!!.replace(" ", "_") + "_(Civ5).png")
addActor(unitImage!!) 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) { if (tileInfo.unit == null && unitImage != null) {
@ -95,9 +115,10 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
addActor(improvementImage) addActor(improvementImage)
improvementImage!!.run { improvementImage!!.run {
setSize(20f, 20f) setSize(20f, 20f)
moveBy(terrainImage.width - width,
terrainImage.height - height) setPosition(this@TileGroup.width/2 - width/2+20f,
} // top right this@TileGroup.height/2 - height/2) // right
}
improvementType = tileInfo.improvement 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. // 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.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.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() image.rotation = (90 + 180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat()
addActor(image) addActor(image)

View File

@ -6,7 +6,6 @@ import com.unciv.logic.map.TileInfo
import com.unciv.ui.cityscreen.CityScreen import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.worldscreen.WorldScreen 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.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 val city = tileInfo.city
if (tileInfo.isCityCenter) { if (tileInfo.isCityCenter) {
val buttonScale = 0.7f val buttonScale = 0.7f