Select city before entering city screen.

This commit is contained in:
Duan Tao 2019-01-08 15:34:32 +08:00
parent eeb494364b
commit 9054496940
5 changed files with 52 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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<unit.getMaxHealth()) nameLabelText+=" ("+unit.health+")"
unitNameLabel.setText(nameLabelText)
unitDescriptionTable.clear()
unitDescriptionTable.defaults().pad(2f).padRight(5f)
selectedUnitHasChanged = true
}
else {
separator.isVisible=false
unitNameLabel.setText("")
@ -121,7 +137,21 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
selectedUnitHasChanged=false
}
fun citySelected(cityInfo: CityInfo) : Boolean {
if (cityInfo == selectedCity) return false
lastSelectedCityButton = true
selectedCity = cityInfo
selectedUnit = null
selectedUnitHasChanged = true
return true
}
fun tileSelected(selectedTile: TileInfo) {
if (lastSelectedCityButton) {
lastSelectedCityButton = false
return
}
val previouslySelectedUnit = selectedUnit
if(currentlyExecutingAction=="moveTo"){
if(selectedUnit!!.movementAlgs()
@ -137,12 +167,16 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
}
else if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.civInfo
&& selectedUnit!=selectedTile.militaryUnit)
&& selectedUnit!=selectedTile.militaryUnit) {
selectedUnit = selectedTile.militaryUnit
selectedCity = null
}
else if (selectedTile.civilianUnit!=null && selectedTile.civilianUnit!!.civInfo == worldScreen.civInfo
&& selectedUnit!=selectedTile.civilianUnit)
selectedUnit = selectedTile.civilianUnit
&& selectedUnit!=selectedTile.civilianUnit) {
selectedUnit = selectedTile.civilianUnit
selectedCity = null
}
if(selectedUnit != previouslySelectedUnit)
selectedUnitHasChanged = true