diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 92d2d81f..a035f11f 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 110fe0e6..1e753ae9 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 5876751b..ac00dd86 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt @@ -26,8 +26,10 @@ class TileGroupIcons(val tileGroup: TileGroup){ updateResourceIcon(showResourcesAndImprovements,viewingCiv) 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() { @@ -47,7 +49,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() @@ -81,7 +83,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 95a5445b..7c239d24 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -20,6 +20,8 @@ import com.unciv.logic.civilization.PlayerType import com.unciv.logic.civilization.diplomacy.DiplomaticStatus import com.unciv.logic.map.MapGenerator import com.unciv.logic.map.MapParameters +import com.unciv.logic.map.MapUnit +import com.unciv.logic.map.TileInfo import com.unciv.models.Tutorial import com.unciv.models.UncivSound import com.unciv.models.ruleset.RulesetCache @@ -54,7 +56,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) @@ -547,14 +549,33 @@ class TotemWorldScreen : CameraStageBaseScreen(){ val tileSetStrings = TileSetStrings() val tileMapHolder = TileGroupMap(tileMap.values.map { TileGroup(it,tileSetStrings) },500f) val newCiv = CivilizationInfo("Babylon") + var selectedUnit : MapUnit? = null + val gameInfo = GameInfo() + val tileInfoTable = TileInfoTable(newCiv) + var selectedTile: TileInfo?=null + init{ newCiv.playerType=PlayerType.Human - val gameInfo = GameInfo() gameInfo.tileMap = tileMap gameInfo.civilizations.add(newCiv) gameInfo.setTransients() ImageGetter.ruleset = RulesetCache.getBaseRuleset() val scrollPane = ScrollPane(tileMapHolder) + for(tileGroup in tileMapHolder.tileGroups) + tileGroup.onClick { + val tileInfo = tileGroup.tileInfo + selectedTile=tileInfo + if(tileInfo.civilianUnit!=null){ + selectedUnit = tileInfo.civilianUnit + } + + else if(selectedUnit!=null + && selectedUnit!!.movement.getDistanceToTiles().containsKey(tileInfo) + && selectedUnit!!.movement.canMoveTo(tileInfo)){ + selectedUnit!!.movement.moveToTile(tileInfo) + } + update() + } scrollPane.setSize(stage.width,stage.height) scrollPane.center(stage) scrollPane.scrollPercentX=0.5f @@ -562,10 +583,27 @@ class TotemWorldScreen : CameraStageBaseScreen(){ stage.addActor(scrollPane) newCiv.placeUnitNearTile(Vector2.Zero, Constants.worker) update() + + stage.addActor(tileInfoTable) } - fun update(){ - for(tileGroup in tileMapHolder.tileGroups) + fun update() { + if(newCiv.getIdleUnits().none()) gameInfo.nextTurn() + for (tileGroup in tileMapHolder.tileGroups) { tileGroup.update(newCiv) + tileGroup.hideCircle() + if (tileGroup.tileInfo.civilianUnit == selectedUnit) { + tileGroup.icons.civilianUnitIcon?.selectUnit() + } + } + if(selectedUnit!=null) { + for (tile in selectedUnit!!.movement.getDistanceToTiles().keys){ + val tileGroup = tileMapHolder.tileGroups.first{it.tileInfo==tile} + tileGroup.showCircle(Color.WHITE) + } + } + if(selectedTile!=null) tileInfoTable.updateTileTable(selectedTile!!) + tileInfoTable.setPosition(stage.width,0f,Align.bottomRight) + } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt index d0280cdd..9ef73b00 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)