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) private val innerTable = Table(skin)
init { init {
align(Align.topLeft)
showConstructionsTableButton.onClick { showConstructionsTableButton.onClick {
cityScreen.showConstructionsTable = true cityScreen.showConstructionsTable = true
cityScreen.update() cityScreen.update()
@ -52,15 +54,25 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
} }
private fun Table.addCategory(str: String, showHideTable: Table) { 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() val showHideTableWrapper = Table()
showHideTableWrapper.add(showHideTable).minWidth(width) .add(showHideTable)
titleTable.add(str.toLabel(fontSize = 24)) .minWidth(width)
titleTable.onClick { .table
if(showHideTableWrapper.hasChildren()) showHideTableWrapper.clear()
else showHideTableWrapper.add(showHideTable).minWidth(width) 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(titleTable).minWidth(width).row()
add(showHideTableWrapper).row() add(showHideTableWrapper).row()
} }
@ -166,7 +178,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
val statValuesTable = Table().apply { defaults().pad(2f) } val statValuesTable = Table().apply { defaults().pad(2f) }
addCategory(stat.name, statValuesTable) 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 var sumOfAllBaseValues = 0f
for(entry in relevantBaseStats) { for(entry in relevantBaseStats) {
val specificStatValue = entry.value.get(stat) 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 } val relevantBonuses = cityStats.statPercentBonusList.filter { it.value.get(stat)!=0f }
if(relevantBonuses.isNotEmpty()) { 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 var sumOfBonuses = 0f
for (entry in relevantBonuses) { for (entry in relevantBonuses) {
val specificStatValue = entry.value.get(stat) 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 var finalTotal = 0f
for (entry in cityStats.finalStatList) { for (entry in cityStats.finalStatList) {
val specificStatValue = entry.value.get(stat) val specificStatValue = entry.value.get(stat)
@ -210,6 +222,8 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
statValuesTable.addSeparator() statValuesTable.addSeparator()
statValuesTable.add("Total".toLabel()) statValuesTable.add("Total".toLabel())
statValuesTable.add(DecimalFormat("0.#").format(finalTotal).toLabel()).row() 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(showCityInfoTableButton).left().padLeft(pad).padBottom(pad).row()
add(constructionsQueueScrollPane).left().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() add(availableConstructionsScrollPane).left().bottom().row()
} }
@ -97,6 +97,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
constructionsQueueTable.defaults().pad(0f) constructionsQueueTable.defaults().pad(0f)
constructionsQueueTable.add(getHeader("Current construction".tr())).fillX() constructionsQueueTable.add(getHeader("Current construction".tr())).fillX()
constructionsQueueTable.addSeparator() constructionsQueueTable.addSeparator()
if (currentConstruction != "") if (currentConstruction != "")
@ -107,7 +108,6 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
constructionsQueueTable.addSeparator() constructionsQueueTable.addSeparator()
constructionsQueueTable.add(getHeader("Construction queue".tr())).fillX() constructionsQueueTable.add(getHeader("Construction queue".tr())).fillX()
constructionsQueueTable.addSeparator()
if (queue.isNotEmpty()) { if (queue.isNotEmpty()) {
queue.forEachIndexed { i, constructionName -> queue.forEachIndexed { i, constructionName ->
@ -165,11 +165,11 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
+ specialConstruction.getProductionTooltip(city)) + specialConstruction.getProductionTooltip(city))
} }
availableConstructionsTable.addCategory("Units", units) availableConstructionsTable.addCategory("Units", units, constructionsQueueTable.width)
availableConstructionsTable.addCategory("Wonders", buildableWonders) availableConstructionsTable.addCategory("Wonders", buildableWonders, constructionsQueueTable.width)
availableConstructionsTable.addCategory("National Wonders", buildableNationalWonders) availableConstructionsTable.addCategory("National Wonders", buildableNationalWonders, constructionsQueueTable.width)
availableConstructionsTable.addCategory("Buildings", buildableBuildings) availableConstructionsTable.addCategory("Buildings", buildableBuildings, constructionsQueueTable.width)
availableConstructionsTable.addCategory("Other", specialConstructions) availableConstructionsTable.addCategory("Other", specialConstructions, constructionsQueueTable.width)
} }
private fun getQueueEntry(constructionQueueIndex: Int, name: String): Table { 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 { private fun getHeader(title: String): Table {
val headerTable = Table() return Table()
headerTable.background = ImageGetter.getBackground(ImageGetter.getBlue()) .background(ImageGetter.getBackground(ImageGetter.getBlue()))
headerTable.add(title.toLabel(fontSize = 24)).fillX() .addCell(title.toLabel(fontSize = 24))
return headerTable .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 if (list.isEmpty()) return
addSeparator() addSeparator()
add(getHeader(title)).fill().row() add(getHeader(title)).prefWidth(prefWidth).fill().row()
addSeparator() addSeparator()
for (table in list) { for (table in list) {

View File

@ -193,6 +193,11 @@ fun Table.addSeparatorVertical(): Cell<Image> {
return cell 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 * Solves concurrent modification problems - everyone who had a reference to the previous arrayList can keep using it because it hasn't changed
*/ */