From 77839b4b9d2749a7c292f0cf6439fbf2c47cc078 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Mon, 21 Mar 2022 20:04:47 +0100 Subject: [PATCH] Empire Overview Units: Persist scroll, unit select, show due, jump city, fixed header (#6368) --- .../EmpireOverviewCategories.kt | 4 +- .../ui/overviewscreen/EmpireOverviewTab.kt | 23 ++ .../ui/overviewscreen/UnitOverviewTable.kt | 267 ++++++++++++------ .../unciv/ui/worldscreen/WorldMapHolder.kt | 10 +- .../unciv/ui/worldscreen/unit/UnitTable.kt | 40 +-- 5 files changed, 228 insertions(+), 116 deletions(-) diff --git a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt index 8ad3ec9299..10efc58acf 100644 --- a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt +++ b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewCategories.kt @@ -34,8 +34,8 @@ enum class EmpireOverviewCategories( = TradesOverviewTab(viewingPlayer, overviewScreen), fun (viewingPlayer: CivilizationInfo) = viewingPlayer.diplomacy.values.all { it.trades.isEmpty() }.toState()), Units("OtherIcons/Shield", 'U', - fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?) - = UnitOverviewTab(viewingPlayer, overviewScreen), + fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?) + = UnitOverviewTab(viewingPlayer, overviewScreen, persistedData), fun (viewingPlayer: CivilizationInfo) = viewingPlayer.getCivUnits().none().toState()), Diplomacy("OtherIcons/DiplomacyW", 'D', fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?) diff --git a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewTab.kt b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewTab.kt index 26f714504a..a9ae8cd952 100644 --- a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewTab.kt +++ b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewTab.kt @@ -1,9 +1,13 @@ package com.unciv.ui.overviewscreen +import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup +import com.badlogic.gdx.utils.Align import com.unciv.logic.civilization.CivilizationInfo import com.unciv.ui.utils.BaseScreen +import com.unciv.ui.utils.packIfNeeded +import com.unciv.ui.utils.toLabel abstract class EmpireOverviewTab ( val viewingPlayer: CivilizationInfo, @@ -23,8 +27,19 @@ abstract class EmpireOverviewTab ( val gameInfo = viewingPlayer.gameInfo + /** Sets first row cell's minWidth to the max of the widths of that column over all given tables + * + * Notes: + * - This aligns columns only if the tables are arranged vertically with equal X coordinates. + * - first table determines columns processed, all others must have at least the same column count. + * - Tables are left as needsLayout==true, so while equal width is ensured, you may have to pack if you want to see the value before this is rendered. + */ protected fun equalizeColumns(vararg tables: Table) { + for (table in tables) + table.packIfNeeded() val columns = tables.first().columns + if (tables.any { it.columns < columns }) + throw IllegalStateException("EmpireOverviewTab.equalizeColumns needs all tables to have at least the same number of columns as the first one") val widths = (0 until columns) .mapTo(ArrayList(columns)) { column -> tables.maxOf { it.getColumnWidth(column) } @@ -32,6 +47,14 @@ abstract class EmpireOverviewTab ( for (table in tables) { for (column in 0 until columns) table.cells[column].run { + if (actor == null) + // Empty cells ignore minWidth, so just doing Table.add() for an empty cell in the top row will break this. Fix! + setActor