From a547acbf4ed023c8b32e0102d818caf7fe32517a Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sat, 11 Mar 2023 19:12:38 +0100 Subject: [PATCH] Debug option to paint coords on map tiles (#8818) * Debug option to paint coords on map tiles * Debug option to paint coords on map tiles - rename flag --- .../extensions/FormattingExtensions.kt | 3 ++ .../tilegroups/layers/TileLayerMisc.kt | 28 +++++++++++++++++-- .../com/unciv/ui/popups/options/DebugTab.kt | 4 +++ .../worldscreen/bottombar/TileInfoTable.kt | 3 +- core/src/com/unciv/utils/Debug.kt | 4 +++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/ui/components/extensions/FormattingExtensions.kt b/core/src/com/unciv/ui/components/extensions/FormattingExtensions.kt index c390fb08dc..1fefef6e25 100644 --- a/core/src/com/unciv/ui/components/extensions/FormattingExtensions.kt +++ b/core/src/com/unciv/ui/components/extensions/FormattingExtensions.kt @@ -1,5 +1,6 @@ package com.unciv.ui.components.extensions +import com.badlogic.gdx.math.Vector2 import com.unciv.models.translations.tr import java.text.SimpleDateFormat import java.time.Duration @@ -95,3 +96,5 @@ fun String.filterCompositeLogic(predicate: (String) -> T?, operation: (T, T) fun String.filterAndLogic(predicate: (String) -> Boolean): Boolean? = if (contains('{')) filterCompositeLogic(predicate) { a, b -> a && b } else null +/** Format a Vector2 like (0,0) instead of (0.0,0.0) like [toString][Vector2.toString] does */ +fun Vector2.toPrettyString(): String = "(${x.toInt()},${y.toInt()})" diff --git a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt index 9351b52a2f..8c48e332af 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerMisc.kt @@ -22,6 +22,8 @@ import com.unciv.ui.components.tilegroups.YieldGroup import com.unciv.ui.components.extensions.center import com.unciv.ui.components.extensions.centerX import com.unciv.ui.components.extensions.toLabel +import com.unciv.ui.components.extensions.toPrettyString +import com.unciv.utils.DebugUtils import kotlin.math.atan2 import kotlin.math.min import kotlin.math.pow @@ -156,13 +158,34 @@ class TileLayerMisc(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, si } private fun updateStartingLocationIcon(isVisible: Boolean) { - // These are visible in map editor only, but making that bit available here seems overkill + // The starting location icons are visible in map editor only, but this method is abused for the + // "Show coordinates on tiles" debug option as well. Calling code made sure this is only called + // with isVisible=false for reset, or for non-WorldMap TileGroups, or with the debug option set. + // Note that starting locations should always be empty on the normal WorldMap - they're cleared after use. + // Also remember the main menu background is an EditorMapHolder which we can't distinguish from + // The actual editor use here. startingLocationIcons.forEach { it.remove() } startingLocationIcons.clear() if (!isVisible || tileGroup.isForMapEditorIcon) return + if (DebugUtils.SHOW_TILE_COORDS) { + val label = this.tile().position.toPrettyString() + startingLocationIcons.add(label.toLabel(Color.BLACK.cpy().apply { a = 0.7f }, 14).apply { + tileGroup.layerMisc.addActor(this) + setOrigin(Align.center) + center(tileGroup) + moveBy(15.4f, -0.6f) + }) + startingLocationIcons.add(label.toLabel(Color.FIREBRICK, 14).apply { + tileGroup.layerMisc.addActor(this) + setOrigin(Align.center) + center(tileGroup) + moveBy(15f, 0f) + }) + } + val tilemap = tile().tileMap if (tilemap.startingLocationsByNation.isEmpty()) @@ -305,7 +328,8 @@ class TileLayerMisc(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, si updateImprovementIcon(viewingCiv, showResourcesAndImprovements) updateYieldIcon(viewingCiv, showTileYields) updateResourceIcon(viewingCiv, showResourcesAndImprovements) - updateStartingLocationIcon(showResourcesAndImprovements) + if (tileGroup !is WorldTileGroup || DebugUtils.SHOW_TILE_COORDS) + updateStartingLocationIcon(true) updateArrows() } diff --git a/core/src/com/unciv/ui/popups/options/DebugTab.kt b/core/src/com/unciv/ui/popups/options/DebugTab.kt index e402721345..b2f0f9024e 100644 --- a/core/src/com/unciv/ui/popups/options/DebugTab.kt +++ b/core/src/com/unciv/ui/popups/options/DebugTab.kt @@ -46,6 +46,10 @@ fun debugTab() = Table(BaseScreen.skin).apply { add("View entire map".toCheckBox(DebugUtils.VISIBLE_MAP) { DebugUtils.VISIBLE_MAP = it }).colspan(2).row() + add("Show coordinates on tiles".toCheckBox(DebugUtils.SHOW_TILE_COORDS) { + DebugUtils.SHOW_TILE_COORDS = it + }).colspan(2).row() + val curGameInfo = game.gameInfo if (curGameInfo != null) { add("God mode (current game)".toCheckBox(curGameInfo.gameParameters.godMode) { diff --git a/core/src/com/unciv/ui/screens/worldscreen/bottombar/TileInfoTable.kt b/core/src/com/unciv/ui/screens/worldscreen/bottombar/TileInfoTable.kt index 87c74d8338..a3ce1dc06e 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/bottombar/TileInfoTable.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/bottombar/TileInfoTable.kt @@ -15,6 +15,7 @@ import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.extensions.addBorderAllowOpacity import com.unciv.ui.components.extensions.darken import com.unciv.ui.components.extensions.toLabel +import com.unciv.ui.components.extensions.toPrettyString import com.unciv.utils.DebugUtils class TileInfoTable(private val viewingCiv :Civilization) : Table(BaseScreen.skin) { @@ -34,7 +35,7 @@ class TileInfoTable(private val viewingCiv :Civilization) : Table(BaseScreen.ski UncivGame.Current.pushScreen(CivilopediaScreen(viewingCiv.gameInfo.ruleset, link = it)) } ).pad(5f).row() if (DebugUtils.VISIBLE_MAP) - add(tile.position.run { "(${x.toInt()},${y.toInt()})" }.toLabel()).colspan(2).pad(5f) + add(tile.position.toPrettyString().toLabel()).colspan(2).pad(5f) } pack() diff --git a/core/src/com/unciv/utils/Debug.kt b/core/src/com/unciv/utils/Debug.kt index db95b76a13..a86a8c4b12 100644 --- a/core/src/com/unciv/utils/Debug.kt +++ b/core/src/com/unciv/utils/Debug.kt @@ -5,9 +5,13 @@ object DebugUtils { /** * This exists so that when debugging we can see the entire map. * Remember to turn this to false before commit and upload! + * Or use the "secret" debug page of the options popup instead. */ var VISIBLE_MAP: Boolean = false + /** This flag paints the tile coordinates directly onto the map tiles. */ + var SHOW_TILE_COORDS: Boolean = false + /** For when you need to test something in an advanced game and don't have time to faff around */ var SUPERCHARGED: Boolean = false