From 62469daff6464f80ea49c854ae51052ed9cd7c1b Mon Sep 17 00:00:00 2001 From: WhoIsJohannes <126110113+WhoIsJohannes@users.noreply.github.com> Date: Wed, 13 Dec 2023 21:45:46 +0100 Subject: [PATCH] =?UTF-8?q?Add=20another=20confirmation=20when=20buying=20?= =?UTF-8?q?a=20religious=20unit=20in=20a=20city=20that=20=E2=80=A6=20(#957?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add another confirmation when buying a religious unit in a city that doesn't follow a religion founded by the city's civ. * There's other stuff that can be purchased with Faith. Better to use UniqueType.Religious unit I guess. * Add string to template.properties * One more space to make unit tests happy * Better template.properties * Reinsert trailing space * Introduce Constants entry for "Cancel" * Redo ConfirmBuyPopup * Dev console command to tweak religion pressures * Translation templates and one test --------- Co-authored-by: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> --- .../jsons/translations/German.properties | 3 +- .../jsons/translations/template.properties | 2 + core/src/com/unciv/Constants.kt | 1 + core/src/com/unciv/logic/files/FileChooser.kt | 2 +- .../com/unciv/ui/components/UncivTextField.kt | 3 +- core/src/com/unciv/ui/popups/ConfirmPopup.kt | 7 +-- .../cityscreen/CityConstructionsTable.kt | 52 ++++++++++++++----- .../screens/devconsole/DevConsoleCommand.kt | 17 +++++- .../overviewscreen/EspionageOverviewScreen.kt | 3 +- 9 files changed, 70 insertions(+), 20 deletions(-) diff --git a/android/assets/jsons/translations/German.properties b/android/assets/jsons/translations/German.properties index 1bfbd239fb..21bbbe393a 100644 --- a/android/assets/jsons/translations/German.properties +++ b/android/assets/jsons/translations/German.properties @@ -1209,6 +1209,8 @@ Buy for [amount] gold = Für [amount] Gold kaufen Buy = Kaufen Currently you have [amount] [stat]. = Zur Zeit besitzt du [amount] [stat]. Would you like to purchase [constructionName] for [buildingGoldCost] [stat]? = [constructionName] für [buildingGoldCost] [stat] kaufen? +You are buying a religious unit in a city that doesn't follow the religion you founded ([yourReligion]). This means that the unit is tied to that foreign religion ([majorityReligion]) and will be less useful. = Du möchtest eine an [majorityReligion] glaubende Einheit kaufen, obwohl Du [yourReligion] gegründet hast? Das wird nicht ganz so nützlich sein! +Are you really sure you want to purchase this unit? = Bist du dir da wirklich ganz sicher? Purchase = Kaufen No space available to place [unit] near [city] = Kein Platz verfügbar, um [unit] nahe [city] zu platzieren Maintenance cost = Wartungskosten @@ -6701,4 +6703,3 @@ In the Resources overview, click on a resource icon to center the world screen o Alternatively, click on the "Unimproved" number to center the world screen only on owned tiles where the resource is not improved. = # Requires translation! If more than one tile is available, click repeatedly on the notification to cycle through all of them. = - diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 4265fb040e..c3d62d317d 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -1194,6 +1194,8 @@ Buy for [amount] gold = Buy = Currently you have [amount] [stat]. = Would you like to purchase [constructionName] for [buildingGoldCost] [stat]? = +You are buying a religious unit in a city that doesn't follow the religion you founded ([yourReligion]). This means that the unit is tied to that foreign religion ([majorityReligion]) and will be less useful. = +Are you really sure you want to purchase this unit? = Purchase = No space available to place [unit] near [city] = Maintenance cost = diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt index 844be93956..ec9cab529a 100644 --- a/core/src/com/unciv/Constants.kt +++ b/core/src/com/unciv/Constants.kt @@ -71,6 +71,7 @@ object Constants { const val OK = "OK" const val close = "Close" + const val cancel = "Cancel" const val yes = "Yes" const val no = "No" const val loading = "Loading..." diff --git a/core/src/com/unciv/logic/files/FileChooser.kt b/core/src/com/unciv/logic/files/FileChooser.kt index a5aaba4a3e..cd44b7ac0a 100644 --- a/core/src/com/unciv/logic/files/FileChooser.kt +++ b/core/src/com/unciv/logic/files/FileChooser.kt @@ -144,7 +144,7 @@ open class FileChooser( fileNameCell = add().colspan(2).growX() row() - addCloseButton("Cancel") { + addCloseButton(Constants.cancel) { reportResult(false) } okButton = addOKButton(Constants.OK) { diff --git a/core/src/com/unciv/ui/components/UncivTextField.kt b/core/src/com/unciv/ui/components/UncivTextField.kt index 4b902288f2..bf0741d296 100644 --- a/core/src/com/unciv/ui/components/UncivTextField.kt +++ b/core/src/com/unciv/ui/components/UncivTextField.kt @@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.InputListener import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.TextField import com.badlogic.gdx.scenes.scene2d.utils.FocusListener +import com.unciv.Constants import com.unciv.logic.event.EventBus import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.getAscendant @@ -173,7 +174,7 @@ class TextfieldPopup( .colspan(2) .row() - addCloseButton("Cancel") + addCloseButton(Constants.cancel) .left() addOKButton { textField.text = popupTextfield.text } .right() diff --git a/core/src/com/unciv/ui/popups/ConfirmPopup.kt b/core/src/com/unciv/ui/popups/ConfirmPopup.kt index a580dfe318..3ab82c9c7c 100644 --- a/core/src/com/unciv/ui/popups/ConfirmPopup.kt +++ b/core/src/com/unciv/ui/popups/ConfirmPopup.kt @@ -3,9 +3,10 @@ package com.unciv.ui.popups import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle import com.badlogic.gdx.utils.Align -import com.unciv.ui.screens.basescreen.BaseScreen -import com.unciv.ui.components.input.KeyboardBinding +import com.unciv.Constants import com.unciv.ui.components.extensions.toLabel +import com.unciv.ui.components.input.KeyboardBinding +import com.unciv.ui.screens.basescreen.BaseScreen /** Variant of [Popup] pre-populated with one label, plus confirm and cancel buttons * @param stageToShowOn Parent [Stage], see [Popup.stageToShowOn] @@ -39,7 +40,7 @@ open class ConfirmPopup( init { promptLabel.setAlignment(Align.center) add(promptLabel).colspan(2).row() - addCloseButton("Cancel", KeyboardBinding.Cancel, action = restoreDefault) + addCloseButton(Constants.cancel, KeyboardBinding.Cancel, action = restoreDefault) val confirmStyleName = if (isConfirmPositive) "positive" else "negative" val confirmStyle = BaseScreen.skin.get(confirmStyleName, TextButtonStyle::class.java) addOKButton(confirmText, KeyboardBinding.Confirm, confirmStyle, action = action) diff --git a/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt b/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt index 16ef7c7643..8819474fcb 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/CityConstructionsTable.kt @@ -12,6 +12,7 @@ import com.unciv.GUI import com.unciv.logic.city.City import com.unciv.logic.city.CityConstructions import com.unciv.logic.map.tile.Tile +import com.unciv.models.Religion import com.unciv.models.UncivSound import com.unciv.models.ruleset.Building import com.unciv.models.ruleset.IConstruction @@ -25,8 +26,6 @@ import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.stats.Stat import com.unciv.models.translations.tr import com.unciv.ui.audio.SoundPlayer -import com.unciv.ui.components.widgets.ColorMarkupLabel -import com.unciv.ui.components.widgets.ExpanderTab import com.unciv.ui.components.UncivTooltip.Companion.addTooltip import com.unciv.ui.components.extensions.addBorder import com.unciv.ui.components.extensions.addCell @@ -45,9 +44,10 @@ import com.unciv.ui.components.input.keyShortcuts import com.unciv.ui.components.input.onActivation import com.unciv.ui.components.input.onClick import com.unciv.ui.components.input.onRightClick +import com.unciv.ui.components.widgets.ColorMarkupLabel +import com.unciv.ui.components.widgets.ExpanderTab import com.unciv.ui.images.ImageGetter import com.unciv.ui.popups.CityScreenConstructionMenu -import com.unciv.ui.popups.ConfirmPopup import com.unciv.ui.popups.Popup import com.unciv.ui.popups.closeAllPopups import com.unciv.ui.screens.basescreen.BaseScreen @@ -667,16 +667,44 @@ class CityConstructionsTable(private val cityScreen: CityScreen) { if (!isConstructionPurchaseAllowed(construction, stat, constructionStatBuyCost)) return cityScreen.closeAllPopups() + ConfirmBuyPopup(construction, stat,constructionStatBuyCost, tile) + } - val purchasePrompt = "Currently you have [${city.getStatReserve(stat)}] [${stat.name}].".tr() + "\n\n" + - "Would you like to purchase [${construction.name}] for [$constructionStatBuyCost] [${stat.character}]?".tr() - ConfirmPopup( - cityScreen, - purchasePrompt, - "Purchase", - true, - restoreDefault = { cityScreen.update() } - ) { purchaseConstruction(construction, stat, tile) }.open() + private inner class ConfirmBuyPopup( + construction: INonPerpetualConstruction, + stat: Stat, + constructionStatBuyCost: Int, + tile: Tile? + ) : Popup(cityScreen.stage) { + init { + val city = cityScreen.city + val balance = city.getStatReserve(stat) + val majorityReligion = city.religion.getMajorityReligion() + val yourReligion = city.civ.religionManager.religion + val isBuyingWithFaithForForeignReligion = construction.hasUnique(UniqueType.ReligiousUnit) && majorityReligion != yourReligion + + addGoodSizedLabel("Currently you have [$balance] [${stat.name}].").padBottom(10f).row() + if (isBuyingWithFaithForForeignReligion) { + // Earlier tests should forbid this Popup unless both religions are non-null, but to be safe: + fun Religion?.getName() = this?.getReligionDisplayName() ?: Constants.unknownCityName + addGoodSizedLabel("You are buying a religious unit in a city that doesn't follow the religion you founded ([${yourReligion.getName()}]). " + + "This means that the unit is tied to that foreign religion ([${majorityReligion.getName()}]) and will be less useful.").row() + addGoodSizedLabel("Are you really sure you want to purchase this unit?", Constants.headingFontSize).run { + actor.color = Color.FIREBRICK + padBottom(10f) + row() + } + } + addGoodSizedLabel("Would you like to purchase [${construction.name}] for [$constructionStatBuyCost] [${stat.character}]?").row() + + addCloseButton(Constants.cancel, KeyboardBinding.Cancel) { cityScreen.update() } + val confirmStyle = BaseScreen.skin.get("positive", TextButton.TextButtonStyle::class.java) + addOKButton("Purchase", KeyboardBinding.Confirm, confirmStyle) { + purchaseConstruction(construction, stat, tile) + } + equalizeLastTwoButtonWidths() + open(true) + } } /** This tests whether the buy button should be _shown_ */ diff --git a/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt b/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt index 5fc2ab1acd..d0a7792280 100644 --- a/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt +++ b/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt @@ -177,7 +177,22 @@ class ConsoleCityCommands : ConsoleCommandNode { val city = selectedTile.getCity() ?: return@ConsoleAction DevConsoleResponse.error("No city for selected tile") city.expansion.relinquishOwnership(selectedTile) return@ConsoleAction DevConsoleResponse.OK - }) + }, + + "religion" to ConsoleAction { console, params -> + if (params.size != 2) + return@ConsoleAction DevConsoleResponse.hint("Format: city religion <±pressure>") + val city = console.screen.bottomUnitTable.selectedCity + ?: return@ConsoleAction DevConsoleResponse.hint("Select a city first") + val religion = city.civ.gameInfo.religions.keys.firstOrNull { it.toCliInput() == params[0] } + ?: return@ConsoleAction DevConsoleResponse.error("'${params[0]}' is not a known religion") + val pressure = params[1].toIntOrNull() + ?: return@ConsoleAction DevConsoleResponse.error("'${params[1]}' is not an integer") + city.religion.addPressure(religion, pressure.coerceAtLeast(-city.religion.getPressures()[religion])) + city.religion.updatePressureOnPopulationChange(0) + return@ConsoleAction DevConsoleResponse.OK + }, + ) } class ConsoleTileCommands: ConsoleCommandNode { diff --git a/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt b/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt index 0ee61e18c6..88d968e312 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.utils.Align +import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.city.City import com.unciv.logic.civilization.Civilization @@ -90,7 +91,7 @@ class EspionageOverviewScreen(val civInfo: Civilization) : PickerScreen(true) { resetSelection() selectedSpyButton = moveSpyButton selectedSpy = spy - selectedSpyButton!!.label.setText("Cancel".tr()) + selectedSpyButton!!.label.setText(Constants.cancel.tr()) for ((button, city) in moveSpyHereButtons) { // For now, only allow spies to be sent to cities of other major civs and their hideout // Not own cities as counterintelligence isn't implemented