Added "current edit" hex to bottom-right of map editor screen

This commit is contained in:
Yair Morgenstern 2019-02-08 00:34:46 +02:00
parent d42416974c
commit d2a48fae38

View File

@ -2,6 +2,7 @@ package com.unciv.ui
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
import com.unciv.GameParameters import com.unciv.GameParameters
@ -28,6 +29,7 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){
var selectedResource:TileResource?=null var selectedResource:TileResource?=null
var tileMap = TileMap(GameParameters()) var tileMap = TileMap(GameParameters())
var mapName = "My first map" var mapName = "My first map"
var currentHex=Group()
fun clearSelection(){ fun clearSelection(){
clearTerrainFeature=false clearTerrainFeature=false
@ -36,10 +38,15 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){
selectedResource=null selectedResource=null
} }
fun getHex(color: Color, image: Actor?=null): Table { fun getHex(color: Color, image: Actor?=null): Group {
val hex = ImageGetter.getImage("TerrainIcons/Hexagon.png") val hex = ImageGetter.getImage("TerrainIcons/Hexagon.png")
hex.color = color hex.color = color
val group = Table().apply { add(hex).size(hex.width*0.3f,hex.height*0.3f); pack() } hex.width*=0.3f
hex.height*=0.3f
val group = Group()
group.setSize(hex.width,hex.height)
hex.center(group)
group.addActor(hex)
if(image!=null) { if(image!=null) {
image.setSize(40f, 40f) image.setSize(40f, 40f)
@ -107,30 +114,49 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){
return scrollPane return scrollPane
} }
fun setCurrentHex(color: Color, image: Actor?=null){
currentHex.remove()
currentHex=getHex(color,image)
currentHex.setPosition(stage.width-currentHex.width-10, 10f)
stage.addActor(currentHex)
}
private fun getTileEditorOptions(): Table { private fun getTileEditorOptions(): Table {
val baseTerrainHolder = Table() val baseTerrainHolder = Table()
val terrainFeatureHolder = Table() val terrainFeatureHolder = Table()
terrainFeatureHolder.add(getHex(Color.WHITE).apply { onClick { clearSelection(); clearTerrainFeature = true } }) terrainFeatureHolder.add(getHex(Color.WHITE).apply {
onClick {
clearSelection()
clearTerrainFeature = true
setCurrentHex(Color.WHITE)
}
})
for (terrain in GameBasics.Terrains.values) { for (terrain in GameBasics.Terrains.values) {
var icon: Image? = null var iconPath: String? = null
var color = Color.WHITE var color = Color.WHITE
if (terrain.type == TerrainType.TerrainFeature) if (terrain.type == TerrainType.TerrainFeature)
icon = ImageGetter.getImage("TerrainIcons/${terrain.name}.png") iconPath = "TerrainIcons/${terrain.name}.png"
else { else {
color = terrain.getColor() color = terrain.getColor()
val imagePath = "TerrainIcons/" + terrain.name val imagePath = "TerrainIcons/" + terrain.name
if (ImageGetter.imageExists(imagePath)) { if (ImageGetter.imageExists(imagePath)) {
icon = ImageGetter.getImage(imagePath) iconPath = imagePath
} }
} }
val group = getHex(color, icon) val group = getHex(color, if(iconPath==null) null else ImageGetter.getImage(iconPath))
group.onClick { clearSelection(); selectedTerrain = terrain } group.onClick {
clearSelection()
selectedTerrain = terrain
setCurrentHex(color, if(iconPath==null) null else ImageGetter.getImage(iconPath))
}
if (terrain.type == TerrainType.TerrainFeature) terrainFeatureHolder.add(group) if (terrain.type == TerrainType.TerrainFeature)
terrainFeatureHolder.add(group)
else baseTerrainHolder.add(group) else baseTerrainHolder.add(group)
} }
@ -142,7 +168,11 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){
for (resource in GameBasics.TileResources.values) { for (resource in GameBasics.TileResources.values) {
val resourceHex = getHex(Color.WHITE, ImageGetter.getResourceImage(resource.name, 40f)) val resourceHex = getHex(Color.WHITE, ImageGetter.getResourceImage(resource.name, 40f))
resourceHex.onClick { clearSelection(); selectedResource = resource } resourceHex.onClick {
clearSelection()
selectedResource = resource
setCurrentHex(Color.WHITE, ImageGetter.getResourceImage(resource.name, 40f))
}
resourcesHolder.add(resourceHex) resourcesHolder.add(resourceHex)
} }