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