Fix wrapping for promotions in unit overview (#9239)

This commit is contained in:
SomeTroglodyte
2023-04-24 21:11:39 +02:00
committed by GitHub
parent ea39fe4713
commit dc5cc6d601

View File

@ -34,7 +34,6 @@ import com.unciv.ui.screens.pickerscreens.PromotionPickerScreen
import com.unciv.ui.screens.pickerscreens.UnitRenamePopup import com.unciv.ui.screens.pickerscreens.UnitRenamePopup
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsUpgrade import com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsUpgrade
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.ceil
/** /**
* Supplies the Unit sub-table for the Empire Overview * Supplies the Unit sub-table for the Empire Overview
@ -235,13 +234,14 @@ class UnitOverviewTab(
// getPromotions goes by json order on demand, so this is same sorting as on picker // getPromotions goes by json order on demand, so this is same sorting as on picker
val promotions = unit.promotions.getPromotions(true) val promotions = unit.promotions.getPromotions(true)
if (promotions.any()) { if (promotions.any()) {
val numberOfLines = ceil(promotions.count() / 8f).toInt() val iconCount = promotions.count() + (if (unit.promotions.canBePromoted()) 1 else 0)
val promotionsPerLine = promotions.count() / numberOfLines val numberOfLines = (iconCount - 1) / 8 + 1
var promotionsThisLine = 0 val promotionsPerLine = (iconCount - 1) / numberOfLines + 1
for (promotion in promotions) { for (linePromotions in promotions.chunked(promotionsPerLine)) {
promotionsTable.add(ImageGetter.getPromotionPortrait(promotion.name)) for (promotion in linePromotions) {
promotionsThisLine++ promotionsTable.add(ImageGetter.getPromotionPortrait(promotion.name))
if (promotionsThisLine == promotionsPerLine && numberOfLines>1) promotionsTable.row() }
if (linePromotions.size == promotionsPerLine) promotionsTable.row()
} }
} }