Adding world wrap support to map editor (#3667)

* Adding world wrap support to MapEditor

* better readability
This commit is contained in:
GGGuenni
2021-03-08 21:19:55 +01:00
committed by GitHub
parent 4324fb5a7a
commit 7d3e2a4e78
3 changed files with 38 additions and 16 deletions

View File

@ -13,20 +13,40 @@ import com.unciv.ui.utils.center
import com.unciv.ui.utils.onClick
class EditorMapHolder(internal val mapEditorScreen: MapEditorScreen, internal val tileMap: TileMap): ZoomableScrollPane() {
val tileGroups = HashMap<TileInfo, TileGroup>()
val tileGroups = HashMap<TileInfo, List<TileGroup>>()
lateinit var tileGroupMap: TileGroupMap<TileGroup>
val allTileGroups = ArrayList<TileGroup>()
init {
continousScrollingX = tileMap.mapParameters.worldWrap
}
internal fun addTiles(padding:Float) {
val tileSetStrings = TileSetStrings()
for (tileInfo in tileMap.values)
tileGroups[tileInfo] = TileGroup(tileInfo, tileSetStrings)
val daTileGroups = tileMap.values.map { TileGroup(it, tileSetStrings) }
tileGroupMap = TileGroupMap(tileGroups.values, padding)
tileGroupMap = TileGroupMap(daTileGroups, padding, continousScrollingX)
actor = tileGroupMap
val mirrorTileGroups = tileGroupMap.getMirrorTiles()
for (tileGroup in daTileGroups) {
if (continousScrollingX){
val mirrorTileGroupLeft = mirrorTileGroups[tileGroup.tileInfo]!!.first
val mirrorTileGroupRight = mirrorTileGroups[tileGroup.tileInfo]!!.second
for (tileGroup in tileGroups.values) {
allTileGroups.add(tileGroup)
allTileGroups.add(mirrorTileGroupLeft)
allTileGroups.add(mirrorTileGroupRight)
tileGroups[tileGroup.tileInfo] = listOf(tileGroup, mirrorTileGroupLeft, mirrorTileGroupRight)
} else {
tileGroups[tileGroup.tileInfo] = listOf(tileGroup)
allTileGroups.add(tileGroup)
}
}
for (tileGroup in allTileGroups) {
// This is a hack to make the unit icons render correctly on the game, even though the map isn't part of a game
// and the units aren't assigned to any "real" CivInfo
@ -43,7 +63,8 @@ class EditorMapHolder(internal val mapEditorScreen: MapEditorScreen, internal va
mapEditorScreen.tileEditorOptions.updateTileWhenClicked(tileInfo)
tileInfo.setTerrainTransients()
tileGroups[tileInfo]!!.update()
for (tileGroup in tileGroups[tileInfo]!!)
tileGroup.update()
}
}
}
@ -60,7 +81,7 @@ class EditorMapHolder(internal val mapEditorScreen: MapEditorScreen, internal va
}
fun updateTileGroups() {
for (tileGroup in tileGroups.values)
for (tileGroup in allTileGroups)
tileGroup.update()
}

View File

@ -97,7 +97,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
if (isPainting) {
for (tileInfo in lastDrawnTiles)
mapHolder.tileGroups[tileInfo]!!.hideCircle()
mapHolder.tileGroups[tileInfo]!!.forEach { it.hideCircle() }
lastDrawnTiles.clear()
val stageCoords = mapHolder.actor.stageToLocalCoordinates(Vector2(event!!.stageX, event.stageY))
@ -109,8 +109,10 @@ class MapEditorScreen(): CameraStageBaseScreen() {
tileEditorOptions.updateTileWhenClicked(tileInfo)
tileInfo.setTerrainTransients()
mapHolder.tileGroups[tileInfo]!!.update()
mapHolder.tileGroups[tileInfo]!!.showCircle(Color.WHITE)
mapHolder.tileGroups[tileInfo]!!.forEach {
it.update()
it.showCircle(Color.WHITE)
}
lastDrawnTiles.add(tileInfo)
}

View File

@ -163,12 +163,11 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
val improvementName = "StartingLocation " + nation.name
tileAction = {
it.improvement = improvementName
for (tileGroup in mapEditorScreen.mapHolder.tileGroups.values) {
val tile = tileGroup.tileInfo
if (tile.improvement == improvementName && tile != it)
tile.improvement = null
tile.setTerrainTransients()
tileGroup.update()
for ((tileInfo, tileGroups) in mapEditorScreen.mapHolder.tileGroups) {
if (tileInfo.improvement == improvementName && tileInfo != it)
tileInfo.improvement = null
tileInfo.setTerrainTransients()
tileGroups.forEach { it.update() }
}
}