Resolved #899 - Added setting to disable city auto-picking construction

This commit is contained in:
Yair Morgenstern 2019-06-24 19:35:45 +03:00
parent 2f97ed54c0
commit 7e50f70bd5
7 changed files with 58 additions and 27 deletions

View File

@ -846,7 +846,7 @@
} }
"Augustus Caesar":{ "Augustus Caesar":{
Italian:"Cesare Augusto"Harun al-Rashid Italian:"Cesare Augusto"
} }
"+25% Production towards any buildings that already exist in the Capital":{ "+25% Production towards any buildings that already exist in the Capital":{

View File

@ -15,6 +15,7 @@ class GameSettings {
var turnsBetweenAutosaves = 1 var turnsBetweenAutosaves = 1
var tileSet:String = "FantasyHex" var tileSet:String = "FantasyHex"
var showTutorials: Boolean = true var showTutorials: Boolean = true
var autoAssignCityProduction: Boolean = true
fun save(){ fun save(){
GameSaver().setGeneralSettings(this) GameSaver().setGeneralSettings(this)

View File

@ -2,6 +2,7 @@ package com.unciv.logic.automation
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.unciv.Constants import com.unciv.Constants
import com.unciv.UnCivGame
import com.unciv.logic.battle.CityCombatant import com.unciv.logic.battle.CityCombatant
import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.CityConstructions
import com.unciv.logic.city.CityInfo import com.unciv.logic.city.CityInfo
@ -85,6 +86,7 @@ class Automation {
fun chooseNextConstruction(cityConstructions: CityConstructions) { fun chooseNextConstruction(cityConstructions: CityConstructions) {
cityConstructions.run { cityConstructions.run {
if(!UnCivGame.Current.settings.autoAssignCityProduction) return
if (getCurrentConstruction() !is SpecialConstruction) return // don't want to be stuck on these forever if (getCurrentConstruction() !is SpecialConstruction) return // don't want to be stuck on these forever
val buildableNotWonders = getBuildableBuildings().filterNot { it.isWonder || it.isNationalWonder } val buildableNotWonders = getBuildableBuildings().filterNot { it.isWonder || it.isNationalWonder }

View File

@ -57,7 +57,8 @@ class CityConstructions {
fun getCityProductionTextForCityButton(): String { fun getCityProductionTextForCityButton(): String {
val currentConstructionSnapshot = currentConstruction // See below val currentConstructionSnapshot = currentConstruction // See below
var result = currentConstructionSnapshot .tr() var result = currentConstructionSnapshot .tr()
if (SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot }) if (currentConstructionSnapshot!=""
&& SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot })
result += "\r\n" + turnsToConstruction(currentConstructionSnapshot ) + " {turns}".tr() result += "\r\n" + turnsToConstruction(currentConstructionSnapshot ) + " {turns}".tr()
return result return result
} }
@ -65,7 +66,8 @@ class CityConstructions {
fun getProductionForTileInfo(): String { fun getProductionForTileInfo(): String {
val currentConstructionSnapshot = currentConstruction // this is because there were rare errors tht I assume were caused because currentContruction changed on another thread val currentConstructionSnapshot = currentConstruction // this is because there were rare errors tht I assume were caused because currentContruction changed on another thread
var result = currentConstructionSnapshot.tr() var result = currentConstructionSnapshot.tr()
if (SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot }) if (currentConstructionSnapshot!=""
&& SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot })
result += "\r\n{in} ".tr() + turnsToConstruction(currentConstructionSnapshot) + " {turns}".tr() result += "\r\n{in} ".tr() + turnsToConstruction(currentConstructionSnapshot) + " {turns}".tr()
return result return result
} }

View File

@ -20,6 +20,19 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
var constructionScrollPane:ScrollPane?=null var constructionScrollPane:ScrollPane?=null
var lastConstruction = "" var lastConstruction = ""
fun update() {
val city = cityScreen.city
pad(10f)
columnDefaults(0).padRight(10f)
clear()
addConstructionPickerScrollpane(city)
addCurrentConstructionTable(city)
pack()
}
private fun getProductionButton(construction: String, buttonText: String, rejectionReason: String=""): Table { private fun getProductionButton(construction: String, buttonText: String, rejectionReason: String=""): Table {
val pickProductionButton = Table() val pickProductionButton = Table()
pickProductionButton.touchable = Touchable.enabled pickProductionButton.touchable = Touchable.enabled
@ -54,18 +67,6 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
return pickProductionButton return pickProductionButton
} }
fun update() {
val city = cityScreen.city
pad(10f)
columnDefaults(0).padRight(10f)
clear()
addConstructionPickerScrollpane(city)
addCurrentConstructionTable(city)
pack()
}
private fun Table.addCategory(title:String,list:ArrayList<Table>){ private fun Table.addCategory(title:String,list:ArrayList<Table>){
if(list.isEmpty()) return if(list.isEmpty()) return
val titleTable = Table() val titleTable = Table()
@ -169,26 +170,35 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
currentConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK,0.5f)) currentConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK,0.5f))
currentConstructionTable.pad(10f) currentConstructionTable.pad(10f)
currentConstructionTable.add( val userNeedsToSetProduction = city.cityConstructions.currentConstruction==""
ImageGetter.getConstructionImage(city.cityConstructions.currentConstruction).surroundWithCircle(50f)) if(!userNeedsToSetProduction) {
.pad(5f) currentConstructionTable.add(
ImageGetter.getConstructionImage(city.cityConstructions.currentConstruction).surroundWithCircle(50f))
.pad(5f)
val buildingText = city.cityConstructions.getCityProductionTextForCityButton() val buildingText = city.cityConstructions.getCityProductionTextForCityButton()
currentConstructionTable.add(buildingText.toLabel().setFontColor(Color.WHITE)).row() currentConstructionTable.add(buildingText.toLabel().setFontColor(Color.WHITE)).row()
}
else{
currentConstructionTable.add() // no icon
currentConstructionTable.add("Pick construction".toLabel()).row()
}
val currentConstruction = city.cityConstructions.getCurrentConstruction()
val description: String val description: String
if (currentConstruction is BaseUnit) if(userNeedsToSetProduction)
description = currentConstruction.getDescription(true) description=""
else if (currentConstruction is Building) else if (construction is BaseUnit)
description = currentConstruction.getDescription(true, city.civInfo) description = construction.getDescription(true)
else description = currentConstruction.description.tr() else if (construction is Building)
description = construction.getDescription(true, city.civInfo)
else description = construction.description.tr()
val descriptionLabel = description.toLabel() val descriptionLabel = description.toLabel()
descriptionLabel.setWrap(true) descriptionLabel.setWrap(true)
descriptionLabel.width = stage.width / 4 descriptionLabel.width = stage.width / 4
val descriptionScroll = ScrollPane(descriptionLabel) val descriptionScroll = ScrollPane(descriptionLabel)
currentConstructionTable.add(descriptionScroll).colspan(2).width(stage.width / 4).height(stage.height / 8) currentConstructionTable.add(descriptionScroll).colspan(2)
.width(stage.width / 4).height(stage.height / 8)
add(currentConstructionTable.addBorder(2f, Color.WHITE)) add(currentConstructionTable.addBorder(2f, Color.WHITE))
} }

View File

@ -16,6 +16,7 @@ import com.unciv.models.gamebasics.tile.ResourceType
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.models.gamebasics.unit.UnitType import com.unciv.models.gamebasics.unit.UnitType
import com.unciv.ui.VictoryScreen import com.unciv.ui.VictoryScreen
import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen import com.unciv.ui.pickerscreens.GreatPersonPickerScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen
import com.unciv.ui.pickerscreens.TechButton import com.unciv.ui.pickerscreens.TechButton
@ -246,6 +247,13 @@ class WorldScreen : CameraStageBaseScreen() {
return@onClick return@onClick
} }
val cityWithNoProductionSet = currentPlayerCiv.cities
.firstOrNull{it.cityConstructions.currentConstruction==""}
if(cityWithNoProductionSet!=null){
game.screen = CityScreen(cityWithNoProductionSet)
return@onClick
}
if (currentPlayerCiv.shouldOpenTechPicker()) { if (currentPlayerCiv.shouldOpenTechPicker()) {
game.screen = TechPickerScreen(currentPlayerCiv.tech.freeTechs != 0, currentPlayerCiv) game.screen = TechPickerScreen(currentPlayerCiv.tech.freeTechs != 0, currentPlayerCiv)
return@onClick return@onClick
@ -297,6 +305,8 @@ class WorldScreen : CameraStageBaseScreen() {
fun updateNextTurnButton() { fun updateNextTurnButton() {
val text = if (currentPlayerCiv.shouldGoToDueUnit()) val text = if (currentPlayerCiv.shouldGoToDueUnit())
"Next unit" "Next unit"
else if(currentPlayerCiv.cities.any{it.cityConstructions.currentConstruction==""})
"Pick construction"
else if(currentPlayerCiv.shouldOpenTechPicker()) else if(currentPlayerCiv.shouldOpenTechPicker())
"Pick a tech" "Pick a tech"
else if(currentPlayerCiv.policies.shouldOpenPolicyPicker) else if(currentPlayerCiv.policies.shouldOpenPolicyPicker)

View File

@ -68,6 +68,12 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){
update() update()
} }
add("Auto-assign city production".toLabel())
addButton(if(settings.autoAssignCityProduction) "Yes".tr() else "No".tr()) {
settings.autoAssignCityProduction= !settings.autoAssignCityProduction
update()
}
addLanguageSelectBox() addLanguageSelectBox()
addResolutionSelectBox() addResolutionSelectBox()