From 7d9b56e3b18944737aac47281a08e1fd46d948e0 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 7 Feb 2021 19:13:10 +0200 Subject: [PATCH] Fixed queue showing "Consumes 1" when no resource is consumed Plus linting --- core/src/com/unciv/logic/map/TileInfo.kt | 3 ++- .../com/unciv/ui/cityscreen/CityInfoTable.kt | 6 +++--- .../cityscreen/CityScreenCityPickerTable.kt | 20 +++++++++---------- .../com/unciv/ui/cityscreen/CityTileGroup.kt | 17 ++++++---------- .../ui/cityscreen/ConstructionInfoTable.kt | 10 +++++----- .../unciv/ui/cityscreen/ConstructionsTable.kt | 5 +++-- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 0e2403ddb3..ee149988d1 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -39,7 +39,8 @@ open class TileInfo { // This will be called often - farm can be built on Hill and tundra if adjacent to fresh water // and farms on adjacent to fresh water tiles will have +1 additional Food after researching Civil Service @delegate:Transient - val isAdjacentToFreshwater: Boolean by lazy { matchesUniqueFilter("River") || matchesUniqueFilter("Fresh water") || neighbors.any { it.matchesUniqueFilter("Fresh water") } } + val isAdjacentToFreshwater: Boolean by lazy { matchesUniqueFilter("River") || matchesUniqueFilter("Fresh water") + || neighbors.any { it.matchesUniqueFilter("Fresh water") } } var militaryUnit: MapUnit? = null var civilianUnit: MapUnit? = null diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index c85e67b6d2..5929e09b49 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -181,8 +181,8 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS for ((key, value) in cityStats.baseStatList) relevantBaseStats[key] = value.get(stat) else relevantBaseStats.putAll(cityStats.happinessList) - for(key in relevantBaseStats.keys.toList()) - if(relevantBaseStats[key]==0f) relevantBaseStats.remove(key) + for (key in relevantBaseStats.keys.toList()) + if (relevantBaseStats[key] == 0f) relevantBaseStats.remove(key) if (relevantBaseStats.isEmpty()) continue @@ -220,7 +220,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS else statValuesTable.add("$decimal%".toLabel()).row() // negative bonus } - if(stat!=Stat.Happiness) { + if (stat != Stat.Happiness) { statValuesTable.add("Final".toLabel(fontSize = FONT_SIZE_STAT_INFO_HEADER)).colspan(2).padTop(20f).row() var finalTotal = 0f for (entry in cityStats.finalStatList) { diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt index c5275f5e1c..6979e054c0 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt @@ -7,7 +7,7 @@ import com.badlogic.gdx.utils.Align import com.unciv.models.translations.tr import com.unciv.ui.utils.* -class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ +class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table() { fun update() { val city = cityScreen.city @@ -25,18 +25,18 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ } else add() val cityNameTable = Table() - if(city.isBeingRazed){ + if (city.isBeingRazed) { val fireImage = ImageGetter.getImage("OtherIcons/Fire") cityNameTable.add(fireImage).size(20f).padRight(5f) } - if(city.isCapital()){ - val starImage = ImageGetter.getImage("OtherIcons/Star").apply { color= Color.LIGHT_GRAY } + if (city.isCapital()) { + val starImage = ImageGetter.getImage("OtherIcons/Star").apply { color = Color.LIGHT_GRAY } cityNameTable.add(starImage).size(20f).padRight(5f) } - if(city.isPuppet){ - val starImage = ImageGetter.getImage("OtherIcons/Puppet").apply { color= Color.LIGHT_GRAY } + if (city.isPuppet) { + val starImage = ImageGetter.getImage("OtherIcons/Puppet").apply { color = Color.LIGHT_GRAY } cityNameTable.add(starImage).size(20f).padRight(5f) } @@ -53,7 +53,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ textArea.alignment = Align.center editCityNamePopup.add(textArea).colspan(2).row() editCityNamePopup.addCloseButton() - editCityNamePopup.addButton("Save".tr()){ + editCityNamePopup.addButton("Save".tr()) { city.name = textArea.text cityScreen.game.setScreen(CityScreen(city)) } @@ -62,14 +62,14 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ cityNameTable.add(currentCityLabel) - add(cityNameTable).width(stage.width/4) + add(cityNameTable).width(stage.width / 4) if (civInfo.cities.size > 1) { val nextCityButton = Table() // so we gt a wider clickable area than just the image itself val image = ImageGetter.getImage("OtherIcons/BackArrow") - image.setSize(25f,25f) + image.setSize(25f, 25f) image.setOrigin(Align.center) image.rotation = 180f image.color = civInfo.nation.getInnerColor() @@ -80,4 +80,4 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ pack() } -} +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt index 0e3425896b..f7aba67a21 100644 --- a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt +++ b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt @@ -40,7 +40,7 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin baseLayerGroup.color.a = 0.5f } - tileInfo.isWorked() && tileInfo.getWorkingCity()!=city -> { + tileInfo.isWorked() && tileInfo.getWorkingCity() != city -> { // Don't fade out, but don't add a population icon either. baseLayerGroup.color.a = 0.5f } @@ -72,13 +72,12 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin yieldGroup.setScale(0.7f) yieldGroup.toFront() yieldGroup.centerX(this) - yieldGroup.y= height * 0.25f - yieldGroup.height / 2 + yieldGroup.y = height * 0.25f - yieldGroup.height / 2 if (tileInfo.isWorked()) { yieldGroup.color = Color.WHITE - } - else if(!tileInfo.isCityCenter()){ - yieldGroup.color = Color.GRAY.cpy().apply { a=0.5f } + } else if (!tileInfo.isCityCenter()) { + yieldGroup.color = Color.GRAY.cpy().apply { a = 0.5f } } } @@ -89,12 +88,8 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin populationIcon.setPosition(width / 2 - populationIcon.width / 2, height * 0.85f - populationIcon.height / 2) - if (tileInfo.isWorked()) { - populationIcon.color = Color.WHITE - } - else if(!tileInfo.isCityCenter()){ - populationIcon.color = Color.GRAY.cpy() - } + if (tileInfo.isWorked()) populationIcon.color = Color.WHITE + else if (!tileInfo.isCityCenter()) populationIcon.color = Color.GRAY.cpy() populationIcon.toFront() } diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt index 665ba4fdf8..35a39b5805 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt @@ -16,7 +16,8 @@ import com.unciv.ui.utils.AutoScrollPane as ScrollPane class ConstructionInfoTable(val city: CityInfo): Table() { val selectedConstructionTable = Table() - init{ + + init { selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) add(selectedConstructionTable).pad(2f).fill() background = ImageGetter.getBackground(Color.WHITE) @@ -41,7 +42,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() { val cityConstructions = city.cityConstructions //val selectedConstructionTable = Table() - selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK,0.5f)) + selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) selectedConstructionTable.pad(10f) selectedConstructionTable.add( @@ -55,8 +56,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() { val turnsToComplete = cityConstructions.turnsToConstruction(construction.name) buildingText += ("\r\n" + "Cost".tr() + " " + construction.getProductionCost(city.civInfo).toString()).tr() buildingText += turnOrTurns(turnsToComplete) - } - else { + } else { buildingText += specialConstruction.getProductionTooltip(city) } selectedConstructionTable.add(buildingText.toLabel()).row() @@ -65,7 +65,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() { val description: String = when (construction) { is BaseUnit -> construction.getDescription(true) is Building -> construction.getDescription(true, city.civInfo, city.civInfo.gameInfo.ruleSet) - is PerpetualConstruction -> construction.description.replace("[rate]","[${construction.getConversionRate(city)}]") .tr() + is PerpetualConstruction -> construction.description.replace("[rate]", "[${construction.getConversionRate(city)}]").tr() else -> "" // Should never happen } diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt index 43f53fe166..a1bd6ef425 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt @@ -228,9 +228,10 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre else turnOrTurns(turnsToComplete) val constructionResource = cityConstructions.getConstruction(name).getResourceRequirements() + for ((resource, amount) in constructionResource) + if (amount == 1) text += "\n" + "Consumes 1 [$resource]".tr() + else text += "\n" + "Consumes [$amount] [$resource]".tr() - if (constructionResource != null) - text += "\n" + "Consumes 1 [$constructionResource]".tr() table.defaults().pad(2f).minWidth(40f) if (isFirstConstructionOfItsKind) table.add(getProgressBar(name)).minWidth(5f)