From b64c209218c761a45e0d07be71526b440d5f30ae Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 4 Dec 2019 19:47:18 +0200 Subject: [PATCH] Resolved #1361 - clicking on a unit's promotions now brings you to the promotion screen --- .../ui/pickerscreens/PromotionPickerScreen.kt | 22 +++++++++++-------- .../unciv/ui/utils/CameraStageBaseScreen.kt | 6 ----- .../unciv/ui/worldscreen/unit/UnitTable.kt | 18 ++++++++++++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt index c49d1173f8..3f5e81b9ed 100644 --- a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt @@ -14,13 +14,13 @@ import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.unit.Promotion import com.unciv.ui.utils.* -class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() { +class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() { private var selectedPromotion: Promotion? = null fun acceptPromotion(promotion: Promotion?) { - mapUnit.promotions.addPromotion(promotion!!.name) - if(mapUnit.promotions.canBePromoted()) game.setScreen(PromotionPickerScreen(mapUnit)) + unit.promotions.addPromotion(promotion!!.name) + if(unit.promotions.canBePromoted()) game.setScreen(PromotionPickerScreen(unit)) else game.setWorldScreen() dispose() game.worldScreen.shouldUpdate=true @@ -35,18 +35,21 @@ class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() { rightSideButton.onClick("promote") { acceptPromotion(selectedPromotion) } + val canBePromoted = unit.promotions.canBePromoted() + if(!canBePromoted) + rightSideButton.disable() val availablePromotionsGroup = VerticalGroup() availablePromotionsGroup.space(10f) - val unitType = mapUnit.type + val unitType = unit.type val promotionsForUnitType = GameBasics.UnitPromotions.values.filter { it.unitTypes.contains(unitType.toString()) } - val unitAvailablePromotions = mapUnit.promotions.getAvailablePromotions() + val unitAvailablePromotions = unit.promotions.getAvailablePromotions() for (promotion in promotionsForUnitType) { - if(promotion.name=="Heal Instantly" && mapUnit.health==100) continue + if(promotion.name=="Heal Instantly" && unit.health==100) continue val isPromotionAvailable = promotion in unitAvailablePromotions - val unitHasPromotion = mapUnit.promotions.promotions.contains(promotion.name) + val unitHasPromotion = unit.promotions.promotions.contains(promotion.name) val selectPromotionButton = Button(skin) selectPromotionButton.add(ImageGetter.getPromotionIcon(promotion.name)).size(30f).pad(10f) @@ -55,7 +58,8 @@ class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() { selectPromotionButton.onClick { selectedPromotion = promotion rightSideButton.setText(promotion.name.tr()) - if(isPromotionAvailable && !unitHasPromotion) rightSideButton.enable() + if(canBePromoted && isPromotionAvailable && !unitHasPromotion) + rightSideButton.enable() else rightSideButton.disable() // we translate it before it goes in to get uniques like "vs units in rough terrain" and after to get "vs city @@ -75,7 +79,7 @@ class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() { promotionTable.add(selectPromotionButton) - if(isPromotionAvailable) { + if(canBePromoted && isPromotionAvailable) { val pickNow = "Pick now!".toLabel() pickNow.setAlignment(Align.center) pickNow.onClick { diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index dffa431851..0c0cffaac9 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -62,8 +62,6 @@ open class CameraStageBaseScreen : Screen { } fun resetFonts(){ - val startTime = System.currentTimeMillis() - skin.get(TextButton.TextButtonStyle::class.java).font = Fonts().getFont(45).apply { data.setScale(20/45f) } skin.get(CheckBox.CheckBoxStyle::class.java).font= Fonts().getFont(45).apply { data.setScale(20/45f) } skin.get(Label.LabelStyle::class.java).apply { @@ -74,10 +72,6 @@ open class CameraStageBaseScreen : Screen { skin.get(SelectBox.SelectBoxStyle::class.java).font = Fonts().getFont(45).apply { data.setScale(20/45f) } skin.get(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts().getFont(45).apply { data.setScale(20/45f) } skin.get(CheckBox.CheckBoxStyle::class.java).fontColor= Color.WHITE - - - val resetFontsTime = System.currentTimeMillis() - startTime - println("Resetting fonts - "+resetFontsTime+"ms") } internal var batch: Batch = SpriteBatch() } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index 0fb77ee139..393b78e2ea 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -6,11 +6,13 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup +import com.unciv.UncivGame import com.unciv.logic.battle.CityCombatant import com.unciv.logic.city.CityInfo import com.unciv.logic.map.MapUnit import com.unciv.logic.map.TileInfo import com.unciv.models.gamebasics.tr +import com.unciv.ui.pickerscreens.PromotionPickerScreen import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.WorldScreen @@ -36,6 +38,8 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ touchable = Touchable.enabled background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) + promotionsTable.touchable=Touchable.enabled + add(VerticalGroup().apply { pad(5f) @@ -47,12 +51,14 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ }).left() add(Table().apply { - add(Table().apply { + val moveBetweenUnitsTable = Table().apply { add(prevIdleUnitButton) add(unitIconHolder) add(unitNameLabel).pad(5f) add(nextIdleUnitButton) - }).colspan(2).fill().row() + } + add(moveBetweenUnitsTable).colspan(2).fill().row() + separator= addSeparator().actor!! add(promotionsTable).colspan(2).row() add(unitDescriptionTable) @@ -167,7 +173,13 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ if(selectedUnit!=null) { unitIconHolder.add(UnitGroup(selectedUnit!!,30f)).pad(5f) for(promotion in selectedUnit!!.promotions.promotions) - promotionsTable.add(ImageGetter.getPromotionIcon(promotion))//.size(20f) + promotionsTable.add(ImageGetter.getPromotionIcon(promotion)) + + // Since Clear also clears the listeners, we need to re-add it every time + promotionsTable.onClick { + if(selectedUnit==null || selectedUnit!!.promotions.promotions.isEmpty()) return@onClick + UncivGame.Current.setScreen(PromotionPickerScreen(selectedUnit!!)) + } }