diff --git a/core/src/com/unciv/ui/components/ZoomableScrollPane.kt b/core/src/com/unciv/ui/components/ZoomableScrollPane.kt index c016078fb3..a2a6055ee7 100644 --- a/core/src/com/unciv/ui/components/ZoomableScrollPane.kt +++ b/core/src/com/unciv/ui/components/ZoomableScrollPane.kt @@ -45,7 +45,7 @@ open class ZoomableScrollPane( this.addListener(zoomListener) } - fun reloadMaxZoom() { + open fun reloadMaxZoom() { maxZoom = UncivGame.Current.settings.maxWorldZoomOut minZoom = 1f / maxZoom @@ -90,17 +90,6 @@ open class ZoomableScrollPane( updatePadding() super.sizeChanged() updateCulling() - - if (continuousScrollingX) { - // For world-wrap we do not allow viewport to become bigger than the map size, - // because we don't want to render the same tiles multiple times (they will be - // flickering because of movement). - // Hence we limit minimal possible zoom to content width + some extra offset. - val content = actor - if (content != null) - minZoom = max((width + 80f) * scaleX / content.width, 1f / UncivGame.Current.settings.maxWorldZoomOut)// add some extra padding offset - } - } private fun updatePadding() { diff --git a/core/src/com/unciv/ui/components/tilegroups/TileGroupMap.kt b/core/src/com/unciv/ui/components/tilegroups/TileGroupMap.kt index 1a6717d09b..0dc9ee90c6 100644 --- a/core/src/com/unciv/ui/components/tilegroups/TileGroupMap.kt +++ b/core/src/com/unciv/ui/components/tilegroups/TileGroupMap.kt @@ -163,9 +163,14 @@ class TileGroupMap( if (worldWrap) { + // Prevent flickering when zoomed out so you can see entire map + val visibleMapWidth: Float + if(mapHolder.width > width) visibleMapWidth = width - groupSize * 1.5f + else visibleMapWidth = mapHolder.width + // Where is viewport's boundaries - val rightSide = mapHolder.scrollX + mapHolder.width/2f - val leftSide = mapHolder.scrollX - mapHolder.width/2f + val rightSide = mapHolder.scrollX + visibleMapWidth/2f + val leftSide = mapHolder.scrollX - visibleMapWidth/2f // Have we looked beyond map? val diffRight = rightSide - topX diff --git a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt index b84e902c0c..2c741bd8e3 100644 --- a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt @@ -169,6 +169,7 @@ private fun addMaxZoomSlider(table: Table, settings: GameSettings) { ) { settings.maxWorldZoomOut = it settings.save() + UncivGame.Current.worldScreen?.mapHolder?.reloadMaxZoom() } table.add(maxZoomSlider).pad(5f).row() } diff --git a/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt index e1c1ad2568..aef06da6c2 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt @@ -53,6 +53,7 @@ import com.unciv.ui.screens.basescreen.UncivStage import com.unciv.utils.Log import com.unciv.utils.concurrency.Concurrency import com.unciv.utils.concurrency.launchOnGLThread +import java.lang.Float.max class WorldMapHolder( @@ -71,7 +72,6 @@ class WorldMapHolder( init { if (Gdx.app.type == Application.ApplicationType.Desktop) this.setFlingTime(0f) continuousScrollingX = tileMap.mapParameters.worldWrap - reloadMaxZoom() setupZoomPanListeners() } @@ -753,6 +753,28 @@ class WorldMapHolder( unitActionOverlays.clear() } + override fun reloadMaxZoom() + { + if (continuousScrollingX) { + // For world-wrap we do not allow viewport to become bigger than the map size, + // because we don't want to render the same tiles multiple times (they will be + // flickering because of movement). + // Hence we limit minimal possible zoom to content width + some extra offset. + + val pad = width / tileMap.mapParameters.mapSize.radius * 0.7f + minZoom = max( + (width + pad) * scaleX / maxX, + 1f / UncivGame.Current.settings.maxWorldZoomOut + )// add some extra padding offset + + // If the window becomes too wide and minZoom > maxZoom, we cannot zoom + maxZoom = max(2f * minZoom, UncivGame.Current.settings.maxWorldZoomOut) + } + else + super.reloadMaxZoom() + } + + // For debugging purposes override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha) override fun act(delta: Float) = super.act(delta) diff --git a/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt index 518d7199eb..47a87e7b14 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt @@ -137,6 +137,7 @@ class WorldScreen( // This is the most memory-intensive operation we have currently, most OutOfMemory errors will occur here mapHolder.addTiles() + mapHolder.reloadMaxZoom() // resume music (in case choices from the menu lead to instantiation of a new WorldScreen) UncivGame.Current.musicController.resume() @@ -242,7 +243,6 @@ class WorldScreen( } globalShortcuts.add(KeyCharAndCode.ctrl('O')) { // Game Options this.openOptionsPopup(onClose = { - mapHolder.reloadMaxZoom() nextTurnButton.update(this) }) }