From 70a18de7ccf9776d878cb37146b96f7a135d027c Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Wed, 21 Jul 2021 09:34:00 +0200 Subject: [PATCH] City construction Civilopedia-linked (#4573) * City construction Civilopedia-linked * City construction Civilopedia-linked - EOF --- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 4 +- .../com/unciv/ui/cityscreen/CityInfoTable.kt | 2 +- .../ui/cityscreen/CityScreenTileTable.kt | 2 +- .../ui/cityscreen/ConstructionInfoTable.kt | 55 +++++++++++-------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index 081fb943e8..41d1680031 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -125,9 +125,9 @@ class BaseUnit : INamed, IConstruction, CivilopediaText() { if (uniqueTo != null) { textList += FormattedLine() - textList += FormattedLine("Unique to [$uniqueTo],", link="Nation/$uniqueTo") + textList += FormattedLine("Unique to [$uniqueTo]", link="Nation/$uniqueTo") if (replaces != null) - textList += FormattedLine("replaces [$replaces]", link="Unit/$replaces", indent=1) + textList += FormattedLine("Replaces [$replaces]", link="Unit/$replaces", indent=1) } if (requiredTech != null || upgradesTo != null || obsoleteTech != null) textList += FormattedLine() diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index 4439f0b471..a9b5126783 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -64,7 +64,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS private fun addBuildingInfo(building: Building, destinationTable: Table) { val icon = ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f) val buildingNameAndIconTable = ExpanderTab(building.name, 18, icon, false, 5f) { - val detailsString = building.getDescription(cityScreen.city, cityScreen.city.civInfo.gameInfo.ruleSet) + val detailsString = building.getDescription(cityScreen.city, cityScreen.city.getRuleset()) it.add(detailsString.toLabel().apply { wrap = true }) .width(cityScreen.stage.width / 4 - 2 * pad).row() // when you set wrap, then you need to manually set the size of the label if (building.isSellable()) { diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt index 5ccb6eab80..572ea93681 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt @@ -36,7 +36,7 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table() { innerTable.add( MarkupRenderer.render(selectedTile.toMarkup(city.civInfo), noLinkImages = true) { // Sorry, this will leave the city screen - UncivGame.Current.setScreen(CivilopediaScreen(city.civInfo.gameInfo.ruleSet, link = it)) + UncivGame.Current.setScreen(CivilopediaScreen(city.getRuleset(), link = it)) } ) innerTable.row() innerTable.add(getTileStatsTable(stats)).row() diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt index f3078ee750..9cf879a1cf 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt @@ -1,19 +1,23 @@ 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.Table +import com.unciv.UncivGame import com.unciv.logic.city.CityInfo import com.unciv.logic.city.IConstruction import com.unciv.logic.city.PerpetualConstruction import com.unciv.models.ruleset.Building import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.translations.tr +import com.unciv.ui.civilopedia.CivilopediaScreen import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.onClick import com.unciv.ui.utils.surroundWithCircle import com.unciv.ui.utils.toLabel class ConstructionInfoTable(val city: CityInfo): Table() { - val selectedConstructionTable = Table() + private val selectedConstructionTable = Table() init { selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) @@ -23,7 +27,6 @@ class ConstructionInfoTable(val city: CityInfo): Table() { fun update(selectedConstruction: IConstruction?) { selectedConstructionTable.clear() - selectedConstructionTable.pad(5f) if (selectedConstruction == null) { isVisible = false @@ -31,42 +34,48 @@ class ConstructionInfoTable(val city: CityInfo): Table() { } isVisible = true - addSelectedConstructionTable(selectedConstruction) + updateSelectedConstructionTable(selectedConstruction) pack() } - private fun addSelectedConstructionTable(construction: IConstruction) { + private fun updateSelectedConstructionTable(construction: IConstruction) { val cityConstructions = city.cityConstructions //val selectedConstructionTable = Table() - selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) - selectedConstructionTable.pad(10f) + selectedConstructionTable.run { + background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) + pad(10f) - selectedConstructionTable.add( - ImageGetter.getConstructionImage(construction.name).surroundWithCircle(50f)) + add(ImageGetter.getConstructionImage(construction.name).surroundWithCircle(50f)) .pad(5f) + var buildingText = construction.name.tr() + val specialConstruction = PerpetualConstruction.perpetualConstructionsMap[construction.name] - var buildingText = construction.name.tr() - val specialConstruction = PerpetualConstruction.perpetualConstructionsMap[construction.name] + buildingText += specialConstruction?.getProductionTooltip(city) + ?: cityConstructions.getTurnsToConstructionString(construction.name) - if (specialConstruction == null) buildingText += cityConstructions.getTurnsToConstructionString(construction.name) - else buildingText += specialConstruction.getProductionTooltip(city) + add(buildingText.toLabel()).row() - selectedConstructionTable.add(buildingText.toLabel()).row() + val (description, link) = when (construction) { + is BaseUnit -> construction.getDescription() to "Unit/${construction.name}" + is Building -> construction.getDescription(city, city.getRuleset()) to construction.makeLink() + is PerpetualConstruction -> construction.description.replace("[rate]", "[${construction.getConversionRate(city)}]") to "" + else -> "" to "" // Should never happen + } + val descriptionLabel = description.toLabel() + descriptionLabel.wrap = true + add(descriptionLabel).colspan(2).width(stage.width / 4) - val description: String = when (construction) { - is BaseUnit -> construction.getDescription() - is Building -> construction.getDescription(city, city.civInfo.gameInfo.ruleSet) - is PerpetualConstruction -> construction.description.replace("[rate]", "[${construction.getConversionRate(city)}]").tr() - else -> "" // Should never happen + clearListeners() + if (link.isEmpty()) return + touchable = Touchable.enabled + onClick { + UncivGame.Current.setScreen(CivilopediaScreen(city.getRuleset(), link = link)) + } } - - val descriptionLabel = description.toLabel() - descriptionLabel.wrap = true - selectedConstructionTable.add(descriptionLabel).colspan(2).width(stage.width / 4) } -} \ No newline at end of file +}