mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Select city before entering city screen.
This commit is contained in:
parent
eeb494364b
commit
9054496940
@ -13,9 +13,10 @@ import com.unciv.logic.city.CityInfo
|
|||||||
import com.unciv.logic.city.SpecialConstruction
|
import com.unciv.logic.city.SpecialConstruction
|
||||||
import com.unciv.logic.map.RoadStatus
|
import com.unciv.logic.map.RoadStatus
|
||||||
import com.unciv.ui.cityscreen.CityScreen
|
import com.unciv.ui.cityscreen.CityScreen
|
||||||
|
import com.unciv.ui.tilegroups.WorldTileGroup
|
||||||
import com.unciv.ui.utils.*
|
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{
|
init{
|
||||||
background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
|
background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
|
||||||
.tint(city.civInfo.getNation().getColor())
|
.tint(city.civInfo.getNation().getColor())
|
||||||
@ -33,7 +34,9 @@ class CityButton(val city: CityInfo, skin: Skin): Table(skin){
|
|||||||
clear()
|
clear()
|
||||||
if (city.civInfo.isPlayerCivilization()) {
|
if (city.civInfo.isPlayerCivilization()) {
|
||||||
onClick {
|
onClick {
|
||||||
UnCivGame.Current.screen = CityScreen(city)
|
if (!tileGroup.selectCity(city)) {
|
||||||
|
UnCivGame.Current.screen = CityScreen(city)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,10 @@ import com.unciv.logic.map.MapUnit
|
|||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.center
|
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
|
var cityButton: CityButton? = null
|
||||||
|
|
||||||
fun selectUnit(unit: MapUnit) {
|
fun selectUnit(unit: MapUnit) {
|
||||||
@ -63,7 +64,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||||||
}
|
}
|
||||||
if (city != null && tileInfo.isCityCenter()) {
|
if (city != null && tileInfo.isCityCenter()) {
|
||||||
if (cityButton == null) {
|
if (cityButton == null) {
|
||||||
cityButton = CityButton(city, CameraStageBaseScreen.skin)
|
cityButton = CityButton(city, this, CameraStageBaseScreen.skin)
|
||||||
addActor(cityButton)
|
addActor(cityButton)
|
||||||
toFront() // so this tile is rendered over neighboring tiles
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
@ -40,7 +40,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||||||
var bottomY = 0f
|
var bottomY = 0f
|
||||||
|
|
||||||
for (tileInfo in tileMap.values) {
|
for (tileInfo in tileMap.values) {
|
||||||
val tileGroup = WorldTileGroup(tileInfo)
|
val tileGroup = WorldTileGroup(worldScreen, tileInfo)
|
||||||
|
|
||||||
tileGroup.onClick{ onTileClicked(tileInfo)}
|
tileGroup.onClick{ onTileClicked(tileInfo)}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.unciv.ui.worldscreen.bottombar
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
|
@ -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.Image
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
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.MapUnit
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
@ -17,7 +18,9 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
private val promotionsTable = Table()
|
private val promotionsTable = Table()
|
||||||
private val unitDescriptionTable = Table(CameraStageBaseScreen.skin)
|
private val unitDescriptionTable = Table(CameraStageBaseScreen.skin)
|
||||||
var selectedUnit : MapUnit? = null
|
var selectedUnit : MapUnit? = null
|
||||||
|
var selectedCity : CityInfo? = null
|
||||||
var currentlyExecutingAction : String? = null
|
var currentlyExecutingAction : String? = null
|
||||||
|
var lastSelectedCityButton : Boolean = false
|
||||||
|
|
||||||
// This is so that not on every update(), we will update the unit table.
|
// 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?
|
// 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!=null) {
|
||||||
if (selectedUnit!!.civInfo != worldScreen.civInfo) { // The unit that was selected, was captured. It exists but is no longer ours.
|
if (selectedUnit!!.civInfo != worldScreen.civInfo) { // The unit that was selected, was captured. It exists but is no longer ours.
|
||||||
selectedUnit = null
|
selectedUnit = null
|
||||||
|
selectedCity = null
|
||||||
currentlyExecutingAction = null
|
currentlyExecutingAction = null
|
||||||
selectedUnitHasChanged = true
|
selectedUnitHasChanged = true
|
||||||
} else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists}
|
} else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists}
|
||||||
selectedUnit = null
|
selectedUnit = null
|
||||||
|
selectedCity = null
|
||||||
currentlyExecutingAction = null
|
currentlyExecutingAction = null
|
||||||
selectedUnitHasChanged = true
|
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!
|
if(unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions!
|
||||||
selectedUnitHasChanged = true
|
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 {
|
else {
|
||||||
separator.isVisible=false
|
separator.isVisible=false
|
||||||
unitNameLabel.setText("")
|
unitNameLabel.setText("")
|
||||||
@ -121,7 +137,21 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
selectedUnitHasChanged=false
|
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) {
|
fun tileSelected(selectedTile: TileInfo) {
|
||||||
|
if (lastSelectedCityButton) {
|
||||||
|
lastSelectedCityButton = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val previouslySelectedUnit = selectedUnit
|
val previouslySelectedUnit = selectedUnit
|
||||||
if(currentlyExecutingAction=="moveTo"){
|
if(currentlyExecutingAction=="moveTo"){
|
||||||
if(selectedUnit!!.movementAlgs()
|
if(selectedUnit!!.movementAlgs()
|
||||||
@ -137,12 +167,16 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.civInfo
|
else if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.civInfo
|
||||||
&& selectedUnit!=selectedTile.militaryUnit)
|
&& selectedUnit!=selectedTile.militaryUnit) {
|
||||||
selectedUnit = selectedTile.militaryUnit
|
selectedUnit = selectedTile.militaryUnit
|
||||||
|
selectedCity = null
|
||||||
|
}
|
||||||
|
|
||||||
else if (selectedTile.civilianUnit!=null && selectedTile.civilianUnit!!.civInfo == worldScreen.civInfo
|
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)
|
if(selectedUnit != previouslySelectedUnit)
|
||||||
selectedUnitHasChanged = true
|
selectedUnitHasChanged = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user