Better wrapping for long construction item names

This commit is contained in:
Yair Morgenstern 2023-04-09 01:20:17 +03:00
parent 0d9cff0922
commit 711655c786
3 changed files with 37 additions and 19 deletions

View File

@ -23,11 +23,6 @@ import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stat import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.audio.SoundPlayer 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.ExpanderTab
import com.unciv.ui.components.UncivTooltip.Companion.addTooltip import com.unciv.ui.components.UncivTooltip.Companion.addTooltip
import com.unciv.ui.components.extensions.addBorder 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.surroundWithCircle
import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.components.extensions.toLabel
import com.unciv.ui.components.extensions.toTextButton 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.Concurrency
import com.unciv.utils.concurrency.launchOnGLThread import com.unciv.utils.concurrency.launchOnGLThread
import kotlin.math.max import kotlin.math.max
@ -380,28 +380,29 @@ class CityConstructionsTable(private val cityScreen: CityScreen) {
pickConstructionButton.add(getProgressBar(construction.name)).padRight(5f) pickConstructionButton.add(getProgressBar(construction.name)).padRight(5f)
pickConstructionButton.add(icon).padRight(10f) pickConstructionButton.add(icon).padRight(10f)
val table = Table().apply { isTransform = false } val constructionTable = Table().apply { isTransform = false }
val tableRes = Table().apply { isTransform = false } val resourceTable = Table().apply { isTransform = false }
val textColor = if (constructionButtonDTO.rejectionReason == null) Color.WHITE else Color.RED 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) { if (constructionButtonDTO.resourcesRequired != null) {
for ((resource, amount) in constructionButtonDTO.resourcesRequired) { for ((resource, amount) in constructionButtonDTO.resourcesRequired) {
if (constructionButtonDTO.rejectionReason?.type == RejectionReasonType.ConsumesResources) val color = if (constructionButtonDTO.rejectionReason?.type == RejectionReasonType.ConsumesResources)
tableRes.add(amount.toString().toLabel(fontColor = Color.RED)).expandX().left().padLeft(5f) Color.RED else Color.WHITE
else resourceTable.add(amount.toString().toLabel(fontColor = color)).expandX().left().padLeft(5f)
tableRes.add(amount.toString().toLabel(fontColor = Color.WHITE)).expandX().left().padLeft(5f) resourceTable.add(ImageGetter.getResourcePortrait(resource, 15f)).padBottom(1f)
tableRes.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)) { 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) { addToQueueButton.onClick(UncivSound.Silent) {
// Since the pickConstructionButton.onClick adds the construction if it's selected, // Since the pickConstructionButton.onClick adds the construction if it's selected,
// this effectively adds the construction even if it's unselected // 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) { if (constructionButtonDTO.rejectionReason.type != RejectionReasonType.ConsumesResources) {
pickConstructionButton.add(constructionButtonDTO.rejectionReason.errorMessage pickConstructionButton.add(constructionButtonDTO.rejectionReason.errorMessage
.toLabel(Color.RED).apply { wrap = true }) .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)
} }
} }

View File

@ -65,7 +65,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s
else Color.GRAY // unassigned else Color.GRAY // unassigned
val icon = ImageGetter.getSpecialistIcon(color) val icon = ImageGetter.getSpecialistIcon(color)
specialistIconTable.add(icon).size(30f) specialistIconTable.add(icon).size(30f)
if (i % 6 == 0) specialistIconTable.row() if (i % 5 == 0) specialistIconTable.row()
} }
return specialistIconTable return specialistIconTable
} }
@ -107,10 +107,20 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s
private fun getSpecialistStatsTable(specialistName: String): Table { private fun getSpecialistStatsTable(specialistName: String): Table {
val specialistStatTable = Table().apply { defaults().padBottom(5f).padTop(5f) } val specialistStatTable = Table().apply { defaults().padBottom(5f).padTop(5f) }
val specialistStats = cityInfo.cityStats.getStatsOfSpecialist(specialistName) 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) { for ((key, value) in specialistStats) {
if (value == 0f) continue if (value == 0f) continue
specialistStatTable.add(value.toInt().toLabel()) specialistStatTable.add(value.toInt().toLabel())
specialistStatTable.add(ImageGetter.getStatIcon(key.name)).size(20f).padRight(10f) specialistStatTable.add(ImageGetter.getStatIcon(key.name)).size(20f).padRight(10f)
incrementItemsInRow()
} }
val specialist = cityInfo.getRuleset().specialists[specialistName]!! val specialist = cityInfo.getRuleset().specialists[specialistName]!!
@ -118,6 +128,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s
for (s in specialist.greatPersonPoints) { for (s in specialist.greatPersonPoints) {
specialistStatTable.add(s.value.toLabel()) specialistStatTable.add(s.value.toLabel())
specialistStatTable.add(ImageGetter.getUnitIcon(s.key, Color.GOLD).toGroup(20f)).padRight(10f) specialistStatTable.add(ImageGetter.getUnitIcon(s.key, Color.GOLD).toGroup(20f)).padRight(10f)
incrementItemsInRow()
} }
return specialistStatTable return specialistStatTable

View File

@ -1671,6 +1671,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Conditional Applicable to: Conditional
??? example "<for [nationFilter]>"
Example: "<for [City-States]>"
Applicable to: Conditional
??? example "<when at war>" ??? example "<when at war>"
Applicable to: Conditional Applicable to: Conditional