From 278288442be4b4412c3bd931099a21e1b304ba1e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 28 Dec 2023 21:57:56 +0200 Subject: [PATCH] Religion button respects "hidden from users" modifier on uniques --- .../com/unciv/models/ruleset/unique/Unique.kt | 4 +-- .../unciv/models/ruleset/unique/UniqueType.kt | 2 +- .../screens/devconsole/DevConsoleCommand.kt | 35 ++++++++++--------- .../ReligionPickerScreenCommon.kt | 11 +++--- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unique/Unique.kt b/core/src/com/unciv/models/ruleset/unique/Unique.kt index 04ec93a028..18ff8e3090 100644 --- a/core/src/com/unciv/models/ruleset/unique/Unique.kt +++ b/core/src/com/unciv/models/ruleset/unique/Unique.kt @@ -44,7 +44,7 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s val isLocalEffect = params.contains("in this city") || conditionals.any { it.type == UniqueType.ConditionalInThisCity } fun hasFlag(flag: UniqueFlag) = type != null && type.flags.contains(flag) - fun isHiddenToUsers() = hasFlag(UniqueFlag.HiddenToUsers) || conditionals.any { it.type == UniqueType.ConditionalHideUniqueFromUsers } + fun isHiddenToUsers() = hasFlag(UniqueFlag.HiddenToUsers) || conditionals.any { it.type == UniqueType.ModifierHiddenFromUsers } fun hasTriggerConditional(): Boolean { if (conditionals.none()) return false @@ -218,7 +218,7 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s return when (condition.type) { // These are 'what to do' and not 'when to do' conditionals UniqueType.ConditionalTimedUnique -> true - UniqueType.ConditionalHideUniqueFromUsers -> true // allowed to be attached to any Unique to hide it, no-op otherwise + UniqueType.ModifierHiddenFromUsers -> true // allowed to be attached to any Unique to hide it, no-op otherwise UniqueType.ConditionalChance -> stateBasedRandom.nextFloat() < condition.params[0].toFloat() / 100f UniqueType.ConditionalBeforeTurns -> checkOnCiv { gameInfo.turns < condition.params[0].toInt() } diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index e5a37dff34..265efed67f 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -791,7 +791,7 @@ enum class UniqueType( HiddenAfterGreatProphet("Hidden after generating a Great Prophet", UniqueTarget.Ruins), HiddenWithoutVictoryType("Hidden when [victoryType] Victory is disabled", UniqueTarget.Building, UniqueTarget.Unit, flags = UniqueFlag.setOfHiddenToUsers), HiddenFromCivilopedia("Will not be displayed in Civilopedia", *UniqueTarget.Displayable, flags = UniqueFlag.setOfHiddenToUsers), - ConditionalHideUniqueFromUsers("hidden from users", UniqueTarget.Conditional), + ModifierHiddenFromUsers("hidden from users", UniqueTarget.Conditional), Comment("Comment [comment]", *UniqueTarget.Displayable, docDescription = "Allows displaying arbitrary text in a Unique listing. Only the text within the '[]' brackets will be displayed, the rest serves to allow Ruleset validation to recognize the intent."), diff --git a/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt b/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt index da04627f83..6d0b62e9d1 100644 --- a/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt +++ b/core/src/com/unciv/ui/screens/devconsole/DevConsoleCommand.kt @@ -82,7 +82,7 @@ class ConsoleUnitCommands : ConsoleCommandNode { val selectedTile = console.getSelectedTile() val civ = console.getCivByName(params[0]) val baseUnit = console.gameInfo.ruleset.units.values.firstOrNull { it.name.toCliInput() == params[1] } - ?: return@ConsoleAction DevConsoleResponse.error("Unknown unit") + ?: throw ConsoleErrorException("Unknown unit") civ.units.placeUnitNearTile(selectedTile.position, baseUnit) return@ConsoleAction DevConsoleResponse.OK }, @@ -98,7 +98,7 @@ class ConsoleUnitCommands : ConsoleCommandNode { validateFormat("unit addpromotion ", params) val unit = console.getSelectedUnit() val promotion = console.gameInfo.ruleset.unitPromotions.values.firstOrNull { it.name.toCliInput() == params[0] } - ?: return@ConsoleAction DevConsoleResponse.error("Unknown promotion") + ?: throw ConsoleErrorException("Unknown promotion") unit.promotions.addPromotion(promotion.name, true) return@ConsoleAction DevConsoleResponse.OK }, @@ -107,7 +107,7 @@ class ConsoleUnitCommands : ConsoleCommandNode { validateFormat("unit removepromotion ", params) val unit = console.getSelectedUnit() val promotion = unit.promotions.getPromotions().firstOrNull { it.name.toCliInput() == params[0] } - ?: return@ConsoleAction DevConsoleResponse.error("Promotion not found on unit") + ?: throw ConsoleErrorException("Promotion not found on unit") // No such action in-game so we need to manually update unit.promotions.promotions.remove(promotion.name) unit.updateUniques() @@ -118,7 +118,7 @@ class ConsoleUnitCommands : ConsoleCommandNode { "setmovement" to ConsoleAction { console, params -> validateFormat("unit setmovement ", params) val movement = params[0].toFloatOrNull() - if (movement == null || movement < 0) return@ConsoleAction DevConsoleResponse.error("Invalid number") + if (movement == null || movement < 0) throw ConsoleErrorException("Invalid number") val unit = console.getSelectedUnit() unit.currentMovement = movement return@ConsoleAction DevConsoleResponse.OK @@ -134,7 +134,7 @@ class ConsoleCityCommands : ConsoleCommandNode { val civ = console.getCivByName(params[0]) val selectedTile = console.getSelectedTile() if (selectedTile.isCityCenter()) - return@ConsoleAction DevConsoleResponse.error("Tile already contains a city center") + throw ConsoleErrorException("Tile already contains a city center") civ.addCity(selectedTile.position) return@ConsoleAction DevConsoleResponse.OK }, @@ -150,7 +150,7 @@ class ConsoleCityCommands : ConsoleCommandNode { validateFormat("city setpop ", params) val city = console.getSelectedCity() val newPop = console.getInt(params[0]) - if (newPop < 1) return@ConsoleAction DevConsoleResponse.error("Population must be at least 1") + if (newPop < 1) throw ConsoleErrorException("Population must be at least 1") city.population.setPopulation(newPop) return@ConsoleAction DevConsoleResponse.OK }, @@ -160,7 +160,8 @@ class ConsoleCityCommands : ConsoleCommandNode { val selectedTile = console.getSelectedTile() val city = console.getCity(params[0]) if (selectedTile.neighbors.none { it.getCity() == city }) - return@ConsoleAction DevConsoleResponse.error("Tile is not adjacent to any tile already owned by the city") + throw ConsoleErrorException("Tile is not adjacent to any tile already owned by the city") + if (selectedTile.isCityCenter()) throw ConsoleErrorException("Cannot tranfer city center") city.expansion.takeOwnership(selectedTile) return@ConsoleAction DevConsoleResponse.OK }, @@ -177,7 +178,7 @@ class ConsoleCityCommands : ConsoleCommandNode { validateFormat("city religion <±pressure>", params) val city = console.getSelectedCity() val religion = city.civ.gameInfo.religions.keys.firstOrNull { it.toCliInput() == params[0] } - ?: return@ConsoleAction DevConsoleResponse.error("'${params[0]}' is not a known religion") + ?: throw ConsoleErrorException("'${params[0]}' is not a known religion") val pressure = console.getInt(params[1]) city.religion.addPressure(religion, pressure.coerceAtLeast(-city.religion.getPressures()[religion])) city.religion.updatePressureOnPopulationChange(0) @@ -194,7 +195,7 @@ class ConsoleTileCommands: ConsoleCommandNode { val selectedTile = console.getSelectedTile() val improvement = console.gameInfo.ruleset.tileImprovements.values.firstOrNull { it.name.toCliInput() == params[0] - } ?: return@ConsoleAction DevConsoleResponse.error("Unknown improvement") + } ?: throw ConsoleErrorException("Unknown improvement") var civ: Civilization? = null if (params.size == 2){ civ = console.getCivByName(params[1]) @@ -215,7 +216,7 @@ class ConsoleTileCommands: ConsoleCommandNode { val selectedTile = console.getSelectedTile() val feature = console.gameInfo.ruleset.terrains.values .firstOrNull { it.type == TerrainType.TerrainFeature && it.name.toCliInput() == params[0] } - ?: return@ConsoleAction DevConsoleResponse.error("Unknown feature") + ?: throw ConsoleErrorException("Unknown feature") selectedTile.addTerrainFeature(feature.name) return@ConsoleAction DevConsoleResponse.OK }, @@ -225,7 +226,7 @@ class ConsoleTileCommands: ConsoleCommandNode { val selectedTile = console.getSelectedTile() val feature = console.gameInfo.ruleset.terrains.values .firstOrNull { it.type == TerrainType.TerrainFeature && it.name.toCliInput() == params[0] } - ?: return@ConsoleAction DevConsoleResponse.error("Unknown feature") + ?: throw ConsoleErrorException("Unknown feature") selectedTile.removeTerrainFeature(feature.name) return@ConsoleAction DevConsoleResponse.OK } @@ -234,9 +235,9 @@ class ConsoleTileCommands: ConsoleCommandNode { class ConsoleCivCommands : ConsoleCommandNode { override val subcommands = hashMapOf( - "add" to ConsoleAction { console, params -> + "addstat" to ConsoleAction { console, params -> var statPos = 0 - validateFormat("civ add [civ] ", params) + validateFormat("civ addstat [civ] ", params) val civ = if (params.size == 2) console.screen.selectedCiv else { statPos++ @@ -244,9 +245,9 @@ class ConsoleCivCommands : ConsoleCommandNode { } val amount = console.getInt(params[statPos+1]) val stat = Stat.safeValueOf(params[statPos].replaceFirstChar(Char::titlecase)) - ?: return@ConsoleAction DevConsoleResponse.error("Whut? \"${params[statPos]}\" is not a Stat!") + ?: throw ConsoleErrorException("Whut? \"${params[statPos]}\" is not a Stat!") if (stat !in Stat.statsWithCivWideField) - return@ConsoleAction DevConsoleResponse.error("$stat is not civ-wide") + throw ConsoleErrorException("$stat is not civ-wide") civ.addStat(stat, amount) DevConsoleResponse.OK }, @@ -255,7 +256,7 @@ class ConsoleCivCommands : ConsoleCommandNode { validateFormat("civ setplayertype ", params) val civ = console.getCivByName(params[0]) val playerType = PlayerType.values().firstOrNull { it.name.lowercase() == params[1].lowercase() } - ?: return@ConsoleAction DevConsoleResponse.error("Invalid player type, valid options are 'ai' or 'human'") + ?: throw ConsoleErrorException("Invalid player type, valid options are 'ai' or 'human'") civ.playerType = playerType DevConsoleResponse.OK } @@ -263,7 +264,7 @@ class ConsoleCivCommands : ConsoleCommandNode { override fun autocomplete(params: List): String? { when (params[0]){ - "add" -> if (params.size == 2) + "addstat" -> if (params.size == 2) return Stat.names() .firstOrNull { it.lowercase().startsWith(params[1]) } ?.drop(params[1].length) diff --git a/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt b/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt index 9233cbee48..57c1272dc6 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt @@ -15,14 +15,14 @@ import com.unciv.models.UncivSound import com.unciv.models.ruleset.Belief import com.unciv.models.ruleset.BeliefType import com.unciv.models.translations.tr -import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen -import com.unciv.ui.screens.civilopediascreen.MarkupRenderer -import com.unciv.ui.components.widgets.WrappableLabel import com.unciv.ui.components.extensions.darken import com.unciv.ui.components.extensions.disable import com.unciv.ui.components.extensions.enable -import com.unciv.ui.components.input.onClick import com.unciv.ui.components.extensions.toLabel +import com.unciv.ui.components.input.onClick +import com.unciv.ui.components.widgets.WrappableLabel +import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen +import com.unciv.ui.screens.civilopediascreen.MarkupRenderer abstract class ReligionPickerScreenCommon( protected val choosingCiv: Civilization, @@ -83,7 +83,8 @@ abstract class ReligionPickerScreenCommon( add(belief.type.name.toLabel(fontColor = Color.valueOf(belief.type.color))).row() val nameLabel = WrappableLabel(belief.name, labelWidth, fontSize = Constants.headingFontSize) add(nameLabel.apply { wrap = true }).row() - val effectLabel = WrappableLabel(belief.uniques.joinToString("\n") { it.tr() }, labelWidth) + val effectLabel = WrappableLabel(belief.uniqueObjects.filter { !it.isHiddenToUsers() }.map { it.text } + .joinToString("\n") { it.tr() }, labelWidth) add(effectLabel.apply { wrap = true }) } beliefType == BeliefType.Any ->