mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04: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.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
@ -251,7 +252,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getProgressBar(constructionName: String): Table {
|
fun getProgressBar(constructionName: String): Group {
|
||||||
val cityConstructions = cityScreen.city.cityConstructions
|
val cityConstructions = cityScreen.city.cityConstructions
|
||||||
val construction = cityConstructions.getConstruction(constructionName)
|
val construction = cityConstructions.getConstruction(constructionName)
|
||||||
if (construction is PerpetualConstruction) return Table()
|
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()
|
add(ImageGetter.getTechIconGroup(techName, 60f)).left()
|
||||||
|
|
||||||
val rightSide = Table()
|
val rightSide = Table()
|
||||||
val techCost = techManager.costOfTech(techName)
|
|
||||||
val remainingTech = techManager.remainingScienceToTech(techName)
|
|
||||||
|
|
||||||
if (isWorldScreen) {
|
if (isWorldScreen) {
|
||||||
|
val techCost = techManager.costOfTech(techName)
|
||||||
|
val remainingTech = techManager.remainingScienceToTech(techName)
|
||||||
|
val techThisTurn = techManager.civInfo.statsForNextTurn.science
|
||||||
|
|
||||||
val percentComplete = (techCost - remainingTech) / techCost.toFloat()
|
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()
|
rightSide.add(text).padBottom(5f).row()
|
||||||
} else rightSide.add(text).height(25f).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.TextureAtlas
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
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.Image
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
|
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) }
|
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 {
|
fun getProgressBarVertical(width: Float, height: Float, percentComplete: Float, progressColor: Color, backgroundColor: Color): Group {
|
||||||
val advancementGroup = Table()
|
return VerticalProgressBar(width, height)
|
||||||
var completionHeight = height * percentComplete
|
.addColor(backgroundColor, 1f)
|
||||||
if (completionHeight > height)
|
.addColor(progressColor, percentComplete)
|
||||||
completionHeight = height
|
}
|
||||||
advancementGroup.add(getImage(whiteDotLocation).apply { color = backgroundColor })
|
|
||||||
.size(width, height - completionHeight).row()
|
class VerticalProgressBar(width: Float, height: Float):Group(){
|
||||||
advancementGroup.add(getImage(whiteDotLocation).apply { color = progressColor }).size(width, completionHeight)
|
init {
|
||||||
advancementGroup.pack()
|
setSize(width, height)
|
||||||
return advancementGroup
|
}
|
||||||
|
|
||||||
|
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 {
|
fun getHealthBar(currentHealth: Float, maxHealth: Float, healthBarSize: Float): Table {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user