diff --git a/core/src/com/unciv/ui/screens/victoryscreen/ReplayMap.kt b/core/src/com/unciv/ui/screens/victoryscreen/ReplayMap.kt index 770705d157..2a47637ddb 100644 --- a/core/src/com/unciv/ui/screens/victoryscreen/ReplayMap.kt +++ b/core/src/com/unciv/ui/screens/victoryscreen/ReplayMap.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.scenes.scene2d.Group import com.unciv.UncivGame import com.unciv.logic.map.TileMap +import com.unciv.ui.screens.worldscreen.minimap.MinimapTileUtil import com.unciv.ui.screens.worldscreen.minimap.MinimapTile import kotlin.math.max import kotlin.math.min @@ -18,32 +19,9 @@ class ReplayMap(val tileMap: TileMap) : Group() { // render time! isTransform = false - var topX = 0f - var topY = 0f - var bottomX = 0f - var bottomY = 0f - val tileSize = calcTileSize(22) minimapTiles = createReplayMap(tileSize) - for (image in minimapTiles.map { it.image }) { - tileLayer.addActor(image) - - // keeps track of the current top/bottom/left/rightmost tiles to size and position the - // minimap correctly - topX = max(topX, image.x + tileSize) - topY = max(topY, image.y + tileSize) - bottomX = min(bottomX, image.x) - bottomY = min(bottomY, image.y) - } - - for (group in tileLayer.children) { - group.moveBy(-bottomX, -bottomY) - } - - // there are tiles "below the zero", - // so we zero out the starting position of the whole board so they will be displayed as well - tileLayer.setSize(topX - bottomX, topY - bottomY) - + MinimapTileUtil.spreadOutMinimapTiles(tileLayer, minimapTiles, tileSize) setSize(tileLayer.width, tileLayer.height) addActor(tileLayer) } diff --git a/core/src/com/unciv/ui/screens/worldscreen/minimap/Minimap.kt b/core/src/com/unciv/ui/screens/worldscreen/minimap/Minimap.kt index cf90551251..ae93bb9d36 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/minimap/Minimap.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/minimap/Minimap.kt @@ -27,31 +27,9 @@ class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Group() { // don't try to resize rotate etc - this table has a LOT of children so that's valuable render time! isTransform = false - var topX = 0f - var topY = 0f - var bottomX = 0f - var bottomY = 0f - val tileSize = calcTileSize(minimapSize) minimapTiles = createMinimapTiles(tileSize) - for (image in minimapTiles.map { it.image }) { - tileLayer.addActor(image) - - // keeps track of the current top/bottom/left/rightmost tiles to size and position the minimap correctly - topX = max(topX, image.x + tileSize) - topY = max(topY, image.y + tileSize) - bottomX = min(bottomX, image.x) - bottomY = min(bottomY, image.y) - } - - for (group in tileLayer.children) { - group.moveBy(-bottomX, -bottomY) - } - - // there are tiles "below the zero", - // so we zero out the starting position of the whole board so they will be displayed as well - tileLayer.setSize(topX - bottomX, topY - bottomY) - + MinimapTileUtil.spreadOutMinimapTiles(tileLayer, minimapTiles, tileSize) scrollPositionIndicators = createScrollPositionIndicators() scrollPositionIndicators.forEach(tileLayer::addActor) diff --git a/core/src/com/unciv/ui/screens/worldscreen/minimap/MinimapTile.kt b/core/src/com/unciv/ui/screens/worldscreen/minimap/MinimapTile.kt index 2ac525b78f..1c64187ee5 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/minimap/MinimapTile.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/minimap/MinimapTile.kt @@ -16,7 +16,7 @@ import com.unciv.utils.DebugUtils import kotlin.math.PI import kotlin.math.atan -internal class MinimapTile(val tile: Tile, tileSize: Float, val onClick: () -> Unit) { +class MinimapTile(val tile: Tile, tileSize: Float, val onClick: () -> Unit) { val image: Image = ImageGetter.getImage("OtherIcons/Hexagon") private var cityCircleImage: IconCircleGroup? = null var owningCiv: Civilization? = null diff --git a/core/src/com/unciv/ui/screens/worldscreen/minimap/MinimapTileUtil.kt b/core/src/com/unciv/ui/screens/worldscreen/minimap/MinimapTileUtil.kt new file mode 100644 index 0000000000..d1d1a7af7a --- /dev/null +++ b/core/src/com/unciv/ui/screens/worldscreen/minimap/MinimapTileUtil.kt @@ -0,0 +1,34 @@ +package com.unciv.ui.screens.worldscreen.minimap + +import com.badlogic.gdx.scenes.scene2d.Group +import kotlin.math.max +import kotlin.math.min + +object MinimapTileUtil { + + fun spreadOutMinimapTiles(tileLayer: Group, tiles: List, tileSize: Float) { + var topX = 0f + var topY = 0f + var bottomX = 0f + var bottomY = 0f + + for (image in tiles.map { it.image }) { + tileLayer.addActor(image) + + // keeps track of the current top/bottom/left/rightmost tiles to size and position the + // minimap correctly + topX = max(topX, image.x + tileSize) + topY = max(topY, image.y + tileSize) + bottomX = min(bottomX, image.x) + bottomY = min(bottomY, image.y) + } + + for (group in tileLayer.children) { + group.moveBy(-bottomX, -bottomY) + } + + // there are tiles "below the zero", + // so we zero out the starting position of the whole board so they will be displayed as well + tileLayer.setSize(topX - bottomX, topY - bottomY) + } +}