diff --git a/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBar.kt b/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBar.kt index 2c243cc6b0..22f8836caa 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBar.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBar.kt @@ -102,6 +102,7 @@ class WorldScreenTopBar(internal val worldScreen: WorldScreen) : Table() { /** Performs the layout tricks mentioned in the class Kdoc */ private fun updateLayout() { val targetWidth = stage.width + val statsWidth = statsTable.minWidth val resourceWidth = resourceTable.minWidth val overviewWidth = overviewButton.minWidth val overviewHeight = overviewButton.minHeight @@ -121,7 +122,6 @@ class WorldScreenTopBar(internal val worldScreen: WorldScreen) : Table() { layout() // force rowHeight calculation - validate is not enough - Table quirks val statsRowHeight = getRowHeight(0) val baseHeight = statsRowHeight + getRowHeight(1) - val statsWidth = statsTable.width fun addFillers(fillerHeight: Float) { add(leftFiller).size(selectedCivWidth, fillerHeight + gapFillingExtraHeight) diff --git a/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBarResources.kt b/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBarResources.kt index 479efc1448..acca1b9a59 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBarResources.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/topbar/WorldScreenTopBarResources.kt @@ -24,12 +24,29 @@ internal class WorldScreenTopBarResources(topbar: WorldScreenTopBar) : Table() { private val resourceActors = ArrayList(12) private val resourcesWrapper = Table() + // Note: For a proper functioning of the "shift floating buttons down when cramped" feature, it is + // important that this entire Widget has only the bare minimum padding to its left and right. + // #7193 did let the resources and turn label swap places, with the side effect of the "first resource getting extra left padding" + // now being on the outside - the buttons moved out of the way despite there being visually ample space. + + private companion object { + const val defaultPad = 5f + const val extraPadBetweenLabelAndResources = 20f + const val bottomPad = 10f + const val extraPadBetweenResources = 5f + const val outerHorizontalPad = 2f + const val iconSize = 20f + const val resourceAmountDescentTweak = 3f + } + init { - resourcesWrapper.defaults().pad(5f, 5f, 10f, 5f) + defaults().space(extraPadBetweenLabelAndResources) + .pad(defaultPad, outerHorizontalPad, bottomPad, outerHorizontalPad) + + resourcesWrapper.defaults().space(defaultPad) resourcesWrapper.touchable = Touchable.enabled val worldScreen = topbar.worldScreen - turnsLabel.onClick { if (worldScreen.selectedCiv.isLongCountDisplay()) { val gameInfo = worldScreen.selectedCiv.gameInfo @@ -45,29 +62,32 @@ internal class WorldScreenTopBarResources(topbar: WorldScreenTopBar) : Table() { val strategicResources = worldScreen.gameInfo.ruleset.tileResources.values .filter { it.resourceType == ResourceType.Strategic && !it.hasUnique(UniqueType.CityResource) } for (resource in strategicResources) { - val resourceImage = ImageGetter.getResourcePortrait(resource.name, 20f) + val resourceImage = ImageGetter.getResourcePortrait(resource.name, iconSize) val resourceLabel = "0".toLabel() resourceActors += ResourceActors(resource, resourceLabel, resourceImage) } + add(turnsLabel) + // in case the icons are configured higher than a label, we add a dummy - height will be measured once before it's updated if (resourceActors.isNotEmpty()) { resourcesWrapper.add(resourceActors[0].icon) add(resourcesWrapper) } - - add(turnsLabel).pad(5f, 5f, 10f, 5f) } + fun update(civInfo: Civilization) { val yearText = YearTextUtil.toYearText( civInfo.gameInfo.getYear(), civInfo.isLongCountDisplay() ) turnsLabel.setText(Fonts.turn + "" + civInfo.gameInfo.turns + " | " + yearText) + resourcesWrapper.clearChildren() - var firstPadLeft = 20f // We want a distance from the turns entry to the first resource, but only if any resource is displayed val civResources = civInfo.getCivResourcesByName() val civResourceSupply = civInfo.getCivResourceSupply() - for ((resource, label, icon) in resourceActors) { + for ((index, resourceActors) in resourceActors.withIndex()) { + val (resource, label, icon) = resourceActors + if (resource.hasUnique(UniqueType.NotShownOnWorldScreen)) continue val amount = civResources[resource.name] ?: 0 @@ -76,8 +96,8 @@ internal class WorldScreenTopBarResources(topbar: WorldScreenTopBar) : Table() { && amount == 0) // You can trade for resources you cannot process yourself yet continue - resourcesWrapper.add(icon).padLeft(firstPadLeft).padRight(0f) - firstPadLeft = 5f + resourcesWrapper.add(icon).padLeft(if (index == 0) 0f else extraPadBetweenResources) + if (!resource.isStockpiled()) label.setText(amount) else { @@ -85,7 +105,7 @@ internal class WorldScreenTopBarResources(topbar: WorldScreenTopBar) : Table() { if (perTurn == 0) label.setText(amount) else label.setText("$amount (${perTurn.toStringSigned()})") } - resourcesWrapper.add(label).padTop(8f) // digits don't have descenders, so push them down a little + resourcesWrapper.add(label).padTop(resourceAmountDescentTweak) // digits don't have descenders, so push them down a little } pack()