mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
City stats details in city screen moved from table to right-side scroller
This commit is contained in:
parent
cd28358289
commit
1301b1181a
@ -278,7 +278,7 @@ class CityStats {
|
|||||||
|
|
||||||
|
|
||||||
val isUnhappy = civInfo.happiness < 0
|
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
|
for (stat in newBaseStatList.values) stat.food *= 1 + statPercentBonuses.food / 100
|
||||||
|
|
||||||
var foodEaten = (cityInfo.population.population * 2).toFloat()
|
var foodEaten = (cityInfo.population.population * 2).toFloat()
|
||||||
|
@ -1,60 +1,25 @@
|
|||||||
package com.unciv.ui.cityscreen
|
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.ui.*
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.models.gamebasics.Building
|
import com.unciv.models.gamebasics.Building
|
||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
|
import com.unciv.models.stats.Stats
|
||||||
import com.unciv.ui.utils.*
|
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){
|
class BuildingsTable(private val cityScreen: CityScreen) : Table(CameraStageBaseScreen.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() {
|
|
||||||
init {
|
init {
|
||||||
defaults().pad(10f)
|
defaults().pad(10f)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun update() {
|
internal fun update() {
|
||||||
clear()
|
clear()
|
||||||
val skin = CameraStageBaseScreen.skin
|
|
||||||
val cityInfo = cityScreen.city
|
val cityInfo = cityScreen.city
|
||||||
val wonders = mutableListOf<Building>()
|
val wonders = mutableListOf<Building>()
|
||||||
val specialistBuildings = mutableListOf<Building>()
|
val specialistBuildings = mutableListOf<Building>()
|
||||||
@ -104,9 +69,45 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() {
|
|||||||
}
|
}
|
||||||
add(buildingsExpanderTab).row()
|
add(buildingsExpanderTab).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addStatInfo()
|
||||||
|
|
||||||
pack()
|
pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addStatInfo() {
|
||||||
|
val cityStats = cityScreen.city.cityStats
|
||||||
|
val unifiedStatList = LinkedHashMap<String, Stats>(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<Stat,HashMap<String,Float>>()
|
||||||
|
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) {
|
private fun addSpecialistAllocation(skin: Skin, cityInfo: CityInfo) {
|
||||||
val specialistAllocationExpander = ExpanderTab("Specialist allocation", skin)
|
val specialistAllocationExpander = ExpanderTab("Specialist allocation", skin)
|
||||||
specialistAllocationExpander.innerTable.defaults().pad(5f)
|
specialistAllocationExpander.innerTable.defaults().pad(5f)
|
||||||
@ -165,7 +166,6 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() {
|
|||||||
add(specialistAllocationExpander).row()
|
add(specialistAllocationExpander).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getSpecialistIcon(stat: Stat, isFilled: Boolean =true): Image {
|
private fun getSpecialistIcon(stat: Stat, isFilled: Boolean =true): Image {
|
||||||
val specialist = ImageGetter.getImage("StatIcons/Specialist")
|
val specialist = ImageGetter.getImage("StatIcons/Specialist")
|
||||||
if (!isFilled) specialist.color = Color.GRAY
|
if (!isFilled) specialist.color = Color.GRAY
|
||||||
@ -180,5 +180,4 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() {
|
|||||||
return specialist
|
return specialist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -49,7 +49,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||||||
stage.addActor(cityStatsTable)
|
stage.addActor(cityStatsTable)
|
||||||
stage.addActor(goToWorldButton)
|
stage.addActor(goToWorldButton)
|
||||||
stage.addActor(cityPickerTable)
|
stage.addActor(cityPickerTable)
|
||||||
stage.addActor(statExplainer)
|
//stage.addActor(statExplainer)
|
||||||
stage.addActor(buildingsTableContainer)
|
stage.addActor(buildingsTableContainer)
|
||||||
update()
|
update()
|
||||||
displayTutorials("CityEntered")
|
displayTutorials("CityEntered")
|
||||||
|
45
core/src/com/unciv/ui/cityscreen/ExpanderTab.kt
Normal file
45
core/src/com/unciv/ui/cityscreen/ExpanderTab.kt
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user