mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 23:40:01 +07:00
Added tech progress bars in tech picking screen
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 143
|
versionCode 144
|
||||||
versionName "2.8.11"
|
versionName "2.8.12"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -36,14 +36,20 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
|||||||
isFreeTechPick = freeTechPick
|
isFreeTechPick = freeTechPick
|
||||||
}
|
}
|
||||||
|
|
||||||
class TechButton(techName:String) : Table(skin) {
|
class TechButton(techName:String, val techManager:TechManager) : Table(skin) {
|
||||||
val text=Label("",skin).setFontColor(Color.WHITE)
|
val text=Label("",skin).setFontColor(Color.WHITE)
|
||||||
init {
|
init {
|
||||||
touchable = Touchable.enabled
|
touchable = Touchable.enabled
|
||||||
defaults().pad(10f)
|
defaults().pad(10f)
|
||||||
background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
|
background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
|
||||||
if(ImageGetter.techIconExists(techName)) {
|
if(ImageGetter.techIconExists(techName))
|
||||||
add(ImageGetter.getTechIconGroup(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)
|
add(text)
|
||||||
pack()
|
pack()
|
||||||
@ -75,7 +81,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
|||||||
topTable.add() // empty cell
|
topTable.add() // empty cell
|
||||||
|
|
||||||
else {
|
else {
|
||||||
val TB = TechButton(tech.name)
|
val TB = TechButton(tech.name,civTech)
|
||||||
|
|
||||||
techNameToButton[tech.name] = TB
|
techNameToButton[tech.name] = TB
|
||||||
TB.onClick {
|
TB.onClick {
|
||||||
|
@ -25,8 +25,10 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||||||
val whiteHalo = if(unit.isFortified()) ImageGetter.getImage("OtherIcons/Shield.png")
|
val whiteHalo = if(unit.isFortified()) ImageGetter.getImage("OtherIcons/Shield.png")
|
||||||
else ImageGetter.getImage("OtherIcons/Circle.png")
|
else ImageGetter.getImage("OtherIcons/Circle.png")
|
||||||
whiteHalo.setSize(30f,30f)
|
whiteHalo.setSize(30f,30f)
|
||||||
val unitImage = if(unit.baseUnit().unitType== UnitType.Civilian) civilianUnitImage!!
|
val unitImage = if(unit.baseUnit().unitType== UnitType.Civilian) civilianUnitImage
|
||||||
else militaryUnitImage!!
|
else militaryUnitImage
|
||||||
|
if(unitImage==null) //Stuff has changed since we requested this, the unit is no longer here...
|
||||||
|
return
|
||||||
whiteHalo.center(unitImage)
|
whiteHalo.center(unitImage)
|
||||||
unitImage.addActor(whiteHalo)
|
unitImage.addActor(whiteHalo)
|
||||||
whiteHalo.toBack()
|
whiteHalo.toBack()
|
||||||
@ -160,11 +162,8 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||||||
val adoptedPolicies = cityConstructions.cityInfo.civInfo.policies.adoptedPolicies
|
val adoptedPolicies = cityConstructions.cityInfo.civInfo.policies.adoptedPolicies
|
||||||
val constructionPercentage = cityConstructions.getWorkDone(cityConstructions.currentConstruction) /
|
val constructionPercentage = cityConstructions.getWorkDone(cityConstructions.currentConstruction) /
|
||||||
cityConstructions.getCurrentConstruction().getProductionCost(adoptedPolicies).toFloat()
|
cityConstructions.getCurrentConstruction().getProductionCost(adoptedPolicies).toFloat()
|
||||||
val productionBar = Table()
|
val productionBar = ImageGetter.getProgressBarVertical(2f, groupHeight, constructionPercentage
|
||||||
val heightOfProductionBar = (constructionPercentage * groupHeight)
|
,Color.BROWN.cpy().lerp(Color.WHITE,0.5f), Color.BLACK )
|
||||||
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()
|
|
||||||
productionBar.x = 10f
|
productionBar.x = 10f
|
||||||
label.x = productionBar.x - label.width - 3
|
label.x = productionBar.x - label.width - 3
|
||||||
group.addActor(productionBar)
|
group.addActor(productionBar)
|
||||||
|
@ -7,6 +7,7 @@ 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.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.utils.Drawable
|
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
@ -143,4 +144,13 @@ object ImageGetter {
|
|||||||
techIconGroup.addActor(techIcon)
|
techIconGroup.addActor(techIcon)
|
||||||
return techIconGroup
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.unciv.ui.worldscreen
|
|||||||
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.math.Vector2
|
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.Label
|
||||||
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
|
||||||
@ -50,6 +51,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
|
|
||||||
tileMapHolder.addTiles()
|
tileMapHolder.addTiles()
|
||||||
|
|
||||||
|
techButton.touchable=Touchable.enabled
|
||||||
techButton.onClick {
|
techButton.onClick {
|
||||||
game.screen = TechPickerScreen(civInfo)
|
game.screen = TechPickerScreen(civInfo)
|
||||||
}
|
}
|
||||||
@ -166,15 +168,11 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
techButton.add(Label("{Pick a tech}!".tr(),skin).setFontColor(Color.WHITE).setFont(22))
|
techButton.add(Label("{Pick a tech}!".tr(),skin).setFontColor(Color.WHITE).setFont(22))
|
||||||
else {
|
else {
|
||||||
val tech = civInfo.tech.currentTechnology()!!
|
val tech = civInfo.tech.currentTechnology()!!
|
||||||
val techHeight = 30f
|
|
||||||
if(ImageGetter.techIconExists(tech))
|
if(ImageGetter.techIconExists(tech))
|
||||||
techButton.add(ImageGetter.getTechIconGroup(tech))
|
techButton.add(ImageGetter.getTechIconGroup(tech))
|
||||||
val advancementGroup = Table()
|
val costOfTech = civInfo.tech.costOfTech(tech).toFloat()
|
||||||
val percentIncomplete = civInfo.tech.remainingScienceToTech(tech) / civInfo.tech.costOfTech(tech).toFloat()
|
val percentComplete = (costOfTech-civInfo.tech.remainingScienceToTech(tech)) / costOfTech
|
||||||
val incompletionHeight = techHeight * percentIncomplete
|
techButton.add(ImageGetter.getProgressBarVertical(2f,30f,percentComplete, Color.BLUE, Color.WHITE))
|
||||||
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 turnsToTech = civInfo.tech.turnsToTech(tech)
|
val turnsToTech = civInfo.tech.turnsToTech(tech)
|
||||||
techButton.add(Label(tech.tr() + "\r\n"
|
techButton.add(Label(tech.tr() + "\r\n"
|
||||||
+ turnsToTech + (if(turnsToTech>1) " {turns}".tr() else " {turn}".tr()),skin)
|
+ turnsToTech + (if(turnsToTech>1) " {turns}".tr() else " {turn}".tr()),skin)
|
||||||
|
Reference in New Issue
Block a user