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