diff --git a/core/src/com/unciv/GameSettings.kt b/core/src/com/unciv/GameSettings.kt index 6ea2709d..5f9bd139 100644 --- a/core/src/com/unciv/GameSettings.kt +++ b/core/src/com/unciv/GameSettings.kt @@ -5,6 +5,7 @@ import com.unciv.logic.GameSaver class GameSettings { var showWorkedTiles: Boolean = false var showResourcesAndImprovements: Boolean = true + var checkForDueUnits: Boolean = false var language: String = "English" var resolution: String = "1050x700" var tutorialsShown = ArrayList() diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 018c1e25..64c6c3f2 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -300,6 +300,26 @@ class CivilizationInfo { units=newList } + fun getDueUnits() = getCivUnits().filter { it.due } + + fun hasDueUnits() = getDueUnits().isNotEmpty() + + fun shouldOpenTechPicker() = tech.freeTechs != 0 + || tech.currentTechnology()==null && cities.isNotEmpty() + + fun shouldGoToDueUnit() = UnCivGame.Current.settings.checkForDueUnits && hasDueUnits() + + fun getNextDueUnit(selectedUnit: MapUnit?): MapUnit? { + val dueUnits = getDueUnits() + if(dueUnits.isNotEmpty()) { + var index = dueUnits.indexOf(selectedUnit) + index = ++index % dueUnits.size // for looping + val unit = dueUnits[index] + unit.due = false + return unit + } + return null + } fun updateViewableTiles() { val newViewableTiles = HashSet() diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index a9b2ae92..4c899dea 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -15,6 +15,7 @@ class PolicyManager { internal val adoptedPolicies = HashSet() var numberOfAdoptedPolicies = 0 var shouldOpenPolicyPicker = false + get() = field && canAdoptPolicy() // from https://forums.civfanatics.com/threads/the-number-crunching-thread.389702/ // round down to nearest 5 diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 42959b26..2a8ea724 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -35,6 +35,8 @@ class MapUnit { var action: String? = null // work, automation, fortifying, I dunno what. var attacksThisTurn = 0 var promotions = UnitPromotions() + var due: Boolean = true + get() = field && isIdle() //region pure functions fun clone(): MapUnit { @@ -402,6 +404,7 @@ class MapUnit { fun startTurn(){ currentMovement = getMaxMovement().toFloat() attacksThisTurn=0 + due = true val tileOwner = getTile().getOwner() if(tileOwner!=null && !civInfo.canEnterTiles(tileOwner) && !tileOwner.isCityState()) // if an enemy city expanded onto this tile while I was in it movementAlgs().teleportToClosestMoveableTile() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 9ce91cb3..ea4efe0d 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -6,11 +6,11 @@ import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.Constants import com.unciv.UnCivGame import com.unciv.logic.GameSaver import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.diplomacy.DiplomaticStatus -import com.unciv.Constants import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.models.gamebasics.tr @@ -48,8 +48,6 @@ class WorldScreen : CameraStageBaseScreen() { topBar.setPosition(0f, stage.height - topBar.height) topBar.width = stage.width - nextTurnButton.setPosition(stage.width - nextTurnButton.width - 10f, - topBar.y - nextTurnButton.height - 10f) notificationsScroll = NotificationsScroll(this) notificationsScroll.width = stage.width/3 @@ -143,6 +141,7 @@ class WorldScreen : CameraStageBaseScreen() { updateTechButton(cloneCivilization) updateDiplomacyButton(cloneCivilization) + updateNextTurnButton() bottomBar.update(tileMapHolder.selectedTile) // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit! battleTable.update() @@ -222,23 +221,28 @@ class WorldScreen : CameraStageBaseScreen() { } private fun createNextTurnButton(): TextButton { - val nextTurnButton = TextButton("Next turn".tr(), skin) - nextTurnButton.onClick { - if(currentPlayerCiv.policies.shouldOpenPolicyPicker && !currentPlayerCiv.policies.canAdoptPolicy()) - currentPlayerCiv.policies.shouldOpenPolicyPicker = false // something has changed and we can no longer adopt the policy, e.g. we conquered another city - if (currentPlayerCiv.tech.freeTechs != 0) { - game.screen = TechPickerScreen(true, currentPlayerCiv) + val nextTurnButton = TextButton("", skin) // text is set in update() + + nextTurnButton.onClick { + + // cycle through units not yet done + if (currentPlayerCiv.shouldGoToDueUnit()) { + currentPlayerCiv.getNextDueUnit(bottomBar.unitTable.selectedUnit)?.let { + tileMapHolder.setCenterPosition(it.currentTile.position) + shouldUpdate=true + return@onClick + } + } + + if (currentPlayerCiv.shouldOpenTechPicker()) { + game.screen = TechPickerScreen(currentPlayerCiv.tech.freeTechs != 0, currentPlayerCiv) return@onClick } else if (currentPlayerCiv.policies.shouldOpenPolicyPicker) { game.screen = PolicyPickerScreen(currentPlayerCiv) currentPlayerCiv.policies.shouldOpenPolicyPicker = false return@onClick } - else if (currentPlayerCiv.tech.currentTechnology() == null && currentPlayerCiv.cities.isNotEmpty()) { - game.screen = TechPickerScreen(currentPlayerCiv) - return@onClick - } bottomBar.unitTable.currentlyExecutingAction = null @@ -264,6 +268,7 @@ class WorldScreen : CameraStageBaseScreen() { if(gameInfo.turns % game.settings.turnsBetweenAutosaves == 0) GameSaver().saveGame(gameInfoClone, "Autosave") nextTurnButton.enable() // only enable the user to next turn once we've saved the current one + updateNextTurnButton() } // If we put this BEFORE the save game, then we try to save the game... @@ -272,7 +277,6 @@ class WorldScreen : CameraStageBaseScreen() { // That's why this needs to be after the game is saved. shouldUpdate=true - nextTurnButton.setText("Next turn".tr()) Gdx.input.inputProcessor = stage } } @@ -280,6 +284,21 @@ class WorldScreen : CameraStageBaseScreen() { return nextTurnButton } + fun updateNextTurnButton() { + val text = if (currentPlayerCiv.shouldGoToDueUnit()) + "Next unit" + else if(currentPlayerCiv.shouldOpenTechPicker()) + "Pick a tech" + else if(currentPlayerCiv.policies.shouldOpenPolicyPicker) + "Pick a policy" + else + "Next turn" + nextTurnButton.setText(text.tr()) + nextTurnButton.color = if(text=="Next turn") Color.WHITE else Color.GRAY + nextTurnButton.pack() + nextTurnButton.setPosition(stage.width - nextTurnButton.width - 10f, topBar.y - nextTurnButton.height - 10f) + } + override fun resize(width: Int, height: Int) { if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) { super.resize(width, height) diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 9fef1b9c..573e6306 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -50,6 +50,12 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){ addButton("Hide") { settings.showResourcesAndImprovements = false; update() } else addButton("Show") { settings.showResourcesAndImprovements = true; update() } + add("Check for idle units".toLabel()) + addButton(if(settings.checkForDueUnits) "Yes" else "No") { + settings.checkForDueUnits = !settings.checkForDueUnits + update() + } + addLanguageSelectBox() addResolutionSelectBox()