Added helper function to create labels from text

This commit is contained in:
Yair Morgenstern 2019-02-13 23:53:50 +02:00
parent ee55839557
commit 9ba360408c
28 changed files with 121 additions and 104 deletions

View File

@ -34,6 +34,7 @@ class CityInfo {
var workedTiles = HashSet<Vector2>() var workedTiles = HashSet<Vector2>()
var isBeingRazed = false var isBeingRazed = false
var attackedThisTurn = false var attackedThisTurn = false
var hasSoldBuildingThisTurn = false
constructor() // for json parsing, we need to have a default constructor constructor() // for json parsing, we need to have a default constructor
constructor(civInfo: CivilizationInfo, cityLocation: Vector2) { constructor(civInfo: CivilizationInfo, cityLocation: Vector2) {
@ -245,7 +246,7 @@ class CityInfo {
return false return false
} }
fun tryUpdateRoadStatus(){ private fun tryUpdateRoadStatus(){
if(getCenterTile().roadStatus==RoadStatus.None if(getCenterTile().roadStatus==RoadStatus.None
&& GameBasics.TileImprovements["Road"]!!.techRequired in civInfo.tech.techsResearched) && GameBasics.TileImprovements["Road"]!!.techRequired in civInfo.tech.techsResearched)
getCenterTile().roadStatus==RoadStatus.Road getCenterTile().roadStatus==RoadStatus.Road
@ -254,5 +255,13 @@ class CityInfo {
&& GameBasics.TileImprovements["Railroad"]!!.techRequired in civInfo.tech.techsResearched) && GameBasics.TileImprovements["Railroad"]!!.techRequired in civInfo.tech.techsResearched)
getCenterTile().roadStatus==RoadStatus.Railroad getCenterTile().roadStatus==RoadStatus.Railroad
} }
fun getGoldForSellingBuilding(buildingName:String) = GameBasics.Buildings[buildingName]!!.cost / 10
fun sellBuilding(buildingName:String){
cityConstructions.builtBuildings.remove(buildingName)
cityConstructions.removeBuilding(buildingName)
civInfo.gold += getGoldForSellingBuilding(buildingName)
}
//endregion //endregion
} }

View File

