From d4ef5cb637050e55be0ee743e7868590b235fb10 Mon Sep 17 00:00:00 2001 From: Jack Rainy Date: Sat, 18 Apr 2020 21:20:50 +0300 Subject: [PATCH] Map Editor UI improvements (#2462) * Better icons for "clear" tools * Map editor layout is reworked --- .../ui/mapeditor/TileEditorOptionsTable.kt | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt index df683a689d..3824165170 100644 --- a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt +++ b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt @@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.ui.Slider import com.badlogic.gdx.scenes.scene2d.ui.Table -import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.map.RoadStatus @@ -22,7 +21,7 @@ import com.unciv.ui.utils.* class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(CameraStageBaseScreen.skin){ - val tileSetLocation = "TileSets/"+ UncivGame.Current.settings.tileSet +"/" + private val tileSetLocation = "TileSets/"+ UncivGame.Current.settings.tileSet +"/" var clearTerrainFeature=false var selectedTerrain : Terrain?=null @@ -37,12 +36,14 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera var toggleBottomRiver=false var toggleBottomLeftRiver=false - val editorPickTable = Table() + private val editorPickTable = Table() var brushSize = 1 private var currentHex: Actor = Group() - val ruleset = mapEditorScreen.ruleset + private val ruleset = mapEditorScreen.ruleset + + private val scrollPanelHeight = mapEditorScreen.stage.height*0.7f - 100f // -100 reserved for currentHex table init{ height = mapEditorScreen.stage.height @@ -104,7 +105,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera } improvementsTable.add(improvementImage).row() } - editorPickTable.add(ScrollPane(improvementsTable)).height(mapEditorScreen.stage.height*0.7f) + editorPickTable.add(ScrollPane(improvementsTable)).height(scrollPanelHeight) val nationsTable = Table() for(nation in ruleset.nations.values){ @@ -118,20 +119,26 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera nationsTable.add(nationImage).row() } - editorPickTable.add(ScrollPane(nationsTable)).height(mapEditorScreen.stage.height*0.7f) + editorPickTable.add(ScrollPane(nationsTable)).height(scrollPanelHeight) } + private fun getRedCross(size: Float, alpha: Float): Actor { + val redCross = ImageGetter.getImage("OtherIcons/Close") + redCross.setSize( size, size) + redCross.color = Color.RED.cpy().apply { a = alpha } + return redCross + } - fun setTerrainsAndResources(){ + private fun setTerrainsAndResources(){ val baseTerrainTable = Table().apply { defaults().pad(20f) } val terrainFeaturesTable = Table().apply { defaults().pad(20f) } - terrainFeaturesTable.add(getHex(Color.WHITE).apply { + terrainFeaturesTable.add(getHex(Color.WHITE, getRedCross(50f, 0.6f)).apply { onClick { clearSelection() clearTerrainFeature = true - setCurrentHex(getHex(Color.WHITE), "Clear terrain features") + setCurrentHex(getHex(Color.WHITE, getRedCross(40f, 0.6f)), "Clear terrain features") } }).row() @@ -145,14 +152,14 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera background = ImageGetter.getBackground(Color.GRAY.cpy().apply { a = 0.7f }) val terrainsAndResourcesTable = Table() - terrainsAndResourcesTable.add(ScrollPane(baseTerrainTable).apply { setScrollingDisabled(true,false) }).height(mapEditorScreen.stage.height*0.7f) + terrainsAndResourcesTable.add(ScrollPane(baseTerrainTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight) - terrainsAndResourcesTable.add(ScrollPane(terrainFeaturesTable).apply { setScrollingDisabled(true,false) }).height(mapEditorScreen.stage.height*0.7f) + terrainsAndResourcesTable.add(ScrollPane(terrainFeaturesTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight) val resourcesTable = Table() for(resource in resources) resourcesTable.add(resource).row() resourcesTable.pack() - terrainsAndResourcesTable.add(ScrollPane(resourcesTable).apply { setScrollingDisabled(true,false) }).height(mapEditorScreen.stage.height*0.7f).row() + terrainsAndResourcesTable.add(ScrollPane(resourcesTable).apply { setScrollingDisabled(true,false) }).height(scrollPanelHeight).row() terrainsAndResourcesTable.pack() @@ -160,13 +167,21 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera editorPickTable.add(terrainsAndResourcesTable) } + private fun getCrossedResource() : Actor { + val redCross = getRedCross(45f, 0.5f) + val group = IconCircleGroup(40f, redCross, false) + group.circle.color = ImageGetter.foodCircleColor + return group + } + + private fun getResourceActors(): ArrayList { val resources = ArrayList() - resources.add(getHex(Color.WHITE).apply { + resources.add(getHex(Color.WHITE, getCrossedResource()).apply { onClick { clearSelection() clearResource = true - setCurrentHex(getHex(Color.WHITE), "Clear resource") + setCurrentHex(getHex(Color.WHITE, getCrossedResource()), "Clear resource") } }) @@ -278,7 +293,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera } - fun getHex(color: Color, image: Actor?=null): Group { + private fun getHex(color: Color, image: Actor?=null): Group { val hex = ImageGetter.getImage(tileSetLocation + "Hexagon") hex.color = color hex.width*=0.3f @@ -297,7 +312,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera } - fun clearSelection(){ + private fun clearSelection(){ clearTerrainFeature=false selectedTerrain=null clearResource=false @@ -392,24 +407,25 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera } - fun setCurrentHex(tileInfo: TileInfo, text:String){ + private fun setCurrentHex(tileInfo: TileInfo, text:String){ val tileGroup = TileGroup(tileInfo,TileSetStrings()) .apply { showEntireMap=true forMapEditorIcon=true update() } + tileGroup.baseLayerGroup.moveBy(-10f, 10f) setCurrentHex(tileGroup,text) } - fun setCurrentHex(actor:Actor, text:String){ + private fun setCurrentHex(actor:Actor, text:String){ currentHex.remove() val currentHexTable = Table() - currentHexTable.add(text.toLabel()).padRight(20f) - currentHexTable.add(actor).pad(10f) + currentHexTable.add(text.toLabel()).padRight(30f) + currentHexTable.add(actor) currentHexTable.pack() currentHex=currentHexTable - currentHex.setPosition(stage.width-currentHex.width-10, 10f) + currentHex.setPosition(stage.width - currentHex.width-10, 10f) stage.addActor(currentHex) }