* Fixes Issue #1697 by adding information to the special production constructions. * Get rid of extra $ sign in the SpecialConstruction tooltips
This commit is contained in:
parent
65e1c90e28
commit
8f757e9ab4
4 changed files with 46 additions and 30 deletions
|
@ -8,9 +8,11 @@ import com.unciv.logic.civilization.PopupAlert
|
|||
import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.cityscreen.ConstructionInfoTable
|
||||
import com.unciv.ui.utils.withItem
|
||||
import com.unciv.ui.utils.withoutItem
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* City constructions manager.
|
||||
|
@ -88,11 +90,15 @@ class CityConstructions {
|
|||
fun getCityProductionTextForCityButton(): String {
|
||||
val currentConstructionSnapshot = currentConstruction // See below
|
||||
var result = currentConstructionSnapshot.tr()
|
||||
if (currentConstructionSnapshot!=""
|
||||
&& SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot }) {
|
||||
val turnsLeft = turnsToConstruction(currentConstructionSnapshot)
|
||||
result += ("\r\n" + "Cost".tr() + " " + getConstruction(currentConstruction).getProductionCost(cityInfo.civInfo).toString()).tr()
|
||||
result += "\r\n" + turnsLeft + (if(turnsLeft>1) " {turns}".tr() else " {turn}".tr())
|
||||
if (currentConstructionSnapshot != "") {
|
||||
val construction = SpecialConstruction.specialConstructionsMap[currentConstructionSnapshot]
|
||||
if (construction == null) {
|
||||
val turnsLeft = turnsToConstruction(currentConstructionSnapshot)
|
||||
result += ("\r\n" + "Cost".tr() + " " + getConstruction(currentConstruction).getProductionCost(cityInfo.civInfo).toString()).tr()
|
||||
result += ConstructionInfoTable.turnOrTurns(turnsLeft)
|
||||
} else {
|
||||
result += construction.getProductionTooltip(cityInfo)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -103,9 +109,9 @@ class CityConstructions {
|
|||
val currentConstructionSnapshot = currentConstruction
|
||||
var result = currentConstructionSnapshot.tr()
|
||||
if (currentConstructionSnapshot!=""
|
||||
&& SpecialConstruction.getSpecialConstructions().none { it.name==currentConstructionSnapshot }) {
|
||||
&& !SpecialConstruction.specialConstructionsMap.containsKey(currentConstructionSnapshot)) {
|
||||
val turnsLeft = turnsToConstruction(currentConstructionSnapshot)
|
||||
result += "\r\n" + turnsLeft + (if(turnsLeft>1) " {turns}".tr() else " {turn}".tr())
|
||||
result += ConstructionInfoTable.turnOrTurns(turnsLeft)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -145,8 +151,7 @@ class CityConstructions {
|
|||
gameBasics.units.containsKey(constructionName) -> return gameBasics.units[constructionName]!!
|
||||
constructionName=="" -> return getConstruction("Nothing")
|
||||
else -> {
|
||||
val special = SpecialConstruction.getSpecialConstructions()
|
||||
.firstOrNull{it.name==constructionName}
|
||||
val special = SpecialConstruction.specialConstructionsMap[constructionName]
|
||||
if(special!=null) return special
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +200,7 @@ class CityConstructions {
|
|||
cityInfo.cityStats.update()
|
||||
}
|
||||
|
||||
var production = Math.round(cityStatsForConstruction.production)
|
||||
var production = cityStatsForConstruction.production.roundToInt()
|
||||
if (constructionName == Constants.settler) production += cityStatsForConstruction.food.toInt()
|
||||
|
||||
return Math.ceil((workLeft / production.toDouble())).toInt()
|
||||
|
@ -232,7 +237,7 @@ class CityConstructions {
|
|||
validateConstructionQueue()
|
||||
|
||||
if(getConstruction(currentConstruction) !is SpecialConstruction)
|
||||
addProductionPoints(Math.round(cityStats.production))
|
||||
addProductionPoints(cityStats.production.roundToInt())
|
||||
}
|
||||
|
||||
private fun stopUnbuildableConstruction() {
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.unciv.logic.city
|
|||
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.models.translations.tr
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
interface IConstruction : INamed {
|
||||
fun getProductionCost(civInfo: CivilizationInfo): Int
|
||||
|
@ -18,26 +20,29 @@ open class SpecialConstruction(override var name: String, val description: Strin
|
|||
override fun shouldBeDisplayed(construction: CityConstructions): Boolean {
|
||||
return isBuildable(construction)
|
||||
}
|
||||
open fun getProductionTooltip(cityInfo: CityInfo) : String
|
||||
= "\r\n${(cityInfo.cityStats.currentCityStats.production / CONVERSION_RATE).roundToInt()}/${"{turn}".tr()}"
|
||||
|
||||
companion object {
|
||||
val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){
|
||||
const val CONVERSION_RATE: Int = 4
|
||||
val science = object : SpecialConstruction("Science", "Convert production to science at a rate of $CONVERSION_RATE to 1") {
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to science")
|
||||
}
|
||||
}
|
||||
val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){
|
||||
val gold = object : SpecialConstruction("Gold", "Convert production to gold at a rate of $CONVERSION_RATE to 1") {
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to gold")
|
||||
}
|
||||
}
|
||||
val idle = object:SpecialConstruction("Nothing", "The city will not produce anything."){
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
fun getSpecialConstructions(): List<SpecialConstruction> {
|
||||
return listOf(science,gold,idle)
|
||||
val idle = object : SpecialConstruction("Nothing", "The city will not produce anything.") {
|
||||
override fun isBuildable(construction: CityConstructions): Boolean = true
|
||||
|
||||
override fun getProductionTooltip(cityInfo: CityInfo): String = ""
|
||||
}
|
||||
|
||||
val specialConstructionsMap: Map<String, SpecialConstruction>
|
||||
= mapOf(science.name to science, gold.name to gold, idle.name to idle)
|
||||
}
|
||||
|
||||
override fun canBePurchased(): Boolean {
|
||||
|
|
|
@ -48,10 +48,14 @@ class ConstructionInfoTable(val city: CityInfo): Table() {
|
|||
|
||||
|
||||
var buildingText = construction.name.tr()
|
||||
if (SpecialConstruction.getSpecialConstructions().none { it.name == construction.name }) {
|
||||
val specialConstruction = SpecialConstruction.specialConstructionsMap[construction.name]
|
||||
if (specialConstruction == null) {
|
||||
val turnsToComplete = cityConstructions.turnsToConstruction(construction.name)
|
||||
buildingText += ("\r\n" + "Cost".tr() + " " + construction.getProductionCost(city.civInfo).toString()).tr()
|
||||
buildingText += "\r\n" + turnsToComplete + turnOrTurns(turnsToComplete)
|
||||
buildingText += turnOrTurns(turnsToComplete)
|
||||
}
|
||||
else {
|
||||
buildingText += specialConstruction.getProductionTooltip(city)
|
||||
}
|
||||
selectedConstructionTable.add(buildingText.toLabel()).row()
|
||||
|
||||
|
@ -74,5 +78,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() {
|
|||
|
||||
}
|
||||
|
||||
private fun turnOrTurns(number: Int): String = if(number > 1) " {turns}".tr() else " {turn}".tr()
|
||||
companion object {
|
||||
internal fun turnOrTurns(turns: Int): String = "\r\n$turns ${(if (turns > 1) " {turns}" else " {turn}").tr()}"
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import com.unciv.logic.city.SpecialConstruction
|
|||
import com.unciv.models.UncivSound
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.cityscreen.ConstructionInfoTable.Companion.turnOrTurns
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) {
|
||||
|
@ -133,7 +134,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||
val useStoredProduction = !cityConstructions.isBeingConstructedOrEnqueued(unit.name)
|
||||
val turnsToUnit = cityConstructions.turnsToConstruction(unit.name, useStoredProduction)
|
||||
val productionButton = getProductionButton(unit.name,
|
||||
unit.name.tr() + "\r\n" + turnsToUnit + turnOrTurns(turnsToUnit),
|
||||
unit.name.tr() + turnOrTurns(turnsToUnit),
|
||||
unit.getRejectionReason(cityConstructions))
|
||||
units.add(productionButton)
|
||||
}
|
||||
|
@ -141,7 +142,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||
for (building in city.getRuleset().buildings.values.filter { it.shouldBeDisplayed(cityConstructions)}) {
|
||||
val turnsToBuilding = cityConstructions.turnsToConstruction(building.name)
|
||||
val productionTextButton = getProductionButton(building.name,
|
||||
building.name.tr() + "\r\n" + turnsToBuilding + turnOrTurns(turnsToBuilding),
|
||||
building.name.tr() + turnOrTurns(turnsToBuilding),
|
||||
building.getRejectionReason(cityConstructions)
|
||||
)
|
||||
if (building.isWonder) buildableWonders += productionTextButton
|
||||
|
@ -149,10 +150,11 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||
else buildableBuildings += productionTextButton
|
||||
}
|
||||
|
||||
for (specialConstruction in SpecialConstruction.getSpecialConstructions()
|
||||
for (specialConstruction in SpecialConstruction.specialConstructionsMap.values
|
||||
.filter { it.shouldBeDisplayed(cityConstructions) }) {
|
||||
specialConstructions += getProductionButton(specialConstruction.name,
|
||||
"Produce [${specialConstruction.name}]".tr())
|
||||
"Produce [${specialConstruction.name}]".tr()
|
||||
+ specialConstruction.getProductionTooltip(city))
|
||||
}
|
||||
|
||||
availableConstructionsTable.addCategory("Units", units)
|
||||
|
@ -175,7 +177,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||
|
||||
val isFirstConstructionOfItsKind = cityConstructions.isFirstConstructionOfItsKind(constructionQueueIndex, name)
|
||||
val turnsToComplete = cityConstructions.turnsToConstruction(name, isFirstConstructionOfItsKind)
|
||||
val text = name.tr() + "\r\n" + turnsToComplete + turnOrTurns(turnsToComplete)
|
||||
val text = name.tr() + turnOrTurns(turnsToComplete)
|
||||
|
||||
table.defaults().pad(2f).minWidth(40f)
|
||||
table.add(ImageGetter.getConstructionImage(name).surroundWithCircle(40f)).padRight(10f)
|
||||
|
@ -345,8 +347,6 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||
return tab
|
||||
}
|
||||
|
||||
private fun turnOrTurns(number: Int): String = if (number > 1) " {turns}".tr() else " {turn}".tr()
|
||||
|
||||
private fun getHeader(title: String): Table {
|
||||
val headerTable = Table()
|
||||
headerTable.background = ImageGetter.getBackground(ImageGetter.getBlue())
|
||||
|
|
Loading…
Reference in a new issue