Add next-turn-progress bar for growth/production on CityButtons (#8506)

* Add next-turn-progress bar for growth/production on CityButtons

* Small nitpicks

---------

Co-authored-by: tunerzinc@gmail.com <vfylfhby>
This commit is contained in:
vegeta1k95 2023-01-31 21:44:57 +01:00 committed by GitHub
parent 02e10b1000
commit 03d5ba0f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -304,7 +304,7 @@ object ImageGetter {
percentComplete: Float,
progressColor: Color,
backgroundColor: Color,
progressPadding: Float = 0f): Group {
progressPadding: Float = 0f): ProgressBar {
return ProgressBar(width, height, true)
.setBackground(backgroundColor)
.setProgress(progressColor, percentComplete, padding = progressPadding)
@ -363,6 +363,7 @@ object ImageGetter {
else
secondaryProgress?.centerY(this)
}
primaryProgress?.toFront()
return this
}

View File

@ -27,11 +27,13 @@ import com.unciv.ui.utils.Fonts
import com.unciv.ui.utils.extensions.center
import com.unciv.ui.utils.extensions.centerX
import com.unciv.ui.utils.extensions.colorFromRGB
import com.unciv.ui.utils.extensions.darken
import com.unciv.ui.utils.extensions.onClick
import com.unciv.ui.utils.extensions.toGroup
import com.unciv.ui.utils.extensions.toLabel
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
class InfluenceTable(
influence: Float,
@ -271,7 +273,15 @@ private class CityTable(city: City, forPopup: Boolean = false) : BorderedTable(
val turnsToStarvation = city.population.getNumTurnsToStarvation()
if (turnsToStarvation != null && turnsToStarvation < 100) turnsToStarvation.toString() else ""
}
else -> ""
else -> "-"
}
if (city.isGrowing()) {
var nextTurnPercentage = (city.foodForNextTurn() + city.population.foodStored) / city.population.getFoodToNextPopulation().toFloat()
if (nextTurnPercentage < 0) nextTurnPercentage = 0.0f
if (nextTurnPercentage > 1) nextTurnPercentage = 1.0f
growthBar.setSemiProgress(CityButton.ColorGrowth.cpy().darken(0.4f), nextTurnPercentage, 1f)
}
val turnLabel = turnLabelText.toLabel(fontColor = textColor, fontSize = 13)
@ -325,8 +335,9 @@ private class CityTable(city: City, forPopup: Boolean = false) : BorderedTable(
val progressTable = Table()
var nextTurnPercentage = 0f
var percentage = 0f
var turns = ""
var turns = "-"
var icon: Group? = null
if (cityConstructions.currentConstructionFromQueue.isNotEmpty()) {
@ -336,12 +347,20 @@ private class CityTable(city: City, forPopup: Boolean = false) : BorderedTable(
turns = turnsToConstruction.toString()
percentage = cityConstructions.getWorkDone(cityCurrentConstruction.name) /
(cityCurrentConstruction as INonPerpetualConstruction).getProductionCost(cityConstructions.city.civInfo).toFloat()
nextTurnPercentage = (cityConstructions.getWorkDone(cityCurrentConstruction.name) + city.cityStats.currentCityStats.production) /
cityCurrentConstruction.getProductionCost(cityConstructions.city.civInfo).toFloat()
if (nextTurnPercentage > 1f) nextTurnPercentage = 1f
if (nextTurnPercentage < 0f) nextTurnPercentage = 0f
} else {
turns = ""
}
icon = ImageGetter.getConstructionPortrait(cityCurrentConstruction.name, 24f)
}
val productionBar = ImageGetter.getProgressBarVertical(4f, 30f, percentage,
CityButton.ColorConstruction, Color.BLACK, 1f)
productionBar.setSemiProgress(CityButton.ColorConstruction.cpy().darken(0.4f), nextTurnPercentage, 1f)
productionBar.color.a = 0.8f
progressTable.add(turns.toLabel(textColor, 13)).expandY().bottom()