mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
Show tech progress for next turn in tech button
This commit is contained in:
parent
a6d0973324
commit
ec33c43c3f
@ -2,6 +2,7 @@ package com.unciv.ui.cityscreen
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
@ -251,7 +252,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
return table
|
||||
}
|
||||
|
||||
fun getProgressBar(constructionName: String): Table {
|
||||
fun getProgressBar(constructionName: String): Group {
|
||||
val cityConstructions = cityScreen.city.cityConstructions
|
||||
val construction = cityConstructions.getConstruction(constructionName)
|
||||
if (construction is PerpetualConstruction) return Table()
|
||||
|
@ -19,12 +19,19 @@ class TechButton(techName:String, private val techManager: TechManager, isWorldS
|
||||
add(ImageGetter.getTechIconGroup(techName, 60f)).left()
|
||||
|
||||
val rightSide = Table()
|
||||
val techCost = techManager.costOfTech(techName)
|
||||
val remainingTech = techManager.remainingScienceToTech(techName)
|
||||
|
||||
if (isWorldScreen) {
|
||||
val techCost = techManager.costOfTech(techName)
|
||||
val remainingTech = techManager.remainingScienceToTech(techName)
|
||||
val techThisTurn = techManager.civInfo.statsForNextTurn.science
|
||||
|
||||
val percentComplete = (techCost - remainingTech) / techCost.toFloat()
|
||||
add(ImageGetter.getProgressBarVertical(2f, 50f, percentComplete, Color.BLUE, Color.WHITE)).pad(10f)
|
||||
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)
|
||||
.addColor(Color.BLUE.cpy().lerp(Color.BLACK, 0.5f), percentComplete)
|
||||
add(progressBar.addBorder(1f, Color.GRAY)).pad(10f)
|
||||
rightSide.add(text).padBottom(5f).row()
|
||||
} else rightSide.add(text).height(25f).padBottom(5f).row()
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.NinePatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
|
||||
@ -302,16 +303,24 @@ object ImageGetter {
|
||||
return getImage("TechIcons/$techName").apply { color = techIconColor.lerp(Color.BLACK, 0.6f) }
|
||||
}
|
||||
|
||||
fun getProgressBarVertical(width: Float, height: Float, percentComplete: Float, progressColor: Color, backgroundColor: Color): Table {
|
||||
val advancementGroup = Table()
|
||||
var completionHeight = height * percentComplete
|
||||
if (completionHeight > height)
|
||||
completionHeight = height
|
||||
advancementGroup.add(getImage(whiteDotLocation).apply { color = backgroundColor })
|
||||
.size(width, height - completionHeight).row()
|
||||
advancementGroup.add(getImage(whiteDotLocation).apply { color = progressColor }).size(width, completionHeight)
|
||||
advancementGroup.pack()
|
||||
return advancementGroup
|
||||
fun getProgressBarVertical(width: Float, height: Float, percentComplete: Float, progressColor: Color, backgroundColor: Color): Group {
|
||||
return VerticalProgressBar(width, height)
|
||||
.addColor(backgroundColor, 1f)
|
||||
.addColor(progressColor, percentComplete)
|
||||
}
|
||||
|
||||
class VerticalProgressBar(width: Float, height: Float):Group(){
|
||||
init {
|
||||
setSize(width, height)
|
||||
}
|
||||
|
||||
fun addColor(color: Color, percentage: Float):VerticalProgressBar {
|
||||
val bar = getWhiteDot()
|
||||
bar.color = color
|
||||
bar.setSize(width, height*percentage)
|
||||
addActor(bar)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
fun getHealthBar(currentHealth: Float, maxHealth: Float, healthBarSize: Float): Table {
|
||||
|
Loading…
Reference in New Issue
Block a user