From 8038dd4c4f5b1fa5bb5c14c0c3169e1d946c21c6 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 29 Jan 2019 21:48:23 +0200 Subject: [PATCH] Separated "Group to hold visual map based on tilegroups" to a separate class, for reuse in CityScreen, the future map editor, and maybe also in the minimap --- android/build.gradle | 2 +- core/src/com/unciv/ui/NewGameScreen.kt | 1 + .../com/unciv/ui/worldscreen/TileGroupMap.kt | 37 +++++++++++++++++++ .../com/unciv/ui/worldscreen/TileMapHolder.kt | 33 +++-------------- 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 core/src/com/unciv/ui/worldscreen/TileGroupMap.kt diff --git a/android/build.gradle b/android/build.gradle index 2b198d939f..38ee34e8a6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,7 +21,7 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 28 - versionCode 197 + versionCode 198 versionName "2.12.5" } diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index 8f4315631c..24e241894e 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -183,6 +183,7 @@ class TranslatedSelectBox(values : Collection, default:String, skin: Ski val translation = value.tr() override fun toString()=translation } + init { val array = Array() values.forEach{array.add(TranslatedString(it))} diff --git a/core/src/com/unciv/ui/worldscreen/TileGroupMap.kt b/core/src/com/unciv/ui/worldscreen/TileGroupMap.kt new file mode 100644 index 0000000000..22d12a7766 --- /dev/null +++ b/core/src/com/unciv/ui/worldscreen/TileGroupMap.kt @@ -0,0 +1,37 @@ +package com.unciv.ui.worldscreen + +import com.badlogic.gdx.scenes.scene2d.Group +import com.unciv.logic.HexMath +import com.unciv.ui.tilegroups.TileGroup + +class TileGroupMap(tileGroups:Collection): Group(){ + init{ + val groupPadding = 600f // This is so that no tile will be stuck "on the side" and be unreachable or difficult to reach + + var topX = 0f + var topY = 0f + var bottomX = 0f + var bottomY = 0f + + for(tileGroup in tileGroups){ + val positionalVector = HexMath().hex2WorldCoords(tileGroup.tileInfo.position) + val groupSize = 50 + tileGroup.setPosition(positionalVector.x * 0.8f * groupSize.toFloat(), + positionalVector.y * 0.8f * groupSize.toFloat()) + + addActor(tileGroup) + topX = Math.max(topX, tileGroup.x + groupSize) + topY = Math.max(topY, tileGroup.y + groupSize) + bottomX = Math.min(bottomX, tileGroup.x) + bottomY = Math.min(bottomY, tileGroup.y) + } + + for (group in tileGroups) { + group.moveBy(-bottomX + groupPadding, -bottomY + groupPadding) + } + + // there are tiles "below the zero", + // so we zero out the starting position of the whole board so they will be displayed as well + setSize(topX - bottomX + groupPadding*2, topY - bottomY + groupPadding*2) + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index 7acd6a6604..afee58c803 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -9,7 +9,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener import com.unciv.UnCivGame -import com.unciv.logic.HexMath import com.unciv.logic.automation.UnitAutomation import com.unciv.logic.city.CityInfo import com.unciv.logic.civilization.CivilizationInfo @@ -32,40 +31,18 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: var moveHereButtonDto :MoveHereButtonDto?=null internal fun addTiles() { - val allTiles = Group() - val groupPadding = 600f // This is so that no tile will be stuck "on the side" and be unreachable or difficult to reach - var topX = 0f - var topY = 0f - var bottomX = 0f - var bottomY = 0f - for (tileInfo in tileMap.values) { - val tileGroup = WorldTileGroup(worldScreen, tileInfo) + val daTileGroups = tileMap.values.map { WorldTileGroup(worldScreen, it) } - tileGroup.onClick{ onTileClicked(tileInfo)} + for(tileGroup in daTileGroups) tileGroups[tileGroup.tileInfo]=tileGroup - val positionalVector = HexMath().hex2WorldCoords(tileInfo.position) - val groupSize = 50 - tileGroup.setPosition(worldScreen.stage.width / 2 + positionalVector.x * 0.8f * groupSize.toFloat(), - worldScreen.stage.height / 2 + positionalVector.y * 0.8f * groupSize.toFloat()) + val allTiles = TileGroupMap(daTileGroups) - tileGroups[tileInfo] = tileGroup - allTiles.addActor(tileGroup) - topX = Math.max(topX, tileGroup.x + groupSize) - topY = Math.max(topY, tileGroup.y + groupSize) - bottomX = Math.min(bottomX, tileGroup.x) - bottomY = Math.min(bottomY, tileGroup.y) + for(tileGroup in tileGroups.values){ + tileGroup.onClick{ onTileClicked(tileGroup.tileInfo)} } - for (group in tileGroups.values) { - group.moveBy(-bottomX + groupPadding, -bottomY + groupPadding) - } - - // there are tiles "below the zero", - // so we zero out the starting position of the whole board so they will be displayed as well - allTiles.setSize(topX - bottomX + groupPadding*2, topY - bottomY + groupPadding*2) - actor = allTiles setFillParent(true) setOrigin(worldScreen.stage.width/2,worldScreen.stage.height/2)