Unit table updates texts even if the unit hasn't changed

This commit is contained in:
Yair Morgenstern 2018-06-22 10:41:53 +03:00
parent c1d196d38c
commit e0961e1b0b
3 changed files with 27 additions and 21 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game" applicationId "com.unciv.game"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 26 targetSdkVersion 26
versionCode 89 versionCode 91
versionName "2.5.4.2" versionName "2.5.5.2"
} }
buildTypes { buildTypes {
release { release {

View File

@ -132,7 +132,6 @@ class WorldScreen : CameraStageBaseScreen() {
// but the main thread does other stuff, including showing tutorials which guess what? Changes the game data // but the main thread does other stuff, including showing tutorials which guess what? Changes the game data
// BOOM! Exception! // BOOM! Exception!
// That's why this needs to be after the game is saved. // That's why this needs to be after the game is saved.
bottomBar.unitTable.shouldUpdateVisually=true
shouldUpdate=true shouldUpdate=true
nextTurnButton.setText("Next turn".tr()) nextTurnButton.setText("Next turn".tr())

View File

@ -19,7 +19,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
// 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?
var shouldUpdateVisually = false var selectedUnitHasChanged = false
init { init {
pad(5f) pad(5f)
@ -39,7 +39,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
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
currentlyExecutingAction = null currentlyExecutingAction = null
shouldUpdateVisually = true selectedUnitHasChanged = true
} }
else { else {
try { try {
@ -47,13 +47,11 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
} catch (ex: Exception) { // The unit that was there no longer exists} } catch (ex: Exception) { // The unit that was there no longer exists}
selectedUnit = null selectedUnit = null
currentlyExecutingAction = null currentlyExecutingAction = null
shouldUpdateVisually=true selectedUnitHasChanged=true
} }
} }
} }
if(!shouldUpdateVisually) return
if(prevIdleUnitButton.getTilesWithIdleUnits().isNotEmpty()) { // more efficient to do this check once for both if(prevIdleUnitButton.getTilesWithIdleUnits().isNotEmpty()) { // more efficient to do this check once for both
prevIdleUnitButton.enable() prevIdleUnitButton.enable()
nextIdleUnitButton.enable() nextIdleUnitButton.enable()
@ -63,40 +61,49 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
nextIdleUnitButton.disable() nextIdleUnitButton.disable()
} }
promotionsTable.clear() if(selectedUnit!=null) { // set texts - this is valid even when it's the same unit, because movement points and health change
unitDescriptionLabel.clearListeners()
if(selectedUnit!=null) {
val unit = selectedUnit!! val unit = selectedUnit!!
var nameLabelText = unit.name var nameLabelText = unit.name
if(unit.health<100) nameLabelText+=" ("+unit.health+")" if(unit.health<100) nameLabelText+=" ("+unit.health+")"
unitNameLabel.setText(nameLabelText) unitNameLabel.setText(nameLabelText)
for(promotion in unit.promotions.promotions)
promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f)
var unitLabelText = "Movement".tr()+": " + unit.getMovementString() var unitLabelText = "Movement".tr()+": " + unit.getMovementString()
if (unit.getBaseUnit().unitType != UnitType.Civilian) { if (unit.getBaseUnit().unitType != UnitType.Civilian)
unitLabelText += "\n"+"Strength".tr()+": " + unit.getBaseUnit().strength unitLabelText += "\n"+"Strength".tr()+": " + unit.getBaseUnit().strength
}
if (unit.getBaseUnit().rangedStrength!=0) if (unit.getBaseUnit().rangedStrength!=0)
unitLabelText += "\n"+"Ranged strength".tr()+": "+unit.getBaseUnit().rangedStrength unitLabelText += "\n"+"Ranged strength".tr()+": "+unit.getBaseUnit().rangedStrength
unitLabelText += "\n"+"XP".tr()+": "+unit.promotions.XP+"/"+unit.promotions.xpForNextPromotion() if (unit.getBaseUnit().unitType != UnitType.Civilian)
unitLabelText += "\n"+"XP".tr()+": "+unit.promotions.XP+"/"+unit.promotions.xpForNextPromotion()
if(unit.isFortified() && unit.getFortificationTurns()>0) if(unit.isFortified() && unit.getFortificationTurns()>0)
unitLabelText+="\n+"+unit.getFortificationTurns()*20+"% fortification" unitLabelText+="\n+"+unit.getFortificationTurns()*20+"% fortification"
unitDescriptionLabel.setText(unitLabelText) unitDescriptionLabel.setText(unitLabelText)
unitDescriptionLabel.addClickListener { worldScreen.tileMapHolder.setCenterPosition(unit.getTile().position) }
if(unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions!
selectedUnitHasChanged = true
} }
else { else {
unitNameLabel.setText("") unitNameLabel.setText("")
unitDescriptionLabel.setText("") unitDescriptionLabel.setText("")
} }
if(!selectedUnitHasChanged) return
promotionsTable.clear()
unitDescriptionLabel.clearListeners()
if(selectedUnit!=null) {
for(promotion in selectedUnit!!.promotions.promotions)
promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f)
unitDescriptionLabel.addClickListener { worldScreen.tileMapHolder.setCenterPosition(selectedUnit!!.getTile().position) }
}
pack() pack()
shouldUpdateVisually=false selectedUnitHasChanged=false
} }
fun tileSelected(selectedTile: TileInfo) { fun tileSelected(selectedTile: TileInfo) {
@ -123,7 +130,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
selectedUnit = selectedTile.civilianUnit selectedUnit = selectedTile.civilianUnit
if(selectedUnit != previouslySelectedUnit) if(selectedUnit != previouslySelectedUnit)
shouldUpdateVisually = true selectedUnitHasChanged = true
} }
} }