From 905449694079d456880b2316d222005eb01ef834 Mon Sep 17 00:00:00 2001 From: Duan Tao Date: Tue, 8 Jan 2019 15:34:32 +0800 Subject: [PATCH] Select city before entering city screen. --- .../src/com/unciv/ui/tilegroups/CityButton.kt | 7 +++- .../com/unciv/ui/tilegroups/WorldTileGroup.kt | 10 ++++- .../com/unciv/ui/worldscreen/TileMapHolder.kt | 2 +- .../bottombar/WorldScreenBottomBar.kt | 1 + .../unciv/ui/worldscreen/unit/UnitTable.kt | 40 +++++++++++++++++-- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/tilegroups/CityButton.kt b/core/src/com/unciv/ui/tilegroups/CityButton.kt index 8d5b6b2e02..e06ba53969 100644 --- a/core/src/com/unciv/ui/tilegroups/CityButton.kt +++ b/core/src/com/unciv/ui/tilegroups/CityButton.kt @@ -13,9 +13,10 @@ import com.unciv.logic.city.CityInfo import com.unciv.logic.city.SpecialConstruction import com.unciv.logic.map.RoadStatus import com.unciv.ui.cityscreen.CityScreen +import com.unciv.ui.tilegroups.WorldTileGroup import com.unciv.ui.utils.* -class CityButton(val city: CityInfo, skin: Skin): Table(skin){ +class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, skin: Skin): Table(skin){ init{ background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png") .tint(city.civInfo.getNation().getColor()) @@ -33,7 +34,9 @@ class CityButton(val city: CityInfo, skin: Skin): Table(skin){ clear() if (city.civInfo.isPlayerCivilization()) { onClick { - UnCivGame.Current.screen = CityScreen(city) + if (!tileGroup.selectCity(city)) { + UnCivGame.Current.screen = CityScreen(city) + } } } diff --git a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index 74088d9138..dbd91baca4 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -6,9 +6,10 @@ import com.unciv.logic.map.MapUnit import com.unciv.logic.map.TileInfo import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.center +import com.unciv.ui.worldscreen.WorldScreen -class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { +class WorldTileGroup(internal val worldScreen: WorldScreen, tileInfo: TileInfo) : TileGroup(tileInfo) { var cityButton: CityButton? = null fun selectUnit(unit: MapUnit) { @@ -63,7 +64,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { } if (city != null && tileInfo.isCityCenter()) { if (cityButton == null) { - cityButton = CityButton(city, CameraStageBaseScreen.skin) + cityButton = CityButton(city, this, CameraStageBaseScreen.skin) addActor(cityButton) toFront() // so this tile is rendered over neighboring tiles } @@ -73,4 +74,9 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { } } + + fun selectCity(city: CityInfo?) : Boolean { + if (city == null) return false + return worldScreen.bottomBar.unitTable.citySelected(city) + } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index 2fba109446..acac4107f1 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -40,7 +40,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: var bottomY = 0f for (tileInfo in tileMap.values) { - val tileGroup = WorldTileGroup(tileInfo) + val tileGroup = WorldTileGroup(worldScreen, tileInfo) tileGroup.onClick{ onTileClicked(tileInfo)} diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt b/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt index 8dddc107d5..6fe602cb59 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt @@ -3,6 +3,7 @@ package com.unciv.ui.worldscreen.bottombar import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.unciv.logic.city.CityInfo import com.unciv.logic.map.TileInfo import com.unciv.ui.utils.ImageGetter import com.unciv.ui.worldscreen.WorldScreen diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index 5fe5a44b93..831dae084b 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -3,6 +3,7 @@ package com.unciv.ui.worldscreen.unit import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.unciv.logic.city.CityInfo import com.unciv.logic.map.MapUnit import com.unciv.logic.map.TileInfo import com.unciv.models.gamebasics.tr @@ -17,7 +18,9 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ private val promotionsTable = Table() private val unitDescriptionTable = Table(CameraStageBaseScreen.skin) var selectedUnit : MapUnit? = null + var selectedCity : CityInfo? = null var currentlyExecutingAction : String? = null + var lastSelectedCityButton : Boolean = false // This is so that not on every update(), we will update the unit table. // Most of the time it's the same unit with the same stats so why waste precious time? @@ -42,10 +45,12 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ if(selectedUnit!=null) { if (selectedUnit!!.civInfo != worldScreen.civInfo) { // The unit that was selected, was captured. It exists but is no longer ours. selectedUnit = null + selectedCity = null currentlyExecutingAction = null selectedUnitHasChanged = true } else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists} selectedUnit = null + selectedCity = null currentlyExecutingAction = null selectedUnitHasChanged = true } @@ -96,6 +101,17 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ if(unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions! selectedUnitHasChanged = true } + else if (selectedCity != null) { + separator.isVisible=true + val unit = selectedCity!! + var nameLabelText = unit.name.tr() + if(unit.health