mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-09 07:18:57 +07:00
Policy images in red text, policy branch icons in pedia (#9365)
This commit is contained in:
@ -16,12 +16,13 @@ import com.unciv.ui.components.tilegroups.TileSetStrings
|
|||||||
import com.unciv.ui.components.KeyCharAndCode
|
import com.unciv.ui.components.KeyCharAndCode
|
||||||
import com.unciv.ui.components.extensions.setSize
|
import com.unciv.ui.components.extensions.setSize
|
||||||
import com.unciv.ui.components.extensions.surroundWithCircle
|
import com.unciv.ui.components.extensions.surroundWithCircle
|
||||||
import java.io.File
|
import com.unciv.ui.images.IconCircleGroup
|
||||||
|
|
||||||
|
|
||||||
/** Encapsulates the knowledge on how to get an icon for each of the Civilopedia categories */
|
/** Encapsulates the knowledge on how to get an icon for each of the Civilopedia categories */
|
||||||
object CivilopediaImageGetters {
|
object CivilopediaImageGetters {
|
||||||
private const val policyIconFolder = "PolicyIcons"
|
private const val policyIconFolder = "PolicyIcons"
|
||||||
|
private const val policyBranchIconFolder = "PolicyBranchIcons"
|
||||||
private const val policyInnerSize = 0.25f
|
private const val policyInnerSize = 0.25f
|
||||||
|
|
||||||
// Todo: potential synergy with map editor
|
// Todo: potential synergy with map editor
|
||||||
@ -64,17 +65,17 @@ object CivilopediaImageGetters {
|
|||||||
if (nation == null) null
|
if (nation == null) null
|
||||||
else ImageGetter.getNationPortrait(nation, size)
|
else ImageGetter.getNationPortrait(nation, size)
|
||||||
}
|
}
|
||||||
val policy = { name: String, size: Float ->
|
val policy = fun(name: String, size: Float): IconCircleGroup? {
|
||||||
// policy branch start and complete have no icons but are linked -> nonexistence must be passed down
|
// result is nullable: policy branch complete have no icons but are linked -> nonexistence must be passed down
|
||||||
val fileName = policyIconFolder + File.separator + name
|
fun tryImage(path: String, color: Color): IconCircleGroup? {
|
||||||
if (ImageGetter.imageExists(fileName))
|
if (ImageGetter.imageExists(path)) return ImageGetter.getImage(path).apply {
|
||||||
ImageGetter.getImage(fileName)
|
setSize(size * policyInnerSize,size * policyInnerSize)
|
||||||
.apply {
|
this.color = color
|
||||||
setSize(size * policyInnerSize,size * policyInnerSize)
|
}.surroundWithCircle(size)
|
||||||
color = Color.BROWN
|
return null
|
||||||
}
|
}
|
||||||
.surroundWithCircle(size)
|
return tryImage("$policyBranchIconFolder/$name", Color.BLACK)
|
||||||
else null
|
?: tryImage("$policyIconFolder/$name", Color.BROWN)
|
||||||
}
|
}
|
||||||
val resource = { name: String, size: Float ->
|
val resource = { name: String, size: Float ->
|
||||||
ImageGetter.getResourcePortrait(name, size)
|
ImageGetter.getResourcePortrait(name, size)
|
||||||
|
@ -18,6 +18,7 @@ import com.unciv.models.ruleset.unique.UniqueType
|
|||||||
import com.unciv.models.translations.fillPlaceholders
|
import com.unciv.models.translations.fillPlaceholders
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.components.BorderedTable
|
import com.unciv.ui.components.BorderedTable
|
||||||
|
import com.unciv.ui.components.ColorMarkupLabel
|
||||||
import com.unciv.ui.components.extensions.addSeparator
|
import com.unciv.ui.components.extensions.addSeparator
|
||||||
import com.unciv.ui.components.extensions.center
|
import com.unciv.ui.components.extensions.center
|
||||||
import com.unciv.ui.components.extensions.colorFromRGB
|
import com.unciv.ui.components.extensions.colorFromRGB
|
||||||
@ -69,8 +70,8 @@ class PolicyButton(viewingCiv: Civilization, canChangeState: Boolean, val policy
|
|||||||
|
|
||||||
val icon = ImageGetter.getImage("PolicyIcons/" + policy.name)
|
val icon = ImageGetter.getImage("PolicyIcons/" + policy.name)
|
||||||
|
|
||||||
val isPickable = policy.isPickable(viewingCiv, canChangeState)
|
private val isPickable = policy.isPickable(viewingCiv, canChangeState)
|
||||||
val isAdopted = viewingCiv.policies.isAdopted(policy.name)
|
private val isAdopted = viewingCiv.policies.isAdopted(policy.name)
|
||||||
|
|
||||||
var isSelected = false
|
var isSelected = false
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -280,7 +281,8 @@ class PolicyPickerScreen(val viewingCiv: Civilization, val canChangeState: Boole
|
|||||||
val conditionals = LinkedHashMap<UniqueType, ArrayList<String>>()
|
val conditionals = LinkedHashMap<UniqueType, ArrayList<String>>()
|
||||||
|
|
||||||
branch.uniqueMap[UniqueType.OnlyAvailableWhen.text]?.forEach {
|
branch.uniqueMap[UniqueType.OnlyAvailableWhen.text]?.forEach {
|
||||||
it.conditionals.forEach {
|
unique ->
|
||||||
|
unique.conditionals.forEach {
|
||||||
if (it.type != null) {
|
if (it.type != null) {
|
||||||
if (conditionals[it.type] == null)
|
if (conditionals[it.type] == null)
|
||||||
conditionals[it.type] = ArrayList()
|
conditionals[it.type] = ArrayList()
|
||||||
@ -294,8 +296,7 @@ class PolicyPickerScreen(val viewingCiv: Civilization, val canChangeState: Boole
|
|||||||
for ((k, v) in conditionals) {
|
for ((k, v) in conditionals) {
|
||||||
warning += "• " + k.text.fillPlaceholders(v.joinToString()).tr() + "\n"
|
warning += "• " + k.text.fillPlaceholders(v.joinToString()).tr() + "\n"
|
||||||
}
|
}
|
||||||
val warningLabel = warning.toLabel(Color.RED.cpy(), 13)
|
val warningLabel = ColorMarkupLabel(warning, Color.RED, fontSize = 13)
|
||||||
warningLabel.setFillParent(false)
|
|
||||||
warningLabel.setAlignment(Align.topLeft)
|
warningLabel.setAlignment(Align.topLeft)
|
||||||
warningLabel.wrap = true
|
warningLabel.wrap = true
|
||||||
labelTable.add(warningLabel).pad(0f, 20f, 17f, 20f).grow()
|
labelTable.add(warningLabel).pad(0f, 20f, 17f, 20f).grow()
|
||||||
@ -520,7 +521,9 @@ class PolicyPickerScreen(val viewingCiv: Civilization, val canChangeState: Boole
|
|||||||
}.toGroup(15f) else null
|
}.toGroup(15f) else null
|
||||||
val expandIcon = ImageGetter.getImage("OtherIcons/BackArrow").apply { rotation = 90f }.toGroup(10f)
|
val expandIcon = ImageGetter.getImage("OtherIcons/BackArrow").apply { rotation = 90f }.toGroup(10f)
|
||||||
table.add(expandIcon).minWidth(15f).expandX().left()
|
table.add(expandIcon).minWidth(15f).expandX().left()
|
||||||
table.add(branch.name.tr(hideIcons = true).uppercase().toLabel(fontSize = 14).apply { setAlignment(Align.center) }).center()
|
table.add(
|
||||||
|
branch.name.tr(hideIcons = true).uppercase().toLabel(fontSize = 14, alignment = Align.center)
|
||||||
|
).center()
|
||||||
table.add(icon).expandX().left().padLeft(5f)
|
table.add(icon).expandX().left().padLeft(5f)
|
||||||
|
|
||||||
header.touchable = Touchable.enabled
|
header.touchable = Touchable.enabled
|
||||||
@ -624,7 +627,7 @@ class PolicyPickerScreen(val viewingCiv: Civilization, val canChangeState: Boole
|
|||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPolicyButton(policy: Policy, size: Float = 30f): PolicyButton {
|
private fun getPolicyButton(policy: Policy, size: Float): PolicyButton {
|
||||||
val button = PolicyButton(viewingCiv, canChangeState, policy, size = size)
|
val button = PolicyButton(viewingCiv, canChangeState, policy, size = size)
|
||||||
button.onClick { pickPolicy(button = button) }
|
button.onClick { pickPolicy(button = button) }
|
||||||
if (policy.isPickable(viewingCiv, canChangeState))
|
if (policy.isPickable(viewingCiv, canChangeState))
|
||||||
|
Reference in New Issue
Block a user