mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-05 00:18:13 +07:00
Dynamically adjust StatsTable height (#6990)
* Dynamically adjust StatsTable height * redo Gradle? * redo Gradle? * Remive undeeded default * Remove reduant init() line * Make top portion fixed and lower section scroll
This commit is contained in:
parent
b8f987d791
commit
37d6233f5d
@ -170,7 +170,12 @@ class CityScreen(
|
||||
cityPickerTable.setPosition(centeredX, exitCityButton.top + 10f, Align.bottom)
|
||||
|
||||
// Top right of screen: Stats / Specialists
|
||||
cityStatsTable.update()
|
||||
var statsHeight = stage.height - posFromEdge * 2
|
||||
if (selectedTile != null)
|
||||
statsHeight -= tileTable.height + 10f
|
||||
if (selectedConstruction != null)
|
||||
statsHeight -= selectedConstructionTable.height + 10f
|
||||
cityStatsTable.update(statsHeight)
|
||||
cityStatsTable.setPosition(stage.width - posFromEdge, stage.height - posFromEdge, Align.topRight)
|
||||
|
||||
// Top center: Annex/Raze button
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.ui.cityscreen
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Cell
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
@ -19,26 +20,34 @@ import kotlin.math.round
|
||||
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
||||
|
||||
class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
private val innerTable = Table()
|
||||
private val outerPane: ScrollPane
|
||||
private val innerTable = Table() // table within this Table. Slightly smaller creates border
|
||||
private val upperTable = Table() // fixed position table
|
||||
private val lowerTable = Table() // table that will be in the ScrollPane
|
||||
private val lowerPane: ScrollPane
|
||||
private val cityInfo = cityScreen.city
|
||||
private val lowerCell: Cell<ScrollPane>
|
||||
|
||||
init {
|
||||
pad(2f)
|
||||
background = ImageGetter.getBackground(colorFromRGB(194, 180, 131))
|
||||
|
||||
innerTable.pad(5f)
|
||||
innerTable.defaults().pad(2f)
|
||||
innerTable.background = ImageGetter.getBackground(Color.BLACK.cpy().apply { a = 0.8f })
|
||||
innerTable.add(upperTable).row()
|
||||
|
||||
outerPane = ScrollPane(innerTable)
|
||||
outerPane.setOverscroll(false, false)
|
||||
outerPane.setScrollingDisabled(true, false)
|
||||
add(outerPane).maxHeight(cityScreen.stage.height / 2)
|
||||
upperTable.defaults().pad(2f)
|
||||
lowerTable.defaults().pad(2f)
|
||||
lowerPane = ScrollPane(lowerTable)
|
||||
lowerPane.setOverscroll(false, false)
|
||||
lowerPane.setScrollingDisabled(true, false)
|
||||
lowerCell = innerTable.add(lowerPane)
|
||||
|
||||
add(innerTable)
|
||||
}
|
||||
|
||||
fun update() {
|
||||
innerTable.clear()
|
||||
fun update(height: Float) {
|
||||
upperTable.clear()
|
||||
lowerTable.clear()
|
||||
|
||||
val miniStatsTable = Table()
|
||||
val selected = BaseScreen.skin.get("selection", Color::class.java)
|
||||
@ -66,10 +75,12 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
val valueToDisplay = if (stat == Stat.Happiness) cityInfo.cityStats.happinessList.values.sum() else amount
|
||||
miniStatsTable.add(round(valueToDisplay).toInt().toLabel()).padRight(10f)
|
||||
}
|
||||
innerTable.add(miniStatsTable)
|
||||
upperTable.add(miniStatsTable)
|
||||
|
||||
innerTable.addSeparator()
|
||||
upperTable.addSeparator()
|
||||
addText()
|
||||
|
||||
// begin lowerTable
|
||||
addCitizenManagement()
|
||||
if (!cityInfo.population.getMaxSpecialists().isEmpty()) {
|
||||
addSpecialistInfo()
|
||||
@ -77,10 +88,14 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
if (cityInfo.religion.getNumberOfFollowers().isNotEmpty() && cityInfo.civInfo.gameInfo.isReligionEnabled())
|
||||
addReligionInfo()
|
||||
|
||||
innerTable.pack()
|
||||
outerPane.layout()
|
||||
outerPane.updateVisualScroll()
|
||||
pack()
|
||||
upperTable.pack()
|
||||
lowerTable.pack()
|
||||
lowerPane.layout()
|
||||
lowerPane.updateVisualScroll()
|
||||
lowerCell.maxHeight(height - upperTable.height - 8f) // 2 on each side of each cell in innerTable
|
||||
|
||||
innerTable.pack() // update innerTable
|
||||
pack() // update self last
|
||||
}
|
||||
|
||||
private fun addText() {
|
||||
@ -112,9 +127,9 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
}.tr()
|
||||
turnsToPopString += " (${cityInfo.population.foodStored}${Fonts.food}/${cityInfo.population.getFoodToNextPopulation()}${Fonts.food})"
|
||||
|
||||
innerTable.add(unassignedPopLabel).row()
|
||||
innerTable.add(turnsToExpansionString.toLabel()).row()
|
||||
innerTable.add(turnsToPopString.toLabel()).row()
|
||||
upperTable.add(unassignedPopLabel).row()
|
||||
upperTable.add(turnsToExpansionString.toLabel()).row()
|
||||
upperTable.add(turnsToPopString.toLabel()).row()
|
||||
|
||||
val tableWithIcons = Table()
|
||||
tableWithIcons.defaults().pad(2f)
|
||||
@ -140,7 +155,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
tableWithIcons.add(wltkLabel).row()
|
||||
}
|
||||
|
||||
innerTable.add(tableWithIcons).row()
|
||||
upperTable.add(tableWithIcons).row()
|
||||
}
|
||||
|
||||
private fun addCitizenManagement() {
|
||||
@ -152,7 +167,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
Align.topRight
|
||||
)
|
||||
}
|
||||
innerTable.add(expanderTab).growX().row()
|
||||
lowerTable.add(expanderTab).growX().row()
|
||||
}
|
||||
|
||||
private fun addSpecialistInfo() {
|
||||
@ -164,7 +179,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
Align.topRight
|
||||
)
|
||||
}
|
||||
innerTable.add(expanderTab).growX().row()
|
||||
lowerTable.add(expanderTab).growX().row()
|
||||
}
|
||||
|
||||
private fun addReligionInfo() {
|
||||
@ -174,6 +189,6 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
// ToDo: This probably should be refactored so its placed somewhere else in due time
|
||||
setPosition(stage.width - CityScreen.posFromEdge, stage.height - CityScreen.posFromEdge, Align.topRight)
|
||||
}
|
||||
innerTable.add(expanderTab).growX().row()
|
||||
lowerTable.add(expanderTab).growX().row()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user