Fix unit promotions shortcut in UnitTable (#4335)

This commit is contained in:
SomeTroglodyte 2021-07-02 09:07:20 +02:00 committed by GitHub
parent 43ff2ea5f9
commit 4e36773cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
private val nextIdleUnitButton = IdleUnitButton(this,worldScreen.mapHolder,false)
private val unitIconHolder = Table()
private val unitNameLabel = "".toLabel()
private val unitIconNameGroup = Table()
private val promotionsTable = Table()
private val unitDescriptionTable = Table(CameraStageBaseScreen.skin)
@ -71,8 +72,10 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
add(Table().apply {
val moveBetweenUnitsTable = Table().apply {
add(prevIdleUnitButton)
add(unitIconHolder)
add(unitNameLabel).pad(5f)
unitIconNameGroup.add(unitIconHolder)
unitIconNameGroup.add(unitNameLabel).pad(5f)
unitIconNameGroup.touchable = Touchable.enabled
add(unitIconNameGroup)
add(nextIdleUnitButton)
}
add(moveBetweenUnitsTable).colspan(2).fill().row()
@ -82,11 +85,10 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
add(unitDescriptionTable)
touchable = Touchable.enabled
onClick {
selectedUnit?.currentTile?.position?.let {
if ( !worldScreen.mapHolder.setCenterPosition(it, false, false) && selectedUnit != null ) {
worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet, CivilopediaCategories.Unit, selectedUnit!!.name))
}
}
val position = selectedUnit?.currentTile?.position
?: selectedCity?.location
if (position != null)
worldScreen.mapHolder.setCenterPosition(position, false, false)
}
}).expand()
@ -107,8 +109,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
if (prevIdleUnitButton.hasIdleUnits()) { // more efficient to do this check once for both
prevIdleUnitButton.enable()
nextIdleUnitButton.enable()
}
else{
} else {
prevIdleUnitButton.disable()
nextIdleUnitButton.disable()
}
@ -123,6 +124,10 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
unitNameLabel.setText(nameLabelText)
selectedUnitHasChanged = true // We need to reload the health bar of the unit in the icon - happens e.g. when picking the Heal Instantly promotion
}
unitIconNameGroup.clearListeners()
unitIconNameGroup.onClick {
worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet, CivilopediaCategories.Unit, unit.name))
}
unitDescriptionTable.clear()
unitDescriptionTable.defaults().pad(2f)
@ -157,8 +162,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
if (unit.promotions.promotions.size != promotionsTable.children.size) // The unit has been promoted! Reload promotions!
selectedUnitHasChanged = true
}
else { // multiple selected units
} else { // multiple selected units
unitNameLabel.setText("")
unitDescriptionTable.clear()
}
@ -179,8 +183,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
unitDescriptionTable.add(CityCombatant(city).getAttackingStrength().toString()).row()
selectedUnitHasChanged = true
}
else {
} else {
isVisible = false
}
@ -193,6 +196,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
if (selectedUnit != null) {
if (selectedUnits.size == 1) { // single selected unit
unitIconHolder.add(UnitGroup(selectedUnit!!, 30f)).pad(5f)
for (promotion in selectedUnit!!.promotions.promotions.sorted())
promotionsTable.add(ImageGetter.getPromotionIcon(promotion))
@ -201,8 +205,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
if (selectedUnit == null || selectedUnit!!.promotions.promotions.isEmpty()) return@onClick
UncivGame.Current.setScreen(PromotionPickerScreen(selectedUnit!!))
}
}
else { // multiple selected units
} else { // multiple selected units
for (unit in selectedUnits)
unitIconHolder.add(UnitGroup(unit, 30f)).pad(5f)
}