Generic'd promises table

This commit is contained in:
yairm210 2025-06-17 15:36:48 +03:00
parent f3ecfae9b6
commit 2ba8ef12b8
2 changed files with 28 additions and 34 deletions

View File

@ -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)"
)
;
}

View File

@ -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,36 +182,17 @@ 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()
}
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()
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()
}
}
return if (promisesTable.cells.isEmpty) null else promisesTable