A Civilopedia category for Religion (#4609)

* A Civilopedia category for Religion

* Civilopedia for Religion - rename cat, template and EOF linting

* Civilopedia for Religion - oversight
This commit is contained in:
SomeTroglodyte 2021-07-22 23:10:47 +02:00 committed by GitHub
parent e514df5b82
commit e41ba0da91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 89 additions and 17 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -945,6 +945,7 @@ Choose a pantheon =
Found Religion =
Found Pantheon =
Follow [belief] =
Religions and Beliefs =
# Terrains

View File

@ -3,6 +3,7 @@ package com.unciv.logic.civilization
import com.unciv.logic.map.MapUnit
import com.unciv.models.Religion
import com.unciv.models.ruleset.Belief
import com.unciv.models.ruleset.BeliefType
import kotlin.random.Random
class ReligionManager {
@ -73,7 +74,7 @@ class ReligionManager {
}
fun isPickablePantheonBelief(belief: Belief): Boolean {
if (belief.type != "Pantheon") return false
if (belief.type != BeliefType.Pantheon) return false
if (civInfo.gameInfo.civilizations.any { it.religionManager.religion != null && it.religionManager.religion!!.followerBeliefs.contains(belief.name)})
return false
return true
@ -179,4 +180,4 @@ enum class ReligionState {
Religion,
EnhancingReligion, // Great prophet used, but religion has not yet been enhanced
EnhancedReligion
}
}

View File

@ -2,6 +2,7 @@ package com.unciv.models
import com.unciv.logic.GameInfo
import com.unciv.models.ruleset.Belief
import com.unciv.models.ruleset.BeliefType
import com.unciv.models.ruleset.Unique
import com.unciv.models.stats.INamed
@ -49,13 +50,13 @@ class Religion() : INamed {
fun getPantheonBeliefs(): Sequence<Belief> {
return mapToExistingBeliefs(followerBeliefs)
.filter { it.type == "Pantheon" }
.filter { it.type == BeliefType.Pantheon }
.asSequence()
}
fun getFollowerBeliefs(): Sequence<Belief> {
return mapToExistingBeliefs(followerBeliefs)
.filter { it.type == "Follower" }
.filter { it.type == BeliefType.Follower }
.asSequence()
}
@ -80,15 +81,16 @@ class Religion() : INamed {
fun isMajorReligion(): Boolean {
if ("" in followerBeliefs) return true // Temporary as a result of follower beliefs not yet being implemented
return founderBeliefs.isNotEmpty() && followerBeliefs.any { gameInfo.ruleSet.beliefs[it]!!.type == "Follower"}
return founderBeliefs.isNotEmpty() && followerBeliefs
.any { gameInfo.ruleSet.beliefs[it]!!.type == BeliefType.Follower}
}
fun hasPantheon(): Boolean { // Currently unused
// Temporary as a result of follower beliefs not yet being implemented
return followerBeliefs.any { it != "" && gameInfo.ruleSet.beliefs[it]!!.type == "Pantheon" }
return followerBeliefs.any { it != "" && gameInfo.ruleSet.beliefs[it]!!.type == BeliefType.Pantheon }
}
fun hasBelief(belief: String): Boolean {
return followerBeliefs.contains(belief) || founderBeliefs.contains(belief)
}
}
}

View File

@ -1,11 +1,33 @@
package com.unciv.models.ruleset
import com.unciv.models.stats.INamed
import com.unciv.ui.civilopedia.CivilopediaText
import com.unciv.ui.civilopedia.FormattedLine
import java.awt.Color
import java.util.ArrayList
class Belief: INamed {
class Belief: INamed, CivilopediaText() {
override var name: String = ""
var type: String = ""
var type: BeliefType = BeliefType.None
var uniques = ArrayList<String>()
val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it) } }
override fun getCivilopediaTextHeader() = FormattedLine(name, icon="Belief/$name", header=2)
override fun replacesCivilopediaDescription() = true
override fun hasCivilopediaTextLines() = true
override fun getCivilopediaTextLines(ruleset: Ruleset): List<FormattedLine> {
val textList = ArrayList<FormattedLine>()
textList += FormattedLine("{Type}: $type", color=type.color )
uniqueObjects.forEach {
textList += FormattedLine(it)
}
return textList
}
}
enum class BeliefType(val color: String) {
None(""),
Pantheon("#44c6cc"),
Follower("#ccaa44"),
Founder("#c00000")
}

View File

