mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 16:28:40 +07:00
City screen purchasable constructions prettier (#4822)
* City screen purchasable constructions prettier * City screen purchasable constructions prettier - patch1 * City screen purchasable constructions prettier - mad modder edition
This commit is contained in:
@ -1132,8 +1132,9 @@
|
|||||||
"cost": 0,
|
"cost": 0,
|
||||||
"culture": 2,
|
"culture": 2,
|
||||||
"faith": 2,
|
"faith": 2,
|
||||||
"uniques": ["[+1 Culture, +1 Faith] from [Wine] tiles [in this city]", "Hidden when religion is disabled",
|
"uniques": ["[+1 Culture, +1 Faith] from [Wine] tiles [in this city]",
|
||||||
"[+1 Culture, +1 Faith] from [Incense] tiles [in this city]","Unbuildable"]
|
"[+1 Culture, +1 Faith] from [Incense] tiles [in this city]",
|
||||||
|
"Unbuildable", "Hidden when religion is disabled"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Mosque",
|
"name": "Mosque",
|
||||||
|
@ -153,16 +153,24 @@ class CityConstructions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @constructionName needs to be a non-perpetual construction, else a cost of -1 is inferred */
|
/** @constructionName needs to be a non-perpetual construction, else an empty string is returned */
|
||||||
internal fun getTurnsToConstructionString(constructionName: String, useStoredProduction:Boolean = true): String {
|
internal fun getTurnsToConstructionString(constructionName: String, useStoredProduction:Boolean = true): String {
|
||||||
val construction = getConstruction(constructionName)
|
val construction = getConstruction(constructionName)
|
||||||
val cost =
|
if (construction !is INonPerpetualConstruction) return "" // shouldn't happen
|
||||||
if (construction is INonPerpetualConstruction) construction.getProductionCost(cityInfo.civInfo)
|
val cost = construction.getProductionCost(cityInfo.civInfo)
|
||||||
else -1 // This could _should_ never be reached
|
|
||||||
val turnsToConstruction = turnsToConstruction(constructionName, useStoredProduction)
|
val turnsToConstruction = turnsToConstruction(constructionName, useStoredProduction)
|
||||||
val currentProgress = if (useStoredProduction) getWorkDone(constructionName) else 0
|
val currentProgress = if (useStoredProduction) getWorkDone(constructionName) else 0
|
||||||
if (currentProgress == 0) return "\n$cost${Fonts.production} $turnsToConstruction${Fonts.turn}"
|
val lines = ArrayList<String>()
|
||||||
else return "\n$currentProgress/$cost${Fonts.production}\n$turnsToConstruction${Fonts.turn}"
|
val buildable = construction.uniques.none{ it == "Unbuildable" }
|
||||||
|
if (buildable)
|
||||||
|
lines += (if (currentProgress == 0) "" else "$currentProgress/") +
|
||||||
|
"$cost${Fonts.production} $turnsToConstruction${Fonts.turn}"
|
||||||
|
val otherStats = Stat.values().filter {
|
||||||
|
(it != Stat.Gold || !buildable) && // Don't show rush cost for consistency
|
||||||
|
construction.canBePurchasedWithStat(cityInfo, it)
|
||||||
|
}.joinToString(" / ") { "${construction.getStatBuyCost(cityInfo, it)}${it.character}" }
|
||||||
|
if (otherStats.isNotEmpty()) lines += otherStats
|
||||||
|
return lines.joinToString("\n", "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function appears unused, can it be removed?
|
// This function appears unused, can it be removed?
|
||||||
|
@ -86,7 +86,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
|||||||
infoList += "Requires worked [" + requiredNearbyImprovedResources!!.joinToString("/") { it.tr() } + "] near city"
|
infoList += "Requires worked [" + requiredNearbyImprovedResources!!.joinToString("/") { it.tr() } + "] near city"
|
||||||
if (uniques.isNotEmpty()) {
|
if (uniques.isNotEmpty()) {
|
||||||
if (replacementTextForUniques != "") infoList += replacementTextForUniques
|
if (replacementTextForUniques != "") infoList += replacementTextForUniques
|
||||||
else infoList += getUniquesStrings()
|
else infoList += getUniquesStringsWithoutDisablers()
|
||||||
}
|
}
|
||||||
if (cityStrength != 0) infoList += "{City strength} +$cityStrength"
|
if (cityStrength != 0) infoList += "{City strength} +$cityStrength"
|
||||||
if (cityHealth != 0) infoList += "{City health} +$cityHealth"
|
if (cityHealth != 0) infoList += "{City health} +$cityHealth"
|
||||||
@ -113,48 +113,46 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
|||||||
if (value.size == 1) value[0] else value.joinToString { it.tr() }
|
if (value.size == 1) value[0] else value.joinToString { it.tr() }
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
private fun getUniquesStringsWithoutDisablers() = getUniquesStrings()
|
||||||
|
.filterNot { it.startsWith("Hidden ") && it.endsWith(" disabled") || it == "Unbuildable" }
|
||||||
|
|
||||||
|
/** used in CityScreen (CityInfoTable and ConstructionInfoTable) */
|
||||||
fun getDescription(cityInfo: CityInfo?, ruleset: Ruleset): String {
|
fun getDescription(cityInfo: CityInfo?, ruleset: Ruleset): String {
|
||||||
val stats = getStats(cityInfo)
|
val stats = getStats(cityInfo)
|
||||||
val stringBuilder = StringBuilder()
|
val lines = ArrayList<String>()
|
||||||
if (uniqueTo != null) stringBuilder.appendLine("Unique to [$uniqueTo], replaces [$replaces]".tr())
|
if (uniqueTo != null) lines += "Unique to [$uniqueTo], replaces [$replaces]"
|
||||||
if (isWonder) stringBuilder.appendLine("Wonder".tr())
|
if (isWonder) lines += "Wonder"
|
||||||
if (isNationalWonder) stringBuilder.appendLine("National Wonder".tr())
|
if (isNationalWonder) lines += "National Wonder"
|
||||||
for ((resource, amount) in getResourceRequirements()) {
|
for ((resource, amount) in getResourceRequirements()) {
|
||||||
if (amount == 1) stringBuilder.appendLine("Consumes 1 [$resource]".tr()) // For now, to keep the existing translations
|
lines += if (amount == 1) "Consumes 1 [$resource]" // For now, to keep the existing translations
|
||||||
else stringBuilder.appendLine("Consumes [$amount] [$resource]".tr())
|
else "Consumes [$amount] [$resource]"
|
||||||
}
|
}
|
||||||
if (providesFreeBuilding != null)
|
if (providesFreeBuilding != null)
|
||||||
stringBuilder.appendLine("Provides a free [$providesFreeBuilding] in the city".tr())
|
lines += "Provides a free [$providesFreeBuilding] in the city"
|
||||||
if (uniques.isNotEmpty()) {
|
if (uniques.isNotEmpty()) {
|
||||||
if (replacementTextForUniques != "") stringBuilder.appendLine(replacementTextForUniques)
|
if (replacementTextForUniques != "") lines += replacementTextForUniques
|
||||||
else stringBuilder.appendLine(getUniquesStrings().map { it.tr() }.joinToString("\n"))
|
else lines += getUniquesStringsWithoutDisablers()
|
||||||
}
|
}
|
||||||
if (!stats.isEmpty())
|
if (!stats.isEmpty())
|
||||||
stringBuilder.appendLine(stats.toString())
|
lines += stats.toString()
|
||||||
|
|
||||||
val percentStats = getStatPercentageBonuses(cityInfo)
|
for ((stat, value) in getStatPercentageBonuses(cityInfo).toHashMap())
|
||||||
if (percentStats.production != 0f) stringBuilder.append("+" + percentStats.production.toInt() + "% {Production}\n".tr())
|
if (value != 0f) lines += "+${value.toInt()}% {${stat.name}}\n"
|
||||||
if (percentStats.gold != 0f) stringBuilder.append("+" + percentStats.gold.toInt() + "% {Gold}\n".tr())
|
|
||||||
if (percentStats.science != 0f) stringBuilder.append("+" + percentStats.science.toInt() + "% {Science}\r\n".tr())
|
|
||||||
if (percentStats.food != 0f) stringBuilder.append("+" + percentStats.food.toInt() + "% {Food}\n".tr())
|
|
||||||
if (percentStats.culture != 0f) stringBuilder.append("+" + percentStats.culture.toInt() + "% {Culture}\r\n".tr())
|
|
||||||
|
|
||||||
for((greatPersonName, value) in greatPersonPoints)
|
for ((greatPersonName, value) in greatPersonPoints)
|
||||||
stringBuilder.appendLine("+$value "+"[$greatPersonName] points".tr())
|
lines += "+$value " + "[$greatPersonName] points".tr()
|
||||||
|
|
||||||
for ((specialistName, amount) in newSpecialists())
|
for ((specialistName, amount) in newSpecialists())
|
||||||
stringBuilder.appendLine("+$amount " + "[$specialistName] slots".tr())
|
lines += "+$amount " + "[$specialistName] slots".tr()
|
||||||
|
|
||||||
if (requiredNearbyImprovedResources != null)
|
if (requiredNearbyImprovedResources != null)
|
||||||
stringBuilder.appendLine(("Requires worked [" + requiredNearbyImprovedResources!!.joinToString("/") { it.tr() } + "] near city").tr())
|
lines += "Requires worked [" + requiredNearbyImprovedResources!!.joinToString("/") { it.tr() } + "] near city"
|
||||||
|
|
||||||
if (cityStrength != 0) stringBuilder.appendLine("{City strength} +".tr() + cityStrength)
|
if (cityStrength != 0) lines += "{City strength} +$cityStrength"
|
||||||
if (cityHealth != 0) stringBuilder.appendLine("{City health} +".tr() + cityHealth)
|
if (cityHealth != 0) lines += "{City health} +$cityHealth"
|
||||||
if (xpForNewUnits != 0) stringBuilder.appendLine("+$xpForNewUnits {XP for new units}".tr())
|
if (xpForNewUnits != 0) lines += "+$xpForNewUnits {XP for new units}"
|
||||||
if (maintenance != 0)
|
if (maintenance != 0) lines += "{Maintenance cost}: $maintenance {Gold}"
|
||||||
stringBuilder.appendLine("{Maintenance cost}: $maintenance {Gold}".tr())
|
return lines.joinToString("\n") { it.tr() }.trim()
|
||||||
return stringBuilder.toString().trim()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStats(city: CityInfo?): Stats {
|
fun getStats(city: CityInfo?): Stats {
|
||||||
|
@ -88,7 +88,9 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
|||||||
lines += "$strengthLine$movement${Fonts.movement}"
|
lines += "$strengthLine$movement${Fonts.movement}"
|
||||||
|
|
||||||
if (replacementTextForUniques != "") lines += replacementTextForUniques
|
if (replacementTextForUniques != "") lines += replacementTextForUniques
|
||||||
else for (unique in uniques)
|
else for (unique in uniques.filterNot {
|
||||||
|
it.startsWith("Hidden ") && it.endsWith(" disabled") || it == "Unbuildable"
|
||||||
|
})
|
||||||
lines += unique.tr()
|
lines += unique.tr()
|
||||||
|
|
||||||
if (promotions.isNotEmpty()) {
|
if (promotions.isNotEmpty()) {
|
||||||
|
@ -2,13 +2,18 @@ package com.unciv.models.stats
|
|||||||
|
|
||||||
import com.unciv.logic.civilization.NotificationIcon
|
import com.unciv.logic.civilization.NotificationIcon
|
||||||
import com.unciv.models.UncivSound
|
import com.unciv.models.UncivSound
|
||||||
|
import com.unciv.ui.utils.Fonts
|
||||||
|
|
||||||
enum class Stat(val notificationIcon: String, val purchaseSound: UncivSound) {
|
enum class Stat(
|
||||||
Production(NotificationIcon.Production, UncivSound.Click),
|
val notificationIcon: String,
|
||||||
Food(NotificationIcon.Food, UncivSound.Click),
|
val purchaseSound: UncivSound,
|
||||||
Gold(NotificationIcon.Gold, UncivSound.Coin),
|
val character: Char
|
||||||
Science(NotificationIcon.Science, UncivSound.Chimes),
|
) {
|
||||||
Culture(NotificationIcon.Culture, UncivSound.Paper),
|
Production(NotificationIcon.Production, UncivSound.Click, Fonts.production),
|
||||||
Happiness(NotificationIcon.Happiness, UncivSound.Click),
|
Food(NotificationIcon.Food, UncivSound.Click, Fonts.food),
|
||||||
Faith(NotificationIcon.Faith, UncivSound.Choir);
|
Gold(NotificationIcon.Gold, UncivSound.Coin, Fonts.gold),
|
||||||
|
Science(NotificationIcon.Science, UncivSound.Chimes, Fonts.science),
|
||||||
|
Culture(NotificationIcon.Culture, UncivSound.Paper, Fonts.culture),
|
||||||
|
Happiness(NotificationIcon.Happiness, UncivSound.Click, Fonts.happiness),
|
||||||
|
Faith(NotificationIcon.Faith, UncivSound.Choir, Fonts.faith);
|
||||||
}
|
}
|
@ -44,7 +44,6 @@ class ConstructionInfoTable(val city: CityInfo): Table() {
|
|||||||
|
|
||||||
//val selectedConstructionTable = Table()
|
//val selectedConstructionTable = Table()
|
||||||
selectedConstructionTable.run {
|
selectedConstructionTable.run {
|
||||||
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
|
||||||
pad(10f)
|
pad(10f)
|
||||||
|
|
||||||
add(ImageGetter.getConstructionImage(construction.name).surroundWithCircle(50f))
|
add(ImageGetter.getConstructionImage(construction.name).surroundWithCircle(50f))
|
||||||
@ -59,7 +58,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() {
|
|||||||
add(buildingText.toLabel()).row()
|
add(buildingText.toLabel()).row()
|
||||||
|
|
||||||
val (description, link) = when (construction) {
|
val (description, link) = when (construction) {
|
||||||
is BaseUnit -> construction.getDescription() to "Unit/${construction.name}"
|
is BaseUnit -> construction.getDescription() to construction.makeLink()
|
||||||
is Building -> construction.getDescription(city, city.getRuleset()) to construction.makeLink()
|
is Building -> construction.getDescription(city, city.getRuleset()) to construction.makeLink()
|
||||||
is PerpetualConstruction -> construction.description.replace("[rate]", "[${construction.getConversionRate(city)}]") to ""
|
is PerpetualConstruction -> construction.description.replace("[rate]", "[${construction.getConversionRate(city)}]") to ""
|
||||||
else -> "" to "" // Should never happen
|
else -> "" to "" // Should never happen
|
||||||
|
Reference in New Issue
Block a user