mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-25 21:03:15 -04:00
Policy picker colors skinnable (#11050)
* Centralize Policy picker colors and make them skinnable * Most Policy picker colors skinnable, names, UiElementDocsWriter tricked
This commit is contained in:
parent
d1b4d31d87
commit
9e9ffa51d4
@ -19,7 +19,6 @@ import com.unciv.models.translations.tr
|
|||||||
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
|
||||||
import com.unciv.ui.components.extensions.darken
|
|
||||||
import com.unciv.ui.components.extensions.disable
|
import com.unciv.ui.components.extensions.disable
|
||||||
import com.unciv.ui.components.extensions.enable
|
import com.unciv.ui.components.extensions.enable
|
||||||
import com.unciv.ui.components.extensions.pad
|
import com.unciv.ui.components.extensions.pad
|
||||||
@ -41,29 +40,46 @@ import java.lang.Integer.max
|
|||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
private object PolicyColors {
|
private enum class PolicyColors(
|
||||||
|
val default: Color
|
||||||
|
) {
|
||||||
|
// The getUIColor comments are picked up by UiElementDocsWriter, the actual call is not.
|
||||||
|
ButtonBGPickable(colorFromRGB(32,46,64)), // getUIColor("PolicyScreen/Colors/ButtonBGPickable", colorFromRGB(32,46,64))
|
||||||
|
ButtonBGPickableSelected(colorFromRGB(37,87,82)), // getUIColor("PolicyScreen/Colors/ButtonBGPickableSelected", colorFromRGB(37,87,82))
|
||||||
|
ButtonBGNotPickable(colorFromRGB(20,20,20)), // getUIColor("PolicyScreen/Colors/ButtonBGNotPickable", colorFromRGB(20,20,20))
|
||||||
|
ButtonBGNotPickableSelected(colorFromRGB(20,20,20)), // getUIColor("PolicyScreen/Colors/ButtonBGNotPickableSelected", colorFromRGB(20,20,20))
|
||||||
|
ButtonBGAdopted(colorFromRGB(1,17,19)), // getUIColor("PolicyScreen/Colors/ButtonBGAdopted", colorFromRGB(1,17,19))
|
||||||
|
ButtonBGAdoptedSelected(colorFromRGB(1,17,19)), // getUIColor("PolicyScreen/Colors/ButtonBGAdoptedSelected", colorFromRGB(1,17,19))
|
||||||
|
|
||||||
val policyPickable = colorFromRGB(47,67,92).darken(0.3f)
|
ButtonIconPickable(Color.WHITE), // getUIColor("PolicyScreen/Colors/ButtonIconPickable", Color.WHITE)
|
||||||
val policyNotPickable = colorFromRGB(20, 20, 20)
|
ButtonIconPickableSelected(Color.WHITE), // getUIColor("PolicyScreen/Colors/ButtonIconPickableSelected", Color.WHITE)
|
||||||
val policySelected = colorFromRGB(37,87,82)
|
ButtonIconNotPickable(Color.valueOf("ffffff33")), // getUIColor("PolicyScreen/Colors/ButtonIconNotPickable", Color(0xffffff33))
|
||||||
|
ButtonIconNotPickableSelected(Color.valueOf("ffffff33")), // getUIColor("PolicyScreen/Colors/ButtonIconNotPickableSelected", Color(0xffffff33))
|
||||||
|
ButtonIconAdopted(Color.GOLD), // getUIColor("PolicyScreen/Colors/ButtonIconAdopted", Color.GOLD)
|
||||||
|
ButtonIconAdoptedSelected(Color.GOLD), // getUIColor("PolicyScreen/Colors/ButtonIconAdoptedSelected", Color.GOLD)
|
||||||
|
|
||||||
val branchCompleted = colorFromRGB(255, 205, 0)
|
BranchBGCompleted(colorFromRGB(255,205,0)), // getUIColor("PolicyScreen/Colors/BranchBGCompleted", colorFromRGB(255,205,0))
|
||||||
val branchNotAdopted = colorFromRGB(10,90,130).darken(0.5f)
|
BranchBGNotAdopted(colorFromRGB(5,45,65)), // getUIColor("PolicyScreen/Colors/BranchBGNotAdopted", colorFromRGB(5,45,65))
|
||||||
val branchAdopted = colorFromRGB(100, 90, 10).darken(0.5f)
|
BranchBGAdopted(colorFromRGB(50,45,5)), // getUIColor("PolicyScreen/Colors/BranchBGAdopted", colorFromRGB(50,45,5))
|
||||||
|
|
||||||
|
BranchHeaderBG(colorFromRGB(47,90,92)), // getUIColor("PolicyScreen/Colors/BranchHeaderBG", colorFromRGB(47,90,92))
|
||||||
|
|
||||||
|
BranchLabelAdopted(colorFromRGB(150,70,40)), // getUIColor("PolicyScreen/Colors/BranchLabelAdopted", colorFromRGB(150,70,40))
|
||||||
|
BranchLabelPickable(Color.WHITE), // getUIColor("PolicyScreen/Colors/BranchLabelPickable", Color.WHITE)
|
||||||
|
BranchLabelNotPickable(Color.valueOf("ffffff7f")), // getUIColor("PolicyScreen/Colors/BranchLabelNotPickable", Color(0xffffff7f))
|
||||||
|
|
||||||
|
;
|
||||||
|
val color get() = BaseScreen.skinStrings.getUIColor("PolicyScreen/Colors/$name", default)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Policy.isPickable(viewingCiv: Civilization, canChangeState: Boolean) : Boolean {
|
private fun Policy.isPickable(viewingCiv: Civilization, canChangeState: Boolean) =
|
||||||
if (!viewingCiv.isCurrentPlayer()
|
viewingCiv.isCurrentPlayer()
|
||||||
|| !canChangeState
|
&& canChangeState
|
||||||
|| viewingCiv.isDefeated()
|
&& !viewingCiv.isDefeated()
|
||||||
|| viewingCiv.policies.isAdopted(this.name)
|
&& !viewingCiv.policies.isAdopted(this.name)
|
||||||
|| this.policyBranchType == PolicyBranchType.BranchComplete
|
&& policyBranchType != PolicyBranchType.BranchComplete
|
||||||
|| !viewingCiv.policies.isAdoptable(this)
|
&& viewingCiv.policies.isAdoptable(this)
|
||||||
|| !viewingCiv.policies.canAdoptPolicy()
|
&& viewingCiv.policies.canAdoptPolicy()
|
||||||
)
|
|
||||||
return false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PolicyButton(viewingCiv: Civilization, canChangeState: Boolean, val policy: Policy, size: Float = 30f) : BorderedTable(
|
private class PolicyButton(viewingCiv: Civilization, canChangeState: Boolean, val policy: Policy, size: Float = 30f) : BorderedTable(
|
||||||
path = "PolicyScreen/PolicyButton",
|
path = "PolicyScreen/PolicyButton",
|
||||||
@ -106,26 +122,22 @@ private class PolicyButton(viewingCiv: Civilization, canChangeState: Boolean, va
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateState() {
|
private fun updateState() {
|
||||||
|
val colors = when {
|
||||||
when {
|
isSelected && isPickable ->
|
||||||
isSelected && isPickable -> {
|
PolicyColors.ButtonBGPickableSelected to PolicyColors.ButtonIconPickableSelected
|
||||||
bgColor = PolicyColors.policySelected
|
isPickable ->
|
||||||
}
|
PolicyColors.ButtonBGPickable to PolicyColors.ButtonIconPickable
|
||||||
|
isSelected && isAdopted ->
|
||||||
isPickable -> {
|
PolicyColors.ButtonBGAdoptedSelected to PolicyColors.ButtonIconAdoptedSelected
|
||||||
bgColor = PolicyColors.policyPickable
|
isAdopted ->
|
||||||
}
|
PolicyColors.ButtonBGAdopted to PolicyColors.ButtonIconAdopted
|
||||||
|
isSelected ->
|
||||||
isAdopted -> {
|
PolicyColors.ButtonBGNotPickableSelected to PolicyColors.ButtonIconNotPickableSelected
|
||||||
icon.color = Color.GOLD.cpy()
|
else ->
|
||||||
bgColor = colorFromRGB(10,90,100).darken(0.8f)
|
PolicyColors.ButtonBGNotPickable to PolicyColors.ButtonIconNotPickable
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
icon.color.a = 0.2f
|
|
||||||
bgColor = PolicyColors.policyNotPickable
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
bgColor = colors.first.color
|
||||||
|
icon.color = colors.second.color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,10 +196,10 @@ class PolicyPickerScreen(
|
|||||||
// TODO If we'd want to use scene2d correctly, this is supposed to happen inside an overridden layout() method
|
// TODO If we'd want to use scene2d correctly, this is supposed to happen inside an overridden layout() method
|
||||||
val numBranchesY = scrollPane.height / 305f
|
val numBranchesY = scrollPane.height / 305f
|
||||||
// Landscape - arrange in as few rows as looks nice
|
// Landscape - arrange in as few rows as looks nice
|
||||||
if (numBranchesY > 1.5f) {
|
rowChangeCount = if (numBranchesY > 1.5f) {
|
||||||
val numRows = if (numBranchesY < 2.9f) 2 else (numBranchesY + 0.1f).toInt()
|
val numRows = if (numBranchesY < 2.9f) 2 else (numBranchesY + 0.1f).toInt()
|
||||||
rowChangeCount = (branches.size + numRows - 1) / numRows
|
(branches.size + numRows - 1) / numRows
|
||||||
} else rowChangeCount = branches.size
|
} else branches.size
|
||||||
|
|
||||||
|
|
||||||
// Actually create and distribute the policy branches
|
// Actually create and distribute the policy branches
|
||||||
@ -280,7 +292,8 @@ class PolicyPickerScreen(
|
|||||||
val prefHeight = Sizes.paddingVertical * 2 + Sizes.iconSize * maxRow + Sizes.paddingBetweenVer * (maxRow - 1)
|
val prefHeight = Sizes.paddingVertical * 2 + Sizes.iconSize * maxRow + Sizes.paddingBetweenVer * (maxRow - 1)
|
||||||
|
|
||||||
// Main table
|
// Main table
|
||||||
bgColor = if (viewingCiv.policies.isAdopted(branch.name)) PolicyColors.branchAdopted else PolicyColors.branchNotAdopted
|
bgColor = if (viewingCiv.policies.isAdopted(branch.name))
|
||||||
|
PolicyColors.BranchBGAdopted.color else PolicyColors.BranchBGNotAdopted.color
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
add(header).growX().row()
|
add(header).growX().row()
|
||||||
@ -356,7 +369,7 @@ class PolicyPickerScreen(
|
|||||||
if (policy.policyBranchType == PolicyBranchType.BranchComplete)
|
if (policy.policyBranchType == PolicyBranchType.BranchComplete)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val button = getPolicyButton(policy, size = Sizes.iconSize)
|
val button = getPolicyButton(policy)
|
||||||
group.addActor(button)
|
group.addActor(button)
|
||||||
|
|
||||||
val policyX = coords[policy.row][policy.column].first
|
val policyX = coords[policy.row][policy.column].first
|
||||||
@ -516,8 +529,8 @@ class PolicyPickerScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getBranchHeader(branch: PolicyBranch): Table {
|
private fun getBranchHeader(branch: PolicyBranch): Table {
|
||||||
val header = BorderedTable(path="PolicyScreen/PolicyBranchHeader")
|
val header = BorderedTable(path = "PolicyScreen/PolicyBranchHeader")
|
||||||
header.bgColor = colorFromRGB(47,90,92)
|
header.bgColor = PolicyColors.BranchHeaderBG.color
|
||||||
header.borderSize = 5f
|
header.borderSize = 5f
|
||||||
header.pad(10f)
|
header.pad(10f)
|
||||||
|
|
||||||
@ -552,7 +565,7 @@ class PolicyPickerScreen(
|
|||||||
var percentage = 0f
|
var percentage = 0f
|
||||||
|
|
||||||
val lockIcon = ImageGetter.getImage("OtherIcons/LockSmall")
|
val lockIcon = ImageGetter.getImage("OtherIcons/LockSmall")
|
||||||
.apply { color = Color.WHITE.cpy() }.toGroup(15f)
|
.apply { color = Color.WHITE }.toGroup(15f)
|
||||||
|
|
||||||
|
|
||||||
if (viewingCiv.policies.isAdopted(branch.name)) {
|
if (viewingCiv.policies.isAdopted(branch.name)) {
|
||||||
@ -575,17 +588,12 @@ class PolicyPickerScreen(
|
|||||||
val label = text.toLabel(fontSize = 14)
|
val label = text.toLabel(fontSize = 14)
|
||||||
label.setAlignment(Align.center)
|
label.setAlignment(Align.center)
|
||||||
|
|
||||||
val color = when {
|
label.color = when {
|
||||||
isPickable -> PolicyColors.policyPickable
|
isAdoptedBranch -> PolicyColors.BranchLabelAdopted
|
||||||
else -> PolicyColors.policyNotPickable
|
isPickable -> PolicyColors.BranchLabelPickable
|
||||||
}
|
else -> PolicyColors.BranchLabelNotPickable
|
||||||
|
}.color
|
||||||
if (isAdoptedBranch)
|
lockIcon.isVisible = !isPickable && !isAdoptedBranch
|
||||||
label.color = colorFromRGB(150, 70, 40)
|
|
||||||
else if (!isPickable)
|
|
||||||
label.color.a = 0.5f
|
|
||||||
else
|
|
||||||
lockIcon.isVisible = false
|
|
||||||
|
|
||||||
val table = object : BorderedTable(
|
val table = object : BorderedTable(
|
||||||
path="PolicyScreen/PolicyBranchAdoptButton",
|
path="PolicyScreen/PolicyBranchAdoptButton",
|
||||||
@ -599,10 +607,10 @@ class PolicyPickerScreen(
|
|||||||
progress = Image(
|
progress = Image(
|
||||||
skinStrings.getUiBackground("",
|
skinStrings.getUiBackground("",
|
||||||
skinStrings.roundedEdgeRectangleSmallShape,
|
skinStrings.roundedEdgeRectangleSmallShape,
|
||||||
tintColor = PolicyColors.branchCompleted
|
tintColor = PolicyColors.BranchBGCompleted.color
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
progress!!.setSize(this.width*percentage, this.height)
|
progress!!.setSize(this.width * percentage, this.height)
|
||||||
this.addActor(progress)
|
this.addActor(progress)
|
||||||
progress!!.toBack()
|
progress!!.toBack()
|
||||||
}
|
}
|
||||||
@ -610,11 +618,14 @@ class PolicyPickerScreen(
|
|||||||
|
|
||||||
override fun sizeChanged() {
|
override fun sizeChanged() {
|
||||||
super.sizeChanged()
|
super.sizeChanged()
|
||||||
progress?.setSize(this.width*percentage, this.height)
|
progress?.setSize(this.width * percentage, this.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
table.bgColor = color
|
table.bgColor = when {
|
||||||
|
isPickable -> PolicyColors.ButtonBGPickable
|
||||||
|
else -> PolicyColors.ButtonBGNotPickable
|
||||||
|
}.color
|
||||||
table.borderSize = 3f
|
table.borderSize = 3f
|
||||||
|
|
||||||
table.add(label).minHeight(30f).minWidth(150f).growX()
|
table.add(label).minHeight(30f).minWidth(150f).growX()
|
||||||
@ -637,8 +648,8 @@ class PolicyPickerScreen(
|
|||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPolicyButton(policy: Policy, size: Float): PolicyButton {
|
private fun getPolicyButton(policy: Policy): PolicyButton {
|
||||||
val button = PolicyButton(viewingCiv, canChangeState, policy, size = size)
|
val button = PolicyButton(viewingCiv, canChangeState, policy, size = Sizes.iconSize)
|
||||||
button.onClick { pickPolicy(button = button) }
|
button.onClick { pickPolicy(button = button) }
|
||||||
if (policy.isPickable(viewingCiv, canChangeState))
|
if (policy.isPickable(viewingCiv, canChangeState))
|
||||||
button.onDoubleClick(UncivSound.Policy) { confirmAction() }
|
button.onDoubleClick(UncivSound.Policy) { confirmAction() }
|
||||||
|
@ -100,6 +100,25 @@ These shapes are used all over Unciv and can be replaced to make a lot of UI ele
|
|||||||
| PolicyScreen/ | PolicyBranchBackgroundBorder | rectangleWithOutline | |
|
| PolicyScreen/ | PolicyBranchBackgroundBorder | rectangleWithOutline | |
|
||||||
| PolicyScreen/ | PolicyBranchHeader | rectangleWithOutline | |
|
| PolicyScreen/ | PolicyBranchHeader | rectangleWithOutline | |
|
||||||
| PolicyScreen/ | PolicyBranchHeaderBorder | rectangleWithOutline | |
|
| PolicyScreen/ | PolicyBranchHeaderBorder | rectangleWithOutline | |
|
||||||
|
| PolicyScreen/Colors/ | BranchBGAdopted | 50,45,5 | |
|
||||||
|
| PolicyScreen/Colors/ | BranchBGCompleted | 255,205,0 | |
|
||||||
|
| PolicyScreen/Colors/ | BranchBGNotAdopted | 5,45,65 | |
|
||||||
|
| PolicyScreen/Colors/ | BranchHeaderBG | 47,90,92 | |
|
||||||
|
| PolicyScreen/Colors/ | BranchLabelAdopted | 150,70,40 | |
|
||||||
|
| PolicyScreen/Colors/ | BranchLabelNotPickable | 0xffffff7f | |
|
||||||
|
| PolicyScreen/Colors/ | BranchLabelPickable | WHITE | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonBGAdopted | 1,17,19 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonBGAdoptedSelected | 1,17,19 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonBGNotPickable | 20,20,20 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonBGNotPickableSelected | 20,20,20 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonBGPickable | 32,46,64 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonBGPickableSelected | 37,87,82 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonIconAdopted | GOLD | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonIconAdoptedSelected | GOLD | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonIconNotPickable | 0xffffff33 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonIconNotPickableSelected | 0xffffff33 | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonIconPickable | WHITE | |
|
||||||
|
| PolicyScreen/Colors/ | ButtonIconPickableSelected | WHITE | |
|
||||||
| PromotionScreen/ | PromotionButton | roundedEdgeRectangleMid | |
|
| PromotionScreen/ | PromotionButton | roundedEdgeRectangleMid | |
|
||||||
| PromotionScreen/ | PromotionButtonBorder | roundedEdgeRectangleMidBorder | |
|
| PromotionScreen/ | PromotionButtonBorder | roundedEdgeRectangleMidBorder | |
|
||||||
| TechPickerScreen/ | Background | null | |
|
| TechPickerScreen/ | Background | null | |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user