From 5232984bd982450be9710056d6ba0db4dd76d46c Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 13 Apr 2023 23:19:57 +0300 Subject: [PATCH] More UI cleanup --- .../com/unciv/ui/components/UncivTooltip.kt | 5 +++-- .../src/com/unciv/ui/images/IconTextButton.kt | 7 ++++--- .../GlobalPoliticsOverviewTable.kt | 21 ++++++++----------- .../NotificationsOverviewTable.kt | 15 ++++++------- .../overviewscreen/ResourcesOverviewTable.kt | 2 +- .../overviewscreen/UnitOverviewTable.kt | 3 ++- .../overviewscreen/WonderOverviewTable.kt | 2 +- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/core/src/com/unciv/ui/components/UncivTooltip.kt b/core/src/com/unciv/ui/components/UncivTooltip.kt index 8ea279e149..1e9fb1340e 100644 --- a/core/src/com/unciv/ui/components/UncivTooltip.kt +++ b/core/src/com/unciv/ui/components/UncivTooltip.kt @@ -180,11 +180,12 @@ class UncivTooltip ( size: Float = 26f, always: Boolean = false, targetAlign: Int = Align.topRight, - tipAlign: Int = Align.top + tipAlign: Int = Align.top, + hideIcons: Boolean = false ) { if (!(always || GUI.keyboardAvailable) || text.isEmpty()) return - val label = text.toLabel(BaseScreen.skinStrings.skinConfig.baseColor, 38) + val label = text.toLabel(BaseScreen.skinStrings.skinConfig.baseColor, 38, hideIcons = hideIcons) label.setAlignment(Align.center) val background = BaseScreen.skinStrings.getUiBackground("General/Tooltip", BaseScreen.skinStrings.roundedEdgeRectangleShape, Color.LIGHT_GRAY) diff --git a/core/src/com/unciv/ui/images/IconTextButton.kt b/core/src/com/unciv/ui/images/IconTextButton.kt index 7ae6f6ed9d..3444e3d029 100644 --- a/core/src/com/unciv/ui/images/IconTextButton.kt +++ b/core/src/com/unciv/ui/images/IconTextButton.kt @@ -7,8 +7,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.Cell import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.utils.Align import com.unciv.Constants -import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.extensions.toLabel +import com.unciv.ui.screens.basescreen.BaseScreen /** * Translate a [String] and make a [Button] widget from it, with control over font size, font colour, an optional icon, and custom formatting. @@ -22,10 +22,11 @@ open class IconTextButton( text: String, val icon: Actor? = null, fontSize: Int = Constants.defaultFontSize, - fontColor: Color = Color.WHITE + fontColor: Color = Color.WHITE, + hideIcons: Boolean = false ): Button(BaseScreen.skin) { /** [Label] instance produced by and with content and formatting as specified to [String.toLabel]. */ - val label = text.toLabel(fontColor, fontSize) + val label = text.toLabel(fontColor, fontSize, hideIcons = hideIcons) /** Table cell containing the [icon] if any, or `null`. */ val iconCell: Cell = if (icon != null) { diff --git a/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt b/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt index b78b672c21..b64677200c 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt @@ -15,10 +15,8 @@ import com.unciv.logic.civilization.diplomacy.DiplomaticStatus import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.map.HexMath import com.unciv.models.ruleset.Policy.PolicyBranchType -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.screens.diplomacyscreen.DiplomacyScreen import com.unciv.ui.components.AutoScrollPane -import com.unciv.ui.screens.basescreen.BaseScreen +import com.unciv.ui.components.ColorMarkupLabel import com.unciv.ui.components.Fonts import com.unciv.ui.components.UncivTooltip.Companion.addTooltip import com.unciv.ui.components.extensions.addBorder @@ -28,6 +26,9 @@ import com.unciv.ui.components.extensions.center import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.components.extensions.toTextButton +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.screens.basescreen.BaseScreen +import com.unciv.ui.screens.diplomacyscreen.DiplomacyScreen import kotlin.math.roundToInt class GlobalPoliticsOverviewTable ( @@ -160,7 +161,7 @@ class GlobalPoliticsOverviewTable ( worldScreen.mapHolder.setCenterPosition(wonder.location.position) } } - wonderTable.add(wonderName).row() + wonderTable.add(wonderName).left().row() } } @@ -183,8 +184,7 @@ class GlobalPoliticsOverviewTable ( // wars for (otherCiv in civ.getKnownCivs()) { if (civ.isAtWarWith(otherCiv)) { - val warText = "At war with [${getCivName(otherCiv)}]".toLabel() - warText.color = Color.RED + val warText = ColorMarkupLabel("At war with [${getCivName(otherCiv)}]", Color.RED) politicsTable.add(warText).row() } } @@ -193,8 +193,7 @@ class GlobalPoliticsOverviewTable ( // declaration of friendships for (otherCiv in civ.getKnownCivs()) { if (civ.diplomacy[otherCiv.civName]?.hasFlag(DiplomacyFlags.DeclarationOfFriendship) == true) { - val friendText = "Friends with [${getCivName(otherCiv)}]".toLabel() - friendText.color = Color.GREEN + val friendText = ColorMarkupLabel("Friends with [${getCivName(otherCiv)}]", Color.GREEN) val turnsLeftText = " (${civ.diplomacy[otherCiv.civName]?.getFlag(DiplomacyFlags.DeclarationOfFriendship)} ${Fonts.turn})".toLabel() politicsTable.add(friendText) politicsTable.add(turnsLeftText).row() @@ -205,8 +204,7 @@ class GlobalPoliticsOverviewTable ( // denounced civs for (otherCiv in civ.getKnownCivs()) { if (civ.diplomacy[otherCiv.civName]?.hasFlag(DiplomacyFlags.Denunciation) == true) { - val denouncedText = "Denounced [${getCivName(otherCiv)}]".toLabel() - denouncedText.color = Color.RED + val denouncedText = ColorMarkupLabel("Denounced [${getCivName(otherCiv)}]", Color.RED) val turnsLeftText = "(${civ.diplomacy[otherCiv.civName]?.getFlag(DiplomacyFlags.Denunciation)} ${Fonts.turn})".toLabel() politicsTable.add(denouncedText) politicsTable.add(turnsLeftText).row() @@ -217,8 +215,7 @@ class GlobalPoliticsOverviewTable ( //allied CS for (cityState in gameInfo.getAliveCityStates()) { if (cityState.diplomacy[civ.civName]?.isRelationshipLevelEQ(RelationshipLevel.Ally) == true) { - val alliedText = "Allied with [${getCivName(cityState)}]".toLabel() - alliedText.color = Color.GREEN + val alliedText = ColorMarkupLabel("Allied with [${getCivName(cityState)}]", Color.GREEN) politicsTable.add(alliedText).row() } } diff --git a/core/src/com/unciv/ui/screens/overviewscreen/NotificationsOverviewTable.kt b/core/src/com/unciv/ui/screens/overviewscreen/NotificationsOverviewTable.kt index 36db5afe54..f2d7f2f53e 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/NotificationsOverviewTable.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/NotificationsOverviewTable.kt @@ -8,13 +8,12 @@ import com.unciv.UncivGame import com.unciv.logic.civilization.Civilization import com.unciv.logic.civilization.Notification import com.unciv.logic.civilization.NotificationCategory -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.screens.basescreen.BaseScreen +import com.unciv.ui.components.ColorMarkupLabel import com.unciv.ui.components.TabbedPager -import com.unciv.ui.components.WrappableLabel import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.toLabel -import com.unciv.ui.screens.worldscreen.WorldScreen +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.screens.basescreen.BaseScreen class NotificationsOverviewTable( viewingPlayer: Civilization, @@ -42,8 +41,6 @@ class NotificationsOverviewTable( private val notificationLog = viewingPlayer.notificationsLog private val notificationTable = Table(BaseScreen.skin) - private val maxEntryWidth = worldScreen.stage.width - 20f - val iconSize = 20f init { @@ -87,10 +84,10 @@ class NotificationsOverviewTable( for (notification in categoryNotifications) { val notificationTable = Table(BaseScreen.skin) - val labelWidth = maxEntryWidth - iconSize * notification.icons.size - 10f - val label = WrappableLabel(notification.text, labelWidth, Color.BLACK, 20) + val label = ColorMarkupLabel(notification.text, Color.BLACK, fontSize = 20) + .apply { wrap = true } - notificationTable.add(label) + notificationTable.add(label).width(worldScreen.stage.width/2 - iconSize * notification.icons.size) notificationTable.background = BaseScreen.skinStrings.getUiBackground("OverviewScreen/NotificationOverviewTable/Notification", BaseScreen.skinStrings.roundedEdgeRectangleShape) notificationTable.touchable = Touchable.enabled notificationTable.onClick { diff --git a/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTable.kt b/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTable.kt index e8979c3091..9f0b80dd62 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTable.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTable.kt @@ -145,7 +145,7 @@ class ResourcesOverviewTab( add(turnImageH) for (resource in resources) { add(getResourceImage(resource.name).apply { - addTooltip(resource.name, tipAlign = Align.topLeft) + addTooltip(resource.name, tipAlign = Align.topLeft, hideIcons = true) }) } addSeparator() diff --git a/core/src/com/unciv/ui/screens/overviewscreen/UnitOverviewTable.kt b/core/src/com/unciv/ui/screens/overviewscreen/UnitOverviewTable.kt index da42788369..72181c1690 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/UnitOverviewTable.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/UnitOverviewTable.kt @@ -184,7 +184,8 @@ class UnitOverviewTab( val button = IconTextButton( unit.displayName(), UnitGroup(unit, 20f), - fontColor = if (unit.due && unit.isIdle()) Color.WHITE else Color.LIGHT_GRAY + fontColor = if (unit.due && unit.isIdle()) Color.WHITE else Color.LIGHT_GRAY, + hideIcons = true ) button.name = getUnitIdentifier(unit) // Marker to find a unit in select() button.onClick { diff --git a/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTable.kt b/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTable.kt index 87b3c65cb5..6e9d525e49 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTable.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTable.kt @@ -73,7 +73,7 @@ class WonderOverviewTab( // Terrain image padding is a bit unpredictable, they need ~5f more. Ensure equal line spacing on name, not image: add(image).pad(0f, 10f, 0f, 10f) - add(wonder.getNameColumn().toLabel()).pad(15f, 10f, 15f, 10f) + add(wonder.getNameColumn().toLabel(hideIcons = true)).pad(15f, 10f, 15f, 10f) add(wonder.getStatusColumn().toLabel()) val locationText = wonder.getLocationColumn() if (locationText.isNotEmpty()) {