diff --git a/core/src/com/unciv/models/UnitAction.kt b/core/src/com/unciv/models/UnitAction.kt index 04ba16f560..cf1236dc6e 100644 --- a/core/src/com/unciv/models/UnitAction.kt +++ b/core/src/com/unciv/models/UnitAction.kt @@ -1,42 +1,144 @@ package com.unciv.models +import com.badlogic.gdx.Input +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.scenes.scene2d.Actor +import com.unciv.ui.utils.KeyCharAndCode +import com.unciv.ui.utils.ImageGetter +import com.unciv.Constants +import com.unciv.models.translations.equalsPlaceholderText +import com.unciv.models.translations.getPlaceholderParameters + + +/** Unit Actions - class - carries dynamic data and actual execution. + * Static properties are in [UnitActionType]. + * Note this is for the buttons offering actions, not the ongoing action stored with a [MapUnit][com.unciv.logic.map.MapUnit] + */ data class UnitAction( val type: UnitActionType, val title: String = type.value, val isCurrentAction: Boolean = false, - val uncivSound: UncivSound = UncivSound.Click, + val uncivSound: UncivSound = type.uncivSound, val action: (() -> Unit)? = null -) +) { + fun getIcon(): Actor { + if (type.imageGetter != null) return type.imageGetter.invoke() + return when { + type == UnitActionType.Upgrade + && title.equalsPlaceholderText("Upgrade to [] ([] gold)") -> { + ImageGetter.getUnitIcon(title.getPlaceholderParameters()[0]) + } + type == UnitActionType.Create + && title.equalsPlaceholderText("Create []") -> { + ImageGetter.getImprovementIcon(title.getPlaceholderParameters()[0]) + } + type == UnitActionType.SpreadReligion + && title.equalsPlaceholderText("Spread []") -> { + val religionName = title.getPlaceholderParameters()[0] + ImageGetter.getReligionIcon( + if (ImageGetter.religionIconExists(religionName)) religionName else "Pantheon" + ).apply { color = Color.BLACK } + } + type == UnitActionType.Fortify || type == UnitActionType.FortifyUntilHealed -> { + val match = fortificationRegex.matchEntire(title) + val percentFortified = match?.groups?.get(1)?.value?.toInt() ?: 0 + ImageGetter.getImage("OtherIcons/Shield").apply { + color = Color.BLACK.cpy().lerp(Color.GREEN, percentFortified / 80f) + } + } + else -> ImageGetter.getImage("OtherIcons/Star") + } + } + companion object { + private val fortificationRegex = Regex(""".* (\d+)%""") + } +} -enum class UnitActionType(val value: String) { - SwapUnits("Swap units"), - Automate("Automate"), - StopAutomation("Stop automation"), - StopMovement("Stop movement"), - Sleep("Sleep"), - SleepUntilHealed("Sleep until healed"), - Fortify("Fortify"), - FortifyUntilHealed("Fortify until healed"), - Explore("Explore"), - StopExploration("Stop exploration"), - Promote("Promote"), - Upgrade("Upgrade"), - Pillage("Pillage"), - Paradrop("Paradrop"), - SetUp("Set up"), - FoundCity("Found city"), - ConstructImprovement("Construct improvement"), +/** Unit Actions - generic enum with static properties + * + * @param value _default_ label to display, can be overridden in UnitAction instantiation + * @param imageGetter optional lambda to get an Icon - `null` if icon is dependent on outside factors and needs special handling + * @param key keyboard binding - can be a [KeyCharAndCode], a [Char], or omitted. + * @param uncivSound _default_ sound, can be overridden in UnitAction instantiation + */ +enum class UnitActionType( + val value: String, + val imageGetter: (()-> Actor)?, + val key: KeyCharAndCode, + val uncivSound: UncivSound = UncivSound.Click +) { + SwapUnits("Swap units", + { ImageGetter.getImage("OtherIcons/Swap") }, 'y'), + Automate("Automate", + { ImageGetter.getUnitIcon("Great Engineer") }, 'm'), + StopAutomation("Stop automation", + { ImageGetter.getImage("OtherIcons/Stop") }, 'm'), + StopMovement("Stop movement", + { imageGetStopMove() }, '.'), + Sleep("Sleep", + { ImageGetter.getImage("OtherIcons/Sleep") }, 'f'), + SleepUntilHealed("Sleep until healed", + { ImageGetter.getImage("OtherIcons/Sleep") }, 'h'), + Fortify("Fortify", + null, 'f', UncivSound.Fortify), + FortifyUntilHealed("Fortify until healed", + null, 'h', UncivSound.Fortify), + Explore("Explore", + { ImageGetter.getUnitIcon("Scout") }, 'x'), + StopExploration("Stop exploration", + { ImageGetter.getImage("OtherIcons/Stop") }, 'x'), + Promote("Promote", + { imageGetPromote() }, 'o', UncivSound.Promote), + Upgrade("Upgrade", + null, 'u', UncivSound.Upgrade), + Pillage("Pillage", + { ImageGetter.getImage("OtherIcons/Pillage") }, 'p'), + Paradrop("Paradrop", + { ImageGetter.getUnitIcon("Paratrooper") }, 'p'), + SetUp("Set up", + { ImageGetter.getUnitIcon("Catapult") }, 't', UncivSound.Setup), + FoundCity("Found city", + { ImageGetter.getUnitIcon(Constants.settler) }, 'c', UncivSound.Silent), + ConstructImprovement("Construct improvement", + { ImageGetter.getUnitIcon(Constants.worker) }, 'i'), // Deprecated since 3.15.4 - ConstructRoad("Construct road"), + ConstructRoad("Construct road", {ImageGetter.getImprovementIcon("Road")}, 'r'), // - Create("Create"), - SpreadReligion("Spread Religion"), - HurryResearch("Hurry Research"), - StartGoldenAge("Start Golden Age"), - HurryWonder("Hurry Wonder"), - ConductTradeMission("Conduct Trade Mission"), - FoundReligion("Found a Religion"), - DisbandUnit("Disband unit"), - GiftUnit("Gift unit"), - ShowAdditionalActions("Show more"), -} \ No newline at end of file + Create("Create", + null, 'i', UncivSound.Chimes), + SpreadReligion("Spread Religion", + null, 'g', UncivSound.Choir), + HurryResearch("Hurry Research", + { ImageGetter.getUnitIcon("Great Scientist") }, 'g', UncivSound.Chimes), + StartGoldenAge("Start Golden Age", + { ImageGetter.getUnitIcon("Great Artist") }, 'g', UncivSound.Chimes), + HurryWonder("Hurry Wonder", + { ImageGetter.getUnitIcon("Great Engineer") }, 'g', UncivSound.Chimes), + ConductTradeMission("Conduct Trade Mission", + { ImageGetter.getUnitIcon("Great Merchant") }, 'g', UncivSound.Chimes), + FoundReligion("Found a Religion", + { ImageGetter.getUnitIcon("Great Prophet") }, 'g', UncivSound.Choir), + DisbandUnit("Disband unit", + { ImageGetter.getImage("OtherIcons/DisbandUnit") }, KeyCharAndCode.DEL), + GiftUnit("Gift unit", + { ImageGetter.getImage("OtherIcons/Present") }, UncivSound.Silent), + ShowAdditionalActions("Show more", + { imageGetShowMore() }, KeyCharAndCode(Input.Keys.PAGE_DOWN)), + HideAdditionalActions("Back", + { imageGetHideMore() }, KeyCharAndCode(Input.Keys.PAGE_UP)), + ; + + // Allow shorter initializations + constructor(value: String, imageGetter: (() -> Actor)?, key: Char, uncivSound: UncivSound = UncivSound.Click) + : this(value, imageGetter, KeyCharAndCode(key), uncivSound) + constructor(value: String, imageGetter: (() -> Actor)?, uncivSound: UncivSound = UncivSound.Click) + : this(value, imageGetter, KeyCharAndCode.UNKNOWN, uncivSound) + + companion object { + // readability factories + private fun imageGetStopMove() = ImageGetter.getStatIcon("Movement").apply { color = Color.RED } + private fun imageGetPromote() = ImageGetter.getImage("OtherIcons/Star").apply { color = Color.GOLD } + private fun imageGetShowMore() = ImageGetter.getImage("OtherIcons/ArrowRight").apply { color = Color.BLACK } + private fun imageGetHideMore() = ImageGetter.getImage("OtherIcons/ArrowLeft").apply { color = Color.BLACK } + } +} diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index 89b2fcbf7d..25339df5d8 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -291,6 +291,7 @@ object ImageGetter { return circle } + fun religionIconExists(iconName: String) = imageExists("ReligionIcons/$iconName") fun getReligionIcon(iconName: String): Image { return getImage("ReligionIcons/$iconName") } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index ef7bf4e53a..67bee77fd6 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -156,7 +156,7 @@ object UnitActions { if (!unit.hasUnique("Founds a new city") || tile.isWater) return null if (unit.currentMovement <= 0 || tile.getTilesInDistance(3).any { it.isCityCenter() }) - return UnitAction(UnitActionType.FoundCity, uncivSound = UncivSound.Silent, action = null) + return UnitAction(UnitActionType.FoundCity, action = null) val foundAction = { UncivGame.Current.settings.addCompletedTutorialTask("Found city") @@ -168,14 +168,14 @@ object UnitActions { } if (unit.civInfo.playerType == PlayerType.AI) - return UnitAction(UnitActionType.FoundCity, uncivSound = UncivSound.Silent, action = foundAction) + return UnitAction(UnitActionType.FoundCity, action = foundAction) return UnitAction( type = UnitActionType.FoundCity, uncivSound = UncivSound.Chimes, action = { // check if we would be breaking a promise - val leaders = TestPromiseNotToSettle(unit.civInfo, tile) + val leaders = testPromiseNotToSettle(unit.civInfo, tile) if (leaders == null) foundAction() else { @@ -193,7 +193,7 @@ object UnitActions { * @param tile The tile where the new city would go * @return null if no promises broken, else a String listing the leader(s) we would p* off. */ - private fun TestPromiseNotToSettle(civInfo: CivilizationInfo, tile: TileInfo): String? { + private fun testPromiseNotToSettle(civInfo: CivilizationInfo, tile: TileInfo): String? { val brokenPromises = HashSet() for (otherCiv in civInfo.getKnownCivs().filter { it.isMajorCiv() && !civInfo.isAtWarWith(it) }) { val diplomacyManager = otherCiv.getDiplomacyManager(civInfo) @@ -211,7 +211,6 @@ object UnitActions { if (unit.isCivilian() || !unit.promotions.canBePromoted()) return // promotion does not consume movement points, so we can do it always actionList += UnitAction(UnitActionType.Promote, - uncivSound = UncivSound.Promote, action = { UncivGame.Current.setScreen(PromotionPickerScreen(unit)) }) @@ -222,7 +221,6 @@ object UnitActions { val isSetUp = unit.action == "Set Up" actionList += UnitAction(UnitActionType.SetUp, isCurrentAction = isSetUp, - uncivSound = UncivSound.Setup, action = { unit.action = Constants.unitActionSetUp unit.useMovementPoints(1f) @@ -251,7 +249,7 @@ object UnitActions { private fun addPillageAction(unit: MapUnit, actionList: ArrayList, worldScreen: WorldScreen) { val pillageAction = getPillageAction(unit) - if (pillageAction == null) return + ?: return if (pillageAction.action == null) actionList += UnitAction(UnitActionType.Pillage, action = null) else actionList += UnitAction(type = UnitActionType.Pillage) { @@ -268,7 +266,7 @@ object UnitActions { return UnitAction(UnitActionType.Pillage, action = { - // http://well-of-souls.com/civ/civ5_improvements.html says that naval improvements are destroyed upon pilllage + // http://well-of-souls.com/civ/civ5_improvements.html says that naval improvements are destroyed upon pillage // and I can't find any other sources so I'll go with that if (tile.isLand) { tile.improvementInProgress = tile.improvement @@ -309,23 +307,22 @@ object UnitActions { return UnitAction(UnitActionType.Upgrade, title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)", - uncivSound = UncivSound.Upgrade, action = { unit.civInfo.addGold(-goldCostOfUpgrade) val unitTile = unit.getTile() unit.destroy() - val newunit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)!! - newunit.health = unit.health - newunit.promotions = unit.promotions - newunit.instanceName = unit.instanceName + val newUnit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)!! + newUnit.health = unit.health + newUnit.promotions = unit.promotions + newUnit.instanceName = unit.instanceName - for (promotion in newunit.baseUnit.promotions) - if (promotion !in newunit.promotions.promotions) - newunit.promotions.addPromotion(promotion, true) + for (promotion in newUnit.baseUnit.promotions) + if (promotion !in newUnit.promotions.promotions) + newUnit.promotions.addPromotion(promotion, true) - newunit.updateUniques() - newunit.updateVisibleTiles() - newunit.currentMovement = 0f + newUnit.updateUniques() + newUnit.updateVisibleTiles() + newUnit.currentMovement = 0f }.takeIf { unit.civInfo.gold >= goldCostOfUpgrade && !unit.isEmbarked() && unit.currentMovement == unit.getMaxMovement().toFloat() @@ -367,7 +364,6 @@ object UnitActions { if (unit.currentMovement > 0) for (unique in unit.getUniques()) when (unique.placeholderText) { "Can hurry technology research" -> { actionList += UnitAction(UnitActionType.HurryResearch, - uncivSound = UncivSound.Chimes, action = { unit.civInfo.tech.addScience(unit.civInfo.tech.getScienceFromGreatScientist()) addGoldPerGreatPersonUsage(unit.civInfo) @@ -378,7 +374,6 @@ object UnitActions { "Can start an []-turn golden age" -> { val turnsToGoldenAge = unique.params[0].toInt() actionList += UnitAction(UnitActionType.StartGoldenAge, - uncivSound = UncivSound.Chimes, action = { unit.civInfo.goldenAges.enterGoldenAge(turnsToGoldenAge) addGoldPerGreatPersonUsage(unit.civInfo) @@ -394,7 +389,6 @@ object UnitActions { else currentConstruction.isAnyWonder() } actionList += UnitAction(UnitActionType.HurryWonder, - uncivSound = UncivSound.Chimes, action = { tile.getCity()!!.cityConstructions.apply { addProductionPoints(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) @@ -410,7 +404,6 @@ object UnitActions { && tile.owningCity?.civInfo?.isAtWarWith(unit.civInfo) == false val influenceEarned = unique.params[0].toInt() actionList += UnitAction(UnitActionType.ConductTradeMission, - uncivSound = UncivSound.Chimes, action = { // http://civilization.wikia.com/wiki/Great_Merchant_(Civ5) var goldEarned = ((350 + 50 * unit.civInfo.getEraNumber()) * unit.civInfo.gameInfo.gameParameters.gameSpeed.modifier).toInt() @@ -432,7 +425,6 @@ object UnitActions { if (!unit.hasUnique("May found a religion")) return // should later also include enhance religion if (!unit.civInfo.religionManager.mayUseGreatProphetAtAll(unit)) return actionList += UnitAction(UnitActionType.FoundReligion, - uncivSound = UncivSound.Choir, action = { addGoldPerGreatPersonUsage(unit.civInfo) unit.civInfo.religionManager.useGreatProphet(unit) @@ -450,7 +442,6 @@ object UnitActions { val city = tile.getCity() actionList += UnitAction(UnitActionType.SpreadReligion, title = "Spread [${unit.religion!!}]", - uncivSound = UncivSound.Choir, action = { unit.abilityUsedCount["Religion Spread"] = unit.abilityUsedCount["Religion Spread"]!! + 1 city!!.religion[unit.religion!!] = 100 @@ -471,10 +462,9 @@ object UnitActions { for (unique in uniquesToCheck) { val improvementName = unique.params[0] val improvement = tile.ruleset.tileImprovements[improvementName] - if (improvement == null) continue + ?: continue finalActions += UnitAction(UnitActionType.Create, title = "Create [$improvementName]", - uncivSound = UncivSound.Chimes, action = { val unitTile = unit.getTile() for (terrainFeature in tile.terrainFeatures.filter { unitTile.ruleset.tileImprovements.containsKey("Remove $it") }) @@ -575,14 +565,12 @@ object UnitActions { if (isDamaged && !showingAdditionalActions) actionList += UnitAction(UnitActionType.FortifyUntilHealed, - title = UnitActionType.FortifyUntilHealed.value, action = { unit.fortifyUntilHealed() }.takeIf { !unit.isFortifyingUntilHealed() } ) else if (isDamaged || !showingAdditionalActions) actionList += UnitAction(UnitActionType.Fortify, - uncivSound = UncivSound.Fortify, action = { unit.fortify() }.takeIf { !isFortified } @@ -630,7 +618,7 @@ object UnitActions { // We need to be in another civs territory. if (recipient == null || recipient.isCurrentPlayer()) return null - // City States only take miliary units (and GPs for certain civs) + // City States only take military units (and GPs for certain civs) if (recipient.isCityState()) { if (unit.isGreatPerson()) { // Do we have a unique ability to gift GPs? @@ -643,7 +631,7 @@ object UnitActions { else if (!tile.isFriendlyTerritory(unit.civInfo)) return null if (unit.currentMovement <= 0) - return UnitAction(UnitActionType.GiftUnit, uncivSound = UncivSound.Silent, action = null) + return UnitAction(UnitActionType.GiftUnit, action = null) val giftAction = { if (recipient.isCityState()) { @@ -667,12 +655,12 @@ object UnitActions { UncivGame.Current.worldScreen.shouldUpdate = true } - return UnitAction(UnitActionType.GiftUnit, uncivSound = UncivSound.Silent, action = giftAction) + return UnitAction(UnitActionType.GiftUnit, action = giftAction) } private fun addToggleActionsAction(unit: MapUnit, actionList: ArrayList, unitTable: UnitTable) { - actionList += UnitAction(UnitActionType.ShowAdditionalActions, - title = if (unit.showAdditionalActions) "Back" else "Show more", + actionList += UnitAction( + type = if (unit.showAdditionalActions) UnitActionType.HideAdditionalActions else UnitActionType.ShowAdditionalActions, action = { unit.showAdditionalActions = !unit.showAdditionalActions unitTable.update() diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt index 2436ed2a85..79ef44ad5a 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt @@ -1,87 +1,19 @@ package com.unciv.ui.worldscreen.unit -import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Table -import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.map.MapUnit -import com.unciv.logic.map.RoadStatus import com.unciv.models.UnitAction -import com.unciv.models.translations.equalsPlaceholderText -import com.unciv.models.translations.getPlaceholderParameters import com.unciv.ui.utils.* import com.unciv.ui.utils.KeyPressDispatcher.Companion.keyboardAvailable import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip import com.unciv.ui.worldscreen.WorldScreen import kotlin.concurrent.thread -private data class UnitIconAndKey(val icon: Actor, var key: KeyCharAndCode = KeyCharAndCode.UNKNOWN) { - constructor(icon: Actor, key: Char) : this(icon, KeyCharAndCode(key)) -} - class UnitActionsTable(val worldScreen: WorldScreen) : Table() { - - private fun getIconAndKeyForUnitAction(unitAction: String): UnitIconAndKey { - when { - unitAction.equalsPlaceholderText("Upgrade to [] ([] gold)") -> { - // Regexplaination: start with a [, take as many non-] chars as you can, until you reach a ]. - // What you find between the first [ and the first ] that comes after it, will be group no. 0 - val unitToUpgradeTo = unitAction.getPlaceholderParameters()[0] - return UnitIconAndKey(ImageGetter.getUnitIcon(unitToUpgradeTo), 'u') - } - unitAction.equalsPlaceholderText("Create []") -> { - // Regexplaination: start with a [, take as many non-] chars as you can, until you reach a ]. - // What you find between the first [ and the first ] that comes after it, will be group no. 0 - val improvementName = unitAction.getPlaceholderParameters()[0] - return UnitIconAndKey(ImageGetter.getImprovementIcon(improvementName), 'i') - } - unitAction.equalsPlaceholderText("Spread []") -> { - // This should later include icons for the different religions. For now, just use the great prophet icon - return UnitIconAndKey(ImageGetter.getUnitIcon("Great Prophet"), 'g') - } - else -> when (unitAction) { - "Sleep" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Sleep"), 'f') - "Sleep until healed" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Sleep"), 'h') - "Fortify" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Shield").apply { color = Color.BLACK }, 'f') - "Fortify until healed" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Shield").apply { color = Color.BLACK }, 'h') - // Move unit is not actually used anywhere - "Move unit" -> return UnitIconAndKey(ImageGetter.getStatIcon("Movement")) - "Stop movement" -> return UnitIconAndKey(ImageGetter.getStatIcon("Movement").apply { color = Color.RED }, KeyCharAndCode(Input.Keys.END)) - "Swap units" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Swap"), 'y') - "Promote" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Star").apply { color = Color.GOLD }, 'o') - "Construct improvement" -> return UnitIconAndKey(ImageGetter.getUnitIcon(Constants.worker), 'i') - "Automate" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Great Engineer"), 'm') - "Stop automation" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Stop"), KeyCharAndCode(Input.Keys.END)) - "Found city" -> return UnitIconAndKey(ImageGetter.getUnitIcon(Constants.settler), 'c') - "Hurry Research" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Great Scientist"), 'g') - "Start Golden Age" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Great Artist"), 'g') - "Hurry Wonder" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Great Engineer"), 'g') - "Conduct Trade Mission" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Great Merchant"), 'g') - // Deprecated since 3.15.4 - "Construct road" -> return UnitIconAndKey(ImageGetter.getImprovementIcon(RoadStatus.Road.name), 'r') - // - "Paradrop" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Paratrooper"), 'p') - "Set up" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Catapult"), 't') - "Explore" -> return UnitIconAndKey(ImageGetter.getUnitIcon("Scout"), 'x') - "Stop exploration" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Stop"), 'x') - "Pillage" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Pillage"), 'p') - "Disband unit" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/DisbandUnit"), KeyCharAndCode.DEL) - "Gift unit" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Present")) - "Show more" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/ArrowRight"), KeyCharAndCode(Input.Keys.PAGE_DOWN)) - "Back" -> return UnitIconAndKey(ImageGetter.getImage("OtherIcons/ArrowLeft"), KeyCharAndCode(Input.Keys.PAGE_UP)) - else -> { - // If the unit has been fortifying for some turns - if (unitAction.startsWith("Fortification")) return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Shield")) - return UnitIconAndKey(ImageGetter.getImage("OtherIcons/Star")) - } - } - } - } - fun update(unit: MapUnit?) { clear() if (unit == null) return @@ -93,16 +25,15 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() { private fun getUnitActionButton(unitAction: UnitAction): Button { - val iconAndKey = getIconAndKeyForUnitAction(unitAction.title) - + val icon = unitAction.getIcon() // If peripheral keyboard not detected, hotkeys will not be displayed - if (!keyboardAvailable) { iconAndKey.key = KeyCharAndCode.UNKNOWN } + val key = if (keyboardAvailable) unitAction.type.key else KeyCharAndCode.UNKNOWN val actionButton = Button(CameraStageBaseScreen.skin) - actionButton.add(iconAndKey.icon).size(20f).pad(5f) + actionButton.add(icon).size(20f).pad(5f) val fontColor = if (unitAction.isCurrentAction) Color.YELLOW else Color.WHITE actionButton.add(unitAction.title.toLabel(fontColor)).pad(5f) - actionButton.addTooltip(iconAndKey.key) + actionButton.addTooltip(key) actionButton.pack() val action = { unitAction.action?.invoke() @@ -111,8 +42,8 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() { if (unitAction.action == null) actionButton.disable() else { actionButton.onClick(unitAction.uncivSound, action) - if (iconAndKey.key != KeyCharAndCode.UNKNOWN) - worldScreen.keyPressDispatcher[iconAndKey.key] = { + if (key != KeyCharAndCode.UNKNOWN) + worldScreen.keyPressDispatcher[key] = { thread(name = "Sound") { Sounds.play(unitAction.uncivSound) } action() }