@ -9,6 +9,7 @@ import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.ICivilopedia import com.unciv.models.gamebasics.ICivilopedia
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import java.util.* import java.util.*
class CivilopediaScreen : CameraStageBaseScreen() { class CivilopediaScreen : CameraStageBaseScreen() {
@ -23,7 +24,7 @@ class CivilopediaScreen : CameraStageBaseScreen() {
stage.addActor(splitPane) stage.addActor(splitPane)
val label = Label("", CameraStageBaseScreen.skin) val label = "".toLabel()
label.setWrap(true) label.setWrap(true)
val goToGameButton = TextButton("Return \r\nto game", CameraStageBaseScreen.skin) val goToGameButton = TextButton("Return \r\nto game", CameraStageBaseScreen.skin)

View File

@ -3,7 +3,6 @@ package com.unciv.ui
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
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.Label
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
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
@ -64,7 +63,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
topTable.add(setCurrentTradesButton) topTable.add(setCurrentTradesButton)
val setUnitsButton = TextButton("Units".tr(),skin) val setUnitsButton = TextButton("Units".tr(),skin)
setUnitsButton .onClick { setUnitsButton.onClick {
centerTable.clear() centerTable.clear()
centerTable.add(ScrollPane(getUnitTable())).height(stage.height*0.8f) centerTable.add(ScrollPane(getUnitTable())).height(stage.height*0.8f)
centerTable.pack() centerTable.pack()
@ -110,15 +109,15 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val table = Table() val table = Table()
table.defaults().pad(10f) table.defaults().pad(10f)
table.background = ImageGetter.getBackground(civ.getNation().getColor()) table.background = ImageGetter.getBackground(civ.getNation().getColor())
table.add(Label(civ.civName.tr(),skin).setFontColor(civ.getNation().getSecondaryColor())).row() table.add(civ.civName.toLabel().setFontColor(civ.getNation().getSecondaryColor())).row()
table.addSeparator() table.addSeparator()
for(offer in offersList){ for(offer in offersList){
var offerText = offer.amount.toString()+" "+offer.name.tr() var offerText = offer.amount.toString()+" "+offer.name.tr()
if(offer.duration>0)offerText += " ("+offer.duration+" {turns})".tr() if(offer.duration>0)offerText += " ("+offer.duration+" {turns})".tr()
table.add(Label(offerText,skin).setFontColor(civ.getNation().getSecondaryColor())).row() table.add(offerText.toLabel().setFontColor(civ.getNation().getSecondaryColor())).row()
} }
for(i in 1..numberOfOtherSidesOffers - offersList.size) for(i in 1..numberOfOtherSidesOffers - offersList.size)
table.add(Label("",skin)).row() // we want both sides of the general table to have the same number of rows table.add("".toLabel()).row() // we want both sides of the general table to have the same number of rows
return table return table
} }
@ -126,7 +125,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
private fun getHappinessTable(): Table { private fun getHappinessTable(): Table {
val happinessTable = Table(skin) val happinessTable = Table(skin)
happinessTable.defaults().pad(5f) happinessTable.defaults().pad(5f)
happinessTable.add(Label("Happiness".tr(), skin).setFontSize(24)).colspan(2).row() happinessTable.add("Happiness".toLabel().setFontSize(24)).colspan(2).row()
happinessTable.addSeparator() happinessTable.addSeparator()
for (entry in currentPlayerCivInfo.getHappinessForNextTurn()) { for (entry in currentPlayerCivInfo.getHappinessForNextTurn()) {
happinessTable.add(entry.key.tr()) happinessTable.add(entry.key.tr())
@ -141,7 +140,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
private fun getGoldTable(): Table { private fun getGoldTable(): Table {
val goldTable = Table(skin) val goldTable = Table(skin)
goldTable.defaults().pad(5f) goldTable.defaults().pad(5f)
goldTable.add(Label("Gold".tr(), skin).setFontSize(24)).colspan(2).row() goldTable.add("Gold".toLabel().setFontSize(24)).colspan(2).row()
goldTable.addSeparator() goldTable.addSeparator()
var total=0f var total=0f
for (entry in currentPlayerCivInfo.getStatMapForNextTurn()) { for (entry in currentPlayerCivInfo.getStatMapForNextTurn()) {
@ -165,7 +164,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val pointsToGreatPerson = currentPlayerCivInfo.greatPeople.pointsForNextGreatPerson val pointsToGreatPerson = currentPlayerCivInfo.greatPeople.pointsForNextGreatPerson
greatPeopleTable.defaults().pad(5f) greatPeopleTable.defaults().pad(5f)
greatPeopleTable.add(Label("Great person points".tr(), skin).setFontSize(24)).colspan(3).row() greatPeopleTable.add("Great person points".toLabel().setFontSize(24)).colspan(3).row()
greatPeopleTable.addSeparator() greatPeopleTable.addSeparator()
greatPeopleTable.add() greatPeopleTable.add()
greatPeopleTable.add("Current points") greatPeopleTable.add("Current points")
@ -180,7 +179,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val pointsForGreatGeneral = currentPlayerCivInfo.greatPeople.greatGeneralPoints.toInt().toString() val pointsForGreatGeneral = currentPlayerCivInfo.greatPeople.greatGeneralPoints.toInt().toString()
val pointsForNextGreatGeneral = currentPlayerCivInfo.greatPeople.pointsForNextGreatGeneral.toInt().toString() val pointsForNextGreatGeneral = currentPlayerCivInfo.greatPeople.pointsForNextGreatGeneral.toInt().toString()
greatPeopleTable.add("Great General".tr()) greatPeopleTable.add("Great General".tr())
greatPeopleTable.add(pointsForGreatGeneral+"/"+pointsForNextGreatGeneral).row() greatPeopleTable.add("$pointsForGreatGeneral/$pointsForNextGreatGeneral").row()
greatPeopleTable.pack() greatPeopleTable.pack()
return greatPeopleTable return greatPeopleTable
} }
@ -194,7 +193,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val cityInfoTableIcons = Table(skin) val cityInfoTableIcons = Table(skin)
cityInfoTableIcons.defaults().pad(padding).align(Align.center) cityInfoTableIcons.defaults().pad(padding).align(Align.center)
cityInfoTableIcons.add(Label("Cities".tr(), skin).setFontSize(24)).colspan(8).align(Align.center).row() cityInfoTableIcons.add("Cities".toLabel().setFontSize(24)).colspan(8).align(Align.center).row()
cityInfoTableIcons.add() cityInfoTableIcons.add()
cityInfoTableIcons.add(ImageGetter.getStatIcon("Population")).size(iconSize) cityInfoTableIcons.add(ImageGetter.getStatIcon("Population")).size(iconSize)
cityInfoTableIcons.add(ImageGetter.getStatIcon("Food")).size(iconSize) cityInfoTableIcons.add(ImageGetter.getStatIcon("Food")).size(iconSize)
@ -305,7 +304,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
var civNameText = civ.civName.tr() var civNameText = civ.civName.tr()
if(civ.isDefeated()) civNameText += "\n({Defeated})".tr() if(civ.isDefeated()) civNameText += "\n({Defeated})".tr()
val label = Label(civNameText, CameraStageBaseScreen.skin) val label = civNameText.toLabel()
label.setAlignment(Align.center) label.setAlignment(Align.center)
if (civ.isDefeated()) { if (civ.isDefeated()) {

View File

@ -85,7 +85,7 @@ class LanguagePickerScreen: PickerScreen(){
"Do you want to download fonts for $spaceSplitLang?", "Do you want to download fonts for $spaceSplitLang?",
{ {
val downloading = PopupTable(this) val downloading = PopupTable(this)
downloading.add(Label("Downloading...",skin)) downloading.add("Downloading...".toLabel())
downloading.open() downloading.open()
Gdx.input.inputProcessor = null // no interaction until download is over Gdx.input.inputProcessor = null // no interaction until download is over

View File

@ -12,6 +12,7 @@ import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.setFontColor import com.unciv.ui.utils.setFontColor
import com.unciv.ui.utils.toLabel
class NationTable(val nation: Nation, val newGameParameters: GameParameters, skin: Skin, width:Float, onClick:()->Unit): Table(skin){ class NationTable(val nation: Nation, val newGameParameters: GameParameters, skin: Skin, width:Float, onClick:()->Unit): Table(skin){
val innerTable = Table() val innerTable = Table()
@ -19,8 +20,9 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
background= ImageGetter.getBackground(nation.getSecondaryColor()) background= ImageGetter.getBackground(nation.getSecondaryColor())
innerTable.pad(10f) innerTable.pad(10f)
innerTable.background= ImageGetter.getBackground(nation.getColor()) innerTable.background= ImageGetter.getBackground(nation.getColor())
innerTable.add(Label(nation.leaderName.tr()+" - "+nation.name.tr(), skin).apply { setFontColor(nation.getSecondaryColor())}).row() innerTable.add(Label(nation.leaderName.tr()+" - "+nation.name.tr(), skin)
innerTable.add(Label(getUniqueLabel(nation), skin) .apply { setFontColor(nation.getSecondaryColor())}).row()
innerTable.add(getUniqueLabel(nation)
.apply { setWrap(true);setFontColor(nation.getSecondaryColor())}) .apply { setWrap(true);setFontColor(nation.getSecondaryColor())})
.width(width) .width(width)
onClick { onClick {
@ -37,7 +39,7 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
add(innerTable) add(innerTable)
} }
private fun getUniqueLabel(nation: Nation): String { private fun getUniqueLabel(nation: Nation): Label {
val textList = ArrayList<String>() val textList = ArrayList<String>()
if(nation.unique!=null) { if(nation.unique!=null) {
@ -81,7 +83,7 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
} }
return textList.joinToString("\n").tr().trim() return textList.joinToString("\n").tr().trim().toLabel()
} }

View File

@ -2,7 +2,10 @@ package com.unciv.ui
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
import com.unciv.GameStarter import com.unciv.GameStarter
@ -16,6 +19,7 @@ import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.disable import com.unciv.ui.utils.disable
import com.unciv.ui.utils.enable import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import kotlin.concurrent.thread import kotlin.concurrent.thread
import kotlin.math.min import kotlin.math.min
@ -77,7 +81,7 @@ class NewGameScreen: PickerScreen(){
mapTypes[type.toString()] = type mapTypes[type.toString()] = type
} }
val mapFileLabel = Label("{Map file}:".tr(),skin) val mapFileLabel = "{Map file}:".toLabel()
val mapFileSelectBox = getMapFileSelectBox() val mapFileSelectBox = getMapFileSelectBox()
mapFileLabel.isVisible=false mapFileLabel.isVisible=false
mapFileSelectBox.isVisible=false mapFileSelectBox.isVisible=false
@ -85,7 +89,7 @@ class NewGameScreen: PickerScreen(){
val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin) val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin)
val worldSizeSelectBox = getWorldSizeSelectBox() val worldSizeSelectBox = getWorldSizeSelectBox()
val worldSizeLabel = Label("{World size}:".tr(),skin) val worldSizeLabel = "{World size}:".toLabel()
mapTypeSelectBox.addListener(object : ChangeListener() { mapTypeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) { override fun changed(event: ChangeEvent?, actor: Actor?) {

View File

@ -38,7 +38,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val wondersExpander = ExpanderTab("Wonders".tr(),skin) val wondersExpander = ExpanderTab("Wonders".tr(),skin)
for (building in wonders) { for (building in wonders) {
wondersExpander.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f)) wondersExpander.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f))
wondersExpander.innerTable.add(Label(building.name.tr(), skin)).pad(5f).align(Align.left).row() wondersExpander.innerTable.add(building.name.toLabel()).pad(5f).align(Align.left).row()
} }
add(wondersExpander).row() add(wondersExpander).row()
} }
@ -47,7 +47,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val specialistBuildingsExpander = ExpanderTab("Specialist Buildings".tr(),skin) val specialistBuildingsExpander = ExpanderTab("Specialist Buildings".tr(),skin)
for (building in specialistBuildings) { for (building in specialistBuildings) {
specialistBuildingsExpander.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f)) specialistBuildingsExpander.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f))
specialistBuildingsExpander.innerTable.add(Label(building.name.tr(), skin)).pad(5f) specialistBuildingsExpander.innerTable.add(building.name.toLabel()).pad(5f)
val specialistIcons = Table() val specialistIcons = Table()
specialistIcons.row().size(20f).pad(5f) specialistIcons.row().size(20f).pad(5f)
for(stat in building.specialistSlots!!.toHashMap()) for(stat in building.specialistSlots!!.toHashMap())
@ -66,7 +66,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val buildingsExpanderTab = ExpanderTab("Buildings".tr(),skin) val buildingsExpanderTab = ExpanderTab("Buildings".tr(),skin)
for (building in otherBuildings) { for (building in otherBuildings) {
buildingsExpanderTab.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f)) buildingsExpanderTab.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f))
buildingsExpanderTab.innerTable.add(Label(building.name.tr(), skin)).pad(5f).row() buildingsExpanderTab.innerTable.add(building.name.toLabel()).pad(5f).row()
} }
add(buildingsExpanderTab).row() add(buildingsExpanderTab).row()
} }
@ -96,13 +96,14 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
for(stat in statToCauses){ for(stat in statToCauses){
val expander = ExpanderTab(stat.key.name.tr(),skin) val expander = ExpanderTab(stat.key.name.tr(),skin)
expander.innerTable.defaults().pad(2f) expander.innerTable.defaults().pad(2f)
for(entry in stat.value) { for(entry in stat.value) {
expander.innerTable.add(Label(entry.key.tr(), skin)) expander.innerTable.add(entry.key.toLabel())
expander.innerTable.add(Label(DecimalFormat("0.#").format(entry.value), skin)).row() expander.innerTable.add(DecimalFormat("0.#").format(entry.value).toLabel()).row()
} }
if(stat.value.isNotEmpty()){ if(stat.value.isNotEmpty()){
expander.innerTable.add(Label("Total".tr(),skin)) expander.innerTable.add("Total".toLabel())
expander.innerTable.add(Label(DecimalFormat("0.#").format(stat.value.values.sum()),skin)) expander.innerTable.add(DecimalFormat("0.#").format(stat.value.values.sum()).toLabel())
add(expander).row() add(expander).row()
} }
} }

View File

@ -20,14 +20,26 @@ import kotlin.math.round
class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() { class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
private var selectedTile: TileInfo? = null private var selectedTile: TileInfo? = null
private var tileTable = Table() // Clockwise from the top-left
private var cityInfoTable = CityInfoTable(this) /** Displays city stats - sits on the top left side */
private var constructionsTable = ConstructionsTable(this)
private var cityPickerTable = Table()
private var razeCityButtonHolder = Table()
private var tileGroups = ArrayList<CityTileGroup>()
var topCityStatsTable=Table() var topCityStatsTable=Table()
private var razeCityButtonHolder = Table() // sits on the top
/** Displays buildings, specialists and stats drilldown - sits on the top left of the city screen */
private var cityInfoTable = CityInfoTable(this)
/** Displays tile info, sits on the bottom right */
private var tileTable = Table()
/** Displays city name, allows switching between cities - sits on the bottom */
private var cityPickerTable = Table()
/** Holds production list and current production - sits on the bottom left */
private var constructionsTable = ConstructionsTable(this)
private var tileGroups = ArrayList<CityTileGroup>()
init { init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
addTiles() addTiles()
@ -131,7 +143,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
if(stat.key==Stat.Happiness) continue if(stat.key==Stat.Happiness) continue
val minitable=Table().padRight(5f).padLeft(5f) val minitable=Table().padRight(5f).padLeft(5f)
minitable.add(ImageGetter.getStatIcon(stat.key.name)).size(20f).padRight(3f) minitable.add(ImageGetter.getStatIcon(stat.key.name)).size(20f).padRight(3f)
minitable.add(Label(round(stat.value).toInt().toString(), CameraStageBaseScreen.skin)) minitable.add(round(stat.value).toInt().toString().toLabel())
table.add(minitable) table.add(minitable)
} }
return table.addBorder(2f, beige) return table.addBorder(2f, beige)
@ -335,4 +347,5 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
tileTable.setPosition(stage.width - 5f - tileTable.width, 5f) tileTable.setPosition(stage.width - 5f - tileTable.width, 5f)
stage.addActor(tileTable) stage.addActor(tileTable)
} }
} }

