From 09cff6e55f42d9403917d165f9a0d12021d81063 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sat, 25 Mar 2023 19:34:49 +0100 Subject: [PATCH] TechPickerScreen colors - skinnable and prettier Future Tech (#9033) --- .../src/com/unciv/models/skins/SkinStrings.kt | 6 +++++ .../screens/pickerscreens/TechPickerScreen.kt | 23 ++++++++----------- .../unciv/app/desktop/UiElementDocsWriter.kt | 21 +++++++++++++---- docs/Modders/Creating-a-UI-skin.md | 5 ++++ 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/core/src/com/unciv/models/skins/SkinStrings.kt b/core/src/com/unciv/models/skins/SkinStrings.kt index 64edaaf277..7cd4dd383c 100644 --- a/core/src/com/unciv/models/skins/SkinStrings.kt +++ b/core/src/com/unciv/models/skins/SkinStrings.kt @@ -63,4 +63,10 @@ class SkinStrings(skin: String = UncivGame.Current.settings.skin) { } return ImageGetter.getNinePatch(location, tint) } + + fun getUIColor(path: String, default: Color? = null) = + skinConfig.skinVariants[path]?.tint + ?: default + ?: skinConfig.clearColor + } diff --git a/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt index 98b9539aea..062f7d9e85 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt @@ -58,11 +58,11 @@ class TechPickerScreen( private var researchableTechs = civInfo.gameInfo.ruleset.technologies.keys .filter { civTech.canBeResearched(it) }.toHashSet() - private val currentTechColor = colorFromRGB(72, 147, 175) - private val researchedTechColor = colorFromRGB(255, 215, 0) - private val researchableTechColor = colorFromRGB(28, 170, 0) - private val queuedTechColor = colorFromRGB(7*2, 46*2, 43*2) - + private val currentTechColor = skinStrings.getUIColor("TechPickerScreen/CurrentTechColor", colorFromRGB(72, 147, 175)) + private val researchedTechColor = skinStrings.getUIColor("TechPickerScreen/ResearchedTechColor", colorFromRGB(255, 215, 0)) + private val researchableTechColor = skinStrings.getUIColor("TechPickerScreen/ResearchableTechColor", colorFromRGB(28, 170, 0)) + private val queuedTechColor = skinStrings.getUIColor("TechPickerScreen/QueuedTechColor", colorFromRGB(7*2, 46*2, 43*2)) + private val researchedFutureTechColor = skinStrings.getUIColor("TechPickerScreen/ResearchedFutureTechColor", colorFromRGB(127, 50, 0)) private val turnsToTech = civInfo.gameInfo.ruleset.technologies.values.associateBy({ it.name }, { civTech.turnsToTech(it.name) }) @@ -201,8 +201,10 @@ class TechPickerScreen( private fun setButtonsInfo() { for ((techName, techButton) in techNameToButton) { + val isResearched = civTech.isResearched(techName) techButton.setButtonColor(when { - civTech.isResearched(techName) && techName != Constants.futureTech -> researchedTechColor + isResearched && techName != Constants.futureTech -> researchedTechColor + isResearched -> researchedFutureTechColor // if we're here to pick a free tech, show the current tech like the rest of the researchables so it'll be obvious what we can pick tempTechsToResearch.firstOrNull() == techName && !freeTechPick -> currentTechColor researchableTechs.contains(techName) -> researchableTechColor @@ -210,16 +212,11 @@ class TechPickerScreen( else -> Color.BLACK.cpy() }) - if (civTech.isResearched(techName) && techName != Constants.futureTech) { + if (isResearched && techName != Constants.futureTech) { techButton.text.color = colorFromRGB(154, 98, 16) - techButton.color = researchedTechColor.cpy().darken(0.5f) } - if (techName == selectedTech?.name && civTech.isResearched(techName)) { - techButton.setButtonColor(colorFromRGB(230, 220, 114)) - } - - if (!civTech.isResearched(techName) || techName == Constants.futureTech) { + if (!isResearched || techName == Constants.futureTech) { techButton.turns.setText(turnsToTech[techName] + "${Fonts.turn}".tr()) } diff --git a/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt b/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt index b5754933ac..0f8a1a53c4 100644 --- a/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt +++ b/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt @@ -20,17 +20,28 @@ class UiElementDocsWriter { val startIndex = originalLines.indexOf(startMarker).takeIf { it != -1 } ?: (endIndex + 1) val elements = mutableListOf() + val backgroundRegex = Regex("""getUiBackground\((\X*?)"(?.*)"[ ,\n\r]*((BaseScreen\.)?skinStrings\.(?.*)Shape)?\X*?\)""") + val colorRegex = Regex(""" + getUIColor\s*\(\s* # function call, whitespace around opening round bracket optional. All \s also allow line breaks! + "(?[^"]*)"\s* # captures "path", anything between double-quotes, not allowing for embedded quotes + (?:,\s* # group for optional default parameter + (?:default\s*=\s*)? # allow for named parameter + (?:Colors\s*\(|colorFromRGB\s*\(|Color\.) # recognize only Color constructor, colorFromRGB helper, or Color.* constants as argument + (?[^)]*) # capture "default" up until a closing round bracket + )\s*\) # ends default parameter group and checks closing round bracket of the getUIColor call + """, RegexOption.COMMENTS) for (file in srcFile.walk()) { if (file.path.endsWith(".kt")) { - val results = Regex("getUiBackground\\((\\X*?)\"(?.*)\"[ ,\n\r]*((BaseScreen\\.)?skinStrings\\.(?.*)Shape)?\\X*?\\)") - .findAll(file.readText()) - for (result in results) { + val sourceText = file.readText() + val matches: Sequence = + backgroundRegex.findAll(sourceText) + colorRegex.findAll(sourceText) + for (result in matches) { val path = result.groups["path"]?.value val name = path?.takeLastWhile { it != '/' } ?: "" - val defaultShape = result.groups["defaultShape"]?.value + val default = result.groups["default"]?.value if (name.isNotBlank()) - elements.add("| ${path!!.dropLast(name.length)} | $name | $defaultShape | |") + elements.add("| ${path!!.dropLast(name.length)} | $name | $default | |") } } } diff --git a/docs/Modders/Creating-a-UI-skin.md b/docs/Modders/Creating-a-UI-skin.md index a2882a752c..d4a4b2a74e 100644 --- a/docs/Modders/Creating-a-UI-skin.md +++ b/docs/Modders/Creating-a-UI-skin.md @@ -94,6 +94,11 @@ These shapes are used all over Unciv and can be replaced to make a lot of UI ele | TechPickerScreen/ | Background | null | | | TechPickerScreen/ | Background | null | | | TechPickerScreen/ | BottomTable | null | | +| TechPickerScreen/ | CurrentTechColor | 72, 147, 175 | | +| TechPickerScreen/ | QueuedTechColor | 7*2, 46*2, 43*2 | | +| TechPickerScreen/ | ResearchableTechColor | 28, 170, 0 | | +| TechPickerScreen/ | ResearchedFutureTechColor | 127, 50, 0 | | +| TechPickerScreen/ | ResearchedTechColor | 255, 215, 0 | | | TechPickerScreen/ | TechButtonIconsOutline | roundedEdgeRectangleSmall | | | VictoryScreen/ | CivGroup | roundedEdgeRectangle | | | WorldScreen/ | AirUnitTable | null | |