From 0b507422f02b2ea1436e62119f35ac39866f60f5 Mon Sep 17 00:00:00 2001 From: Gualdimar Date: Mon, 20 Feb 2023 16:44:30 +0200 Subject: [PATCH] Option to disable max zoom limit (#8702) * Option to disable max zoom limit * Reverted old flickering fix * Reworked * Removed redundant import * Added comment --- .../unciv/ui/components/ZoomableScrollPane.kt | 2 +- .../mapeditorscreen/MapEditorScreen.kt | 5 ----- .../ui/screens/worldscreen/WorldMapHolder.kt | 19 +++++++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/core/src/com/unciv/ui/components/ZoomableScrollPane.kt b/core/src/com/unciv/ui/components/ZoomableScrollPane.kt index a2a6055ee7..52d0dca4b5 100644 --- a/core/src/com/unciv/ui/components/ZoomableScrollPane.kt +++ b/core/src/com/unciv/ui/components/ZoomableScrollPane.kt @@ -86,7 +86,7 @@ open class ZoomableScrollPane( onViewportChanged() } - public override fun sizeChanged() { + override fun sizeChanged() { updatePadding() super.sizeChanged() updateCulling() diff --git a/core/src/com/unciv/ui/screens/mapeditorscreen/MapEditorScreen.kt b/core/src/com/unciv/ui/screens/mapeditorscreen/MapEditorScreen.kt index 542f8b775d..ed499493b6 100644 --- a/core/src/com/unciv/ui/screens/mapeditorscreen/MapEditorScreen.kt +++ b/core/src/com/unciv/ui/screens/mapeditorscreen/MapEditorScreen.kt @@ -134,11 +134,6 @@ class MapEditorScreen(map: TileMap? = null): BaseScreen(), RecreateOnResize { tileClickHandler?.invoke(it) } - if (tileMap.mapParameters.worldWrap) { - result.sizeChanged() - result.zoom(result.minZoom) - } - stage.root.addActorAt(0, result) stage.scrollFocus = result diff --git a/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt index c3be51edba..6b3f1c3726 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/WorldMapHolder.kt @@ -755,20 +755,23 @@ class WorldMapHolder( 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 maxWorldZoomOut = UncivGame.Current.settings.maxWorldZoomOut + val mapRadius = tileMap.mapParameters.mapSize.radius - val pad = width / tileMap.mapParameters.mapSize.radius * 0.7f + // Limit max zoom out by the map width + val enableZoomLimit = (mapRadius < 21 && maxWorldZoomOut < 3f) || (mapRadius > 20 && maxWorldZoomOut < 4f) + + if (enableZoomLimit) { + // For world-wrap we limit minimal possible zoom to content width + some extra offset + // to hide one column of tiles so that the player doesn't see it teleporting from side to side + val pad = if (continuousScrollingX) width / mapRadius * 0.7f else 0f minZoom = max( (width + pad) * scaleX / maxX, - 1f / UncivGame.Current.settings.maxWorldZoomOut + 1f / 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) + maxZoom = max(2f * minZoom, maxWorldZoomOut) } else super.reloadMaxZoom()