mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-30 23:41:03 -04:00
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:
parent
cf9194f767
commit
d2541e6c4a
@ -5,6 +5,7 @@ import com.unciv.logic.GameSaver
|
|||||||
class GameSettings {
|
class GameSettings {
|
||||||
var showWorkedTiles: Boolean = false
|
var showWorkedTiles: Boolean = false
|
||||||
var showResourcesAndImprovements: Boolean = true
|
var showResourcesAndImprovements: Boolean = true
|
||||||
|
var checkForDueUnits: Boolean = false
|
||||||
var language: String = "English"
|
var language: String = "English"
|
||||||
var resolution: String = "1050x700"
|
var resolution: String = "1050x700"
|
||||||
var tutorialsShown = ArrayList<String>()
|
var tutorialsShown = ArrayList<String>()
|
||||||
|
@ -300,6 +300,26 @@ class CivilizationInfo {
|
|||||||
units=newList
|
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() {
|
fun updateViewableTiles() {
|
||||||
val newViewableTiles = HashSet<TileInfo>()
|
val newViewableTiles = HashSet<TileInfo>()
|
||||||
|
@ -15,6 +15,7 @@ class PolicyManager {
|
|||||||
internal val adoptedPolicies = HashSet<String>()
|
internal val adoptedPolicies = HashSet<String>()
|
||||||
var numberOfAdoptedPolicies = 0
|
var numberOfAdoptedPolicies = 0
|
||||||
var shouldOpenPolicyPicker = false
|
var shouldOpenPolicyPicker = false
|
||||||
|
get() = field && canAdoptPolicy()
|
||||||
|
|
||||||
// from https://forums.civfanatics.com/threads/the-number-crunching-thread.389702/
|
// from https://forums.civfanatics.com/threads/the-number-crunching-thread.389702/
|
||||||
// round down to nearest 5
|
// round down to nearest 5
|
||||||
|
@ -35,6 +35,8 @@ class MapUnit {
|
|||||||
var action: String? = null // work, automation, fortifying, I dunno what.
|
var action: String? = null // work, automation, fortifying, I dunno what.
|
||||||
var attacksThisTurn = 0
|
var attacksThisTurn = 0
|
||||||
var promotions = UnitPromotions()
|
var promotions = UnitPromotions()
|
||||||
|
var due: Boolean = true
|
||||||
|
get() = field && isIdle()
|
||||||
|
|
||||||
//region pure functions
|
//region pure functions
|
||||||
fun clone(): MapUnit {
|
fun clone(): MapUnit {
|
||||||
@ -402,6 +404,7 @@ class MapUnit {
|
|||||||
fun startTurn(){
|
fun startTurn(){
|
||||||
currentMovement = getMaxMovement().toFloat()
|
currentMovement = getMaxMovement().toFloat()
|
||||||
attacksThisTurn=0
|
attacksThisTurn=0
|
||||||
|
due = true
|
||||||
val tileOwner = getTile().getOwner()
|
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
|
if(tileOwner!=null && !civInfo.canEnterTiles(tileOwner) && !tileOwner.isCityState()) // if an enemy city expanded onto this tile while I was in it
|
||||||
movementAlgs().teleportToClosestMoveableTile()
|
movementAlgs().teleportToClosestMoveableTile()
|
||||||
|
@ -6,11 +6,11 @@ import com.badlogic.gdx.math.Vector2
|
|||||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
|
import com.unciv.Constants
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||||
import com.unciv.Constants
|
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import com.unciv.models.gamebasics.tile.ResourceType
|
import com.unciv.models.gamebasics.tile.ResourceType
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
@ -48,8 +48,6 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
topBar.setPosition(0f, stage.height - topBar.height)
|
topBar.setPosition(0f, stage.height - topBar.height)
|
||||||
topBar.width = stage.width
|
topBar.width = stage.width
|
||||||
|
|
||||||
nextTurnButton.setPosition(stage.width - nextTurnButton.width - 10f,
|
|
||||||
topBar.y - nextTurnButton.height - 10f)
|
|
||||||
notificationsScroll = NotificationsScroll(this)
|
notificationsScroll = NotificationsScroll(this)
|
||||||
notificationsScroll.width = stage.width/3
|
notificationsScroll.width = stage.width/3
|
||||||
|
|
||||||
@ -143,6 +141,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
|
|
||||||
updateTechButton(cloneCivilization)
|
updateTechButton(cloneCivilization)
|
||||||
updateDiplomacyButton(cloneCivilization)
|
updateDiplomacyButton(cloneCivilization)
|
||||||
|
updateNextTurnButton()
|
||||||
|
|
||||||
bottomBar.update(tileMapHolder.selectedTile) // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit!
|
bottomBar.update(tileMapHolder.selectedTile) // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit!
|
||||||
battleTable.update()
|
battleTable.update()
|
||||||
@ -222,23 +221,28 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createNextTurnButton(): TextButton {
|
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) {
|
val nextTurnButton = TextButton("", skin) // text is set in update()
|
||||||
game.screen = TechPickerScreen(true, currentPlayerCiv)
|
|
||||||
|
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
|
return@onClick
|
||||||
} else if (currentPlayerCiv.policies.shouldOpenPolicyPicker) {
|
} else if (currentPlayerCiv.policies.shouldOpenPolicyPicker) {
|
||||||
game.screen = PolicyPickerScreen(currentPlayerCiv)
|
game.screen = PolicyPickerScreen(currentPlayerCiv)
|
||||||
currentPlayerCiv.policies.shouldOpenPolicyPicker = false
|
currentPlayerCiv.policies.shouldOpenPolicyPicker = false
|
||||||
return@onClick
|
return@onClick
|
||||||
}
|
}
|
||||||
else if (currentPlayerCiv.tech.currentTechnology() == null && currentPlayerCiv.cities.isNotEmpty()) {
|
|
||||||
game.screen = TechPickerScreen(currentPlayerCiv)
|
|
||||||
return@onClick
|
|
||||||
}
|
|
||||||
|
|
||||||
bottomBar.unitTable.currentlyExecutingAction = null
|
bottomBar.unitTable.currentlyExecutingAction = null
|
||||||
|
|
||||||
@ -264,6 +268,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
if(gameInfo.turns % game.settings.turnsBetweenAutosaves == 0)
|
if(gameInfo.turns % game.settings.turnsBetweenAutosaves == 0)
|
||||||
GameSaver().saveGame(gameInfoClone, "Autosave")
|
GameSaver().saveGame(gameInfoClone, "Autosave")
|
||||||
nextTurnButton.enable() // only enable the user to next turn once we've saved the current one
|
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...
|
// 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.
|
// That's why this needs to be after the game is saved.
|
||||||
shouldUpdate=true
|
shouldUpdate=true
|
||||||
|
|
||||||
nextTurnButton.setText("Next turn".tr())
|
|
||||||
Gdx.input.inputProcessor = stage
|
Gdx.input.inputProcessor = stage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,6 +284,21 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
return nextTurnButton
|
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) {
|
override fun resize(width: Int, height: Int) {
|
||||||
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
|
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
|
||||||
super.resize(width, height)
|
super.resize(width, height)
|
||||||
|
@ -50,6 +50,12 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){
|
|||||||
addButton("Hide") { settings.showResourcesAndImprovements = false; update() }
|
addButton("Hide") { settings.showResourcesAndImprovements = false; update() }
|
||||||
else addButton("Show") { settings.showResourcesAndImprovements = true; 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()
|
addLanguageSelectBox()
|
||||||
|
|
||||||
addResolutionSelectBox()
|
addResolutionSelectBox()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user