Added tech progress bars in tech picking screen

This commit is contained in:
Yair Morgenstern
2018-10-06 20:19:51 +03:00
parent 7e6fa0e895
commit 4277bbc403
5 changed files with 32 additions and 19 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 143
versionName "2.8.11"
versionCode 144
versionName "2.8.12"
}
buildTypes {
release {

View File

@ -36,14 +36,20 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
isFreeTechPick = freeTechPick
}
class TechButton(techName:String) : Table(skin) {
class TechButton(techName:String, val techManager:TechManager) : Table(skin) {
val text=Label("",skin).setFontColor(Color.WHITE)
init {
touchable = Touchable.enabled
defaults().pad(10f)
background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
if(ImageGetter.techIconExists(techName)) {
if(ImageGetter.techIconExists(techName))
add(ImageGetter.getTechIconGroup(techName))
val techCost = techManager.costOfTech(techName)
val remainingTech = techManager.remainingScienceToTech(techName)
if(techCost!=remainingTech){
val percentComplete = (techCost-remainingTech)/techCost.toFloat()
add(ImageGetter.getProgressBarVertical(2f,30f,percentComplete, Color.BLUE, Color.WHITE))
}
add(text)
pack()
@ -75,7 +81,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
topTable.add() // empty cell
else {
val TB = TechButton(tech.name)
val TB = TechButton(tech.name,civTech)
techNameToButton[tech.name] = TB
TB.onClick {

View File

@ -25,8 +25,10 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
val whiteHalo = if(unit.isFortified()) ImageGetter.getImage("OtherIcons/Shield.png")
else ImageGetter.getImage("OtherIcons/Circle.png")
whiteHalo.setSize(30f,30f)
val unitImage = if(unit.baseUnit().unitType== UnitType.Civilian) civilianUnitImage!!
else militaryUnitImage!!
val unitImage = if(unit.baseUnit().unitType== UnitType.Civilian) civilianUnitImage
else militaryUnitImage
if(unitImage==null) //Stuff has changed since we requested this, the unit is no longer here...
return
whiteHalo.center(unitImage)
unitImage.addActor(whiteHalo)
whiteHalo.toBack()
@ -160,11 +162,8 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
val adoptedPolicies = cityConstructions.cityInfo.civInfo.policies.adoptedPolicies
val constructionPercentage = cityConstructions.getWorkDone(cityConstructions.currentConstruction) /
cityConstructions.getCurrentConstruction().getProductionCost(adoptedPolicies).toFloat()
val productionBar = Table()
val heightOfProductionBar = (constructionPercentage * groupHeight)
productionBar.add(ImageGetter.getImage(ImageGetter.WhiteDot).apply { color = Color.BLACK}).width(2f).height(groupHeight - heightOfProductionBar).row()
productionBar.add(ImageGetter.getImage(ImageGetter.WhiteDot).apply { color = Color.BROWN.cpy().lerp(Color.WHITE,0.5f)}).width(2f).height(heightOfProductionBar)
productionBar.pack()
val productionBar = ImageGetter.getProgressBarVertical(2f, groupHeight, constructionPercentage
,Color.BROWN.cpy().lerp(Color.WHITE,0.5f), Color.BLACK )
productionBar.x = 10f
label.x = productionBar.x - label.width - 3
group.addActor(productionBar)

View File

@ -7,6 +7,7 @@ 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
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import com.unciv.models.gamebasics.GameBasics
@ -143,4 +144,13 @@ object ImageGetter {
techIconGroup.addActor(techIcon)
return techIconGroup
}
fun getProgressBarVertical(width:Float,height:Float,percentComplete:Float,progressColor:Color,backgroundColor:Color): Table {
val advancementGroup = Table()
val completionHeight = height * percentComplete
advancementGroup.add(ImageGetter.getImage(ImageGetter.WhiteDot).apply { color = backgroundColor }).width(width).height(height-completionHeight).row()
advancementGroup.add(ImageGetter.getImage(ImageGetter.WhiteDot).apply { color= progressColor}).width(width).height(completionHeight)
advancementGroup.pack()
return advancementGroup
}
}

View File

@ -3,6 +3,7 @@ package com.unciv.ui.worldscreen
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
@ -50,6 +51,7 @@ class WorldScreen : CameraStageBaseScreen() {
tileMapHolder.addTiles()
techButton.touchable=Touchable.enabled
techButton.onClick {
game.screen = TechPickerScreen(civInfo)
}
@ -166,15 +168,11 @@ class WorldScreen : CameraStageBaseScreen() {
techButton.add(Label("{Pick a tech}!".tr(),skin).setFontColor(Color.WHITE).setFont(22))
else {
val tech = civInfo.tech.currentTechnology()!!
val techHeight = 30f
if(ImageGetter.techIconExists(tech))
techButton.add(ImageGetter.getTechIconGroup(tech))
val advancementGroup = Table()
val percentIncomplete = civInfo.tech.remainingScienceToTech(tech) / civInfo.tech.costOfTech(tech).toFloat()
val incompletionHeight = techHeight * percentIncomplete
advancementGroup.add(ImageGetter.getImage(ImageGetter.WhiteDot)).width(2f).height(incompletionHeight).row()
advancementGroup.add(ImageGetter.getImage(ImageGetter.WhiteDot).apply { color= Color.BLUE }).width(2f).height(techHeight-incompletionHeight)
techButton.add(advancementGroup)
val costOfTech = civInfo.tech.costOfTech(tech).toFloat()
val percentComplete = (costOfTech-civInfo.tech.remainingScienceToTech(tech)) / costOfTech
techButton.add(ImageGetter.getProgressBarVertical(2f,30f,percentComplete, Color.BLUE, Color.WHITE))
val turnsToTech = civInfo.tech.turnsToTech(tech)
techButton.add(Label(tech.tr() + "\r\n"
+ turnsToTech + (if(turnsToTech>1) " {turns}".tr() else " {turn}".tr()),skin)