mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 17:28:57 +07:00
Resolved #1361 - clicking on a unit's promotions now brings you to the promotion screen
This commit is contained in:
@ -14,13 +14,13 @@ import com.unciv.models.gamebasics.tr
|
|||||||
import com.unciv.models.gamebasics.unit.Promotion
|
import com.unciv.models.gamebasics.unit.Promotion
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
|
|
||||||
class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() {
|
class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() {
|
||||||
private var selectedPromotion: Promotion? = null
|
private var selectedPromotion: Promotion? = null
|
||||||
|
|
||||||
|
|
||||||
fun acceptPromotion(promotion: Promotion?) {
|
fun acceptPromotion(promotion: Promotion?) {
|
||||||
mapUnit.promotions.addPromotion(promotion!!.name)
|
unit.promotions.addPromotion(promotion!!.name)
|
||||||
if(mapUnit.promotions.canBePromoted()) game.setScreen(PromotionPickerScreen(mapUnit))
|
if(unit.promotions.canBePromoted()) game.setScreen(PromotionPickerScreen(unit))
|
||||||
else game.setWorldScreen()
|
else game.setWorldScreen()
|
||||||
dispose()
|
dispose()
|
||||||
game.worldScreen.shouldUpdate=true
|
game.worldScreen.shouldUpdate=true
|
||||||
@ -35,18 +35,21 @@ class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() {
|
|||||||
rightSideButton.onClick("promote") {
|
rightSideButton.onClick("promote") {
|
||||||
acceptPromotion(selectedPromotion)
|
acceptPromotion(selectedPromotion)
|
||||||
}
|
}
|
||||||
|
val canBePromoted = unit.promotions.canBePromoted()
|
||||||
|
if(!canBePromoted)
|
||||||
|
rightSideButton.disable()
|
||||||
|
|
||||||
val availablePromotionsGroup = VerticalGroup()
|
val availablePromotionsGroup = VerticalGroup()
|
||||||
availablePromotionsGroup.space(10f)
|
availablePromotionsGroup.space(10f)
|
||||||
|
|
||||||
val unitType = mapUnit.type
|
val unitType = unit.type
|
||||||
val promotionsForUnitType = GameBasics.UnitPromotions.values.filter { it.unitTypes.contains(unitType.toString()) }
|
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) {
|
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 isPromotionAvailable = promotion in unitAvailablePromotions
|
||||||
val unitHasPromotion = mapUnit.promotions.promotions.contains(promotion.name)
|
val unitHasPromotion = unit.promotions.promotions.contains(promotion.name)
|
||||||
|
|
||||||
val selectPromotionButton = Button(skin)
|
val selectPromotionButton = Button(skin)
|
||||||
selectPromotionButton.add(ImageGetter.getPromotionIcon(promotion.name)).size(30f).pad(10f)
|
selectPromotionButton.add(ImageGetter.getPromotionIcon(promotion.name)).size(30f).pad(10f)
|
||||||
@ -55,7 +58,8 @@ class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() {
|
|||||||
selectPromotionButton.onClick {
|
selectPromotionButton.onClick {
|
||||||
selectedPromotion = promotion
|
selectedPromotion = promotion
|
||||||
rightSideButton.setText(promotion.name.tr())
|
rightSideButton.setText(promotion.name.tr())
|
||||||
if(isPromotionAvailable && !unitHasPromotion) rightSideButton.enable()
|
if(canBePromoted && isPromotionAvailable && !unitHasPromotion)
|
||||||
|
rightSideButton.enable()
|
||||||
else rightSideButton.disable()
|
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
|
// 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)
|
promotionTable.add(selectPromotionButton)
|
||||||
|
|
||||||
|
|
||||||
if(isPromotionAvailable) {
|
if(canBePromoted && isPromotionAvailable) {
|
||||||
val pickNow = "Pick now!".toLabel()
|
val pickNow = "Pick now!".toLabel()
|
||||||
pickNow.setAlignment(Align.center)
|
pickNow.setAlignment(Align.center)
|
||||||
pickNow.onClick {
|
pickNow.onClick {
|
||||||
|
@ -62,8 +62,6 @@ open class CameraStageBaseScreen : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun resetFonts(){
|
fun resetFonts(){
|
||||||
val startTime = System.currentTimeMillis()
|
|
||||||
|
|
||||||
skin.get(TextButton.TextButtonStyle::class.java).font = Fonts().getFont(45).apply { data.setScale(20/45f) }
|
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(CheckBox.CheckBoxStyle::class.java).font= Fonts().getFont(45).apply { data.setScale(20/45f) }
|
||||||
skin.get(Label.LabelStyle::class.java).apply {
|
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).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(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts().getFont(45).apply { data.setScale(20/45f) }
|
||||||
skin.get(CheckBox.CheckBoxStyle::class.java).fontColor= Color.WHITE
|
skin.get(CheckBox.CheckBoxStyle::class.java).fontColor= Color.WHITE
|
||||||
|
|
||||||
|
|
||||||
val resetFontsTime = System.currentTimeMillis() - startTime
|
|
||||||
println("Resetting fonts - "+resetFontsTime+"ms")
|
|
||||||
}
|
}
|
||||||
internal var batch: Batch = SpriteBatch()
|
internal var batch: Batch = SpriteBatch()
|
||||||
}
|
}
|
||||||
|
@ -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.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
|
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
|
||||||
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.battle.CityCombatant
|
import com.unciv.logic.battle.CityCombatant
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.map.MapUnit
|
import com.unciv.logic.map.MapUnit
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
|
import com.unciv.ui.pickerscreens.PromotionPickerScreen
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
|
|
||||||
@ -36,6 +38,8 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
touchable = Touchable.enabled
|
touchable = Touchable.enabled
|
||||||
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||||
|
|
||||||
|
promotionsTable.touchable=Touchable.enabled
|
||||||
|
|
||||||
add(VerticalGroup().apply {
|
add(VerticalGroup().apply {
|
||||||
pad(5f)
|
pad(5f)
|
||||||
|
|
||||||
@ -47,12 +51,14 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
}).left()
|
}).left()
|
||||||
|
|
||||||
add(Table().apply {
|
add(Table().apply {
|
||||||
add(Table().apply {
|
val moveBetweenUnitsTable = Table().apply {
|
||||||
add(prevIdleUnitButton)
|
add(prevIdleUnitButton)
|
||||||
add(unitIconHolder)
|
add(unitIconHolder)
|
||||||
add(unitNameLabel).pad(5f)
|
add(unitNameLabel).pad(5f)
|
||||||
add(nextIdleUnitButton)
|
add(nextIdleUnitButton)
|
||||||
}).colspan(2).fill().row()
|
}
|
||||||
|
add(moveBetweenUnitsTable).colspan(2).fill().row()
|
||||||
|
|
||||||
separator= addSeparator().actor!!
|
separator= addSeparator().actor!!
|
||||||
add(promotionsTable).colspan(2).row()
|
add(promotionsTable).colspan(2).row()
|
||||||
add(unitDescriptionTable)
|
add(unitDescriptionTable)
|
||||||
@ -167,7 +173,13 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
if(selectedUnit!=null) {
|
if(selectedUnit!=null) {
|
||||||
unitIconHolder.add(UnitGroup(selectedUnit!!,30f)).pad(5f)
|
unitIconHolder.add(UnitGroup(selectedUnit!!,30f)).pad(5f)
|
||||||
for(promotion in selectedUnit!!.promotions.promotions)
|
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!!))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user