View File

@ -2,7 +2,6 @@ package com.unciv.ui.cityscreen
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
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
@ -32,7 +31,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
pickProductionButton.background = ImageGetter.getBackground(Color.BLACK) pickProductionButton.background = ImageGetter.getBackground(Color.BLACK)
pickProductionButton.add(ImageGetter.getConstructionImage(construction).surroundWithCircle(40f)).padRight(10f) pickProductionButton.add(ImageGetter.getConstructionImage(construction).surroundWithCircle(40f)).padRight(10f)
pickProductionButton.add(Label(buttonText, CameraStageBaseScreen.skin).setFontColor(Color.WHITE)) pickProductionButton.add(buttonText.toLabel().setFontColor(Color.WHITE))
pickProductionButton.onClick { pickProductionButton.onClick {
cityScreen.city.cityConstructions.currentConstruction = construction cityScreen.city.cityConstructions.currentConstruction = construction
update() update()
@ -58,7 +57,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
if(list.isEmpty()) return if(list.isEmpty()) return
val titleTable = Table() val titleTable = Table()
titleTable.background = ImageGetter.getBackground(ImageGetter.getBlue()) titleTable.background = ImageGetter.getBackground(ImageGetter.getBlue())
titleTable.add(Label(title.tr(),CameraStageBaseScreen.skin)) titleTable.add(title.toLabel())
addSeparator() addSeparator()
add(titleTable).fill().row() add(titleTable).fill().row()
@ -151,7 +150,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
.pad(5f) .pad(5f)
val buildingText = city.cityConstructions.getCityProductionTextForCityButton() val buildingText = city.cityConstructions.getCityProductionTextForCityButton()
currentConstructionTable.add(Label(buildingText, CameraStageBaseScreen.skin).setFontColor(Color.WHITE)).row() currentConstructionTable.add(buildingText.toLabel().setFontColor(Color.WHITE)).row()
val currentConstruction = city.cityConstructions.getCurrentConstruction() val currentConstruction = city.cityConstructions.getCurrentConstruction()
val description: String val description: String
@ -161,7 +160,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
description = currentConstruction.getDescription(true, city.civInfo.policies.adoptedPolicies) description = currentConstruction.getDescription(true, city.civInfo.policies.adoptedPolicies)
else description = currentConstruction.description.tr() else description = currentConstruction.description.tr()
val descriptionLabel = Label(description, CameraStageBaseScreen.skin) val descriptionLabel = description.toLabel()
descriptionLabel.setWrap(true) descriptionLabel.setWrap(true)
descriptionLabel.width = stage.width / 4 descriptionLabel.width = stage.width / 4
val descriptionScroll = ScrollPane(descriptionLabel) val descriptionScroll = ScrollPane(descriptionLabel)

View File

@ -2,14 +2,15 @@ package com.unciv.ui.pickerscreens
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.logic.civilization.GreatPersonManager import com.unciv.logic.civilization.GreatPersonManager
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.tr
import com.unciv.models.gamebasics.unit.BaseUnit import com.unciv.models.gamebasics.unit.BaseUnit
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.setFontColor import com.unciv.ui.utils.setFontColor
import com.unciv.ui.utils.toLabel
class GreatPersonPickerScreen : PickerScreen() { class GreatPersonPickerScreen : PickerScreen() {
private var theChosenOne: BaseUnit? = null private var theChosenOne: BaseUnit? = null
@ -23,7 +24,7 @@ class GreatPersonPickerScreen : PickerScreen() {
val button = Button(skin) val button = Button(skin)
button.add(ImageGetter.getUnitIcon(unit.name)).size(30f).pad(10f) button.add(ImageGetter.getUnitIcon(unit.name)).size(30f).pad(10f)
button.add(Label(unit.name, skin).setFontColor(Color.WHITE)).pad(10f) button.add(unit.name.toLabel().setFontColor(Color.WHITE)).pad(10f)
button.pack() button.pack()
button.onClick { button.onClick {
theChosenOne = unit theChosenOne = unit
@ -41,4 +42,4 @@ class GreatPersonPickerScreen : PickerScreen() {
} }
} }
} }

View File

@ -3,10 +3,7 @@ package com.unciv.ui.pickerscreens
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.*
import com.unciv.ui.utils.disable
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick
open class PickerScreen : CameraStageBaseScreen() { open class PickerScreen : CameraStageBaseScreen() {
@ -22,7 +19,7 @@ open class PickerScreen : CameraStageBaseScreen() {
init { init {
bottomTable.add(closeButton).width(stage.width / 4) bottomTable.add(closeButton).width(stage.width / 4)
descriptionLabel = Label("", CameraStageBaseScreen.skin) descriptionLabel = "".toLabel()
descriptionLabel.setWrap(true) descriptionLabel.setWrap(true)
val labelScroll = ScrollPane(descriptionLabel) val labelScroll = ScrollPane(descriptionLabel)
bottomTable.add(labelScroll).pad(5f).width(stage.width / 2) bottomTable.add(labelScroll).pad(5f).width(stage.width / 2)

View File

@ -2,7 +2,6 @@ package com.unciv.ui.pickerscreens
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.logic.map.MapUnit import com.unciv.logic.map.MapUnit
@ -37,7 +36,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() {
if(!isPromotionAvailable) promotionButton.color = Color.GRAY if(!isPromotionAvailable) promotionButton.color = Color.GRAY
promotionButton.add(ImageGetter.getPromotionIcon(promotion.name)).size(30f).pad(10f) promotionButton.add(ImageGetter.getPromotionIcon(promotion.name)).size(30f).pad(10f)
promotionButton.add(Label(promotion.name, skin) promotionButton.add(promotion.name.toLabel()
.setFontColor(Color.WHITE)).pad(10f) .setFontColor(Color.WHITE)).pad(10f)
if(unitHasPromotion) promotionButton.color = Color.GREEN if(unitHasPromotion) promotionButton.color = Color.GREEN

View File

@ -51,7 +51,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
} }
val eras = ArrayList<Label>() val eras = ArrayList<Label>()
for(i in techMatrix.indices) eras.add(Label("",CameraStageBaseScreen.skin).apply { setFontColor(Color.WHITE) }) for(i in techMatrix.indices)
eras.add("".toLabel().setFontColor(Color.WHITE))
eras.forEach { topTable.add(it) } eras.forEach { topTable.add(it) }
// Create tech table (row by row) // Create tech table (row by row)

View File

@ -2,7 +2,6 @@ package com.unciv.ui.saves
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.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
import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.Json
@ -61,7 +60,7 @@ class LoadScreen : PickerScreen() {
val rightSideTable = Table() val rightSideTable = Table()
val loadFromClipboardButton = TextButton("Load copied data".tr(),skin) val loadFromClipboardButton = TextButton("Load copied data".tr(),skin)
val errorLabel = Label("",skin).setFontColor(Color.RED) val errorLabel = "".toLabel().setFontColor(Color.RED)
loadFromClipboardButton.onClick { loadFromClipboardButton.onClick {
try{ try{
val clipboardContentsString = Gdx.app.clipboard.contents val clipboardContentsString = Gdx.app.clipboard.contents

View File

@ -1,7 +1,6 @@
package com.unciv.ui.saves package com.unciv.ui.saves
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
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
import com.badlogic.gdx.scenes.scene2d.ui.TextField import com.badlogic.gdx.scenes.scene2d.ui.TextField
@ -13,6 +12,7 @@ import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.enable import com.unciv.ui.utils.enable
import com.unciv.ui.utils.getRandom import com.unciv.ui.utils.getRandom
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
class SaveScreen : PickerScreen() { class SaveScreen : PickerScreen() {
@ -22,7 +22,7 @@ class SaveScreen : PickerScreen() {
setDefaultCloseAction() setDefaultCloseAction()
val currentSaves = Table() val currentSaves = Table()
currentSaves.add(Label("Current saves".tr(),skin)).row() currentSaves.add("Current saves".toLabel()).row()
val saves = GameSaver().getSaves() val saves = GameSaver().getSaves()
saves.forEach { saves.forEach {
val textButton = TextButton(it, skin) val textButton = TextButton(it, skin)
@ -44,7 +44,7 @@ class SaveScreen : PickerScreen() {
val defaultSaveName = adjectives.getRandom()+" "+nouns.getRandom() val defaultSaveName = adjectives.getRandom()+" "+nouns.getRandom()
textField.text = defaultSaveName textField.text = defaultSaveName
newSave.add(Label("Saved game name".tr(),skin)).row() newSave.add("Saved game name".toLabel()).row()
newSave.add(textField).width(300f).pad(10f).row() newSave.add(textField).width(300f).pad(10f).row()
val copyJsonButton = TextButton("Copy game info".tr(),skin) val copyJsonButton = TextButton("Copy game info".tr(),skin)

View File

@ -3,7 +3,6 @@ package com.unciv.ui.tilegroups
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.Group
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
@ -13,7 +12,6 @@ import com.unciv.logic.city.CityInfo
import com.unciv.logic.city.SpecialConstruction import com.unciv.logic.city.SpecialConstruction
import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.RoadStatus
import com.unciv.ui.cityscreen.CityScreen import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.tilegroups.WorldTileGroup
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, skin: Skin): Table(skin){ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, skin: Skin): Table(skin){
@ -28,7 +26,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
val cityButtonText = city.population.population.toString() + " | " + city.name val cityButtonText = city.population.population.toString() + " | " + city.name
background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png") background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
.tint(city.civInfo.getNation().getColor()) .tint(city.civInfo.getNation().getColor())
val label = Label(cityButtonText, CameraStageBaseScreen.skin) val label = cityButtonText.toLabel()
label.setFontColor(city.civInfo.getNation().getSecondaryColor()) label.setFontColor(city.civInfo.getNation().getSecondaryColor())
clear() clear()
@ -97,7 +95,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
val secondaryColor = cityConstructions.cityInfo.civInfo.getNation().getSecondaryColor() val secondaryColor = cityConstructions.cityInfo.civInfo.getNation().getSecondaryColor()
if(cityConstructions.getCurrentConstruction() !is SpecialConstruction) { if(cityConstructions.getCurrentConstruction() !is SpecialConstruction) {
val turnsToConstruction = cityConstructions.turnsToConstruction(cityConstructions.currentConstruction) val turnsToConstruction = cityConstructions.turnsToConstruction(cityConstructions.currentConstruction)
val label = Label(turnsToConstruction.toString(), CameraStageBaseScreen.skin) val label = turnsToConstruction.toString().toLabel()
label.setFontColor(secondaryColor) label.setFontColor(secondaryColor)
label.setFontSize(10) label.setFontSize(10)
label.pack() label.pack()

View File

@ -44,7 +44,7 @@ class DiplomacyScreen:CameraStageBaseScreen(){
civTable.defaults().pad(10f) civTable.defaults().pad(10f)
val peaceWarStatus = civDiplomacy.diplomaticStatus.toString() val peaceWarStatus = civDiplomacy.diplomaticStatus.toString()
civTable.add(Label(civ.civName.tr() + " ({$peaceWarStatus})".tr(), skin) civTable.add(Label(civ.civName.tr() + " ({$peaceWarStatus})".tr(), skin)
.apply { setFontSize(22); setFontColor(civ.getNation().getSecondaryColor()) }).row() .setFontSize(22).setFontColor(civ.getNation().getSecondaryColor())).row()
civTable.addSeparator() civTable.addSeparator()
val tradeButton = TextButton("Trade".tr(), skin) val tradeButton = TextButton("Trade".tr(), skin)
@ -68,7 +68,7 @@ class DiplomacyScreen:CameraStageBaseScreen(){
val responsePopup = PopupTable(this) val responsePopup = PopupTable(this)
val otherCivLeaderName = civ.getNation().leaderName + " of " + civ.civName val otherCivLeaderName = civ.getNation().leaderName + " of " + civ.civName
responsePopup.add(Label(otherCivLeaderName, skin)) responsePopup.add(otherCivLeaderName.toLabel())
responsePopup.addSeparator() responsePopup.addSeparator()
responsePopup.addGoodSizedLabel(civ.getNation().attacked).row() responsePopup.addGoodSizedLabel(civ.getNation().attacked).row()
responsePopup.addButton("Very well.".tr()) { responsePopup.remove() } responsePopup.addButton("Very well.".tr()) { responsePopup.remove() }

View File

@ -12,6 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
import com.badlogic.gdx.utils.viewport.ExtendViewport import com.badlogic.gdx.utils.viewport.ExtendViewport
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.models.gamebasics.tr
open class CameraStageBaseScreen : Screen { open class CameraStageBaseScreen : Screen {
@ -53,8 +54,6 @@ open class CameraStageBaseScreen : Screen {
} }
companion object { companion object {
var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json")) var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json"))
@ -135,8 +134,9 @@ fun Actor.onClick(sound:String,function: () -> Unit){
} ) } )
} }
fun Actor.onClick(function: () -> Unit) { fun Actor.onClick(function: () -> Unit): Actor {
onClick("click",function) onClick("click",function)
return this
} }
fun Actor.surroundWithCircle(size:Float): IconCircleGroup { fun Actor.surroundWithCircle(size:Float): IconCircleGroup {
@ -196,3 +196,6 @@ fun <T> HashSet<T>.withoutItem(item:T): HashSet<T> {
newHashSet.remove(item) newHashSet.remove(item)
return newHashSet return newHashSet
} }
/** also translates */
fun String.toLabel() = Label(this.tr(),CameraStageBaseScreen.skin)

View File

@ -1,7 +1,6 @@
package com.unciv.ui.worldscreen package com.unciv.ui.worldscreen
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.civilization.Notification import com.unciv.logic.civilization.Notification
@ -19,7 +18,7 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu
internal fun update(notifications: MutableList<Notification>) { internal fun update(notifications: MutableList<Notification>) {
notificationsTable.clearChildren() notificationsTable.clearChildren()
for (notification in notifications.toList()) { // tolist to avoid concurrecy problems for (notification in notifications.toList()) { // tolist to avoid concurrecy problems
val label = Label(notification.text.tr(), CameraStageBaseScreen.skin).setFontColor(Color.BLACK) val label = notification.text.toLabel().setFontColor(Color.BLACK)
.setFontSize(14) .setFontSize(14)
val minitable = Table() val minitable = Table()

View File

@ -1,11 +1,9 @@
package com.unciv.ui.worldscreen package com.unciv.ui.worldscreen
import com.badlogic.gdx.scenes.scene2d.Touchable 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.Table
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScreen(){ class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScreen(){
@ -14,7 +12,7 @@ class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScr
table.touchable= Touchable.enabled table.touchable= Touchable.enabled
table.background= ImageGetter.getBackground(currentPlayerCiv.getNation().getColor()) table.background= ImageGetter.getBackground(currentPlayerCiv.getNation().getColor())
table.add(Label("[$currentPlayerCiv] ready?".tr(), skin).setFontSize(24) table.add("[$currentPlayerCiv] ready?".toLabel().setFontSize(24)
.setFontColor(currentPlayerCiv.getNation().getSecondaryColor())) .setFontColor(currentPlayerCiv.getNation().getSecondaryColor()))
table.onClick { table.onClick {

View File

@ -5,7 +5,6 @@ import com.badlogic.gdx.math.Vector2
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.InputEvent import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener
import com.unciv.UnCivGame import com.unciv.UnCivGame
@ -89,7 +88,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
private fun queueAddMoveHereButton(selectedUnit: MapUnit, tileInfo: TileInfo) { private fun queueAddMoveHereButton(selectedUnit: MapUnit, tileInfo: TileInfo) {
thread { thread {
/** LibGdx sometimes has these weird errors when you try to edit the UI layout from 2 separate thread. /** LibGdx sometimes has these weird errors when you try to edit the UI layout from 2 separate threads.
* And so, all UI editing will be done on the main thread. * And so, all UI editing will be done on the main thread.
* The only "heavy lifting" that needs to be done is getting the turns to get there, * The only "heavy lifting" that needs to be done is getting the turns to get there,
* so that and that alone will be relegated to the concurrent thread. * so that and that alone will be relegated to the concurrent thread.
@ -110,7 +109,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
val numberCircle = ImageGetter.getCircle().apply { width = size / 2; height = size / 2;color = Color.BLUE } val numberCircle = ImageGetter.getCircle().apply { width = size / 2; height = size / 2;color = Color.BLUE }
moveHereButton.addActor(numberCircle) moveHereButton.addActor(numberCircle)
moveHereButton.addActor(Label(dto.turnsToGetThere.toString(), CameraStageBaseScreen.skin) moveHereButton.addActor(dto.turnsToGetThere.toString().toLabel()
.apply { center(numberCircle); setFontColor(Color.WHITE) }) .apply { center(numberCircle); setFontColor(Color.WHITE) })
val unitIcon = UnitGroup(dto.unit, size / 2) val unitIcon = UnitGroup(dto.unit, size / 2)
@ -223,7 +222,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
tileGroups[attackableTile]!!.showCrosshair() tileGroups[attackableTile]!!.showCrosshair()
} }
// Fadeout less relevant images if a military unit is selected // Fade out less relevant images if a military unit is selected
val fadeout = if (unit.type.isCivilian()) 1f val fadeout = if (unit.type.isCivilian()) 1f
else 0.5f else 0.5f
for (tile in tileGroups.values) { for (tile in tileGroups.values) {
@ -255,5 +254,4 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
worldScreen.shouldUpdate=true worldScreen.shouldUpdate=true
} }
} }

View File

@ -4,7 +4,6 @@ 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.Touchable
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
import com.unciv.UnCivGame import com.unciv.UnCivGame
@ -187,8 +186,11 @@ class WorldScreen : CameraStageBaseScreen() {
techButton.clearChildren() techButton.clearChildren()
if (civInfo.tech.currentTechnology() == null) { if (civInfo.tech.currentTechnology() == null) {
val buttonPic = Table().apply { background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png").tint(colorFromRGB(7, 46, 43)); defaults().pad(10f) } val buttonPic = Table()
buttonPic.add(Label("{Pick a tech}!".tr(), skin).setFontColor(Color.WHITE).setFontSize(22)) buttonPic.background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
.tint(colorFromRGB(7, 46, 43))
buttonPic.defaults().pad(10f)
buttonPic.add("{Pick a tech}!".toLabel().setFontColor(Color.WHITE).setFontSize(22))
techButton.add(buttonPic) techButton.add(buttonPic)
} }
else { else {
@ -320,7 +322,7 @@ class DiplomaticIncidentPopup(val worldScreen: WorldScreen, val diplomaticIncide
init { init {
val otherCiv = worldScreen.gameInfo.getCivilization(diplomaticIncident.civName) val otherCiv = worldScreen.gameInfo.getCivilization(diplomaticIncident.civName)
val otherCivLeaderName = otherCiv.getNation().leaderName+" of "+otherCiv.civName val otherCivLeaderName = otherCiv.getNation().leaderName+" of "+otherCiv.civName
add(Label(otherCivLeaderName,skin)) add(otherCivLeaderName.toLabel())
addSeparator() addSeparator()
when(diplomaticIncident.type){ when(diplomaticIncident.type){

View File

@ -23,11 +23,11 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val labelSkin = CameraStageBaseScreen.skin val labelSkin = CameraStageBaseScreen.skin
private val turnsLabel = Label("Turns: 0/400",labelSkin).setFontColor(Color.WHITE) private val turnsLabel = "Turns: 0/400".toLabel().setFontColor(Color.WHITE)
private val goldLabel = Label("Gold:", labelSkin).setFontColor(colorFromRGB(225, 217, 71) ) private val goldLabel = "Gold:".toLabel().setFontColor(colorFromRGB(225, 217, 71) )
private val scienceLabel = Label("Science:", labelSkin).setFontColor(colorFromRGB(78, 140, 151) ) private val scienceLabel = "Science:".toLabel().setFontColor(colorFromRGB(78, 140, 151) )
private val happinessLabel = Label("Happiness:", labelSkin) private val happinessLabel = "Happiness:".toLabel()
private val cultureLabel = Label("Culture:", labelSkin).setFontColor(colorFromRGB(210, 94, 210) ) private val cultureLabel = "Culture:".toLabel().setFontColor(colorFromRGB(210, 94, 210) )
private val resourceLabels = HashMap<String, Label>() private val resourceLabels = HashMap<String, Label>()
private val resourceImages = HashMap<String, Actor>() private val resourceImages = HashMap<String, Actor>()
private val happinessImage = Group() private val happinessImage = Group()
@ -63,7 +63,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val resourceImage = ImageGetter.getResourceImage(resource.name,20f) val resourceImage = ImageGetter.getResourceImage(resource.name,20f)
resourceImages[resource.name] = resourceImage resourceImages[resource.name] = resourceImage
resourceTable.add(resourceImage) resourceTable.add(resourceImage)
val resourceLabel = Label("0", labelSkin) val resourceLabel = "0".toLabel()
resourceLabels[resource.name] = resourceLabel resourceLabels[resource.name] = resourceLabel
resourceTable.add(resourceLabel) resourceTable.add(resourceLabel)
} }

View File

@ -58,7 +58,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
defaults().pad(5f) defaults().pad(5f)
val attackerNameWrapper = Table() val attackerNameWrapper = Table()
val attackerLabel = Label(attacker.getName(), skin) val attackerLabel = attacker.getName().toLabel()
if(attacker is MapUnitCombatant) if(attacker is MapUnitCombatant)
attackerNameWrapper.add(UnitGroup(attacker.unit,25f)).padRight(5f) attackerNameWrapper.add(UnitGroup(attacker.unit,25f)).padRight(5f)
attackerNameWrapper.add(attackerLabel) attackerNameWrapper.add(attackerLabel)

View File

@ -7,6 +7,7 @@ import com.unciv.UnCivGame
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.toLabel
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
class TileInfoTable(private val worldScreen: WorldScreen) : Table() { class TileInfoTable(private val worldScreen: WorldScreen) : Table() {
@ -21,7 +22,7 @@ class TileInfoTable(private val worldScreen: WorldScreen) : Table() {
if (UnCivGame.Current.viewEntireMapForDebug || civInfo.exploredTiles.contains(tile.position)) { if (UnCivGame.Current.viewEntireMapForDebug || civInfo.exploredTiles.contains(tile.position)) {
add(getStatsTable(tile)).pad(10f) add(getStatsTable(tile)).pad(10f)
add(Label(tile.toString(), skin)).colspan(2) add(tile.toString().toLabel()).colspan(2)
} }
pack() pack()

View File

@ -7,10 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.*
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.center
import com.unciv.ui.utils.onClick
open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen.skin){ open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen.skin){
init { init {
@ -28,7 +25,7 @@ open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseS
} }
fun addGoodSizedLabel(text: String): Cell<Label> { fun addGoodSizedLabel(text: String): Cell<Label> {
val label = Label(text,CameraStageBaseScreen.skin) val label = text.toLabel()
label.setWrap(true) label.setWrap(true)
return add(label).width(screen.stage.width/2) return add(label).width(screen.stage.width/2)
} }
@ -45,10 +42,10 @@ class YesNoPopupTable(question:String, action:()->Unit,
init{ init{
if(!isOpen) { if(!isOpen) {
isOpen=true isOpen=true
add(Label(question, skin)).colspan(2).row() add(question.toLabel()).colspan(2).row()
add(TextButton("No".tr(), skin).apply { onClick { close() } }) add(TextButton("No".tr(), skin).onClick { close() })
add(TextButton("Yes".tr(), skin).apply { onClick { close(); action() } }) add(TextButton("Yes".tr(), skin).onClick { close(); action() })
open() open()
} }
} }

View File

@ -3,17 +3,13 @@ package com.unciv.ui.worldscreen.optionstable
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Slider import com.badlogic.gdx.scenes.scene2d.ui.Slider
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.*
import com.unciv.ui.utils.Fonts
import com.unciv.ui.utils.Sounds
import com.unciv.ui.utils.center
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -110,7 +106,7 @@ class WorldScreenDisplayOptionsTable(screen:WorldScreen) : PopupTable(screen){
{ {
val downloading = PopupTable(screen) val downloading = PopupTable(screen)
downloading.add(Label("Downloading...", skin)) downloading.add("Downloading...".toLabel())
downloading.open() downloading.open()
Gdx.input.inputProcessor = null // no interaction until download is over Gdx.input.inputProcessor = null // no interaction until download is over
@ -126,7 +122,7 @@ class WorldScreenDisplayOptionsTable(screen:WorldScreen) : PopupTable(screen){
}) })
if (languageSelectBox.selected.percentComplete != 100) { if (languageSelectBox.selected.percentComplete != 100) {
add(Label("Missing translations:", skin)).pad(5f).row() add("Missing translations:".toLabel()).pad(5f).row()
val missingTextSelectBox = SelectBox<String>(skin) val missingTextSelectBox = SelectBox<String>(skin)
val missingTextArray = Array<String>() val missingTextArray = Array<String>()
val currentLanguage = UnCivGame.Current.settings.language val currentLanguage = UnCivGame.Current.settings.language

View File

@ -17,7 +17,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
private val prevIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,true) private val prevIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,true)
private val nextIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,false) private val nextIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,false)
private val unitIconHolder=Table() private val unitIconHolder=Table()
private val unitNameLabel = Label("",CameraStageBaseScreen.skin) private val unitNameLabel = "".toLabel()
private val promotionsTable = Table() private val promotionsTable = Table()
private val unitDescriptionTable = Table(CameraStageBaseScreen.skin) private val unitDescriptionTable = Table(CameraStageBaseScreen.skin)
var selectedUnit : MapUnit? = null var selectedUnit : MapUnit? = null