@ -75,6 +75,13 @@ object CivilopediaImageGetters {
if (terrain == null) null
else terrainImage(terrain, ImageGetter.ruleset, size)
}
val belief = { name: String, size: Float ->
// Kludge until we decide how exactly to show Religions
if (ImageGetter.imageExists("ReligionIcons/$name")) {
ImageGetter.getReligionIcon(name).surroundWithCircle(size, color = Color.BLACK)
}
else null
}
}
/** Enum used as keys for Civilopedia "pages" (categories).
@ -100,6 +107,7 @@ enum class CivilopediaCategories (
Policy ("Policies", true, CivilopediaImageGetters.policy ),
Tutorial ("Tutorials", false, null ),
Difficulty ("Difficulty levels", false, null ),
Belief("Religions and Beliefs", false, CivilopediaImageGetters.belief)
;
companion object {

View File

@ -40,9 +40,10 @@ class CivilopediaScreen(
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 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)
fun withCoordinates(y: Float, height: Float) = CivilopediaEntry(name, description, image, flavour, y, height, sortBy)
}
private val categoryToEntries = LinkedHashMap<CivilopediaCategories, Collection<CivilopediaEntry>>()
@ -99,7 +100,10 @@ class CivilopediaScreen(
var entries = categoryToEntries[category]!!
if (category != CivilopediaCategories.Difficulty) // this is the only case where we need them in order
// Alphabetical order of localized names, using system default locale
entries = entries.sortedWith(compareBy(Collator.getInstance(), { it.name.tr() }))
entries = entries.sortedWith(
compareBy<CivilopediaEntry>{ it.sortBy }
.thenBy (Collator.getInstance(), { it.name.tr() })
)
var currentY = -1f
@ -283,6 +287,26 @@ class CivilopediaScreen(
)
}
if (!hideReligionItems)
categoryToEntries[CivilopediaCategories.Belief] = (
ruleset.beliefs.values.asSequence()
.map {
CivilopediaEntry(
it.name,
"",
CivilopediaCategories.Belief.getImage?.invoke(it.type.name, imageSize),
(it as? ICivilopediaText).takeUnless { ct -> ct==null || ct.isCivilopediaTextEmpty() },
sortBy = it.type.ordinal
)
} + CivilopediaEntry(
"Religions",
"",
CivilopediaCategories.Belief.getImage?.invoke("Religion", imageSize),
getReligionText(),
sortBy = -1
)
).toList()
val buttonTable = Table()
buttonTable.pad(15f)
buttonTable.defaults().pad(10f)
@ -341,6 +365,16 @@ class CivilopediaScreen(
selectEntry(link, noScrollAnimation = true)
}
private fun getReligionText(): ICivilopediaText {
val lines = ArrayList<FormattedLine>()
lines += FormattedLine("Religions", header=2, color="#e34a2b")
lines += FormattedLine(separator=true)
ruleset.religions.sortedWith(compareBy(Collator.getInstance(), { it.tr() })).forEach {
lines += FormattedLine(it, icon="Belief/$it")
}
return SimpleCivilopediaText(lines, true)
}
override fun resize(width: Int, height: Int) {
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
game.setScreen(CivilopediaScreen(game.worldScreen.gameInfo.ruleSet, currentCategory, currentEntry))

View File

@ -153,6 +153,7 @@ class FormattedLine (
val ruleSet = UncivGame.Current.gameInfo.ruleSet
// order these with the categories that should take precedence in case of name conflicts (e.g. Railroad) _last_
val allObjectMapsSequence = sequence {
yield(CivilopediaCategories.Belief to ruleSet.beliefs)
yield(CivilopediaCategories.Difficulty to ruleSet.difficulties)
yield(CivilopediaCategories.Promotion to ruleSet.unitPromotions)
yield(CivilopediaCategories.Policy to ruleSet.policies)

View File

@ -9,6 +9,7 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.Religion
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.utils.*
@ -126,7 +127,7 @@ class FoundReligionPickerScreen (
rightBeliefsToChoose.clear()
val availableBeliefs = gameInfo.ruleSet.beliefs.values
.filter {
it.type == beliefType
it.type.name == beliefType
&& gameInfo.religions.values.none {
religion -> religion.hasBelief(it.name)
}
@ -135,8 +136,8 @@ class FoundReligionPickerScreen (
for (belief in availableBeliefs) {
val beliefButton = convertBeliefToButton(belief)
beliefButton.onClick {
if (beliefType == "Follower") chosenFollowerBeliefs[leftButtonIndex] = belief
else if (beliefType == "Founder") chosenFounderBeliefs[leftButtonIndex] = belief
if (beliefType == BeliefType.Follower.name) chosenFollowerBeliefs[leftButtonIndex] = belief
else if (beliefType == BeliefType.Founder.name) chosenFounderBeliefs[leftButtonIndex] = belief
updateLeftTable()
checkAndEnableRightSideButton()
}
@ -146,7 +147,7 @@ class FoundReligionPickerScreen (
private fun convertBeliefToButton(belief: Belief): Button {
val contentsTable = Table()
contentsTable.add(belief.type.toLabel()).row()
contentsTable.add(belief.type.name.toLabel()).row()
contentsTable.add(belief.name.toLabel(fontSize = 24)).row()
contentsTable.add(belief.uniques.joinToString().toLabel())
return Button(contentsTable, skin)
@ -157,4 +158,4 @@ class FoundReligionPickerScreen (
contentsTable.add("Choose a [$beliefType] belief!".toLabel())
return Button(contentsTable, skin)
}
}
}

View File

@ -562,6 +562,8 @@ Unless otherwise specified, all the following are from [the Noun Project](https:
* [taoism](https://thenounproject.com/search/?q=Taoism&i=740812) by parkjisun for Taosim
* [Buddhism](https://thenounproject.com/search/?q=buddhism&i=38764) by Julio Yanes for Buddhism
* [Hinduism](https://thenounproject.com/search/?q=hinduism&i=20383) by Mugda Damle for Hinduism
* [praying](https://thenounproject.com/term/praying/740809/) by parkjisun for Religion (Civilopedia concept entry)
* [praying](https://thenounproject.com/term/praying/886367/) by Gan Khoon Lay for Follower
## Others