From e0961e1b0bf4ae217c125cfbc97564b28b84f15a Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 22 Jun 2018 10:41:53 +0300 Subject: [PATCH] Unit table updates texts even if the unit hasn't changed --- android/build.gradle | 4 +- .../com/unciv/ui/worldscreen/WorldScreen.kt | 1 - .../unciv/ui/worldscreen/unit/UnitTable.kt | 43 +++++++++++-------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 07ca93b58e..02baa7877c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 89 - versionName "2.5.4.2" + versionCode 91 + versionName "2.5.5.2" } buildTypes { release { diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index e9d6d287db..2f3cd3ced7 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -132,7 +132,6 @@ class WorldScreen : CameraStageBaseScreen() { // but the main thread does other stuff, including showing tutorials which guess what? Changes the game data // BOOM! Exception! // That's why this needs to be after the game is saved. - bottomBar.unitTable.shouldUpdateVisually=true shouldUpdate=true nextTurnButton.setText("Next turn".tr()) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index 86f38cc34d..878a0a5333 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -19,7 +19,7 @@ class UnitTable(val worldScreen: WorldScreen) : 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? - var shouldUpdateVisually = false + var selectedUnitHasChanged = false init { 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. selectedUnit = null currentlyExecutingAction = null - shouldUpdateVisually = true + selectedUnitHasChanged = true } else { try { @@ -47,13 +47,11 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ } catch (ex: Exception) { // The unit that was there no longer exists} selectedUnit = null currentlyExecutingAction = null - shouldUpdateVisually=true + selectedUnitHasChanged=true } } } - if(!shouldUpdateVisually) return - if(prevIdleUnitButton.getTilesWithIdleUnits().isNotEmpty()) { // more efficient to do this check once for both prevIdleUnitButton.enable() nextIdleUnitButton.enable() @@ -63,40 +61,49 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ nextIdleUnitButton.disable() } - promotionsTable.clear() - unitDescriptionLabel.clearListeners() - - if(selectedUnit!=null) { + if(selectedUnit!=null) { // set texts - this is valid even when it's the same unit, because movement points and health change val unit = selectedUnit!! var nameLabelText = unit.name if(unit.health<100) nameLabelText+=" ("+unit.health+")" unitNameLabel.setText(nameLabelText) - for(promotion in unit.promotions.promotions) - promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f) - 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 - } + if (unit.getBaseUnit().rangedStrength!=0) 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) unitLabelText+="\n+"+unit.getFortificationTurns()*20+"% fortification" 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 { unitNameLabel.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() - shouldUpdateVisually=false + selectedUnitHasChanged=false } fun tileSelected(selectedTile: TileInfo) { @@ -123,7 +130,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ selectedUnit = selectedTile.civilianUnit if(selectedUnit != previouslySelectedUnit) - shouldUpdateVisually = true + selectedUnitHasChanged = true } }