mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Empire Overview Tweaks to better utilize new TabbedPager (#6434)
This commit is contained in:
parent
2c2ffd02d1
commit
892fc1f936
@ -19,12 +19,6 @@ import com.unciv.ui.utils.*
|
|||||||
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
|
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private fun String.isStat() = Stat.values().any { it.name == this }
|
|
||||||
private fun CityInfo.getStat(stat: Stat) =
|
|
||||||
if (stat == Stat.Happiness)
|
|
||||||
cityStats.happinessList.values.sum().roundToInt()
|
|
||||||
else cityStats.currentCityStats[stat].roundToInt()
|
|
||||||
|
|
||||||
class CityOverviewTab(
|
class CityOverviewTab(
|
||||||
viewingPlayer: CivilizationInfo,
|
viewingPlayer: CivilizationInfo,
|
||||||
overviewScreen: EmpireOverviewScreen,
|
overviewScreen: EmpireOverviewScreen,
|
||||||
@ -60,6 +54,17 @@ class CityOverviewTab(
|
|||||||
.apply { color = Color.BLACK }
|
.apply { color = Color.BLACK }
|
||||||
.surroundWithCircle(iconSize, color = Color.LIGHT_GRAY)
|
.surroundWithCircle(iconSize, color = Color.LIGHT_GRAY)
|
||||||
.apply { addTooltip("Current construction", 18f, tipAlign = Align.center) }
|
.apply { addTooltip("Current construction", 18f, tipAlign = Align.center) }
|
||||||
|
|
||||||
|
// Readability helpers
|
||||||
|
private fun String.isStat() = Stat.values().any { it.name == this }
|
||||||
|
|
||||||
|
private fun CityInfo.getStat(stat: Stat) =
|
||||||
|
if (stat == Stat.Happiness)
|
||||||
|
cityStats.happinessList.values.sum().roundToInt()
|
||||||
|
else cityStats.currentCityStats[stat].roundToInt()
|
||||||
|
|
||||||
|
private fun Int.toCenteredLabel(): Label =
|
||||||
|
this.toLabel().apply { setAlignment(Align.center) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val columnsNames = arrayListOf("Population", "Food", "Gold", "Science", "Production", "Culture", "Happiness")
|
private val columnsNames = arrayListOf("Population", "Food", "Gold", "Science", "Production", "Culture", "Happiness")
|
||||||
@ -85,6 +90,7 @@ class CityOverviewTab(
|
|||||||
updateTotal()
|
updateTotal()
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
top()
|
||||||
add(cityInfoTableDetails).row()
|
add(cityInfoTableDetails).row()
|
||||||
addSeparator(Color.GRAY).pad(paddingVert, 0f)
|
addSeparator(Color.GRAY).pad(paddingVert, 0f)
|
||||||
add(cityInfoTableTotal)
|
add(cityInfoTableTotal)
|
||||||
@ -234,8 +240,4 @@ class CityOverviewTab(
|
|||||||
cityInfoTableTotal.add(viewingPlayer.cities.count { it.isWeLoveTheKingDayActive() }.toCenteredLabel())
|
cityInfoTableTotal.add(viewingPlayer.cities.count { it.isWeLoveTheKingDayActive() }.toCenteredLabel())
|
||||||
cityInfoTableTotal.pack()
|
cityInfoTableTotal.pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Int.toCenteredLabel(): Label =
|
|
||||||
this.toLabel().apply { setAlignment(Align.center) }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.unciv.ui.overviewscreen
|
package com.unciv.ui.overviewscreen
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.ui.utils.KeyCharAndCode
|
import com.unciv.ui.utils.KeyCharAndCode
|
||||||
import com.unciv.ui.overviewscreen.EmpireOverviewTab.EmpireOverviewTabPersistableData
|
import com.unciv.ui.overviewscreen.EmpireOverviewTab.EmpireOverviewTabPersistableData
|
||||||
@ -18,34 +19,35 @@ private fun Boolean.toState(): EmpireOverviewTabState = if (this) EmpireOverview
|
|||||||
enum class EmpireOverviewCategories(
|
enum class EmpireOverviewCategories(
|
||||||
val iconName: String,
|
val iconName: String,
|
||||||
val shortcutKey: KeyCharAndCode,
|
val shortcutKey: KeyCharAndCode,
|
||||||
|
val scrollAlign: Int,
|
||||||
val factory: FactoryType,
|
val factory: FactoryType,
|
||||||
val stateTester: StateTesterType
|
val stateTester: StateTesterType
|
||||||
) {
|
) {
|
||||||
Cities("OtherIcons/Cities", 'C',
|
Cities("OtherIcons/Cities", 'C', Align.topLeft,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
||||||
= CityOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
= CityOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
||||||
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.cities.isEmpty().toState()),
|
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.cities.isEmpty().toState()),
|
||||||
Stats("StatIcons/Gold", 'S',
|
Stats("StatIcons/Gold", 'S', Align.top,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
||||||
= StatsOverviewTab(viewingPlayer, overviewScreen),
|
= StatsOverviewTab(viewingPlayer, overviewScreen),
|
||||||
fun (_: CivilizationInfo) = EmpireOverviewTabState.Normal),
|
fun (_: CivilizationInfo) = EmpireOverviewTabState.Normal),
|
||||||
Trades("StatIcons/Acquire", 'T',
|
Trades("StatIcons/Acquire", 'T', Align.top,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
||||||
= TradesOverviewTab(viewingPlayer, overviewScreen),
|
= TradesOverviewTab(viewingPlayer, overviewScreen),
|
||||||
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.diplomacy.values.all { it.trades.isEmpty() }.toState()),
|
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.diplomacy.values.all { it.trades.isEmpty() }.toState()),
|
||||||
Units("OtherIcons/Shield", 'U',
|
Units("OtherIcons/Shield", 'U', Align.topLeft,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
||||||
= UnitOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
= UnitOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
||||||
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.getCivUnits().none().toState()),
|
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.getCivUnits().none().toState()),
|
||||||
Diplomacy("OtherIcons/DiplomacyW", 'D',
|
Diplomacy("OtherIcons/DiplomacyW", 'D', Align.top,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
||||||
= DiplomacyOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
= DiplomacyOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
||||||
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.diplomacy.isEmpty().toState()),
|
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.diplomacy.isEmpty().toState()),
|
||||||
Resources("StatIcons/Happiness", 'R',
|
Resources("StatIcons/Happiness", 'R', Align.topLeft,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
||||||
= ResourcesOverviewTab(viewingPlayer, overviewScreen),
|
= ResourcesOverviewTab(viewingPlayer, overviewScreen),
|
||||||
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.detailedCivResources.isEmpty().toState()),
|
fun (viewingPlayer: CivilizationInfo) = viewingPlayer.detailedCivResources.isEmpty().toState()),
|
||||||
Religion("StatIcons/Faith", 'F',
|
Religion("StatIcons/Faith", 'F', Align.top,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
||||||
= ReligionOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
= ReligionOverviewTab(viewingPlayer, overviewScreen, persistedData),
|
||||||
fun (viewingPlayer: CivilizationInfo) = when {
|
fun (viewingPlayer: CivilizationInfo) = when {
|
||||||
@ -53,13 +55,12 @@ enum class EmpireOverviewCategories(
|
|||||||
viewingPlayer.gameInfo.religions.isEmpty() -> EmpireOverviewTabState.Disabled
|
viewingPlayer.gameInfo.religions.isEmpty() -> EmpireOverviewTabState.Disabled
|
||||||
else -> EmpireOverviewTabState.Normal
|
else -> EmpireOverviewTabState.Normal
|
||||||
}),
|
}),
|
||||||
Wonders("OtherIcons/Wonders", 'W',
|
Wonders("OtherIcons/Wonders", 'W', Align.top,
|
||||||
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
fun (viewingPlayer: CivilizationInfo, overviewScreen: EmpireOverviewScreen, _: EmpireOverviewTabPersistableData?)
|
||||||
= WonderOverviewTab(viewingPlayer, overviewScreen),
|
= WonderOverviewTab(viewingPlayer, overviewScreen),
|
||||||
fun (viewingPlayer: CivilizationInfo) = (viewingPlayer.naturalWonders.isEmpty() && viewingPlayer.cities.isEmpty()).toState()),
|
fun (viewingPlayer: CivilizationInfo) = (viewingPlayer.naturalWonders.isEmpty() && viewingPlayer.cities.isEmpty()).toState()),
|
||||||
;
|
;
|
||||||
|
|
||||||
constructor(iconName: String, shortcutChar: Char, factory: FactoryType, stateTester: StateTesterType = { _ -> EmpireOverviewTabState.Normal })
|
constructor(iconName: String, shortcutChar: Char, scrollAlign: Int, factory: FactoryType, stateTester: StateTesterType = { _ -> EmpireOverviewTabState.Normal })
|
||||||
: this(iconName, KeyCharAndCode(shortcutChar), factory, stateTester)
|
: this(iconName, KeyCharAndCode(shortcutChar), scrollAlign, factory, stateTester)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ class EmpireOverviewScreen(
|
|||||||
icon, iconSize,
|
icon, iconSize,
|
||||||
disabled = tabState != EmpireOverviewTabState.Normal,
|
disabled = tabState != EmpireOverviewTabState.Normal,
|
||||||
shortcutKey = category.shortcutKey,
|
shortcutKey = category.shortcutKey,
|
||||||
|
scrollAlign = category.scrollAlign,
|
||||||
fixedContent = pageObject.getFixedContent(),
|
fixedContent = pageObject.getFixedContent(),
|
||||||
onDeactivation = { _, _, scrollY -> pageObject.deactivated(scrollY) }
|
onDeactivation = { _, _, scrollY -> pageObject.deactivated(scrollY) }
|
||||||
) {
|
) {
|
||||||
@ -96,4 +97,8 @@ class EmpireOverviewScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resizePage(tab: EmpireOverviewTab) {
|
||||||
|
val category = (pageObjects.entries.find { it.value == tab } ?: return).key
|
||||||
|
tabbedPager.replacePage(category.name, tab, tab.getFixedContent())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,18 +38,18 @@ class UnitOverviewTab(
|
|||||||
private val supplyTableWidth = (overviewScreen.stage.width * 0.25f).coerceAtLeast(240f)
|
private val supplyTableWidth = (overviewScreen.stage.width * 0.25f).coerceAtLeast(240f)
|
||||||
private val unitListTable = Table() // could be `this` instead, extra nesting helps readability a little
|
private val unitListTable = Table() // could be `this` instead, extra nesting helps readability a little
|
||||||
private val unitHeaderTable = Table()
|
private val unitHeaderTable = Table()
|
||||||
|
private val fixedContent = Table()
|
||||||
|
|
||||||
override fun getFixedContent(): WidgetGroup {
|
override fun getFixedContent(): WidgetGroup {
|
||||||
return Table().apply {
|
return fixedContent
|
||||||
add(getUnitSupplyTable()).align(Align.top).padBottom(10f).row()
|
|
||||||
add(unitHeaderTable.updateUnitHeaderTable())
|
|
||||||
|
|
||||||
equalizeColumns(unitListTable, unitHeaderTable)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
fixedContent.add(getUnitSupplyTable()).align(Align.top).padBottom(10f).row()
|
||||||
|
fixedContent.add(unitHeaderTable.updateUnitHeaderTable())
|
||||||
|
top()
|
||||||
add(unitListTable.updateUnitListTable())
|
add(unitListTable.updateUnitListTable())
|
||||||
|
equalizeColumns(unitListTable, unitHeaderTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here overloads are simpler than a generic:
|
// Here overloads are simpler than a generic:
|
||||||
@ -89,7 +89,10 @@ class UnitOverviewTab(
|
|||||||
icon = icon,
|
icon = icon,
|
||||||
startsOutOpened = deficit > 0,
|
startsOutOpened = deficit > 0,
|
||||||
defaultPad = 0f,
|
defaultPad = 0f,
|
||||||
expanderWidth = supplyTableWidth
|
expanderWidth = supplyTableWidth,
|
||||||
|
onChange = {
|
||||||
|
overviewScreen.resizePage(this)
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
it.defaults().pad(5f).fill(false)
|
it.defaults().pad(5f).fill(false)
|
||||||
it.background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.6f))
|
it.background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.6f))
|
||||||
|
@ -2,6 +2,7 @@ package com.unciv.ui.overviewscreen
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
@ -79,8 +80,30 @@ class WonderOverviewTab(
|
|||||||
|
|
||||||
private val wonders: Array<WonderInfo> = collectInfo()
|
private val wonders: Array<WonderInfo> = collectInfo()
|
||||||
|
|
||||||
|
private val fixedContent = Table()
|
||||||
|
override fun getFixedContent(): WidgetGroup {
|
||||||
|
return fixedContent
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
fixedContent.apply {
|
||||||
|
defaults().pad(10f).align(Align.center)
|
||||||
|
add()
|
||||||
|
add("Name".toLabel())
|
||||||
|
add("Status".toLabel())
|
||||||
|
add("Location".toLabel())
|
||||||
|
add().minWidth(30f)
|
||||||
|
row()
|
||||||
|
}
|
||||||
|
|
||||||
|
defaults().pad(10f).align(Align.center)
|
||||||
|
(1..5).forEach { _ -> add() } // dummies so equalizeColumns can work because the first grid cell is colspan(5)
|
||||||
|
row()
|
||||||
|
top()
|
||||||
|
|
||||||
createGrid()
|
createGrid()
|
||||||
|
|
||||||
|
equalizeColumns(fixedContent, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shouldBeDisplayed(wonder: Building, wonderEra: Int) = when {
|
private fun shouldBeDisplayed(wonder: Building, wonderEra: Int) = when {
|
||||||
@ -114,8 +137,7 @@ class WonderOverviewTab(
|
|||||||
val wonderEraMap: Map<String, Era> =
|
val wonderEraMap: Map<String, Era> =
|
||||||
ruleSet.buildings.values.asSequence()
|
ruleSet.buildings.values.asSequence()
|
||||||
.filter { it.isWonder }
|
.filter { it.isWonder }
|
||||||
.map { it.name to (ruleSet.eras[ruleSet.technologies[it.requiredTech]?.era()] ?: viewingPlayer.getEra()) }
|
.associate { it.name to (ruleSet.eras[ruleSet.technologies[it.requiredTech]?.era()] ?: viewingPlayer.getEra()) }
|
||||||
.toMap()
|
|
||||||
|
|
||||||
// Maps all World Wonders by their position in sort order to their name
|
// Maps all World Wonders by their position in sort order to their name
|
||||||
val allWonderMap: Map<Int, String> =
|
val allWonderMap: Map<Int, String> =
|
||||||
@ -123,8 +145,7 @@ class WonderOverviewTab(
|
|||||||
.filter { it.isWonder }
|
.filter { it.isWonder }
|
||||||
.sortedWith(compareBy<Building> { wonderEraMap[it.name]!!.eraNumber }.thenBy(collator, { it.name.tr() }))
|
.sortedWith(compareBy<Building> { wonderEraMap[it.name]!!.eraNumber }.thenBy(collator, { it.name.tr() }))
|
||||||
.withIndex()
|
.withIndex()
|
||||||
.map { it.index to it.value.name }
|
.associate { it.index to it.value.name }
|
||||||
.toMap()
|
|
||||||
val wonderCount = allWonderMap.size
|
val wonderCount = allWonderMap.size
|
||||||
|
|
||||||
// Inverse of the above
|
// Inverse of the above
|
||||||
@ -134,16 +155,14 @@ class WonderOverviewTab(
|
|||||||
val allNaturalsMap: Map<String, TileInfo> =
|
val allNaturalsMap: Map<String, TileInfo> =
|
||||||
gameInfo.tileMap.values.asSequence()
|
gameInfo.tileMap.values.asSequence()
|
||||||
.filter { it.isNaturalWonder() }
|
.filter { it.isNaturalWonder() }
|
||||||
.map { it.naturalWonder!! to it }
|
.associateBy { it.naturalWonder!! }
|
||||||
.toMap()
|
|
||||||
val naturalsCount = allNaturalsMap.size
|
val naturalsCount = allNaturalsMap.size
|
||||||
|
|
||||||
// Natural Wonders sort order index to name
|
// Natural Wonders sort order index to name
|
||||||
val naturalsIndexMap: Map<Int, String> = allNaturalsMap.keys
|
val naturalsIndexMap: Map<Int, String> = allNaturalsMap.keys
|
||||||
.sortedWith(compareBy(collator, { it.tr() }))
|
.sortedWith(compareBy(collator) { it.tr() })
|
||||||
.withIndex()
|
.withIndex()
|
||||||
.map { it.index to it.value }
|
.associate { it.index to it.value }
|
||||||
.toMap()
|
|
||||||
|
|
||||||
// Pre-populate result with "Unknown" entries
|
// Pre-populate result with "Unknown" entries
|
||||||
val wonders = Array(wonderCount + naturalsCount) { index ->
|
val wonders = Array(wonderCount + naturalsCount) { index ->
|
||||||
@ -197,14 +216,6 @@ class WonderOverviewTab(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createGrid() {
|
fun createGrid() {
|
||||||
defaults().pad(10f).align(Align.center)
|
|
||||||
add()
|
|
||||||
add("Name".toLabel())
|
|
||||||
add("Status".toLabel())
|
|
||||||
add("Location".toLabel())
|
|
||||||
add().minWidth(30f)
|
|
||||||
row()
|
|
||||||
//addSeparator()
|
|
||||||
var lastGroup = ""
|
var lastGroup = ""
|
||||||
|
|
||||||
for (wonder in wonders) {
|
for (wonder in wonders) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user