From 2ba8ef12b86541193ef4fbe34ca2814a783bd2a9 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Tue, 17 Jun 2025 15:36:48 +0300 Subject: [PATCH] Generic'd promises table --- .../logic/civilization/diplomacy/Demand.kt | 18 ++++++-- .../diplomacyscreen/MajorCivDiplomacyTable.kt | 44 ++++++------------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/diplomacy/Demand.kt b/core/src/com/unciv/logic/civilization/diplomacy/Demand.kt index 72b78fd096..be9d7a10f4 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/Demand.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/Demand.kt @@ -13,8 +13,14 @@ enum class Demand( val demandAlert: AlertType, val violationDiscoveredAlert: AlertType, val demandText: String, + /** Must contain 1 parameter, to be replaced with civ name */ val agreedToDemandText: String, - val refusedDemandText: String) { + /** Must contain 1 parameter, to be replaced with civ name */ + val refusedDemandText: String, + /** Must contain 1 parameter, to be replaced with turns left */ + val wePromisedText: String, + /** Must contain 1 parameter, to be replaced with turns left */ + val theyPromisedText: String) { DontSpyOnUs( agreedToDemand = DiplomacyFlags.AgreedToNotSendSpies, violationOccurred = DiplomacyFlags.DiscoveredSpiesInOurCities, @@ -26,7 +32,9 @@ enum class Demand( violationDiscoveredAlert = AlertType.SpyingOnUsDespiteOurPromise, demandText = "Stop spying on us.", agreedToDemandText = "[civName] agreed to stop spying on us!", - refusedDemandText = "[civName] refused to stop spying on us!" + refusedDemandText = "[civName] refused to stop spying on us!", + wePromisedText = "We promised not to send spies to them ([turns] turns remaining)", + theyPromisedText = "They promised not to send spies to us ([turns] turns remaining)" ), DoNotSpreadReligion( agreedToDemand = DiplomacyFlags.AgreedToNotSpreadReligion, @@ -40,6 +48,8 @@ enum class Demand( demandText = "Please don't spread your religion to us.", agreedToDemandText = "[civName] agreed to stop spreading religion to us!", refusedDemandText = "[civName] refused to stop spreading religion to us!", + wePromisedText = "We promised not to spread religion to them ([turns] turns remaining)", + theyPromisedText = "They promised not to spread religion to us ([turns] turns remaining)", ), DoNotSettleNearUs( agreedToDemand = DiplomacyFlags.AgreedToNotSettleNearUs, @@ -52,7 +62,9 @@ enum class Demand( violationDiscoveredAlert = AlertType.CitySettledNearOtherCivDespiteOurPromise, demandText = "Please don't settle new cities near us.", agreedToDemandText = "[civName] agreed to stop settling cities near us!", - refusedDemandText = "[civName] refused to stop settling cities near us!" + refusedDemandText = "[civName] refused to stop settling cities near us!", + wePromisedText = "We promised not to settle near them ([turns] turns remaining)", + theyPromisedText = "They promised not to settle near us ([turns] turns remaining)" ) ; } diff --git a/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt b/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt index e54457359f..2098189a82 100644 --- a/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt +++ b/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt @@ -12,6 +12,7 @@ import com.unciv.logic.civilization.diplomacy.* import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.unique.UniqueType +import com.unciv.models.translations.fillPlaceholders import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.addSeparator import com.unciv.ui.components.extensions.disable @@ -181,38 +182,19 @@ class MajorCivDiplomacyTable(private val diplomacyScreen: DiplomacyScreen) { ): Table? { val promisesTable = Table() - if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs)) { - val text = - "We promised not to settle near them ([${otherCivDiplomacyManager.getFlag(DiplomacyFlags.AgreedToNotSettleNearUs)}] turns remaining)" - promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() + for (demand in Demand.entries){ + if (otherCivDiplomacyManager.hasFlag(demand.agreedToDemand)) { + val turnsLeft = otherCivDiplomacyManager.getFlag(demand.agreedToDemand) + val text = demand.wePromisedText.fillPlaceholders(turnsLeft.toString()) + promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() + } + if (diplomacyManager.hasFlag(demand.agreedToDemand)) { + val turnsLeft = diplomacyManager.getFlag(demand.agreedToDemand) + val text = demand.theyPromisedText.fillPlaceholders(turnsLeft.toString()) + promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() + } } - if (diplomacyManager.hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs)) { - val text = - "They promised not to settle near us ([${diplomacyManager.getFlag(DiplomacyFlags.AgreedToNotSettleNearUs)}] turns remaining)" - promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() - } - - if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.AgreedToNotSpreadReligion)) { - val text = - "We promised not to spread religion to them ([${otherCivDiplomacyManager.getFlag(DiplomacyFlags.AgreedToNotSpreadReligion)}] turns remaining)" - promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() - } - if (diplomacyManager.hasFlag(DiplomacyFlags.AgreedToNotSpreadReligion)) { - val text = - "They promised not to spread religion to us ([${diplomacyManager.getFlag(DiplomacyFlags.AgreedToNotSpreadReligion)}] turns remaining)" - promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() - } - if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.AgreedToNotSendSpies)) { - val text = - "We promised not to send spies to them ([${otherCivDiplomacyManager.getFlag(DiplomacyFlags.AgreedToNotSendSpies)}] turns remaining)" - promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() - } - if (diplomacyManager.hasFlag(DiplomacyFlags.AgreedToNotSendSpies)) { - val text = - "They promised not to send spies to us ([${diplomacyManager.getFlag(DiplomacyFlags.AgreedToNotSendSpies)}] turns remaining)" - promisesTable.add(text.toLabel(Color.LIGHT_GRAY)).row() - } - + return if (promisesTable.cells.isEmpty) null else promisesTable }