From 848637c78c63643c99c35bc637f60ccd003e238e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 3 Feb 2020 15:57:09 +0200 Subject: [PATCH] Better top-down trickling of information instead of relying on UncivGame.Current info --- core/src/com/unciv/logic/map/TileInfo.kt | 4 ++-- .../com/unciv/ui/cityscreen/CityScreenTileTable.kt | 2 +- core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt | 10 ++++++---- core/src/com/unciv/ui/worldscreen/WorldScreen.kt | 2 +- .../unciv/ui/worldscreen/bottombar/TileInfoTable.kt | 11 +++++------ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 92d2d81f04..a035f11f17 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -288,10 +288,10 @@ open class TileInfo { fun isRoughTerrain() = getBaseTerrain().rough || getTerrainFeature()?.rough == true - override fun toString(): String { + fun toString(viewingCiv: CivilizationInfo): String { val lineList = ArrayList() // more readable than StringBuilder, with same performance for our use-case val isViewableToPlayer = UncivGame.Current.viewEntireMapForDebug - || UncivGame.Current.gameInfo.getCurrentPlayerCivilization().viewableTiles.contains(this) + || viewingCiv.viewableTiles.contains(this) if (isCityCenter()) { val city = getCity()!! diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt index 110fe0e69e..1e753ae99e 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt @@ -32,7 +32,7 @@ class CityScreenTileTable(val city: CityInfo): Table(){ val stats = selectedTile.getTileStats(city, city.civInfo) innerTable.pad(20f) - innerTable.add(selectedTile.toString().toLabel()).colspan(2) + innerTable.add(selectedTile.toString(city.civInfo).toLabel()).colspan(2) innerTable.row() innerTable.add(getTileStatsTable(stats)).row() diff --git a/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt b/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt index c9a49ca094..4f509354fd 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt @@ -22,8 +22,10 @@ class TileGroupIcons(val tileGroup: TileGroup){ updateResourceIcon(showResourcesAndImprovements) updateImprovementIcon(showResourcesAndImprovements) - civilianUnitIcon = newUnitIcon(tileGroup.tileInfo.civilianUnit, civilianUnitIcon, tileIsViewable, -20f) - militaryUnitIcon = newUnitIcon(tileGroup.tileInfo.militaryUnit, militaryUnitIcon, tileIsViewable && showMilitaryUnit, 20f) + civilianUnitIcon = newUnitIcon(tileGroup.tileInfo.civilianUnit, civilianUnitIcon, + tileIsViewable, -20f, viewingCiv) + militaryUnitIcon = newUnitIcon(tileGroup.tileInfo.militaryUnit, militaryUnitIcon, + tileIsViewable && showMilitaryUnit, 20f, viewingCiv) } fun addPopulationIcon() { @@ -43,7 +45,7 @@ class TileGroupIcons(val tileGroup: TileGroup){ } - fun newUnitIcon(unit: MapUnit?, oldUnitGroup: UnitGroup?, isViewable: Boolean, yFromCenter: Float): UnitGroup? { + fun newUnitIcon(unit: MapUnit?, oldUnitGroup: UnitGroup?, isViewable: Boolean, yFromCenter: Float, viewingCiv: CivilizationInfo?): UnitGroup? { var newImage: UnitGroup? = null // The unit can change within one update - for instance, when attacking, the attacker replaces the defender! oldUnitGroup?.remove() @@ -77,7 +79,7 @@ class TileGroupIcons(val tileGroup: TileGroup){ // Instead of fading out the entire unit with its background, we just fade out its central icon, // that way it remains much more visible on the map - if (!unit.isIdle() && unit.civInfo == UncivGame.Current.worldScreen.viewingCiv) + if (!unit.isIdle() && unit.civInfo == viewingCiv) newImage.unitBaseImage.color.a = 0.5f } return newImage diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index da9e1f240e..b06730c33b 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -45,7 +45,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { private val topBar = WorldScreenTopBar(this) val bottomUnitTable = UnitTable(this) - val bottomTileInfoTable = TileInfoTable(this) + val bottomTileInfoTable = TileInfoTable(viewingCiv) val battleTable = BattleTable(this) val unitActionsTable = UnitActionsTable(this) diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt index d0280cdddd..9ef73b00a2 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt @@ -4,24 +4,23 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align import com.unciv.UncivGame +import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.map.TileInfo import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.toLabel -import com.unciv.ui.worldscreen.WorldScreen -class TileInfoTable(private val worldScreen: WorldScreen) : Table(CameraStageBaseScreen.skin) { +class TileInfoTable(private val viewingCiv :CivilizationInfo) : Table(CameraStageBaseScreen.skin) { init { background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) } internal fun updateTileTable(tile: TileInfo) { clearChildren() - val civInfo = worldScreen.viewingCiv - if (UncivGame.Current.viewEntireMapForDebug || civInfo.exploredTiles.contains(tile.position)) { + if (UncivGame.Current.viewEntireMapForDebug || viewingCiv.exploredTiles.contains(tile.position)) { add(getStatsTable(tile)) - add(tile.toString().toLabel()).colspan(2).pad(10f) + add(tile.toString(viewingCiv).toLabel()).colspan(2).pad(10f) } pack() @@ -31,7 +30,7 @@ class TileInfoTable(private val worldScreen: WorldScreen) : Table(CameraStageBas val table = Table() table.defaults().pad(2f) - for (entry in tile.getTileStats(worldScreen.viewingCiv).toHashMap() + for (entry in tile.getTileStats(viewingCiv).toHashMap() .filterNot { it.value == 0f || it.key.toString() == "" }) { table.add(ImageGetter.getStatIcon(entry.key.toString())).size(20f).align(Align.right) table.add(entry.value.toInt().toString().toLabel()).align(Align.left).padRight(10f)