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
This commit is contained in:
SomeTroglodyte
2023-03-11 19:12:38 +01:00
committed by GitHub
parent 793d3387bf
commit a547acbf4e
5 changed files with 39 additions and 3 deletions

View File

@ -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 <T> 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()})"

View File

@ -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()
}

View File

@ -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) {

View File

@ -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()

View File

@ -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