diff --git a/android/assets/jsons/TileImprovements.json b/android/assets/jsons/TileImprovements.json index f32e26a225..6327ef2d70 100644 --- a/android/assets/jsons/TileImprovements.json +++ b/android/assets/jsons/TileImprovements.json @@ -136,6 +136,9 @@ "name": "Remove Railroad", "turnsToBuild": 2 }, + { + "name": "Cancel improvement order", + }, // Great Person improvements { diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt index f3af663c59..031bb38422 100644 --- a/core/src/com/unciv/Constants.kt +++ b/core/src/com/unciv/Constants.kt @@ -46,12 +46,13 @@ object Constants { const val random = "Random" val greatImprovements = listOf("Academy", "Landmark", "Manufactory", "Customs house", "Citadel") - val unitActionSetUp = "Set Up" - val unitActionSleep = "Sleep" - val unitActionSleepUntilHealed = "Sleep until healed" - val unitActionAutomation = "Automate" - val unitActionExplore = "Explore" - val futureTech = "Future Tech" + const val unitActionSetUp = "Set Up" + const val unitActionSleep = "Sleep" + const val unitActionSleepUntilHealed = "Sleep until healed" + const val unitActionAutomation = "Automate" + const val unitActionExplore = "Explore" + const val futureTech = "Future Tech" + const val cancelImprovementOrder = "Cancel improvement order" const val tutorialPopupNamePrefix = "Tutorial: " } \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index fee4a4867c..16c065bc83 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -280,6 +280,7 @@ open class TileInfo { improvement.name == "Railroad" && this.roadStatus != RoadStatus.Railroad -> true improvement.name == "Remove Road" && this.roadStatus == RoadStatus.Road -> true improvement.name == "Remove Railroad" && this.roadStatus == RoadStatus.Railroad -> true + improvement.name == Constants.cancelImprovementOrder && this.improvementInProgress != null -> true topTerrain.unbuildable && !(topTerrain.name == Constants.forest && improvement.name == "Camp") -> false "Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile() -> true else -> hasViewableResource(civInfo) && getTileResource().improvement == improvement.name @@ -387,6 +388,10 @@ open class TileInfo { improvementInProgress = improvement.name turnsToImprovement = improvement.getTurnsToBuild(civInfo) } + fun stopWorkingOnImprovement() { + improvementInProgress = null + turnsToImprovement = 0 + } fun hasEnemySubmarine(viewingCiv:CivilizationInfo): Boolean { val unitsInTile = getUnits() diff --git a/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt index c77408d4f1..dd4e801106 100644 --- a/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt @@ -7,6 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup import com.badlogic.gdx.utils.Align +import com.unciv.Constants import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.TileInfo import com.unciv.models.ruleset.tile.TileImprovement @@ -23,9 +24,14 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc fun accept(improvement: TileImprovement?) { if (improvement != null) { - tileInfo.startWorkingOnImprovement(improvement, currentPlayerCiv) - if (tileInfo.civilianUnit != null) tileInfo.civilianUnit!!.action = null // this is to "wake up" the worker if it's sleeping - onAccept() + if (improvement.name == Constants.cancelImprovementOrder ) { + tileInfo.stopWorkingOnImprovement() + // no onAccept() - Worker can stay selected + } else { + tileInfo.startWorkingOnImprovement(improvement, currentPlayerCiv) + if (tileInfo.civilianUnit != null) tileInfo.civilianUnit!!.action = null // this is to "wake up" the worker if it's sleeping + onAccept() + } game.setWorldScreen() dispose() } @@ -50,11 +56,13 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc group.add(image).size(30f).pad(10f) - var labelText = improvement.name.tr() + " - " + improvement.getTurnsToBuild(currentPlayerCiv) + " {turns}" + var labelText = improvement.name.tr() + val turnsToBuild = improvement.getTurnsToBuild(currentPlayerCiv) + if (turnsToBuild > 0) labelText += " - $turnsToBuild {turns}" val provideResource = tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == improvement.name if (provideResource) labelText += "\n"+"Provides [${tileInfo.resource}]".tr() val removeImprovement = (improvement.name!=RoadStatus.Road.name - && improvement.name!=RoadStatus.Railroad.name && !improvement.name.startsWith("Remove")) + && improvement.name!=RoadStatus.Railroad.name && !improvement.name.startsWith("Remove") && improvement.name != Constants.cancelImprovementOrder) if (tileInfo.improvement!=null && removeImprovement) labelText += "\n" + "Replaces [${tileInfo.improvement}]".tr() group.add(labelText.toLabel()).pad(10f) @@ -124,6 +132,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc regularImprovements.add(pickNow).padLeft(10f) regularImprovements.row() } + topTable.add(regularImprovements) } } diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index f5779ac4aa..3fa8174534 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -12,6 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.utils.Drawable import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable import com.badlogic.gdx.utils.Align +import com.unciv.Constants import com.unciv.models.ruleset.Nation import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.tile.ResourceType @@ -123,7 +124,7 @@ object ImageGetter { val productionCircleColor = Color.BROWN.cpy().lerp(Color.WHITE,0.5f)!! val goldCircleColor = Color.GOLD.cpy().lerp(Color.WHITE,0.5f)!! fun getImprovementIcon(improvementName:String, size:Float=20f):Actor{ - if(improvementName.startsWith("Remove")) + if(improvementName.startsWith("Remove") || improvementName == Constants.cancelImprovementOrder) return getImage("OtherIcons/Stop") if(improvementName.startsWith("StartingLocation ")){ val nationName = improvementName.removePrefix("StartingLocation ")