mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04: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)
|
cityPickerTable.setPosition(centeredX, exitCityButton.top + 10f, Align.bottom)
|
||||||
|
|
||||||
// Top right of screen: Stats / Specialists
|
// 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)
|
cityStatsTable.setPosition(stage.width - posFromEdge, stage.height - posFromEdge, Align.topRight)
|
||||||
|
|
||||||
// Top center: Annex/Raze button
|
// Top center: Annex/Raze button
|
||||||
|
@ -2,6 +2,7 @@ package com.unciv.ui.cityscreen
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
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.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
@ -19,26 +20,34 @@ import kotlin.math.round
|
|||||||
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
||||||
|
|
||||||
class CityStatsTable(val cityScreen: CityScreen): Table() {
|
class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||||
private val innerTable = Table()
|
private val innerTable = Table() // table within this Table. Slightly smaller creates border
|
||||||
private val outerPane: ScrollPane
|
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 cityInfo = cityScreen.city
|
||||||
|
private val lowerCell: Cell<ScrollPane>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
pad(2f)
|
pad(2f)
|
||||||
background = ImageGetter.getBackground(colorFromRGB(194, 180, 131))
|
background = ImageGetter.getBackground(colorFromRGB(194, 180, 131))
|
||||||
|
|
||||||
innerTable.pad(5f)
|
innerTable.pad(5f)
|
||||||
innerTable.defaults().pad(2f)
|
|
||||||
innerTable.background = ImageGetter.getBackground(Color.BLACK.cpy().apply { a = 0.8f })
|
innerTable.background = ImageGetter.getBackground(Color.BLACK.cpy().apply { a = 0.8f })
|
||||||
|
innerTable.add(upperTable).row()
|
||||||
|
|
||||||
outerPane = ScrollPane(innerTable)
|
upperTable.defaults().pad(2f)
|
||||||
outerPane.setOverscroll(false, false)
|
lowerTable.defaults().pad(2f)
|
||||||
outerPane.setScrollingDisabled(true, false)
|
lowerPane = ScrollPane(lowerTable)
|
||||||
add(outerPane).maxHeight(cityScreen.stage.height / 2)
|
lowerPane.setOverscroll(false, false)
|
||||||
|
lowerPane.setScrollingDisabled(true, false)
|
||||||
|
lowerCell = innerTable.add(lowerPane)
|
||||||
|
|
||||||
|
add(innerTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update() {
|
fun update(height: Float) {
|
||||||
innerTable.clear()
|
upperTable.clear()
|
||||||
|
lowerTable.clear()
|
||||||
|
|
||||||
val miniStatsTable = Table()
|
val miniStatsTable = Table()
|
||||||
val selected = BaseScreen.skin.get("selection", Color::class.java)
|
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
|
val valueToDisplay = if (stat == Stat.Happiness) cityInfo.cityStats.happinessList.values.sum() else amount
|
||||||
miniStatsTable.add(round(valueToDisplay).toInt().toLabel()).padRight(10f)
|
miniStatsTable.add(round(valueToDisplay).toInt().toLabel()).padRight(10f)
|
||||||
}
|
}
|
||||||
innerTable.add(miniStatsTable)
|
upperTable.add(miniStatsTable)
|
||||||
|
|
||||||
innerTable.addSeparator()
|
upperTable.addSeparator()
|
||||||
addText()
|
addText()
|
||||||
|
|
||||||
|
// begin lowerTable
|
||||||
addCitizenManagement()
|
addCitizenManagement()
|
||||||
if (!cityInfo.population.getMaxSpecialists().isEmpty()) {
|
if (!cityInfo.population.getMaxSpecialists().isEmpty()) {
|
||||||
addSpecialistInfo()
|
addSpecialistInfo()
|
||||||
@ -77,10 +88,14 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
|||||||
if (cityInfo.religion.getNumberOfFollowers().isNotEmpty() && cityInfo.civInfo.gameInfo.isReligionEnabled())
|
if (cityInfo.religion.getNumberOfFollowers().isNotEmpty() && cityInfo.civInfo.gameInfo.isReligionEnabled())
|
||||||
addReligionInfo()
|
addReligionInfo()
|
||||||
|
|
||||||
innerTable.pack()
|
upperTable.pack()
|
||||||
outerPane.layout()
|
lowerTable.pack()
|
||||||
outerPane.updateVisualScroll()
|
lowerPane.layout()
|
||||||
pack()
|
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() {
|
private fun addText() {
|
||||||
@ -112,9 +127,9 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
|||||||
}.tr()
|
}.tr()
|
||||||
turnsToPopString += " (${cityInfo.population.foodStored}${Fonts.food}/${cityInfo.population.getFoodToNextPopulation()}${Fonts.food})"
|
turnsToPopString += " (${cityInfo.population.foodStored}${Fonts.food}/${cityInfo.population.getFoodToNextPopulation()}${Fonts.food})"
|
||||||
|
|
||||||
innerTable.add(unassignedPopLabel).row()
|
upperTable.add(unassignedPopLabel).row()
|
||||||
innerTable.add(turnsToExpansionString.toLabel()).row()
|
upperTable.add(turnsToExpansionString.toLabel()).row()
|
||||||
innerTable.add(turnsToPopString.toLabel()).row()
|
upperTable.add(turnsToPopString.toLabel()).row()
|
||||||
|
|
||||||
val tableWithIcons = Table()
|
val tableWithIcons = Table()
|
||||||
tableWithIcons.defaults().pad(2f)
|
tableWithIcons.defaults().pad(2f)
|
||||||
@ -140,7 +155,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
|||||||
tableWithIcons.add(wltkLabel).row()
|
tableWithIcons.add(wltkLabel).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
innerTable.add(tableWithIcons).row()
|
upperTable.add(tableWithIcons).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addCitizenManagement() {
|
private fun addCitizenManagement() {
|
||||||
@ -152,7 +167,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
|||||||
Align.topRight
|
Align.topRight
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
innerTable.add(expanderTab).growX().row()
|
lowerTable.add(expanderTab).growX().row()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addSpecialistInfo() {
|
private fun addSpecialistInfo() {
|
||||||
@ -164,7 +179,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
|||||||
Align.topRight
|
Align.topRight
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
innerTable.add(expanderTab).growX().row()
|
lowerTable.add(expanderTab).growX().row()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addReligionInfo() {
|
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
|
// 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)
|
setPosition(stage.width - CityScreen.posFromEdge, stage.height - CityScreen.posFromEdge, Align.topRight)
|
||||||
}
|
}
|
||||||
innerTable.add(expanderTab).growX().row()
|
lowerTable.add(expanderTab).growX().row()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user