City construction Civilopedia-linked (#4573)

* City construction Civilopedia-linked

* City construction Civilopedia-linked - EOF
This commit is contained in:
SomeTroglodyte 2021-07-21 09:34:00 +02:00 committed by GitHub
parent 92c4e4e083
commit 70a18de7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 27 deletions

View File

@ -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()

View File

@ -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()) {

View File

@ -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()

View File

@ -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)
}
}
}