From 356f8b6bbd3c9c5bf81814d8b41b34f316db969a Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 16 Feb 2019 23:39:03 +0200 Subject: [PATCH] Resolved #455 - add great person point breakdown to city info --- android/assets/jsons/Translations.json | 4 ++ core/src/com/unciv/logic/city/CityInfo.kt | 38 +++++++++++------ core/src/com/unciv/ui/NewGameScreen.kt | 2 +- .../com/unciv/ui/cityscreen/CityInfoTable.kt | 41 +++++++++++++++---- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/android/assets/jsons/Translations.json b/android/assets/jsons/Translations.json index bf371c2d05..ef2968248d 100644 --- a/android/assets/jsons/Translations.json +++ b/android/assets/jsons/Translations.json @@ -795,6 +795,10 @@ Italian:"La resistenza dura per altri [numberOfTurns] turni" } + "[greatPerson] points":{ // e.g "Great Scientist points" + + } + // Tech picker "Pick a tech":{ Italian:"Scegli una tecnologia" diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 65a36bedf3..782684e26a 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -134,24 +134,38 @@ class CityInfo { fun getBuildingUniques(): List = cityConstructions.getBuiltBuildings().flatMap { it.uniques } - fun getGreatPersonPoints(): Stats { - var greatPersonPoints = population.specialists.times(3f) + fun getGreatPersonMap():HashMap{ + val stats = HashMap() + if(population.specialists.toString()!="") + stats["Specialists"] = population.specialists.times(3f) + val buildingStats = Stats() for (building in cityConstructions.getBuiltBuildings()) if (building.greatPersonPoints != null) - greatPersonPoints.add(building.greatPersonPoints!!) + buildingStats.add(building.greatPersonPoints!!) + if(buildingStats.toString()!="") + stats["Buildings"] = buildingStats - if (civInfo.getBuildingUniques().contains("+33% great person generation in all cities")) - greatPersonPoints = greatPersonPoints.times(1.33f) - if (civInfo.policies.isAdopted("Entrepreneurship")) - greatPersonPoints.gold *= 1.25f - if (civInfo.policies.isAdopted("Freedom")) - greatPersonPoints = greatPersonPoints.times(1.25f) + for(entry in stats){ + if(civInfo.getNation().unique=="Receive free Great Scientist when you discover Writing, Earn Great Scientists 50% faster") + entry.value.science *= 1.5f + if (civInfo.policies.isAdopted("Entrepreneurship")) + entry.value.gold *= 1.25f - if(civInfo.getNation().unique=="Receive free Great Scientist when you discover Writing, Earn Great Scientists 50% faster") - greatPersonPoints.science *= 1.5f + if (civInfo.getBuildingUniques().contains("+33% great person generation in all cities")) + stats[entry.key] = stats[entry.key]!!.times(1.33f) + if (civInfo.policies.isAdopted("Freedom")) + stats[entry.key] = stats[entry.key]!!.times(1.25f) + } - return greatPersonPoints + return stats + } + + fun getGreatPersonPoints(): Stats { + val stats=Stats() + for(entry in getGreatPersonMap().values) + stats.add(entry) + return stats } fun isCapital() = cityConstructions.isBuilt("Palace") diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index d06fb5cd87..0b2c99df88 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -122,7 +122,7 @@ class NewGameScreen: PickerScreen(){ newGameOptionsTable.add("{Number of human players}:".tr()) val humanPlayers = SelectBox(skin) val humanPlayersArray = Array() - (1..GameBasics.Nations.size).forEach { humanPlayersArray .add(it) } + (1..GameBasics.Nations.size).forEach { humanPlayersArray.add(it) } humanPlayers.items = humanPlayersArray humanPlayers.selected = newGameParameters.numberOfHumanPlayers newGameOptionsTable.add(humanPlayers).pad(10f).row() diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index c1697efa1b..3b51f18f34 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.utils.Align import com.unciv.logic.city.CityInfo +import com.unciv.logic.civilization.GreatPersonManager import com.unciv.models.gamebasics.Building import com.unciv.models.gamebasics.tr import com.unciv.models.stats.Stat @@ -22,6 +23,32 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS internal fun update() { clear() val cityInfo = cityScreen.city + + addBuildingInfo(cityInfo) + + addStatInfo() + + val greatPersonPoints = cityInfo.getGreatPersonMap() + val statToGreatPerson = GreatPersonManager().statToGreatPersonMapping + for(stat in Stat.values()){ + if(!statToGreatPerson.containsKey(stat)) continue + val expanderName = "["+statToGreatPerson[stat]!!+"] points" + val expanderTab = ExpanderTab(expanderName.tr(),skin) + expanderTab.innerTable.defaults().pad(3f) + for(entry in greatPersonPoints){ + val value = entry.value.toHashMap()[stat]!! + if(value==0f) continue + expanderTab.innerTable.add(entry.key.toLabel()) + expanderTab.innerTable.add(DecimalFormat("0.#").format(value).toLabel()).row() + } + if(expanderTab.innerTable.hasChildren()) + add(expanderTab).row() + } + + pack() + } + + private fun addBuildingInfo(cityInfo: CityInfo) { val wonders = mutableListOf() val specialistBuildings = mutableListOf() val otherBuildings = mutableListOf() @@ -35,7 +62,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS } if (!wonders.isEmpty()) { - val wondersExpander = ExpanderTab("Wonders".tr(),skin) + val wondersExpander = ExpanderTab("Wonders".tr(), skin) for (building in wonders) { wondersExpander.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f)) wondersExpander.innerTable.add(building.name.toLabel()).pad(5f).align(Align.left).row() @@ -44,14 +71,14 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS } if (!specialistBuildings.isEmpty()) { - val specialistBuildingsExpander = ExpanderTab("Specialist Buildings".tr(),skin) + val specialistBuildingsExpander = ExpanderTab("Specialist Buildings".tr(), skin) for (building in specialistBuildings) { specialistBuildingsExpander.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f)) specialistBuildingsExpander.innerTable.add(building.name.toLabel()).pad(5f) val specialistIcons = Table() specialistIcons.row().size(20f).pad(5f) - for(stat in building.specialistSlots!!.toHashMap()) - for(i in 0 until stat.value.toInt()) + for (stat in building.specialistSlots!!.toHashMap()) + for (i in 0 until stat.value.toInt()) specialistIcons.add(getSpecialistIcon(stat.key)).size(20f) specialistBuildingsExpander.innerTable.add(specialistIcons).row() @@ -63,17 +90,13 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS } if (!otherBuildings.isEmpty()) { - val buildingsExpanderTab = ExpanderTab("Buildings".tr(),skin) + val buildingsExpanderTab = ExpanderTab("Buildings".tr(), skin) for (building in otherBuildings) { buildingsExpanderTab.innerTable.add(ImageGetter.getConstructionImage(building.name).surroundWithCircle(30f)) buildingsExpanderTab.innerTable.add(building.name.toLabel()).pad(5f).row() } add(buildingsExpanderTab).row() } - - addStatInfo() - - pack() } private fun addStatInfo() {