mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-09 07:18:57 +07:00
Show available resources from CityScreen (bottom right info only) (#6667)
This commit is contained in:
@ -73,6 +73,7 @@ Requires a [buildingName] in this city =
|
||||
Cannot be built with [buildingName] =
|
||||
Consumes 1 [resource] =
|
||||
Consumes [amount] [resource] =
|
||||
[amount] available =
|
||||
Required tech: [requiredTech] =
|
||||
Requires [PolicyOrNationalWonder] =
|
||||
Cannot be purchased =
|
||||
|
@ -99,7 +99,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
}
|
||||
|
||||
/** used in CityScreen (CityInfoTable and ConstructionInfoTable) */
|
||||
fun getDescription(cityInfo: CityInfo, showMissingRequiredCities:Boolean): String {
|
||||
fun getDescription(cityInfo: CityInfo, showAdditionalInfo: Boolean): String {
|
||||
val stats = getStats(cityInfo)
|
||||
val lines = ArrayList<String>()
|
||||
val isFree = name in cityInfo.civInfo.civConstructions.getFreeBuildings(cityInfo.id)
|
||||
@ -109,8 +109,13 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
if (isWonder) lines += "Wonder"
|
||||
if (isNationalWonder) lines += "National Wonder"
|
||||
if (!isFree) {
|
||||
val availableResources = if(!showAdditionalInfo) emptyMap()
|
||||
else cityInfo.civInfo.getCivResources().associate { it.resource.name to it.amount }
|
||||
for ((resource, amount) in getResourceRequirements()) {
|
||||
lines += "Consumes [$amount] [$resource]"
|
||||
val available = availableResources[resource] ?: 0
|
||||
lines += if (showAdditionalInfo)
|
||||
"{Consumes [$amount] [$resource]} ({[$available] available})"
|
||||
else "Consumes [$amount] [$resource]"
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +153,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
if (cityStrength != 0) lines += "{City strength} +$cityStrength"
|
||||
if (cityHealth != 0) lines += "{City health} +$cityHealth"
|
||||
if (maintenance != 0 && !isFree) lines += "{Maintenance cost}: $maintenance {Gold}"
|
||||
if (showMissingRequiredCities && missingCities.isNotEmpty()) {
|
||||
if (showAdditionalInfo && missingCities.isNotEmpty()) {
|
||||
// Could be red. But IMO that should be done by enabling GDX's ColorMarkupLanguage globally instead of adding a separate label.
|
||||
lines += "\n" +
|
||||
"[${cityInfo.civInfo.getEquivalentBuilding(missingUnique!!.params[0])}] required:".tr() +
|
||||
@ -407,8 +412,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
}
|
||||
|
||||
override fun getStatBuyCost(cityInfo: CityInfo, stat: Stat): Int? {
|
||||
var cost = getBaseBuyCost(cityInfo, stat)?.toDouble()
|
||||
if (cost == null) return null
|
||||
var cost = getBaseBuyCost(cityInfo, stat)?.toDouble() ?: return null
|
||||
|
||||
for (unique in cityInfo.getMatchingUniques(UniqueType.BuyItemsDiscount))
|
||||
if (stat.name == unique.params[0])
|
||||
|
@ -71,12 +71,14 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
||||
return infoList.joinToString()
|
||||
}
|
||||
|
||||
/** Generate description as multi-line string for Nation description addUniqueUnitsText and CityScreen addSelectedConstructionTable */
|
||||
fun getDescription(): String {
|
||||
/** Generate description as multi-line string for CityScreen addSelectedConstructionTable
|
||||
* @param cityInfo Supplies civInfo to show available resources after resource requirements */
|
||||
fun getDescription(cityInfo: CityInfo): String {
|
||||
val lines = mutableListOf<String>()
|
||||
val availableResources = cityInfo.civInfo.getCivResources().associate { it.resource.name to it.amount }
|
||||
for ((resource, amount) in getResourceRequirements()) {
|
||||
lines += if (amount == 1) "Consumes 1 [$resource]".tr()
|
||||
else "Consumes [$amount] [$resource]".tr()
|
||||
val available = availableResources[resource] ?: 0
|
||||
lines += "Consumes ${if (amount == 1) "1" else "[$amount]"} [$resource] ({[$available] available})".tr()
|
||||
}
|
||||
var strengthLine = ""
|
||||
if (strength != 0) {
|
||||
@ -89,6 +91,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
||||
if (replacementTextForUniques != "") lines += replacementTextForUniques
|
||||
else for (unique in uniqueObjects.filterNot {
|
||||
it.type == UniqueType.Unbuildable
|
||||
|| it.type == UniqueType.ConsumesResources // already shown from getResourceRequirements
|
||||
|| it.type?.flags?.contains(UniqueFlag.HiddenToUsers) == true
|
||||
})
|
||||
lines += unique.text.tr()
|
||||
@ -325,8 +328,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
||||
}
|
||||
|
||||
override fun getStatBuyCost(cityInfo: CityInfo, stat: Stat): Int? {
|
||||
var cost = getBaseBuyCost(cityInfo, stat)?.toDouble()
|
||||
if (cost == null) return null
|
||||
var cost = getBaseBuyCost(cityInfo, stat)?.toDouble() ?: return null
|
||||
|
||||
for (unique in cityInfo.getMatchingUniques(UniqueType.BuyUnitsDiscount)) {
|
||||
if (stat.name == unique.params[0] && matchesFilter(unique.params[1]))
|
||||
|
@ -2,11 +2,13 @@ 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.Table
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.city.PerpetualConstruction
|
||||
import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.ruleset.RulesetObject
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.CivilopediaScreen
|
||||
@ -53,20 +55,21 @@ class ConstructionInfoTable(val cityScreen: CityScreen): Table() {
|
||||
buildingText += specialConstruction?.getProductionTooltip(city)
|
||||
?: cityConstructions.getTurnsToConstructionString(construction.name)
|
||||
|
||||
add(buildingText.toLabel()).row()
|
||||
add(Label(buildingText, BaseScreen.skin)).row() // already translated
|
||||
|
||||
val (description, link) = when (construction) {
|
||||
is BaseUnit -> construction.getDescription() to construction.makeLink()
|
||||
is Building -> construction.getDescription(city, true) to construction.makeLink()
|
||||
is PerpetualConstruction -> construction.description.replace("[rate]", "[${construction.getConversionRate(city)}]") to ""
|
||||
else -> "" to "" // Should never happen
|
||||
val description = when (construction) {
|
||||
is BaseUnit -> construction.getDescription(city)
|
||||
is Building -> construction.getDescription(city, true)
|
||||
is PerpetualConstruction -> construction.description.replace("[rate]", "[${construction.getConversionRate(city)}]").tr()
|
||||
else -> "" // Should never happen
|
||||
}
|
||||
|
||||
val descriptionLabel = description.toLabel()
|
||||
val descriptionLabel = Label(description, BaseScreen.skin) // already translated
|
||||
descriptionLabel.wrap = true
|
||||
add(descriptionLabel).colspan(2).width(stage.width / 4)
|
||||
|
||||
clearListeners()
|
||||
val link = (construction as? RulesetObject)?.makeLink() ?: return
|
||||
if (link.isEmpty()) return
|
||||
touchable = Touchable.enabled
|
||||
onClick {
|
||||
|
Reference in New Issue
Block a user