Minor UI improvements construction menu (#2657)

* Fix padding for headers in construction menu

* Sync width of queue and available construction tables

* Left align "Add to queue" button to prevent jumping

* Remove duplicate separator and padding

* Improve design of CityInfoTable

* Fix padding for headers in construction menu

* Sync width of queue and available construction tables

* Left align "Add to queue" button to prevent jumping

* Remove duplicate separator and padding

* Improve design of CityInfoTable
This commit is contained in:
Daniel Bälz 2020-05-24 20:30:34 +02:00 committed by GitHub
parent ee5ef800c7
commit fcffbbb9bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 24 deletions

View file

@ -22,6 +22,8 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
private val innerTable = Table(skin)
init {
align(Align.topLeft)
showConstructionsTableButton.onClick {
cityScreen.showConstructionsTable = true
cityScreen.update()
@ -52,15 +54,25 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
}
private fun Table.addCategory(str: String, showHideTable: Table) {
val titleTable = Table().background(ImageGetter.getBackground(ImageGetter.getBlue()))
val width = cityScreen.stage.width/4 - 2*pad
val width = cityScreen.stage.width / 4 - 2 * pad
val showHideTableWrapper = Table()
showHideTableWrapper.add(showHideTable).minWidth(width)
titleTable.add(str.toLabel(fontSize = 24))
titleTable.onClick {
if(showHideTableWrapper.hasChildren()) showHideTableWrapper.clear()
else showHideTableWrapper.add(showHideTable).minWidth(width)
}
.add(showHideTable)
.minWidth(width)
.table
val titleTable = Table()
.background(ImageGetter.getBackground(ImageGetter.getBlue()))
.pad(4f)
.addCell(str.toLabel(fontSize = FONT_SIZE_CATEGORY_HEADER))
.onClick {
if (showHideTableWrapper.hasChildren()) {
showHideTableWrapper.clear()
} else {
showHideTableWrapper.add(showHideTable).minWidth(width)
}
}
addSeparator()
add(titleTable).minWidth(width).row()
add(showHideTableWrapper).row()
}
@ -166,7 +178,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val statValuesTable = Table().apply { defaults().pad(2f) }
addCategory(stat.name, statValuesTable)
statValuesTable.add("Base values".toLabel(fontSize= 24)).colspan(2).row()
statValuesTable.add("Base values".toLabel(fontSize= FONT_SIZE_STAT_INFO_HEADER)).pad(4f).colspan(2).row()
var sumOfAllBaseValues = 0f
for(entry in relevantBaseStats) {
val specificStatValue = entry.value.get(stat)
@ -180,7 +192,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val relevantBonuses = cityStats.statPercentBonusList.filter { it.value.get(stat)!=0f }
if(relevantBonuses.isNotEmpty()) {
statValuesTable.add("Bonuses".toLabel(fontSize = 24)).colspan(2).padTop(20f).row()
statValuesTable.add("Bonuses".toLabel(fontSize = FONT_SIZE_STAT_INFO_HEADER)).colspan(2).padTop(20f).row()
var sumOfBonuses = 0f
for (entry in relevantBonuses) {
val specificStatValue = entry.value.get(stat)
@ -198,7 +210,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
}
statValuesTable.add("Final".toLabel(fontSize = 24)).colspan(2).padTop(20f).row()
statValuesTable.add("Final".toLabel(fontSize = FONT_SIZE_STAT_INFO_HEADER)).colspan(2).padTop(20f).row()
var finalTotal = 0f
for (entry in cityStats.finalStatList) {
val specificStatValue = entry.value.get(stat)
@ -210,6 +222,8 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
statValuesTable.addSeparator()
statValuesTable.add("Total".toLabel())
statValuesTable.add(DecimalFormat("0.#").format(finalTotal).toLabel()).row()
statValuesTable.padBottom(4f)
}
}
@ -232,5 +246,10 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
}
}
companion object {
private const val FONT_SIZE_CATEGORY_HEADER: Int = 24
private const val FONT_SIZE_STAT_INFO_HEADER = 22
}
}

View file

@ -47,7 +47,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
add(showCityInfoTableButton).left().padLeft(pad).padBottom(pad).row()
add(constructionsQueueScrollPane).left().padBottom(pad).row()
add(buttons).center().bottom().padBottom(pad).row()
add(buttons).left().bottom().padBottom(pad).row()
add(availableConstructionsScrollPane).left().bottom().row()
}
@ -97,6 +97,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
constructionsQueueTable.defaults().pad(0f)
constructionsQueueTable.add(getHeader("Current construction".tr())).fillX()
constructionsQueueTable.addSeparator()
if (currentConstruction != "")
@ -107,7 +108,6 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
constructionsQueueTable.addSeparator()
constructionsQueueTable.add(getHeader("Construction queue".tr())).fillX()
constructionsQueueTable.addSeparator()
if (queue.isNotEmpty()) {
queue.forEachIndexed { i, constructionName ->
@ -165,11 +165,11 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
+ specialConstruction.getProductionTooltip(city))
}
availableConstructionsTable.addCategory("Units", units)
availableConstructionsTable.addCategory("Wonders", buildableWonders)
availableConstructionsTable.addCategory("National Wonders", buildableNationalWonders)
availableConstructionsTable.addCategory("Buildings", buildableBuildings)
availableConstructionsTable.addCategory("Other", specialConstructions)
availableConstructionsTable.addCategory("Units", units, constructionsQueueTable.width)
availableConstructionsTable.addCategory("Wonders", buildableWonders, constructionsQueueTable.width)
availableConstructionsTable.addCategory("National Wonders", buildableNationalWonders, constructionsQueueTable.width)
availableConstructionsTable.addCategory("Buildings", buildableBuildings, constructionsQueueTable.width)
availableConstructionsTable.addCategory("Other", specialConstructions, constructionsQueueTable.width)
}
private fun getQueueEntry(constructionQueueIndex: Int, name: String): Table {
@ -409,17 +409,17 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
}
private fun getHeader(title: String): Table {
val headerTable = Table()
headerTable.background = ImageGetter.getBackground(ImageGetter.getBlue())
headerTable.add(title.toLabel(fontSize = 24)).fillX()
return headerTable
return Table()
.background(ImageGetter.getBackground(ImageGetter.getBlue()))
.addCell(title.toLabel(fontSize = 24))
.pad(4f)
}
private fun Table.addCategory(title: String, list: ArrayList<Table>) {
private fun Table.addCategory(title: String, list: ArrayList<Table>, prefWidth: Float) {
if (list.isEmpty()) return
addSeparator()
add(getHeader(title)).fill().row()
add(getHeader(title)).prefWidth(prefWidth).fill().row()
addSeparator()
for (table in list) {

View file

@ -193,6 +193,11 @@ fun Table.addSeparatorVertical(): Cell<Image> {
return cell
}
fun <T : Actor> Table.addCell(actor: T): Table {
add(actor)
return this
}
/**
* Solves concurrent modification problems - everyone who had a reference to the previous arrayList can keep using it because it hasn't changed
*/