From 711655c786b06ccd1c1cc695b1239c3973a743d7 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 9 Apr 2023 01:20:17 +0300 Subject: [PATCH] Better wrapping for long construction item names --- .../cityscreen/CityConstructionsTable.kt | 38 ++++++++++--------- .../cityscreen/SpecialistAllocationTable.kt | 13 ++++++- docs/Modders/uniques.md | 5 +++ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt b/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt index 87ea5f15be..b4ed626b67 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt @@ -23,11 +23,6 @@ import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.stats.Stat import com.unciv.models.translations.tr import com.unciv.ui.audio.SoundPlayer -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.popups.ConfirmPopup -import com.unciv.ui.popups.Popup -import com.unciv.ui.popups.closeAllPopups -import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.ExpanderTab import com.unciv.ui.components.UncivTooltip.Companion.addTooltip import com.unciv.ui.components.extensions.addBorder @@ -45,6 +40,11 @@ import com.unciv.ui.components.extensions.packIfNeeded import com.unciv.ui.components.extensions.surroundWithCircle import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.components.extensions.toTextButton +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.popups.ConfirmPopup +import com.unciv.ui.popups.Popup +import com.unciv.ui.popups.closeAllPopups +import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.utils.concurrency.Concurrency import com.unciv.utils.concurrency.launchOnGLThread import kotlin.math.max @@ -380,28 +380,29 @@ class CityConstructionsTable(private val cityScreen: CityScreen) { pickConstructionButton.add(getProgressBar(construction.name)).padRight(5f) pickConstructionButton.add(icon).padRight(10f) - val table = Table().apply { isTransform = false } - val tableRes = Table().apply { isTransform = false } + val constructionTable = Table().apply { isTransform = false } + val resourceTable = Table().apply { isTransform = false } val textColor = if (constructionButtonDTO.rejectionReason == null) Color.WHITE else Color.RED - table.add(construction.name.tr().toLabel(fontColor = textColor)).expandX().left().row() + constructionTable.add(construction.name.toLabel(fontColor = textColor).apply { wrap=true }) + .width(cityScreen.stage.width/5).expandX().left().row() - tableRes.add(constructionButtonDTO.buttonText.toLabel()).expandX().left() + resourceTable.add(constructionButtonDTO.buttonText.toLabel()).expandX().left() if (constructionButtonDTO.resourcesRequired != null) { for ((resource, amount) in constructionButtonDTO.resourcesRequired) { - if (constructionButtonDTO.rejectionReason?.type == RejectionReasonType.ConsumesResources) - tableRes.add(amount.toString().toLabel(fontColor = Color.RED)).expandX().left().padLeft(5f) - else - tableRes.add(amount.toString().toLabel(fontColor = Color.WHITE)).expandX().left().padLeft(5f) - tableRes.add(ImageGetter.getResourcePortrait(resource, 15f)).padBottom(1f) + val color = if (constructionButtonDTO.rejectionReason?.type == RejectionReasonType.ConsumesResources) + Color.RED else Color.WHITE + resourceTable.add(amount.toString().toLabel(fontColor = color)).expandX().left().padLeft(5f) + resourceTable.add(ImageGetter.getResourcePortrait(resource, 15f)).padBottom(1f) } } - table.add(tableRes).expandX().left() + constructionTable.add(resourceTable).expandX().left() - pickConstructionButton.add(table).expandX().left() + pickConstructionButton.add(constructionTable).expandX().left() if (!cannotAddConstructionToQueue(construction, cityScreen.city, cityScreen.city.cityConstructions)) { - val addToQueueButton = ImageGetter.getImage("OtherIcons/New").apply { color = Color.BLACK }.surroundWithCircle(40f) + val addToQueueButton = ImageGetter.getImage("OtherIcons/New") + .apply { color = Color.BLACK }.surroundWithCircle(40f) addToQueueButton.onClick(UncivSound.Silent) { // Since the pickConstructionButton.onClick adds the construction if it's selected, // this effectively adds the construction even if it's unselected @@ -418,7 +419,8 @@ class CityConstructionsTable(private val cityScreen: CityScreen) { if (constructionButtonDTO.rejectionReason.type != RejectionReasonType.ConsumesResources) { pickConstructionButton.add(constructionButtonDTO.rejectionReason.errorMessage .toLabel(Color.RED).apply { wrap = true }) - .colspan(pickConstructionButton.columns).fillX().left().padTop(2f) + .colspan(pickConstructionButton.columns) + .width(cityScreen.stage.width/4).fillX().left().padTop(2f) } } diff --git a/core/src/com/unciv/ui/screens/cityscreen/SpecialistAllocationTable.kt b/core/src/com/unciv/ui/screens/cityscreen/SpecialistAllocationTable.kt index 3997440dd9..33eb520cd8 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/SpecialistAllocationTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/SpecialistAllocationTable.kt @@ -65,7 +65,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s else Color.GRAY // unassigned val icon = ImageGetter.getSpecialistIcon(color) specialistIconTable.add(icon).size(30f) - if (i % 6 == 0) specialistIconTable.row() + if (i % 5 == 0) specialistIconTable.row() } return specialistIconTable } @@ -107,10 +107,20 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s private fun getSpecialistStatsTable(specialistName: String): Table { val specialistStatTable = Table().apply { defaults().padBottom(5f).padTop(5f) } val specialistStats = cityInfo.cityStats.getStatsOfSpecialist(specialistName) + var itemsInRow = 0 + fun incrementItemsInRow(){ + itemsInRow++ + if (itemsInRow % 3 == 0){ + itemsInRow = 0 + specialistStatTable.row() + } + } + for ((key, value) in specialistStats) { if (value == 0f) continue specialistStatTable.add(value.toInt().toLabel()) specialistStatTable.add(ImageGetter.getStatIcon(key.name)).size(20f).padRight(10f) + incrementItemsInRow() } val specialist = cityInfo.getRuleset().specialists[specialistName]!! @@ -118,6 +128,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s for (s in specialist.greatPersonPoints) { specialistStatTable.add(s.value.toLabel()) specialistStatTable.add(ImageGetter.getUnitIcon(s.key, Color.GOLD).toGroup(20f)).padRight(10f) + incrementItemsInRow() } return specialistStatTable diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 1cfb947976..95ef9d0326 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -1671,6 +1671,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: Conditional +??? example "<for [nationFilter]>" + Example: "<for [City-States]>" + + Applicable to: Conditional + ??? example "<when at war>" Applicable to: Conditional