mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -04:00
Mini-UI to see Religion info on foreign cities (#5321)
This commit is contained in:
parent
3a858a7051
commit
e1b2814b5d
77
core/src/com/unciv/ui/cityscreen/CityReligionInfoTable.kt
Normal file
77
core/src/com/unciv/ui/cityscreen/CityReligionInfoTable.kt
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package com.unciv.ui.cityscreen
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
|
import com.unciv.logic.city.CityInfoReligionManager
|
||||||
|
import com.unciv.models.Religion
|
||||||
|
import com.unciv.ui.utils.*
|
||||||
|
|
||||||
|
class CityReligionInfoTable(
|
||||||
|
private val religionManager: CityInfoReligionManager,
|
||||||
|
showMajority: Boolean = false
|
||||||
|
) : Table(CameraStageBaseScreen.skin) {
|
||||||
|
private val gameInfo = religionManager.cityInfo.civInfo.gameInfo
|
||||||
|
|
||||||
|
init {
|
||||||
|
val gridColor = Color.DARK_GRAY
|
||||||
|
val followers = religionManager.getNumberOfFollowers()
|
||||||
|
val futurePressures = religionManager.getPressuresFromSurroundingCities()
|
||||||
|
|
||||||
|
if (showMajority) {
|
||||||
|
val (icon, label) = getIconAndLabel(religionManager.getMajorityReligion())
|
||||||
|
add(ImageGetter.getCircledReligionIcon(icon, 30f)).pad(5f)
|
||||||
|
add() // skip vertical separator
|
||||||
|
add("Majority Religion: [$label]".toLabel()).colspan(3).center().row()
|
||||||
|
}
|
||||||
|
|
||||||
|
val (icon, label) = getIconAndLabel(religionManager.religionThisIsTheHolyCityOf)
|
||||||
|
if (label != "None") {
|
||||||
|
add(ImageGetter.getCircledReligionIcon(icon, 30f)).pad(5f)
|
||||||
|
add()
|
||||||
|
add("Holy city of: [$label]".toLabel()).colspan(3).center().row()
|
||||||
|
}
|
||||||
|
|
||||||
|
add().pad(5f) // column for icon
|
||||||
|
addSeparatorVertical(gridColor)
|
||||||
|
add("Followers".toLabel()).pad(5f)
|
||||||
|
addSeparatorVertical(gridColor)
|
||||||
|
add("Pressure".toLabel()).pad(5f).row()
|
||||||
|
addSeparator(gridColor)
|
||||||
|
|
||||||
|
for ((religion, followerCount) in followers) {
|
||||||
|
val iconName = gameInfo.religions[religion]!!.getIconName()
|
||||||
|
add(ImageGetter.getCircledReligionIcon(iconName, 30f)).pad(5f)
|
||||||
|
addSeparatorVertical(gridColor)
|
||||||
|
add(followerCount.toLabel()).pad(5f)
|
||||||
|
addSeparatorVertical(gridColor)
|
||||||
|
if (futurePressures.containsKey(religion))
|
||||||
|
add(("+ [${futurePressures[religion]!!}] pressure").toLabel()).pad(5f)
|
||||||
|
else
|
||||||
|
add()
|
||||||
|
row()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getIconAndLabel(religionName: String?) =
|
||||||
|
getIconAndLabel(gameInfo.religions[religionName])
|
||||||
|
private fun getIconAndLabel(religion: Religion?): Pair<String, String> {
|
||||||
|
return if (religion == null) "Religion" to "None"
|
||||||
|
else religion.getIconName() to religion.getReligionDisplayName()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun asExpander(onChange: (()->Unit)?): ExpanderTab {
|
||||||
|
val (icon, label) = getIconAndLabel(religionManager.getMajorityReligion())
|
||||||
|
return ExpanderTab(
|
||||||
|
title = "Majority Religion: [$label]",
|
||||||
|
fontSize = 18,
|
||||||
|
icon = ImageGetter.getCircledReligionIcon(icon, 30f),
|
||||||
|
defaultPad = 0f,
|
||||||
|
persistenceID = "CityStatsTable.Religion",
|
||||||
|
startsOutOpened = false,
|
||||||
|
onChange = onChange
|
||||||
|
) {
|
||||||
|
defaults().center().pad(5f)
|
||||||
|
it.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -83,67 +83,12 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addReligionInfo() {
|
private fun addReligionInfo() {
|
||||||
val label = cityInfo.religion.getMajorityReligion()?.getReligionDisplayName()
|
val expanderTab = CityReligionInfoTable(cityInfo.religion).asExpander {
|
||||||
?: "None"
|
pack()
|
||||||
val icon =
|
// We have to re-anchor as our position in the city screen, otherwise it expands upwards.
|
||||||
if (label == "None") "Religion"
|
// ToDo: This probably should be refactored so its placed somewhere else in due time
|
||||||
else cityInfo.religion.getMajorityReligion()!!.getIconName()
|
setPosition(stage.width - CityScreen.posFromEdge, stage.height - CityScreen.posFromEdge, Align.topRight)
|
||||||
val expanderTab =
|
}
|
||||||
ExpanderTab(
|
|
||||||
title = "Majority Religion: [$label]",
|
|
||||||
fontSize = 18,
|
|
||||||
icon = ImageGetter.getCircledReligionIcon(icon, 30f),
|
|
||||||
defaultPad = 0f,
|
|
||||||
persistenceID = "CityStatsTable.Religion",
|
|
||||||
startsOutOpened = false,
|
|
||||||
onChange = {
|
|
||||||
pack()
|
|
||||||
// We have to re-anchor as our position in the city screen, otherwise it expands upwards.
|
|
||||||
// ToDo: This probably should be refactored so its placed somewhere else in due time
|
|
||||||
setPosition(stage.width - CityScreen.posFromEdge, stage.height - CityScreen.posFromEdge, Align.topRight)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
if (cityInfo.religion.religionThisIsTheHolyCityOf != null) {
|
|
||||||
// I want this to be centered, but `.center()` doesn't seem to do anything,
|
|
||||||
// regardless of where I place it :(
|
|
||||||
it.add(
|
|
||||||
"Holy city of: [${cityInfo.civInfo.gameInfo.religions[cityInfo.religion.religionThisIsTheHolyCityOf!!]!!.getReligionDisplayName()}]".toLabel()
|
|
||||||
).center().colspan(2).pad(5f).row()
|
|
||||||
}
|
|
||||||
it.add(getReligionsTable()).colspan(2).pad(5f)
|
|
||||||
}
|
|
||||||
|
|
||||||
innerTable.add(expanderTab).growX().row()
|
innerTable.add(expanderTab).growX().row()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private fun getReligionsTable(): Table {
|
|
||||||
val gridColor = Color.DARK_GRAY
|
|
||||||
val religionsTable = Table(CameraStageBaseScreen.skin)
|
|
||||||
val followers = cityInfo.religion.getNumberOfFollowers()
|
|
||||||
val futurePressures = cityInfo.religion.getPressuresFromSurroundingCities()
|
|
||||||
|
|
||||||
religionsTable.add().pad(5f)
|
|
||||||
religionsTable.addSeparatorVertical(gridColor)
|
|
||||||
religionsTable.add("Followers".toLabel()).pad(5f)
|
|
||||||
religionsTable.addSeparatorVertical(gridColor)
|
|
||||||
religionsTable.add("Pressure".toLabel()).pad(5f)
|
|
||||||
religionsTable.row()
|
|
||||||
religionsTable.addSeparator(gridColor)
|
|
||||||
|
|
||||||
for ((religion, followerCount) in followers) {
|
|
||||||
religionsTable.add(
|
|
||||||
ImageGetter.getCircledReligionIcon(cityInfo.civInfo.gameInfo.religions[religion]!!.getIconName(), 30f)
|
|
||||||
).pad(5f)
|
|
||||||
religionsTable.addSeparatorVertical(gridColor)
|
|
||||||
religionsTable.add(followerCount.toLabel()).pad(5f)
|
|
||||||
religionsTable.addSeparatorVertical(gridColor)
|
|
||||||
if (futurePressures.containsKey(religion))
|
|
||||||
religionsTable.add(("+ [${futurePressures[religion]!!}] pressure").toLabel()).pad(5f)
|
|
||||||
else
|
|
||||||
religionsTable.add()
|
|
||||||
religionsTable.row()
|
|
||||||
}
|
|
||||||
|
|
||||||
return religionsTable
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -15,8 +15,8 @@ import com.unciv.logic.city.CityConstructions
|
|||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.city.INonPerpetualConstruction
|
import com.unciv.logic.city.INonPerpetualConstruction
|
||||||
import com.unciv.logic.city.PerpetualConstruction
|
import com.unciv.logic.city.PerpetualConstruction
|
||||||
import com.unciv.logic.civilization.CityStateType
|
|
||||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||||
|
import com.unciv.ui.cityscreen.CityReligionInfoTable
|
||||||
import com.unciv.ui.cityscreen.CityScreen
|
import com.unciv.ui.cityscreen.CityScreen
|
||||||
import com.unciv.ui.trade.DiplomacyScreen
|
import com.unciv.ui.trade.DiplomacyScreen
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
@ -129,13 +129,13 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
|
|
||||||
private fun addAirUnitTable() {
|
private fun addAirUnitTable() {
|
||||||
if (!showAdditionalInfoTags || tileGroup.tileInfo.airUnits.isEmpty()) return
|
if (!showAdditionalInfoTags || tileGroup.tileInfo.airUnits.isEmpty()) return
|
||||||
val secondarycolor = city.civInfo.nation.getInnerColor()
|
val secondaryColor = city.civInfo.nation.getInnerColor()
|
||||||
val airUnitTable = Table()
|
val airUnitTable = Table()
|
||||||
airUnitTable.background = ImageGetter.getRoundedEdgeRectangle(city.civInfo.nation.getOuterColor()).apply { setMinSize(0f,0f) }
|
airUnitTable.background = ImageGetter.getRoundedEdgeRectangle(city.civInfo.nation.getOuterColor()).apply { setMinSize(0f,0f) }
|
||||||
val aircraftImage = ImageGetter.getImage("OtherIcons/Aircraft")
|
val aircraftImage = ImageGetter.getImage("OtherIcons/Aircraft")
|
||||||
aircraftImage.color = secondarycolor
|
aircraftImage.color = secondaryColor
|
||||||
airUnitTable.add(aircraftImage).size(15f)
|
airUnitTable.add(aircraftImage).size(15f)
|
||||||
airUnitTable.add(tileGroup.tileInfo.airUnits.size.toString().toLabel(secondarycolor,14))
|
airUnitTable.add(tileGroup.tileInfo.airUnits.size.toString().toLabel(secondaryColor,14))
|
||||||
add(airUnitTable).row()
|
add(airUnitTable).row()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,10 +158,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
if (uncivGame.viewEntireMapForDebug || belongsToViewingCiv() || viewingCiv.isSpectator()) {
|
if (uncivGame.viewEntireMapForDebug || belongsToViewingCiv() || viewingCiv.isSpectator()) {
|
||||||
uncivGame.setScreen(CityScreen(city))
|
uncivGame.setScreen(CityScreen(city))
|
||||||
} else if (viewingCiv.knows(city.civInfo)) {
|
} else if (viewingCiv.knows(city.civInfo)) {
|
||||||
// If city doesn't belong to you, go directly to its owner's diplomacy screen.
|
foreignCityInfoPopup()
|
||||||
val screen = DiplomacyScreen(viewingCiv)
|
|
||||||
screen.updateRightSide(city.civInfo)
|
|
||||||
uncivGame.setScreen(screen)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
moveButtonDown()
|
moveButtonDown()
|
||||||
@ -180,13 +177,13 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getIconTable(): Table {
|
private fun getIconTable(forPopup: Boolean = false): Table {
|
||||||
val secondaryColor = city.civInfo.nation.getInnerColor()
|
val secondaryColor = city.civInfo.nation.getInnerColor()
|
||||||
class IconTable:Table(){
|
class IconTable: Table() {
|
||||||
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
||||||
}
|
}
|
||||||
val iconTable = IconTable()
|
val iconTable = IconTable()
|
||||||
iconTable.touchable=Touchable.enabled
|
iconTable.touchable = Touchable.enabled
|
||||||
iconTable.background = ImageGetter.getRoundedEdgeRectangle(city.civInfo.nation.getOuterColor())
|
iconTable.background = ImageGetter.getRoundedEdgeRectangle(city.civInfo.nation.getOuterColor())
|
||||||
|
|
||||||
if (city.isInResistance()) {
|
if (city.isInResistance()) {
|
||||||
@ -204,6 +201,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
val fireImage = ImageGetter.getImage("OtherIcons/Fire")
|
val fireImage = ImageGetter.getImage("OtherIcons/Fire")
|
||||||
iconTable.add(fireImage).size(20f).padLeft(5f)
|
iconTable.add(fireImage).size(20f).padLeft(5f)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (city.isCapital()) {
|
if (city.isCapital()) {
|
||||||
if (city.civInfo.isCityState()) {
|
if (city.civInfo.isCityState()) {
|
||||||
val cityStateImage = ImageGetter.getNationIcon("CityState")
|
val cityStateImage = ImageGetter.getNationIcon("CityState")
|
||||||
@ -233,11 +231,14 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
label.toBack() // this is so the label is rendered right before the population group,
|
label.toBack() // this is so the label is rendered right before the population group,
|
||||||
// so we save the font texture and avoid another texture switch
|
// so we save the font texture and avoid another texture switch
|
||||||
|
|
||||||
// City strength is added NOT inside the table, but rather - top-center to it
|
|
||||||
val cityStrength = CityCombatant(city).getCityStrength()
|
val cityStrength = CityCombatant(city).getCityStrength()
|
||||||
val cityStrengthLabel = "${Fonts.strength}$cityStrength".toLabel(city.civInfo.nation.getInnerColor(), 10)
|
val cityStrengthLabel =
|
||||||
iconTable.addActor(cityStrengthLabel) // We create this here to we can .toBack() it as well.
|
"${Fonts.strength}$cityStrength".toLabel(city.civInfo.nation.getInnerColor(), 10)
|
||||||
cityStrengthLabel.toBack()
|
if (!forPopup) {
|
||||||
|
// City strength is added NOT inside the table, but rather - top-center to it
|
||||||
|
iconTable.addActor(cityStrengthLabel) // We create this here to we can .toBack() it as well.
|
||||||
|
cityStrengthLabel.toBack()
|
||||||
|
}
|
||||||
|
|
||||||
if (city.civInfo.isCityState()) {
|
if (city.civInfo.isCityState()) {
|
||||||
val cityStateImage = ImageGetter.getImage(city.civInfo.cityStateType.icon).apply { color = secondaryColor }
|
val cityStateImage = ImageGetter.getImage(city.civInfo.cityStateType.icon).apply { color = secondaryColor }
|
||||||
@ -253,22 +254,25 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
// and the two labels in the the population group are rendered *first* (toBack()),
|
// and the two labels in the the population group are rendered *first* (toBack()),
|
||||||
// What we get is that ALL 4 LABELS are rendered one after the other,
|
// What we get is that ALL 4 LABELS are rendered one after the other,
|
||||||
// and so the glyph texture only needs to be swapped in once rather than 4 times! :)
|
// and so the glyph texture only needs to be swapped in once rather than 4 times! :)
|
||||||
}
|
} else if (city.civInfo.isMajorCiv()) {
|
||||||
else if (city.civInfo.isMajorCiv()) {
|
|
||||||
val nationIcon = ImageGetter.getNationIcon(city.civInfo.nation.name)
|
val nationIcon = ImageGetter.getNationIcon(city.civInfo.nation.name)
|
||||||
nationIcon.color = secondaryColor
|
nationIcon.color = secondaryColor
|
||||||
iconTable.add(nationIcon).size(20f)
|
iconTable.add(nationIcon).size(20f)
|
||||||
}
|
}
|
||||||
|
|
||||||
val cityReligion = city.religion.getMajorityReligion()
|
if (!forPopup) {
|
||||||
if (cityReligion != null) {
|
val cityReligion = city.religion.getMajorityReligion()
|
||||||
val religionImage = ImageGetter.getReligionImage(cityReligion.getIconName())
|
if (cityReligion != null) {
|
||||||
iconTable.add(religionImage).size(20f).padLeft(5f).fillY()
|
val religionImage = ImageGetter.getReligionImage(cityReligion.getIconName())
|
||||||
|
iconTable.add(religionImage).size(20f).padLeft(5f).fillY()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iconTable.pack()
|
iconTable.pack()
|
||||||
cityStrengthLabel.x = label.x // so it'll be aligned right above the city name
|
if (!forPopup) {
|
||||||
cityStrengthLabel.setY(iconTable.height, Align.top)
|
cityStrengthLabel.x = label.x // so it'll be aligned right above the city name
|
||||||
|
cityStrengthLabel.setY(iconTable.height, Align.top)
|
||||||
|
}
|
||||||
return iconTable
|
return iconTable
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +284,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
updateHiddenUnitMarkers()
|
updateHiddenUnitMarkers()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
parent.addAction(moveButtonAction) // Move the whole cityButtonLayerGroup down, so the citybutton remains clickable
|
parent.addAction(moveButtonAction) // Move the whole cityButtonLayerGroup down, so the CityButton remains clickable
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moveButtonUp() {
|
private fun moveButtonUp() {
|
||||||
@ -329,17 +333,16 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
|
|
||||||
group.addActor(growthBar)
|
group.addActor(growthBar)
|
||||||
|
|
||||||
val turnLabel : Label
|
val turnLabel: Label = when {
|
||||||
when {
|
|
||||||
city.isGrowing() -> {
|
city.isGrowing() -> {
|
||||||
val turnsToGrowth = city.getNumTurnsToNewPopulation()
|
val turnsToGrowth = city.getNumTurnsToNewPopulation()
|
||||||
turnLabel = if (turnsToGrowth != null && turnsToGrowth < 100) turnsToGrowth.toString().toLabel() else "∞".toLabel()
|
if (turnsToGrowth != null && turnsToGrowth < 100) turnsToGrowth.toString().toLabel() else "∞".toLabel()
|
||||||
}
|
}
|
||||||
city.isStarving() -> {
|
city.isStarving() -> {
|
||||||
val turnsToStarvation = city.getNumTurnsToStarvation()
|
val turnsToStarvation = city.getNumTurnsToStarvation()
|
||||||
turnLabel = if (turnsToStarvation != null && turnsToStarvation < 100) turnsToStarvation.toString().toLabel() else "∞".toLabel()
|
if (turnsToStarvation != null && turnsToStarvation < 100) turnsToStarvation.toString().toLabel() else "∞".toLabel()
|
||||||
}
|
}
|
||||||
else -> turnLabel = "∞".toLabel()
|
else -> "∞".toLabel()
|
||||||
}
|
}
|
||||||
turnLabel.color = city.civInfo.nation.getInnerColor()
|
turnLabel.color = city.civInfo.nation.getInnerColor()
|
||||||
turnLabel.setFontSize(14)
|
turnLabel.setFontSize(14)
|
||||||
@ -409,6 +412,28 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun foreignCityInfoPopup() {
|
||||||
|
fun openDiplomacy() {
|
||||||
|
// If city doesn't belong to you, go directly to its owner's diplomacy screen.
|
||||||
|
val screen = DiplomacyScreen(worldScreen.viewingCiv)
|
||||||
|
screen.updateRightSide(city.civInfo)
|
||||||
|
worldScreen.game.setScreen(screen)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's nothing to display cuz no Religion - skip popup
|
||||||
|
if (!city.civInfo.gameInfo.isReligionEnabled()) return openDiplomacy()
|
||||||
|
|
||||||
|
val popup = Popup(worldScreen).apply {
|
||||||
|
name = "ForeignCityInfoPopup"
|
||||||
|
add(getIconTable(true)).fillX().padBottom(5f).colspan(3).row()
|
||||||
|
add(CityReligionInfoTable(city.religion, true)).colspan(3).row()
|
||||||
|
addOKButton("Diplomacy") { openDiplomacy() }
|
||||||
|
add().expandX()
|
||||||
|
addCloseButton()
|
||||||
|
}
|
||||||
|
popup.open()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getInfluenceBar(influence: Float, relationshipLevel: RelationshipLevel, width: Float = 100f, height: Float = 5f): Table {
|
fun getInfluenceBar(influence: Float, relationshipLevel: RelationshipLevel, width: Float = 100f, height: Float = 5f): Table {
|
||||||
val normalizedInfluence = max(-60f, min(influence, 60f)) / 30f
|
val normalizedInfluence = max(-60f, min(influence, 60f)) / 30f
|
||||||
|
Loading…
x
Reference in New Issue
Block a user