mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-09 23:39:40 +07:00
Unified "progress bars can't go beyond 100%"
This commit is contained in:
@ -259,9 +259,8 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
if (construction is PerpetualConstruction) return Table()
|
||||
if (cityConstructions.getWorkDone(constructionName) == 0) return Table()
|
||||
|
||||
val constructionPercentage = min(cityConstructions.getWorkDone(constructionName) /
|
||||
construction.getProductionCost(cityConstructions.cityInfo.civInfo).toFloat(),
|
||||
1f)
|
||||
val constructionPercentage = cityConstructions.getWorkDone(constructionName) /
|
||||
construction.getProductionCost(cityConstructions.cityInfo.civInfo).toFloat()
|
||||
return ImageGetter.getProgressBarVertical(2f, 30f, constructionPercentage,
|
||||
Color.BROWN.cpy().lerp(Color.WHITE, 0.5f), Color.WHITE)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.logic.civilization.TechManager
|
||||
import com.unciv.ui.utils.*
|
||||
import kotlin.math.min
|
||||
|
||||
class TechButton(techName:String, private val techManager: TechManager, isWorldScreen: Boolean = true) : Table(CameraStageBaseScreen.skin) {
|
||||
val text = "".toLabel().apply { setAlignment(Align.center) }
|
||||
@ -27,7 +26,7 @@ class TechButton(techName:String, private val techManager: TechManager, isWorldS
|
||||
val techThisTurn = techManager.civInfo.statsForNextTurn.science
|
||||
|
||||
val percentComplete = (techCost - remainingTech) / techCost.toFloat()
|
||||
val percentWillBeComplete = min((techCost - (remainingTech-techThisTurn)) / techCost.toFloat(), 1f)
|
||||
val percentWillBeComplete = (techCost - (remainingTech-techThisTurn)) / techCost.toFloat()
|
||||
val progressBar = ImageGetter.VerticalProgressBar(2f, 50f)
|
||||
.addColor(Color.WHITE, 1f)
|
||||
.addColor(Color.BLUE.cpy().lerp(Color.WHITE, 0.3f), percentWillBeComplete)
|
||||
|
@ -366,9 +366,8 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
||||
label.pack()
|
||||
group.addActor(label)
|
||||
|
||||
val constructionPercentage = min(cityConstructions.getWorkDone(cityCurrentConstruction.name) /
|
||||
cityCurrentConstruction.getProductionCost(cityConstructions.cityInfo.civInfo).toFloat(),
|
||||
1f)
|
||||
val constructionPercentage = cityConstructions.getWorkDone(cityCurrentConstruction.name) /
|
||||
cityCurrentConstruction.getProductionCost(cityConstructions.cityInfo.civInfo).toFloat()
|
||||
val productionBar = ImageGetter.getProgressBarVertical(2f, groupHeight, constructionPercentage,
|
||||
Color.BROWN.cpy().lerp(Color.WHITE, 0.5f), Color.BLACK)
|
||||
productionBar.x = 10f
|
||||
|
@ -21,6 +21,7 @@ import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.stats.Stats
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sqrt
|
||||
|
||||
object ImageGetter {
|
||||
@ -309,15 +310,15 @@ object ImageGetter {
|
||||
.addColor(progressColor, percentComplete)
|
||||
}
|
||||
|
||||
class VerticalProgressBar(width: Float, height: Float):Group(){
|
||||
class VerticalProgressBar(width: Float, height: Float):Group() {
|
||||
init {
|
||||
setSize(width, height)
|
||||
}
|
||||
|
||||
fun addColor(color: Color, percentage: Float):VerticalProgressBar {
|
||||
fun addColor(color: Color, percentage: Float): VerticalProgressBar {
|
||||
val bar = getWhiteDot()
|
||||
bar.color = color
|
||||
bar.setSize(width, height*percentage)
|
||||
bar.setSize(width, height * min(percentage, 1f))
|
||||
addActor(bar)
|
||||
return this
|
||||
}
|
||||
|
Reference in New Issue
Block a user