mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Civilopedia remove migration-only interface elements (#5150)
This commit is contained in:
parent
9c876ad84e
commit
ffdc289611
@ -17,8 +17,6 @@ class Belief : INamed, ICivilopediaText, IHasUniques {
|
||||
|
||||
override fun makeLink() = "Belief/$name"
|
||||
override fun getCivilopediaTextHeader() = FormattedLine(name, icon = makeLink(), header = 2, color = if (type == BeliefType.None) "#e34a2b" else "")
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun getSortGroup(ruleset: Ruleset) = type.ordinal
|
||||
override fun getIconName() = if (type == BeliefType.None) "Religion" else type.name
|
||||
|
||||
|
@ -16,7 +16,6 @@ import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
import com.unciv.ui.utils.Fonts
|
||||
import com.unciv.ui.utils.toPercent
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
@ -28,7 +27,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
var cost: Int = 0
|
||||
var maintenance = 0
|
||||
private var percentStatBonus: Stats? = null
|
||||
var specialistSlots: Counter<String>? = null
|
||||
private var specialistSlots: Counter<String>? = null
|
||||
fun newSpecialists(): Counter<String> {
|
||||
if (specialistSlots == null) return Counter()
|
||||
// Could have old specialist values of "gold", "science" etc - change them to the new specialist names
|
||||
@ -58,8 +57,6 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
|
||||
/** City can only be built if one of these resources is nearby - it must be improved! */
|
||||
var requiredNearbyImprovedResources: List<String>? = null
|
||||
@Deprecated("As of 3.15.19, replace with 'Cannot be built with []' unique")
|
||||
private var cannotBeBuiltWith: String? = null
|
||||
var cityStrength = 0
|
||||
var cityHealth = 0
|
||||
var replaces: String? = null
|
||||
@ -67,7 +64,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
var quote: String = ""
|
||||
override var uniques = ArrayList<String>()
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it) } }
|
||||
var replacementTextForUniques = ""
|
||||
private var replacementTextForUniques = ""
|
||||
|
||||
override var civilopediaText = listOf<FormattedLine>()
|
||||
|
||||
@ -167,6 +164,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
if (unique.params[2].toInt() <= city.religion.getFollowersOfMajorityReligion() && matchesFilter(unique.params[1]))
|
||||
stats.add(unique.stats)
|
||||
|
||||
@Suppress("RemoveRedundantQualifierName") // make it clearer Building inherits Stats
|
||||
for (unique in uniqueObjects)
|
||||
if (unique.placeholderText == "[] with []" && civInfo.hasResource(unique.params[1])
|
||||
&& Stats.isStats(unique.params[0]))
|
||||
@ -198,10 +196,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
return stats
|
||||
}
|
||||
|
||||
override fun getCivilopediaTextHeader() = FormattedLine(name, header=2, icon=makeLink())
|
||||
override fun makeLink() = if (isAnyWonder()) "Wonder/$name" else "Building/$name"
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
fun Float.formatSignedInt() = (if (this > 0f) "+" else "") + this.toInt().toString()
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
@ -33,7 +32,7 @@ class Difficulty: INamed, ICivilopediaText {
|
||||
var aiUnhappinessModifier = 1f
|
||||
var turnBarbariansCanEnterPlayerTiles = 0
|
||||
var clearBarbarianCampReward = 25
|
||||
|
||||
|
||||
// property defined in json but so far unused:
|
||||
// var aisExchangeTechs = false
|
||||
|
||||
@ -41,8 +40,6 @@ class Difficulty: INamed, ICivilopediaText {
|
||||
|
||||
|
||||
override fun makeLink() = "Difficulty/$name"
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
|
||||
private fun Float.toPercent() = (this * 100).toInt()
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
|
@ -194,8 +194,6 @@ class Nation : INamed, ICivilopediaText, IHasUniques {
|
||||
}
|
||||
|
||||
override fun makeLink() = "Nation/$name"
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun getSortGroup(ruleset: Ruleset) = when {
|
||||
isCityState() -> 1
|
||||
isBarbarian() -> 9
|
||||
|
@ -51,8 +51,6 @@ open class Policy : INamed, IHasUniques, ICivilopediaText {
|
||||
}
|
||||
|
||||
override fun makeLink() = "Policy/$name"
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun getSortGroup(ruleset: Ruleset) =
|
||||
ruleset.eras[branch.era]!!.eraNumber * 10000 +
|
||||
ruleset.policyBranches.keys.indexOf(branch.name) * 100 +
|
||||
|
@ -144,8 +144,6 @@ class Technology: INamed, ICivilopediaText, IHasUniques {
|
||||
|
||||
|
||||
override fun makeLink() = "Technology/$name"
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
val lineList = ArrayList<FormattedLine>()
|
||||
|
@ -62,8 +62,6 @@ class Terrain : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
}
|
||||
|
||||
override fun makeLink() = "Terrain/$name"
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
//todo where should we explain Rivers?
|
||||
|
@ -101,8 +101,6 @@ class TileImprovement : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
}
|
||||
|
||||
override fun makeLink() = "Improvement/$name"
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
val textList = ArrayList<FormattedLine>()
|
||||
|
@ -22,8 +22,6 @@ class TileResource : NamedStats(), ICivilopediaText {
|
||||
|
||||
|
||||
override fun makeLink() = "Resource/$name"
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
val textList = ArrayList<FormattedLine>()
|
||||
|
@ -38,10 +38,10 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
lateinit var unitType: String
|
||||
fun getType() = ruleset.unitTypes[unitType]!!
|
||||
var requiredTech: String? = null
|
||||
var requiredResource: String? = null
|
||||
private var requiredResource: String? = null
|
||||
override var uniques = ArrayList<String>() // Can not be a hashset as that would remove doubles
|
||||
override val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it) } }
|
||||
var replacementTextForUniques = ""
|
||||
private var replacementTextForUniques = ""
|
||||
var promotions = HashSet<String>()
|
||||
var obsoleteTech: String? = null
|
||||
var upgradesTo: String? = null
|
||||
@ -105,8 +105,6 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
}
|
||||
|
||||
override fun makeLink() = "Unit/$name"
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
val textList = ArrayList<FormattedLine>()
|
||||
@ -323,27 +321,23 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
return rejectionReasons
|
||||
}
|
||||
|
||||
/** @param ignoreTechPolicyRequirements: its `true` value is used when upgrading via ancient ruins,
|
||||
* as there we don't care whether we have the required tech, policy or building for the unit,
|
||||
* but do still care whether we have the resources required for the unit
|
||||
*/
|
||||
fun getRejectionReasons(civInfo: CivilizationInfo): RejectionReasons {
|
||||
val rejectionReasons = RejectionReasons()
|
||||
val ruleSet = civInfo.gameInfo.ruleSet
|
||||
|
||||
|
||||
if (uniques.contains("Unbuildable"))
|
||||
rejectionReasons.add(RejectionReason.Unbuildable)
|
||||
|
||||
|
||||
if (requiredTech != null && !civInfo.tech.isResearched(requiredTech!!))
|
||||
rejectionReasons.add(RejectionReason.RequiresTech.apply { this.errorMessage = "$requiredTech not researched" })
|
||||
if (obsoleteTech != null && civInfo.tech.isResearched(obsoleteTech!!))
|
||||
rejectionReasons.add(RejectionReason.Obsoleted.apply { this.errorMessage = "Obsolete by $obsoleteTech" })
|
||||
|
||||
|
||||
if (uniqueTo != null && uniqueTo != civInfo.civName)
|
||||
rejectionReasons.add(RejectionReason.UniqueToOtherNation.apply { this.errorMessage = "Unique to $uniqueTo" })
|
||||
if (ruleSet.units.values.any { it.uniqueTo == civInfo.civName && it.replaces == name })
|
||||
rejectionReasons.add(RejectionReason.ReplacedByOurUnique.apply { this.errorMessage = "Our unique unit replaces this" })
|
||||
|
||||
|
||||
if (!civInfo.gameInfo.gameParameters.nuclearWeaponsEnabled && isNuclearWeapon())
|
||||
rejectionReasons.add(RejectionReason.DisabledBySetting)
|
||||
|
||||
@ -372,7 +366,7 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
errorMessage = "Consumes [$amount] [$resource]"
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (uniques.contains(Constants.settlerUnique) &&
|
||||
(civInfo.isCityState() || civInfo.isOneCityChallenger())
|
||||
)
|
||||
@ -385,7 +379,7 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean {
|
||||
return getRejectionReasons(cityConstructions).isEmpty()
|
||||
}
|
||||
|
||||
|
||||
fun isBuildableIgnoringTechs(civInfo: CivilizationInfo): Boolean {
|
||||
val rejectionReasons = getRejectionReasons(civInfo)
|
||||
return rejectionReasons.filterTechPolicyEraWonderRequirements().isEmpty()
|
||||
|
@ -46,8 +46,6 @@ class Promotion : INamed, ICivilopediaText, IHasUniques {
|
||||
}
|
||||
|
||||
override fun makeLink() = "Promotion/$name"
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun replacesCivilopediaDescription() = true
|
||||
|
||||
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
|
||||
val textList = ArrayList<FormattedLine>()
|
||||
|
@ -6,10 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.Unique
|
||||
import com.unciv.models.ruleset.VictoryType
|
||||
import com.unciv.models.ruleset.*
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.*
|
||||
@ -29,7 +26,6 @@ class CivilopediaScreen(
|
||||
|
||||
/** Container collecting data per Civilopedia entry
|
||||
* @param name From [Ruleset] object [INamed.name]
|
||||
* @param description Multiline text
|
||||
* @param image Icon for button
|
||||
* @param flavour [ICivilopediaText]
|
||||
* @param y Y coordinate for scrolling to
|
||||
@ -37,14 +33,13 @@ class CivilopediaScreen(
|
||||
*/
|
||||
private class CivilopediaEntry (
|
||||
val name: String,
|
||||
val description: String,
|
||||
val image: Actor? = null,
|
||||
val flavour: ICivilopediaText? = null,
|
||||
val y: Float = 0f, // coordinates of button cell used to scroll to entry
|
||||
val height: Float = 0f,
|
||||
val sortBy: Int = 0 // optional, enabling overriding alphabetical order
|
||||
) {
|
||||
fun withCoordinates(y: Float, height: Float) = CivilopediaEntry(name, description, image, flavour, y, height, sortBy)
|
||||
fun withCoordinates(y: Float, height: Float) = CivilopediaEntry(name, image, flavour, y, height, sortBy)
|
||||
}
|
||||
|
||||
private val categoryToEntries = LinkedHashMap<CivilopediaCategories, Collection<CivilopediaEntry>>()
|
||||
@ -53,7 +48,6 @@ class CivilopediaScreen(
|
||||
|
||||
private val entrySelectTable = Table().apply { defaults().pad(6f).left() }
|
||||
private val entrySelectScroll: ScrollPane
|
||||
private val descriptionLabel = "".toLabel()
|
||||
private val flavourTable = Table()
|
||||
|
||||
private var currentCategory: CivilopediaCategories = CivilopediaCategories.Tutorial
|
||||
@ -90,7 +84,6 @@ class CivilopediaScreen(
|
||||
currentCategory = category
|
||||
entrySelectTable.clear()
|
||||
entryIndex.clear()
|
||||
descriptionLabel.setText("")
|
||||
flavourTable.clear()
|
||||
|
||||
for (button in categoryToButtons.values) button.color = Color.WHITE
|
||||
@ -147,13 +140,6 @@ class CivilopediaScreen(
|
||||
}
|
||||
private fun selectEntry(entry: CivilopediaEntry) {
|
||||
currentEntry = entry.name
|
||||
if(entry.flavour != null && entry.flavour.replacesCivilopediaDescription()) {
|
||||
descriptionLabel.setText("")
|
||||
descriptionLabel.isVisible = false
|
||||
} else {
|
||||
descriptionLabel.setText(entry.description)
|
||||
descriptionLabel.isVisible = true
|
||||
}
|
||||
flavourTable.clear()
|
||||
if (entry.flavour != null) {
|
||||
flavourTable.isVisible = true
|
||||
@ -207,11 +193,11 @@ class CivilopediaScreen(
|
||||
if (hideReligionItems && loopCategory == CivilopediaCategories.Belief) continue
|
||||
categoryToEntries[loopCategory] =
|
||||
getCategoryIterator(loopCategory)
|
||||
.filter { it.getUniquesAsObjects()?.let { uniques -> shouldBeDisplayed(uniques) } ?: true }
|
||||
.filter { (it as? IHasUniques)?.let { obj -> shouldBeDisplayed(obj.uniqueObjects) } ?: true }
|
||||
.map { CivilopediaEntry(
|
||||
(it as INamed).name, "",
|
||||
(it as INamed).name,
|
||||
loopCategory.getImage?.invoke(it.getIconName(), imageSize),
|
||||
it.takeUnless { ct -> ct.isCivilopediaTextEmpty() },
|
||||
flavour = it,
|
||||
sortBy = it.getSortGroup(ruleset)
|
||||
) }
|
||||
}
|
||||
@ -257,8 +243,6 @@ class CivilopediaScreen(
|
||||
entrySelectScroll.setOverscroll(false, false)
|
||||
val descriptionTable = Table()
|
||||
descriptionTable.add(flavourTable).row()
|
||||
descriptionLabel.wrap = true // requires explicit cell width!
|
||||
descriptionTable.add(descriptionLabel).width(stage.width * 0.5f).padTop(10f).row()
|
||||
val entrySplitPane = SplitPane(entrySelectScroll, ScrollPane(descriptionTable), false, skin)
|
||||
entrySplitPane.splitAmount = 0.3f
|
||||
entryTable.addActor(entrySplitPane)
|
||||
|
@ -7,7 +7,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.metadata.BaseRuleset
|
||||
import com.unciv.models.ruleset.IHasUniques
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.ruleset.Unique
|
||||
@ -381,16 +380,13 @@ object MarkupRenderer {
|
||||
|
||||
/** Storage class for instantiation of the simplest form containing only the lines collection */
|
||||
open class SimpleCivilopediaText(
|
||||
override var civilopediaText: List<FormattedLine>,
|
||||
val isComplete: Boolean = false
|
||||
override var civilopediaText: List<FormattedLine>
|
||||
) : ICivilopediaText {
|
||||
constructor(strings: Sequence<String>, isComplete: Boolean = false) : this(
|
||||
strings.map { FormattedLine(it) }.toList(), isComplete)
|
||||
constructor(first: Sequence<FormattedLine>, strings: Sequence<String>, isComplete: Boolean = false) : this(
|
||||
(first + strings.map { FormattedLine(it) }).toList(), isComplete)
|
||||
constructor(strings: Sequence<String>) : this(
|
||||
strings.map { FormattedLine(it) }.toList())
|
||||
constructor(first: Sequence<FormattedLine>, strings: Sequence<String>) : this(
|
||||
(first + strings.map { FormattedLine(it) }).toList())
|
||||
|
||||
override fun hasCivilopediaTextLines() = true
|
||||
override fun replacesCivilopediaDescription() = isComplete
|
||||
override fun makeLink() = ""
|
||||
}
|
||||
|
||||
@ -428,13 +424,6 @@ interface ICivilopediaText {
|
||||
*/
|
||||
fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> = listOf()
|
||||
|
||||
/** Override this and return true to tell the Civilopedia that the legacy description is no longer needed */
|
||||
fun replacesCivilopediaDescription() = false
|
||||
/** Override this and return true to tell the Civilopedia that this is not empty even if nothing came from json */
|
||||
fun hasCivilopediaTextLines() = false
|
||||
/** Indicates that neither json nor getCivilopediaTextLines have content */
|
||||
fun isCivilopediaTextEmpty() = civilopediaText.isEmpty() && !hasCivilopediaTextLines()
|
||||
|
||||
/** Build a Gdx [Table] showing our [formatted][FormattedLine] [content][civilopediaText]. */
|
||||
fun renderCivilopediaText (labelWidth: Float, linkAction: ((id: String)->Unit)? = null): Table {
|
||||
return MarkupRenderer.render(civilopediaText, labelWidth, linkAction = linkAction)
|
||||
@ -461,32 +450,24 @@ interface ICivilopediaText {
|
||||
val next = outerLines.next()
|
||||
if (!middleDone && !next.isEmpty() && next.linkType != FormattedLine.LinkType.None) {
|
||||
middleDone = true
|
||||
if (hasCivilopediaTextLines()) {
|
||||
if (outerNotEmpty) yield(FormattedLine())
|
||||
yieldAll(getCivilopediaTextLines(ruleset))
|
||||
yield(FormattedLine())
|
||||
}
|
||||
if (outerNotEmpty) yield(FormattedLine())
|
||||
yieldAll(getCivilopediaTextLines(ruleset))
|
||||
yield(FormattedLine())
|
||||
}
|
||||
outerNotEmpty = true
|
||||
yield(next)
|
||||
}
|
||||
if (!middleDone) {
|
||||
if (outerNotEmpty && hasCivilopediaTextLines()) yield(FormattedLine())
|
||||
if (outerNotEmpty) yield(FormattedLine())
|
||||
yieldAll(getCivilopediaTextLines(ruleset))
|
||||
}
|
||||
}
|
||||
return SimpleCivilopediaText(newLines.toList(), isComplete = true)
|
||||
return SimpleCivilopediaText(newLines.toList())
|
||||
}
|
||||
|
||||
/** Create the correct string for a Civilopedia link */
|
||||
fun makeLink(): String
|
||||
|
||||
/** This just marshals access to the uniques so they can be queried as part of the ICivilopediaText interface.
|
||||
* Used exclusively by CivilopediaScreen, named to avoid JVM signature confusion
|
||||
* (a getUniqueObjects exists in IHasUniques and most civilopedia objects will implement that interface)
|
||||
*/
|
||||
fun getUniquesAsObjects() = (this as? IHasUniques)?.uniqueObjects
|
||||
|
||||
/** Overrides alphabetical sorting in Civilopedia
|
||||
* @param ruleset The current ruleset in case the function needs to do lookups
|
||||
*/
|
||||
|
@ -62,8 +62,7 @@ class TutorialController(screen: CameraStageBaseScreen) {
|
||||
lines: Array<String>
|
||||
) : INamed, SimpleCivilopediaText(
|
||||
sequenceOf(FormattedLine(extraImage = rawName)),
|
||||
lines.asSequence(),
|
||||
true
|
||||
lines.asSequence()
|
||||
) {
|
||||
override var name = rawName.replace("_", " ")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user