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 isBeingRazed = false
var attackedThisTurn = false
var hasSoldBuildingThisTurn = false
constructor() // for json parsing, we need to have a default constructor
constructor(civInfo: CivilizationInfo, cityLocation: Vector2) {
@ -245,7 +246,7 @@ class CityInfo {
return false
}
fun tryUpdateRoadStatus(){
private fun tryUpdateRoadStatus(){
if(getCenterTile().roadStatus==RoadStatus.None
&& GameBasics.TileImprovements["Road"]!!.techRequired in civInfo.tech.techsResearched)
getCenterTile().roadStatus==RoadStatus.Road
@ -254,5 +255,13 @@ class CityInfo {
&& GameBasics.TileImprovements["Railroad"]!!.techRequired in civInfo.tech.techsResearched)
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
}

View file

@ -9,6 +9,7 @@ import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.ICivilopedia
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import java.util.*
class CivilopediaScreen : CameraStageBaseScreen() {
@ -23,7 +24,7 @@ class CivilopediaScreen : CameraStageBaseScreen() {
stage.addActor(splitPane)
val label = Label("", CameraStageBaseScreen.skin)
val label = "".toLabel()
label.setWrap(true)
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.scenes.scene2d.Actor
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.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
@ -64,7 +63,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
topTable.add(setCurrentTradesButton)
val setUnitsButton = TextButton("Units".tr(),skin)
setUnitsButton .onClick {
setUnitsButton.onClick {
centerTable.clear()
centerTable.add(ScrollPane(getUnitTable())).height(stage.height*0.8f)
centerTable.pack()
@ -110,15 +109,15 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val table = Table()
table.defaults().pad(10f)
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()
for(offer in offersList){
var offerText = offer.amount.toString()+" "+offer.name.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)
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
}
@ -126,7 +125,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
private fun getHappinessTable(): Table {
val happinessTable = Table(skin)
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()
for (entry in currentPlayerCivInfo.getHappinessForNextTurn()) {
happinessTable.add(entry.key.tr())
@ -141,7 +140,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
private fun getGoldTable(): Table {
val goldTable = Table(skin)
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()
var total=0f
for (entry in currentPlayerCivInfo.getStatMapForNextTurn()) {
@ -165,7 +164,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val pointsToGreatPerson = currentPlayerCivInfo.greatPeople.pointsForNextGreatPerson
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.add()
greatPeopleTable.add("Current points")
@ -180,7 +179,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val pointsForGreatGeneral = currentPlayerCivInfo.greatPeople.greatGeneralPoints.toInt().toString()
val pointsForNextGreatGeneral = currentPlayerCivInfo.greatPeople.pointsForNextGreatGeneral.toInt().toString()
greatPeopleTable.add("Great General".tr())
greatPeopleTable.add(pointsForGreatGeneral+"/"+pointsForNextGreatGeneral).row()
greatPeopleTable.add("$pointsForGreatGeneral/$pointsForNextGreatGeneral").row()
greatPeopleTable.pack()
return greatPeopleTable
}
@ -194,7 +193,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val cityInfoTableIcons = Table(skin)
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(ImageGetter.getStatIcon("Population")).size(iconSize)
cityInfoTableIcons.add(ImageGetter.getStatIcon("Food")).size(iconSize)
@ -305,7 +304,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
var civNameText = civ.civName.tr()
if(civ.isDefeated()) civNameText += "\n({Defeated})".tr()
val label = Label(civNameText, CameraStageBaseScreen.skin)
val label = civNameText.toLabel()
label.setAlignment(Align.center)
if (civ.isDefeated()) {

View file

@ -85,7 +85,7 @@ class LanguagePickerScreen: PickerScreen(){
"Do you want to download fonts for $spaceSplitLang?",
{
val downloading = PopupTable(this)
downloading.add(Label("Downloading...",skin))
downloading.add("Downloading...".toLabel())
downloading.open()
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.onClick
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){
val innerTable = Table()
@ -19,8 +20,9 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
background= ImageGetter.getBackground(nation.getSecondaryColor())
innerTable.pad(10f)
innerTable.background= ImageGetter.getBackground(nation.getColor())
innerTable.add(Label(nation.leaderName.tr()+" - "+nation.name.tr(), skin).apply { setFontColor(nation.getSecondaryColor())}).row()
innerTable.add(Label(getUniqueLabel(nation), skin)
innerTable.add(Label(nation.leaderName.tr()+" - "+nation.name.tr(), skin)
.apply { setFontColor(nation.getSecondaryColor())}).row()
innerTable.add(getUniqueLabel(nation)
.apply { setWrap(true);setFontColor(nation.getSecondaryColor())})
.width(width)
onClick {
@ -37,7 +39,7 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
add(innerTable)
}
private fun getUniqueLabel(nation: Nation): String {
private fun getUniqueLabel(nation: Nation): Label {
val textList = ArrayList<String>()
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.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.utils.Array
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.enable
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import com.unciv.ui.worldscreen.WorldScreen
import kotlin.concurrent.thread
import kotlin.math.min
@ -77,7 +81,7 @@ class NewGameScreen: PickerScreen(){
mapTypes[type.toString()] = type
}
val mapFileLabel = Label("{Map file}:".tr(),skin)
val mapFileLabel = "{Map file}:".toLabel()
val mapFileSelectBox = getMapFileSelectBox()
mapFileLabel.isVisible=false
mapFileSelectBox.isVisible=false
@ -85,7 +89,7 @@ class NewGameScreen: PickerScreen(){
val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin)
val worldSizeSelectBox = getWorldSizeSelectBox()
val worldSizeLabel = Label("{World size}:".tr(),skin)
val worldSizeLabel = "{World size}:".toLabel()
mapTypeSelectBox.addListener(object : ChangeListener() {
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)
for (building in wonders) {
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()
}
@ -47,7 +47,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val specialistBuildingsExpander = ExpanderTab("Specialist Buildings".tr(),skin)
for (building in specialistBuildings) {
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()
specialistIcons.row().size(20f).pad(5f)
for(stat in building.specialistSlots!!.toHashMap())
@ -66,7 +66,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val buildingsExpanderTab = ExpanderTab("Buildings".tr(),skin)
for (building in otherBuildings) {
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()
}
@ -96,13 +96,14 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
for(stat in statToCauses){
val expander = ExpanderTab(stat.key.name.tr(),skin)
expander.innerTable.defaults().pad(2f)
for(entry in stat.value) {
expander.innerTable.add(Label(entry.key.tr(), skin))
expander.innerTable.add(Label(DecimalFormat("0.#").format(entry.value), skin)).row()
expander.innerTable.add(entry.key.toLabel())
expander.innerTable.add(DecimalFormat("0.#").format(entry.value).toLabel()).row()
}
if(stat.value.isNotEmpty()){
expander.innerTable.add(Label("Total".tr(),skin))
expander.innerTable.add(Label(DecimalFormat("0.#").format(stat.value.values.sum()),skin))
expander.innerTable.add("Total".toLabel())
expander.innerTable.add(DecimalFormat("0.#").format(stat.value.values.sum()).toLabel())
add(expander).row()
}
}

View file

@ -20,14 +20,26 @@ import kotlin.math.round
class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
private var selectedTile: TileInfo? = null
private var tileTable = Table()
private var cityInfoTable = CityInfoTable(this)
private var constructionsTable = ConstructionsTable(this)
private var cityPickerTable = Table()
private var razeCityButtonHolder = Table()
private var tileGroups = ArrayList<CityTileGroup>()
// Clockwise from the top-left
/** Displays city stats - sits on the top left side */
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 {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
addTiles()
@ -131,7 +143,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
if(stat.key==Stat.Happiness) continue
val minitable=Table().padRight(5f).padLeft(5f)
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)
}
return table.addBorder(2f, beige)
@ -335,4 +347,5 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
tileTable.setPosition(stage.width - 5f - tileTable.width, 5f)
stage.addActor(tileTable)
}
}
}

View file

@ -2,7 +2,6 @@ package com.unciv.ui.cityscreen
import com.badlogic.gdx.graphics.Color
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.Table
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.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 {
cityScreen.city.cityConstructions.currentConstruction = construction
update()
@ -58,7 +57,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
if(list.isEmpty()) return
val titleTable = Table()
titleTable.background = ImageGetter.getBackground(ImageGetter.getBlue())
titleTable.add(Label(title.tr(),CameraStageBaseScreen.skin))
titleTable.add(title.toLabel())
addSeparator()
add(titleTable).fill().row()
@ -151,7 +150,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
.pad(5f)
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 description: String
@ -161,7 +160,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
description = currentConstruction.getDescription(true, city.civInfo.policies.adoptedPolicies)
else description = currentConstruction.description.tr()
val descriptionLabel = Label(description, CameraStageBaseScreen.skin)
val descriptionLabel = description.toLabel()
descriptionLabel.setWrap(true)
descriptionLabel.width = stage.width / 4
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.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.unciv.UnCivGame
import com.unciv.logic.civilization.GreatPersonManager
import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.tr
import com.unciv.models.gamebasics.unit.BaseUnit
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.setFontColor
import com.unciv.ui.utils.toLabel
class GreatPersonPickerScreen : PickerScreen() {
private var theChosenOne: BaseUnit? = null
@ -23,7 +24,7 @@ class GreatPersonPickerScreen : PickerScreen() {
val button = Button(skin)
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.onClick {
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.utils.Align
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.disable
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.*
open class PickerScreen : CameraStageBaseScreen() {
@ -22,7 +19,7 @@ open class PickerScreen : CameraStageBaseScreen() {
init {
bottomTable.add(closeButton).width(stage.width / 4)
descriptionLabel = Label("", CameraStageBaseScreen.skin)
descriptionLabel = "".toLabel()
descriptionLabel.setWrap(true)
val labelScroll = ScrollPane(descriptionLabel)
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.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.unciv.UnCivGame
import com.unciv.logic.map.MapUnit
@ -37,7 +36,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() {
if(!isPromotionAvailable) promotionButton.color = Color.GRAY
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)
if(unitHasPromotion) promotionButton.color = Color.GREEN

View file

@ -51,7 +51,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
}
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) }
// 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.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.TextButton
import com.badlogic.gdx.utils.Json
@ -61,7 +60,7 @@ class LoadScreen : PickerScreen() {
val rightSideTable = Table()
val loadFromClipboardButton = TextButton("Load copied data".tr(),skin)
val errorLabel = Label("",skin).setFontColor(Color.RED)
val errorLabel = "".toLabel().setFontColor(Color.RED)
loadFromClipboardButton.onClick {
try{
val clipboardContentsString = Gdx.app.clipboard.contents

View file

@ -1,7 +1,6 @@
package com.unciv.ui.saves
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.TextButton
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.getRandom
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
class SaveScreen : PickerScreen() {
@ -22,7 +22,7 @@ class SaveScreen : PickerScreen() {
setDefaultCloseAction()
val currentSaves = Table()
currentSaves.add(Label("Current saves".tr(),skin)).row()
currentSaves.add("Current saves".toLabel()).row()
val saves = GameSaver().getSaves()
saves.forEach {
val textButton = TextButton(it, skin)
@ -44,7 +44,7 @@ class SaveScreen : PickerScreen() {
val defaultSaveName = adjectives.getRandom()+" "+nouns.getRandom()
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()
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.scenes.scene2d.Group
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.Table
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.map.RoadStatus
import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.tilegroups.WorldTileGroup
import com.unciv.ui.utils.*
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
background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
.tint(city.civInfo.getNation().getColor())
val label = Label(cityButtonText, CameraStageBaseScreen.skin)
val label = cityButtonText.toLabel()
label.setFontColor(city.civInfo.getNation().getSecondaryColor())
clear()
@ -97,7 +95,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
val secondaryColor = cityConstructions.cityInfo.civInfo.getNation().getSecondaryColor()
if(cityConstructions.getCurrentConstruction() !is SpecialConstruction) {
val turnsToConstruction = cityConstructions.turnsToConstruction(cityConstructions.currentConstruction)
val label = Label(turnsToConstruction.toString(), CameraStageBaseScreen.skin)
val label = turnsToConstruction.toString().toLabel()
label.setFontColor(secondaryColor)
label.setFontSize(10)
label.pack()

View file

@ -44,7 +44,7 @@ class DiplomacyScreen:CameraStageBaseScreen(){
civTable.defaults().pad(10f)
val peaceWarStatus = civDiplomacy.diplomaticStatus.toString()
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()
val tradeButton = TextButton("Trade".tr(), skin)
@ -68,7 +68,7 @@ class DiplomacyScreen:CameraStageBaseScreen(){
val responsePopup = PopupTable(this)
val otherCivLeaderName = civ.getNation().leaderName + " of " + civ.civName
responsePopup.add(Label(otherCivLeaderName, skin))
responsePopup.add(otherCivLeaderName.toLabel())
responsePopup.addSeparator()
responsePopup.addGoodSizedLabel(civ.getNation().attacked).row()
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.utils.viewport.ExtendViewport
import com.unciv.UnCivGame
import com.unciv.models.gamebasics.tr
open class CameraStageBaseScreen : Screen {
@ -53,8 +54,6 @@ open class CameraStageBaseScreen : Screen {
}
companion object {
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)
return this
}
fun Actor.surroundWithCircle(size:Float): IconCircleGroup {
@ -196,3 +196,6 @@ fun <T> HashSet<T>.withoutItem(item:T): HashSet<T> {
newHashSet.remove(item)
return newHashSet
}
/** also translates */
fun String.toLabel() = Label(this.tr(),CameraStageBaseScreen.skin)

View file

@ -1,7 +1,6 @@
package com.unciv.ui.worldscreen
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.Table
import com.unciv.logic.civilization.Notification
@ -19,7 +18,7 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu
internal fun update(notifications: MutableList<Notification>) {
notificationsTable.clearChildren()
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)
val minitable = Table()

View file

@ -1,11 +1,9 @@
package com.unciv.ui.worldscreen
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.unciv.UnCivGame
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.*
class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScreen(){
@ -14,7 +12,7 @@ class PlayerReadyScreen(currentPlayerCiv: CivilizationInfo) : CameraStageBaseScr
table.touchable= Touchable.enabled
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()))
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.Group
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.utils.ActorGestureListener
import com.unciv.UnCivGame
@ -89,7 +88,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
private fun queueAddMoveHereButton(selectedUnit: MapUnit, tileInfo: TileInfo) {
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.
* 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.
@ -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 }
moveHereButton.addActor(numberCircle)
moveHereButton.addActor(Label(dto.turnsToGetThere.toString(), CameraStageBaseScreen.skin)
moveHereButton.addActor(dto.turnsToGetThere.toString().toLabel()
.apply { center(numberCircle); setFontColor(Color.WHITE) })
val unitIcon = UnitGroup(dto.unit, size / 2)
@ -223,7 +222,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
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
else 0.5f
for (tile in tileGroups.values) {
@ -255,5 +254,4 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
worldScreen.shouldUpdate=true
}
}

View file

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

View file

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

View file

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

View file

@ -7,6 +7,7 @@ import com.unciv.UnCivGame
import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.toLabel
import com.unciv.ui.worldscreen.WorldScreen
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)) {
add(getStatsTable(tile)).pad(10f)
add(Label(tile.toString(), skin)).colspan(2)
add(tile.toString().toLabel()).colspan(2)
}
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.unciv.UnCivGame
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.center
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.*
open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen.skin){
init {
@ -28,7 +25,7 @@ open class PopupTable(val screen: CameraStageBaseScreen): Table(CameraStageBaseS
}
fun addGoodSizedLabel(text: String): Cell<Label> {
val label = Label(text,CameraStageBaseScreen.skin)
val label = text.toLabel()
label.setWrap(true)
return add(label).width(screen.stage.width/2)
}
@ -45,10 +42,10 @@ class YesNoPopupTable(question:String, action:()->Unit,
init{
if(!isOpen) {
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("Yes".tr(), skin).apply { onClick { close(); action() } })
add(TextButton("No".tr(), skin).onClick { close() })
add(TextButton("Yes".tr(), skin).onClick { close(); action() })
open()
}
}

View file

@ -3,17 +3,13 @@ package com.unciv.ui.worldscreen.optionstable
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.g2d.Batch
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.Slider
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.Array
import com.unciv.UnCivGame
import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.Fonts
import com.unciv.ui.utils.Sounds
import com.unciv.ui.utils.center
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.WorldScreen
import kotlin.concurrent.thread
@ -110,7 +106,7 @@ class WorldScreenDisplayOptionsTable(screen:WorldScreen) : PopupTable(screen){
{
val downloading = PopupTable(screen)
downloading.add(Label("Downloading...", skin))
downloading.add("Downloading...".toLabel())
downloading.open()
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) {
add(Label("Missing translations:", skin)).pad(5f).row()
add("Missing translations:".toLabel()).pad(5f).row()
val missingTextSelectBox = SelectBox<String>(skin)
val missingTextArray = Array<String>()
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 nextIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,false)
private val unitIconHolder=Table()
private val unitNameLabel = Label("",CameraStageBaseScreen.skin)
private val unitNameLabel = "".toLabel()
private val promotionsTable = Table()
private val unitDescriptionTable = Table(CameraStageBaseScreen.skin)
var selectedUnit : MapUnit? = null