mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Added a growth progress bar to CityButton. (#1626)
* Added temporary growth number to CityButton. * Added a growth bar to CityButton. * Made relevant changes based on comments in pull request #1626 * Added the unicode infinity symbol to reflect no growth. * New growth functions now return null instead of -1. * Adjusted the population group width to account for large numbers. * Changed the colour of the growth number.
This commit is contained in:
parent
6420f36fb3
commit
a13570f109
@ -19,6 +19,8 @@ import com.unciv.models.ruleset.tile.ResourceSupplyList
|
|||||||
import com.unciv.models.ruleset.tile.ResourceType
|
import com.unciv.models.ruleset.tile.ResourceType
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
import com.unciv.ui.utils.withoutItem
|
import com.unciv.ui.utils.withoutItem
|
||||||
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.floor
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@ -192,6 +194,35 @@ class CityInfo {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isGrowing(): Boolean {
|
||||||
|
return cityStats.currentCityStats.food > 0 && cityConstructions.currentConstruction != Constants.settler
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isStarving(): Boolean {
|
||||||
|
return cityStats.currentCityStats.food < 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Take null to mean infinity. */
|
||||||
|
fun getNumTurnsToNewPopulation(): Int? {
|
||||||
|
if (isGrowing()) {
|
||||||
|
var turnsToGrowth = ceil((population.getFoodToNextPopulation() - population.foodStored)
|
||||||
|
/ cityStats.currentCityStats.food).toInt()
|
||||||
|
if (turnsToGrowth < 1) turnsToGrowth = 1
|
||||||
|
return turnsToGrowth
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Take null to mean infinity. */
|
||||||
|
fun getNumTurnsToStarvation(): Int? {
|
||||||
|
if (isStarving()) {
|
||||||
|
return floor(population.foodStored / -cityStats.currentCityStats.food).toInt() + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
fun getBuildingUniques(): Sequence<String> = cityConstructions.getBuiltBuildings().flatMap { it.uniques.asSequence() }
|
fun getBuildingUniques(): Sequence<String> = cityConstructions.getBuiltBuildings().flatMap { it.uniques.asSequence() }
|
||||||
fun containsBuildingUnique(unique:String) = cityConstructions.getBuiltBuildings().any { it.uniques.contains(unique) }
|
fun containsBuildingUnique(unique:String) = cityConstructions.getBuiltBuildings().any { it.uniques.contains(unique) }
|
||||||
|
|
||||||
|
@ -133,18 +133,14 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||||||
skin)).colspan(columns).row()
|
skin)).colspan(columns).row()
|
||||||
|
|
||||||
val turnsToPopString : String
|
val turnsToPopString : String
|
||||||
if (city.cityStats.currentCityStats.food > 0) {
|
if (city.isGrowing()) {
|
||||||
if (city.cityConstructions.currentConstruction == Constants.settler) {
|
var turnsToGrowth = city.getNumTurnsToNewPopulation()
|
||||||
turnsToPopString = "Food converts to production".tr()
|
turnsToPopString = "[$turnsToGrowth] turns to new population".tr()
|
||||||
} else {
|
} else if (city.isStarving()) {
|
||||||
var turnsToPopulation = ceil((city.population.getFoodToNextPopulation()-city.population.foodStored)
|
var turnsToStarvation = city.getNumTurnsToStarvation()
|
||||||
/ city.cityStats.currentCityStats.food).toInt()
|
|
||||||
if (turnsToPopulation < 1) turnsToPopulation = 1
|
|
||||||
turnsToPopString = "[$turnsToPopulation] turns to new population".tr()
|
|
||||||
}
|
|
||||||
} else if (city.cityStats.currentCityStats.food < 0) {
|
|
||||||
val turnsToStarvation = floor(city.population.foodStored / -city.cityStats.currentCityStats.food).toInt() + 1
|
|
||||||
turnsToPopString = "[$turnsToStarvation] turns to lose population".tr()
|
turnsToPopString = "[$turnsToStarvation] turns to lose population".tr()
|
||||||
|
} else if (city.cityConstructions.currentConstruction == Constants.settler) {
|
||||||
|
turnsToPopString = "Food converts to production".tr()
|
||||||
} else {
|
} else {
|
||||||
turnsToPopString = "Stopped population growth".tr()
|
turnsToPopString = "Stopped population growth".tr()
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Interpolation
|
|||||||
import com.badlogic.gdx.scenes.scene2d.Group
|
import com.badlogic.gdx.scenes.scene2d.Group
|
||||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
@ -124,7 +125,10 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
|
|||||||
iconTable.add(connectionImage).size(20f).pad(2f).padLeft(5f)
|
iconTable.add(connectionImage).size(20f).pad(2f).padLeft(5f)
|
||||||
}
|
}
|
||||||
|
|
||||||
val cityButtonText = city.population.population.toString() + " | " + city.name
|
iconTable.add(getPopulationGroup(UncivGame.Current.viewEntireMapForDebug || belongsToViewingCiv()))
|
||||||
|
.padLeft(10f)
|
||||||
|
|
||||||
|
val cityButtonText = city.name
|
||||||
val label = cityButtonText.toLabel(secondaryColor)
|
val label = cityButtonText.toLabel(secondaryColor)
|
||||||
iconTable.add(label).pad(10f) // sufficient horizontal padding
|
iconTable.add(label).pad(10f) // sufficient horizontal padding
|
||||||
.fillY() // provide full-height clicking area
|
.fillY() // provide full-height clicking area
|
||||||
@ -155,6 +159,72 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
|
|||||||
parent.addAction(floatAction)
|
parent.addAction(floatAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getPopulationGroup(showGrowth: Boolean): Group {
|
||||||
|
val growthGreen = Color(0.0f, 0.5f, 0.0f, 1.0f)
|
||||||
|
|
||||||
|
val group = Group()
|
||||||
|
|
||||||
|
val populationLabel = city.population.population.toString().toLabel()
|
||||||
|
populationLabel.color = city.civInfo.nation.getInnerColor()
|
||||||
|
|
||||||
|
group.addActor(populationLabel)
|
||||||
|
|
||||||
|
val groupHeight = 25f
|
||||||
|
var groupWidth = populationLabel.width
|
||||||
|
if (showGrowth) groupWidth += 20f
|
||||||
|
group.setSize(groupWidth, groupHeight)
|
||||||
|
|
||||||
|
if (showGrowth) {
|
||||||
|
var growthPercentage = city.population.foodStored / city.population.getFoodToNextPopulation().toFloat()
|
||||||
|
if (growthPercentage < 0) growthPercentage = 0.0f
|
||||||
|
|
||||||
|
val growthBar = ImageGetter.getProgressBarVertical(2f, groupHeight,
|
||||||
|
if (city.isStarving()) 1.0f else growthPercentage,
|
||||||
|
if (city.isStarving()) Color.RED else growthGreen, Color.BLACK)
|
||||||
|
growthBar.x = populationLabel.width + 3
|
||||||
|
growthBar.centerY(group)
|
||||||
|
|
||||||
|
group.addActor(growthBar)
|
||||||
|
|
||||||
|
val turnLabel : Label
|
||||||
|
if (city.isGrowing()) {
|
||||||
|
val turnsToGrowth = city.getNumTurnsToNewPopulation()
|
||||||
|
if (turnsToGrowth != null) {
|
||||||
|
if (turnsToGrowth < 100) {
|
||||||
|
turnLabel = turnsToGrowth.toString().toLabel()
|
||||||
|
} else {
|
||||||
|
turnLabel = "∞".toLabel()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
turnLabel = "∞".toLabel()
|
||||||
|
}
|
||||||
|
} else if (city.isStarving()) {
|
||||||
|
val turnsToStarvation = city.getNumTurnsToStarvation()
|
||||||
|
if (turnsToStarvation != null) {
|
||||||
|
if (turnsToStarvation < 100) {
|
||||||
|
turnLabel = turnsToStarvation.toString().toLabel()
|
||||||
|
} else {
|
||||||
|
turnLabel = "∞".toLabel()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
turnLabel = "∞".toLabel()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
turnLabel = "∞".toLabel()
|
||||||
|
}
|
||||||
|
turnLabel.color = city.civInfo.nation.getInnerColor()
|
||||||
|
turnLabel.setFontSize(14)
|
||||||
|
turnLabel.pack()
|
||||||
|
|
||||||
|
group.addActor(turnLabel)
|
||||||
|
turnLabel.x = growthBar.x + growthBar.width + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
populationLabel.centerY(group)
|
||||||
|
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
private fun getConstructionGroup(cityConstructions: CityConstructions): Group {
|
private fun getConstructionGroup(cityConstructions: CityConstructions): Group {
|
||||||
val group= Group()
|
val group= Group()
|
||||||
val groupHeight = 25f
|
val groupHeight = 25f
|
||||||
|
@ -24,7 +24,7 @@ class Fonts {
|
|||||||
"ÀÄĂÂĎÊĚÉÈÍÎŁĹĽÔÓÖƠŘŔŚŤƯŮÚÜÝŻŹäâąďêęěłĺľńňñôöơřŕśťưůýżźáèìíóûú" +
|
"ÀÄĂÂĎÊĚÉÈÍÎŁĹĽÔÓÖƠŘŔŚŤƯŮÚÜÝŻŹäâąďêęěłĺľńňñôöơřŕśťưůýżźáèìíóûú" +
|
||||||
"กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำิีึืฺุู฿เแโใไๅๆ็่้๊๋์ํ๎๏๐๑๒๓๔๕๖๗๘๙๚๛" + // Thai
|
"กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำิีึืฺุู฿เแโใไๅๆ็่้๊๋์ํ๎๏๐๑๒๓๔๕๖๗๘๙๚๛" + // Thai
|
||||||
"1234567890" +
|
"1234567890" +
|
||||||
"‘?’'“!”(%)[#]{@}/&\\<-+÷×=>®©\$€£¥¢:;,.¡*|«»—"
|
"‘?’'“!”(%)[#]{@}/&\\<-+÷×=>®©\$€£¥¢:;,.¡*|«»—∞"
|
||||||
val charSet = HashSet<Char>()
|
val charSet = HashSet<Char>()
|
||||||
charSet.addAll(defaultText.asIterable())
|
charSet.addAll(defaultText.asIterable())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user