New Citizen Focus Options (#10745)

* Add Gold Growth and Production Growth Focus
New Manual Focus doesn't reallocate population

* Use Stat Names (and symbols) for focus

* Missing reassign code

* Clean up table for efficiency

* Table v2

* minor translation changes

* COMPATIBILITY

* v3 table

* Minor fixups
This commit is contained in:
itanasi
2023-12-21 23:38:43 -08:00
committed by GitHub
parent ffd5fc62ed
commit 07c6728123
5 changed files with 48 additions and 21 deletions

View File

@ -91,7 +91,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
companion object {
/** The current compatibility version of [GameInfo]. This number is incremented whenever changes are made to the save file structure that guarantee that
* previous versions of the game will not be able to load or play a game normally. */
const val CURRENT_COMPATIBILITY_NUMBER = 3
const val CURRENT_COMPATIBILITY_NUMBER = 4
val CURRENT_COMPATIBILITY_VERSION = CompatibilityVersion(CURRENT_COMPATIBILITY_NUMBER, UncivGame.VERSION)

View File

@ -358,7 +358,7 @@ class City : IsPartOfGameInfoSerialization {
if (resetLocked) {
workedTiles = hashSetOf()
lockedTiles = hashSetOf()
} else {
} else if(cityAIFocus != CityFocus.Manual){
workedTiles = lockedTiles
}
if (!manualSpecialists)

View File

@ -7,6 +7,7 @@ import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
import com.unciv.ui.components.input.KeyboardBinding
import com.unciv.ui.screens.cityscreen.CitizenManagementTable
import com.unciv.ui.images.ImageGetter
/**
* Controls automatic worker-to-tile assignment
@ -16,6 +17,7 @@ import com.unciv.ui.screens.cityscreen.CitizenManagementTable
* @param binding Bindable keyboard key in UI - this is an override, by default matching enum names in [KeyboardBinding] are assigned automatically
* @see CityPopulationManager.autoAssignPopulation
* @see Automation.rankStatsForCityWork
* Order matters for building the [CitizenManagementTable]
*/
enum class CityFocus(
val label: String,
@ -24,28 +26,31 @@ enum class CityFocus(
binding: KeyboardBinding? = null
) : IsPartOfGameInfoSerialization {
// region Enum values
NoFocus("Default Focus", true, null) {
NoFocus("Default", true, null) {
override fun getStatMultiplier(stat: Stat) = 1f // actually redundant, but that's two steps to see
},
FoodFocus("[${Stat.Food.name}] Focus", true, Stat.Food),
ProductionFocus("[${Stat.Production.name}] Focus", true, Stat.Production),
GoldFocus("[${Stat.Gold.name}] Focus", true, Stat.Gold),
ScienceFocus("[${Stat.Science.name}] Focus", true, Stat.Science),
CultureFocus("[${Stat.Culture.name}] Focus", true, Stat.Culture),
GoldGrowthFocus("Gold Growth Focus", false) {
Manual("Manual", true, null) {
override fun getStatMultiplier(stat: Stat) = 1f
},
FoodFocus("${Stat.Food.character}", true, Stat.Food),
ProductionFocus("${Stat.Production.character}", true, Stat.Production),
GoldFocus("${Stat.Gold.character}", true, Stat.Gold),
ScienceFocus("${Stat.Science.character}", true, Stat.Science),
CultureFocus("${Stat.Culture.character}", true, Stat.Culture),
HappinessFocus("${Stat.Happiness.character}", false, Stat.Happiness),
FaithFocus("${Stat.Faith.character}", true, Stat.Faith),
GoldGrowthFocus("${Stat.Gold.character} ${Stat.Food.character}", true) {
override fun getStatMultiplier(stat: Stat) = when (stat) {
Stat.Gold, Stat.Food -> 2f
else -> 1f
}
},
ProductionGrowthFocus("Production Growth Focus", false) {
ProductionGrowthFocus("${Stat.Production.character} ${Stat.Food.character}", true) {
override fun getStatMultiplier(stat: Stat) = when (stat) {
Stat.Production, Stat.Food -> 2f
else -> 1f
}
},
FaithFocus("[${Stat.Faith.name}] Focus", true, Stat.Faith),
HappinessFocus("[${Stat.Happiness.name}] Focus", false, Stat.Happiness),
//GreatPersonFocus
;

View File

@ -12,12 +12,15 @@ import com.unciv.ui.screens.basescreen.BaseScreen
class CitizenManagementTable(val cityScreen: CityScreen) : Table(BaseScreen.skin) {
val city = cityScreen.city
private val numCol = 4
fun update() {
clear()
val colorSelected = BaseScreen.skin.getColor("selection")
val colorButton = BaseScreen.skin.getColor("color")
val topTable = Table() // holds 2 buttons
// effectively a button, but didn't want to rewrite TextButton style
// and much more compact and can control backgrounds easily based on settings
val resetLabel = "Reset Citizens".toLabel()
@ -34,8 +37,7 @@ class CitizenManagementTable(val cityScreen: CityScreen) : Table(BaseScreen.skin
"CityScreen/CitizenManagementTable/ResetCell",
tintColor = colorButton
)
add(resetCell).colspan(2).growX().pad(3f)
row()
topTable.add(resetCell).pad(3f)
val avoidLabel = "Avoid Growth".toLabel()
val avoidCell = Table()
@ -52,10 +54,18 @@ class CitizenManagementTable(val cityScreen: CityScreen) : Table(BaseScreen.skin
"CityScreen/CitizenManagementTable/AvoidCell",
tintColor = if (city.avoidGrowth) colorSelected else colorButton
)
add(avoidCell).colspan(2).growX().pad(3f)
topTable.add(avoidCell).pad(3f)
add(topTable).colspan(numCol).growX()
row()
var newRow = false
val focusLabel = "Citizen Focus".toLabel()
val focusCell = Table()
focusCell.add(focusLabel).pad(5f)
add(focusCell).colspan(numCol).growX().pad(3f)
row()
var currCol = numCol
val defaultTable = Table()
for (focus in CityFocus.values()) {
if (!focus.tableEnabled) continue
if (focus == CityFocus.FaithFocus && !city.civ.gameInfo.isReligionEnabled()) continue
@ -77,10 +87,22 @@ class CitizenManagementTable(val cityScreen: CityScreen) : Table(BaseScreen.skin
"CityScreen/CitizenManagementTable/FocusCell",
tintColor = if (city.cityAIFocus == focus) colorSelected else colorButton
)
add(cell).growX().pad(3f)
if (newRow) // every 2 make new row
// make NoFocus and Manual their own special row
if(focus == CityFocus.NoFocus) {
defaultTable.add(cell).growX().pad(3f)
} else if (focus == CityFocus.Manual) {
defaultTable.add(cell).growX().pad(3f)
add(defaultTable).colspan(numCol).growX()
row()
newRow = !newRow
} else {
cell.padTop(5f) // Stat symbols need extra padding on top
add(cell).growX().pad(3f)
--currCol
if (currCol == 0) { // make new row
row()
currCol = numCol
}
}
}
pack()