mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-04 14:44:10 +07:00
Resolved #11356 - Policy tables no longer repeat on some height/width configurations
This commit is contained in:
parent
bd71ba683f
commit
f2dd64f684
@ -38,6 +38,7 @@ import com.unciv.ui.screens.basescreen.RecreateOnResize
|
||||
import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen
|
||||
import java.lang.Integer.max
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.min
|
||||
|
||||
private enum class PolicyColors(
|
||||
@ -190,13 +191,13 @@ class PolicyPickerScreen(
|
||||
topTable.row()
|
||||
|
||||
val branches = viewingCiv.gameInfo.ruleset.policyBranches
|
||||
val rowChangeCount: Int
|
||||
val branchesPerRow: Int
|
||||
|
||||
// estimate how many branch boxes fit using average size (including pad)
|
||||
// TODO If we'd want to use scene2d correctly, this is supposed to happen inside an overridden layout() method
|
||||
val numBranchesY = scrollPane.height / 305f
|
||||
// Landscape - arrange in as few rows as looks nice
|
||||
rowChangeCount = if (numBranchesY > 1.5f) {
|
||||
branchesPerRow = if (numBranchesY > 1.5f) {
|
||||
val numRows = if (numBranchesY < 2.9f) 2 else (numBranchesY + 0.1f).toInt()
|
||||
(branches.size + numRows - 1) / numRows
|
||||
} else branches.size
|
||||
@ -204,29 +205,36 @@ class PolicyPickerScreen(
|
||||
|
||||
// Actually create and distribute the policy branches
|
||||
var wrapper = Table()
|
||||
val size = ((branches.size / rowChangeCount) + if (branches.size % rowChangeCount == 0) 0 else 1)*rowChangeCount
|
||||
for (i in 0 until size) {
|
||||
val numberOfRows = ceil(branches.size / branchesPerRow.toFloat()).toInt()
|
||||
val size = numberOfRows * branchesPerRow
|
||||
|
||||
val change = (i % rowChangeCount == 0)
|
||||
val rightToLeft = ((i / rowChangeCount) % 2)
|
||||
val r = (i % rowChangeCount) + (i / rowChangeCount)*(rowChangeCount-rightToLeft) + rightToLeft*(rowChangeCount-2*(i % rowChangeCount))
|
||||
|
||||
if (i > 0 && change) {
|
||||
topTable.add(wrapper).pad(5f,10f)
|
||||
topTable.addSeparator().pad(0f, 10f)
|
||||
wrapper = Table()
|
||||
}
|
||||
|
||||
if (r >= branches.size) {
|
||||
wrapper.add().expand()
|
||||
} else {
|
||||
val branch = branches.values.elementAt(r)
|
||||
val branchGroup = BranchGroup(branch)
|
||||
wrapper.add(branchGroup).growY().growX()
|
||||
branchToGroup[branch.name] = branchGroup
|
||||
val positionToTable = HashMap<String,Table>()
|
||||
val allPoliciesTable = Table()
|
||||
for (rowNum in 0 until numberOfRows){
|
||||
val row = Table()
|
||||
for (columnNum in 0 until branchesPerRow){
|
||||
val branchTable = Table()
|
||||
row.add(branchTable).grow()
|
||||
positionToTable["$rowNum-$columnNum"] = branchTable
|
||||
}
|
||||
allPoliciesTable.add(row).pad(5f,10f)
|
||||
if (rowNum != numberOfRows-1) allPoliciesTable.addSeparator().pad(0f, 10f)
|
||||
}
|
||||
topTable.add(wrapper).pad(5f,10f)
|
||||
|
||||
for ((index, branch) in branches.values.withIndex()){
|
||||
val branchGroup = BranchGroup(branch)
|
||||
branchToGroup[branch.name] = branchGroup
|
||||
|
||||
val rowNumber = index / branchesPerRow
|
||||
val isRowLeftToRight = rowNumber % 2 == 0
|
||||
val numberInRow = index % branchesPerRow // RTL rows
|
||||
val rowPosition = if (isRowLeftToRight) numberInRow else branchesPerRow-1-numberInRow
|
||||
val policyTable = positionToTable["$rowNumber-$rowPosition"]!!
|
||||
policyTable.add(branchGroup).grow()
|
||||
}
|
||||
topTable.add(allPoliciesTable)
|
||||
|
||||
|
||||
// If topTable is larger than available space, scroll in a little - up to top/left
|
||||
// total padding, or up to where the axis is centered, whichever is smaller
|
||||
|
Loading…
Reference in New Issue
Block a user