improved "next turn" - button (#741)

* as long as there are units due to be checked by the player, replace "next turn" button by "next unit" button

* fixed the next-turn button to update within WorldScreen.update()

* moved due methods to CivilizationInfo.kt

* "next turn" button will also show "pick a tech" and "pick a policy" when needed

* added "check for idle units" to the game settings

* "check for idle units" - default to false
This commit is contained in:
sulai 2019-05-12 18:20:06 +02:00 committed by Yair Morgenstern
parent cf9194f767
commit d2541e6c4a
6 changed files with 64 additions and 14 deletions

View file

@ -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<String>()

View file

@ -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<TileInfo>()

View file

@ -15,6 +15,7 @@ class PolicyManager {
internal val adoptedPolicies = HashSet<String>()
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

View file

@ -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()

View file

@ -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)

View file

@ -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()