diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index cfab399baf..9563fa46d6 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -278,7 +278,7 @@ class CityStats { val isUnhappy = civInfo.happiness < 0 - if (!isUnhappy) // Regular food bonus revoked when unhappy per https://forums.civfanatics.com/resources/complete-guide-to-happiness-vanilla.25584/ + if (isUnhappy) // Regular food bonus revoked when unhappy per https://forums.civfanatics.com/resources/complete-guide-to-happiness-vanilla.25584/ for (stat in newBaseStatList.values) stat.food *= 1 + statPercentBonuses.food / 100 var foodEaten = (cityInfo.population.population * 2).toFloat() diff --git a/core/src/com/unciv/ui/cityscreen/BuildingsTable.kt b/core/src/com/unciv/ui/cityscreen/BuildingsTable.kt index 48d3678d66..fd161f0266 100644 --- a/core/src/com/unciv/ui/cityscreen/BuildingsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/BuildingsTable.kt @@ -1,60 +1,25 @@ 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.* import com.badlogic.gdx.utils.Align import com.unciv.logic.city.CityInfo import com.unciv.models.gamebasics.Building import com.unciv.models.stats.Stat +import com.unciv.models.stats.Stats import com.unciv.ui.utils.* +import java.text.DecimalFormat +import java.util.* +import kotlin.collections.HashMap -class ExpanderTab(private val title:String,skin: Skin):Table(skin){ - private val toggle = Table(skin) // the show/hide toggler - private val tab = Table() // what holds the information to be shown/hidden - val innerTable=Table() // the information itself - var isOpen=true - - init{ - toggle.defaults().pad(10f) - toggle.touchable=Touchable.enabled - toggle.background(ImageGetter.getBackground(ImageGetter.getBlue())) - toggle.add("+ $title").apply { actor.setFontSize(24) } - toggle.onClick { - if(isOpen) close() - else open() - } - add(toggle).row() - tab.add(innerTable).pad(10f) - add(tab) - } - - fun close(){ - if(!isOpen) return - toggle.clearChildren() - toggle.add("- $title").apply { actor.setFontSize(24) } - tab.clear() - isOpen=false - } - - fun open(){ - if(isOpen) return - toggle.clearChildren() - toggle.add("+ $title").apply { actor.setFontSize(24) } - tab.add(innerTable) - isOpen=true - } -} - -class BuildingsTable(private val cityScreen: CityScreen) : Table() { +class BuildingsTable(private val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) { init { defaults().pad(10f) } internal fun update() { clear() - val skin = CameraStageBaseScreen.skin val cityInfo = cityScreen.city val wonders = mutableListOf() val specialistBuildings = mutableListOf() @@ -104,9 +69,45 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() { } add(buildingsExpanderTab).row() } + + addStatInfo() + pack() } + private fun addStatInfo() { + val cityStats = cityScreen.city.cityStats + val unifiedStatList = LinkedHashMap(cityStats.baseStatList) + for(entry in cityStats.happinessList.filter { it.value!=0f }){ + if(!unifiedStatList.containsKey(entry.key)) unifiedStatList[entry.key]= Stats() + unifiedStatList[entry.key]!!.happiness=entry.value + } + + val statToCauses = HashMap>() + for(stat in Stat.values()) statToCauses[stat] = hashMapOf() + + for(cause in unifiedStatList) { + val statHashmap = cause.value.toHashMap() + for (statEntry in statHashmap.filter { it.value != 0f }) + statToCauses[statEntry.key]!![cause.key] = statEntry.value + } + + for(stat in statToCauses){ + val expander = ExpanderTab(stat.key.name.tr(),skin) + expander.innerTable.defaults().pad(2f) + for(entry in stat.value) { + expander.innerTable.add(Label(entry.key.tr(), skin)) + expander.innerTable.add(Label(DecimalFormat("0.#").format(entry.value), skin)).row() + } + if(stat.value.isNotEmpty()){ + expander.innerTable.add(Label("Total".tr(),skin)) + expander.innerTable.add(Label(DecimalFormat("0.#").format(stat.value.values.sum()),skin)) + } + add(expander).row() + } + + } + private fun addSpecialistAllocation(skin: Skin, cityInfo: CityInfo) { val specialistAllocationExpander = ExpanderTab("Specialist allocation", skin) specialistAllocationExpander.innerTable.defaults().pad(5f) @@ -165,7 +166,6 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() { add(specialistAllocationExpander).row() } - private fun getSpecialistIcon(stat: Stat, isFilled: Boolean =true): Image { val specialist = ImageGetter.getImage("StatIcons/Specialist") if (!isFilled) specialist.color = Color.GRAY @@ -180,5 +180,4 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() { return specialist } - } \ No newline at end of file diff --git a/core/src/com/unciv/ui/cityscreen/CityScreen.kt b/core/src/com/unciv/ui/cityscreen/CityScreen.kt index d855dba048..4e046496b5 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreen.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreen.kt @@ -49,7 +49,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() { stage.addActor(cityStatsTable) stage.addActor(goToWorldButton) stage.addActor(cityPickerTable) - stage.addActor(statExplainer) + //stage.addActor(statExplainer) stage.addActor(buildingsTableContainer) update() displayTutorials("CityEntered") diff --git a/core/src/com/unciv/ui/cityscreen/ExpanderTab.kt b/core/src/com/unciv/ui/cityscreen/ExpanderTab.kt new file mode 100644 index 0000000000..8fb39b60df --- /dev/null +++ b/core/src/com/unciv/ui/cityscreen/ExpanderTab.kt @@ -0,0 +1,45 @@ +package com.unciv.ui.cityscreen + +import com.badlogic.gdx.scenes.scene2d.Touchable +import com.badlogic.gdx.scenes.scene2d.ui.Skin +import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.onClick +import com.unciv.ui.utils.setFontSize + +class ExpanderTab(private val title:String,skin: Skin): Table(skin){ + private val toggle = Table(skin) // the show/hide toggler + private val tab = Table() // what holds the information to be shown/hidden + val innerTable= Table() // the information itself + var isOpen=true + + init{ + toggle.defaults().pad(10f) + toggle.touchable= Touchable.enabled + toggle.background(ImageGetter.getBackground(ImageGetter.getBlue())) + toggle.add("+ $title").apply { actor.setFontSize(24) } + toggle.onClick { + if(isOpen) close() + else open() + } + add(toggle).row() + tab.add(innerTable).pad(10f) + add(tab) + } + + fun close(){ + if(!isOpen) return + toggle.clearChildren() + toggle.add("- $title").apply { actor.setFontSize(24) } + tab.clear() + isOpen=false + } + + fun open(){ + if(isOpen) return + toggle.clearChildren() + toggle.add("+ $title").apply { actor.setFontSize(24) } + tab.add(innerTable) + isOpen=true + } +} \ No newline at end of file