mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 09:48:12 +07:00
Some Color.lerp simplification (#6300)
This commit is contained in:
@ -9,6 +9,7 @@ import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.Constants
|
||||
import com.unciv.models.translations.equalsPlaceholderText
|
||||
import com.unciv.models.translations.getPlaceholderParameters
|
||||
import com.unciv.ui.utils.darken
|
||||
|
||||
|
||||
/** Unit Actions - class - carries dynamic data and actual execution.
|
||||
@ -45,7 +46,7 @@ data class UnitAction(
|
||||
val match = fortificationRegex.matchEntire(title)
|
||||
val percentFortified = match?.groups?.get(1)?.value?.toInt() ?: 0
|
||||
ImageGetter.getImage("OtherIcons/Shield").apply {
|
||||
color = Color.BLACK.cpy().lerp(Color.GREEN, percentFortified / 80f)
|
||||
color = Color.GREEN.darken(1f - percentFortified / 80f)
|
||||
}
|
||||
}
|
||||
else -> ImageGetter.getImage("OtherIcons/Star")
|
||||
|
@ -56,8 +56,9 @@ class Terrain : RulesetStatsObject() {
|
||||
}
|
||||
|| ruleset.terrains[this.turnsInto]?.type == asType
|
||||
|
||||
fun getColor(): Color { // Can't be a lazy initialize, because we play around with the resulting color with lerp()s and the like
|
||||
if (RGB == null) return Color.GOLD
|
||||
/** Gets a new [Color] instance from the [RGB] property, mutation e.g. via [Color.lerp] allowed */
|
||||
fun getColor(): Color { // Can't be a lazy initialize, see above
|
||||
if (RGB == null) return Color.GOLD.cpy()
|
||||
return colorFromRGB(RGB!!)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.unciv.ui.cityscreen
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
@ -261,7 +260,7 @@ class CityConstructionsTable(private val cityScreen: CityScreen) {
|
||||
table.background = ImageGetter.getBackground(Color.BLACK)
|
||||
|
||||
if (constructionQueueIndex == selectedQueueEntry)
|
||||
table.background = ImageGetter.getBackground(Color.GREEN.cpy().lerp(Color.BLACK, 0.5f))
|
||||
table.background = ImageGetter.getBackground(Color.GREEN.darken(0.5f))
|
||||
|
||||
val isFirstConstructionOfItsKind = cityConstructions.isFirstConstructionOfItsKind(constructionQueueIndex, constructionName)
|
||||
|
||||
@ -307,7 +306,7 @@ class CityConstructionsTable(private val cityScreen: CityScreen) {
|
||||
val constructionPercentage = cityConstructions.getWorkDone(constructionName) /
|
||||
(construction as INonPerpetualConstruction).getProductionCost(cityConstructions.cityInfo.civInfo).toFloat()
|
||||
return ImageGetter.getProgressBarVertical(2f, 30f, constructionPercentage,
|
||||
Color.BROWN.cpy().lerp(Color.WHITE, 0.5f), Color.WHITE)
|
||||
Color.BROWN.brighten(0.5f), Color.WHITE)
|
||||
}
|
||||
|
||||
private class ConstructionButtonDTO(val construction: IConstruction, val buttonText: String, val rejectionReason: String? = null)
|
||||
@ -321,7 +320,7 @@ class CityConstructionsTable(private val cityScreen: CityScreen) {
|
||||
pickConstructionButton.touchable = Touchable.enabled
|
||||
|
||||
if (!isSelectedQueueEntry() && cityScreen.selectedConstruction != null && cityScreen.selectedConstruction == construction) {
|
||||
pickConstructionButton.background = ImageGetter.getBackground(Color.GREEN.cpy().lerp(Color.BLACK, 0.5f))
|
||||
pickConstructionButton.background = ImageGetter.getBackground(Color.GREEN.darken(0.5f))
|
||||
}
|
||||
|
||||
pickConstructionButton.add(getProgressBar(construction.name)).padRight(5f)
|
||||
|
@ -33,7 +33,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(BaseScreen.skin)
|
||||
}
|
||||
|
||||
innerTable.width = cityScreen.stage.width / 4
|
||||
innerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||
innerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f))
|
||||
scrollPane = ScrollPane(innerTable.addBorder(2f, Color.WHITE))
|
||||
scrollPane.setOverscroll(false, false)
|
||||
|
||||
|
@ -20,7 +20,7 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table() {
|
||||
val city = cityScreen.city
|
||||
|
||||
init {
|
||||
innerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||
innerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f))
|
||||
add(innerTable).pad(2f).fill()
|
||||
background = ImageGetter.getBackground(Color.WHITE)
|
||||
}
|
||||
|
@ -10,17 +10,14 @@ import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.CivilopediaScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.surroundWithCircle
|
||||
import com.unciv.ui.utils.toLabel
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
class ConstructionInfoTable(val cityScreen: CityScreen): Table() {
|
||||
private val selectedConstructionTable = Table()
|
||||
val city = cityScreen.city
|
||||
|
||||
init {
|
||||
selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||
selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f))
|
||||
add(selectedConstructionTable).pad(2f).fill()
|
||||
background = ImageGetter.getBackground(Color.WHITE)
|
||||
}
|
||||
|
@ -14,12 +14,11 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(BaseScreen.sk
|
||||
fun update() {
|
||||
clear()
|
||||
|
||||
for ((specialistName, amount) in cityInfo.population.getMaxSpecialists()) {
|
||||
for ((specialistName, maxSpecialists) in cityInfo.population.getMaxSpecialists()) {
|
||||
if (!cityInfo.getRuleset().specialists.containsKey(specialistName)) // specialist doesn't exist in this ruleset, probably a mod
|
||||
continue
|
||||
val newSpecialists = cityInfo.population.getNewSpecialists()
|
||||
val assignedSpecialists = newSpecialists[specialistName]!!
|
||||
val maxSpecialists = amount
|
||||
|
||||
if (cityScreen.canChangeState) add(getUnassignButton(assignedSpecialists, specialistName))
|
||||
add(getAllocationTable(assignedSpecialists, maxSpecialists, specialistName)).pad(10f)
|
||||
@ -49,7 +48,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(BaseScreen.sk
|
||||
if (assignedSpecialists >= maxSpecialists || cityInfo.isPuppet) return Table()
|
||||
val assignButton = "+".toLabel(Color.BLACK, Constants.headingFontSize)
|
||||
.apply { this.setAlignment(Align.center) }
|
||||
.surroundWithCircle(30f).apply { circle.color= Color.GREEN.cpy().lerp(Color.BLACK,0.2f) }
|
||||
.surroundWithCircle(30f).apply { circle.color= Color.GREEN.darken(0.2f) }
|
||||
assignButton.onClick {
|
||||
cityInfo.population.specialistAllocations.add(specialistName, 1)
|
||||
cityInfo.cityStats.update()
|
||||
@ -63,7 +62,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(BaseScreen.sk
|
||||
private fun getUnassignButton(assignedSpecialists: Int, specialistName: String):Actor {
|
||||
val unassignButton = "-".toLabel(Color.BLACK,Constants.headingFontSize)
|
||||
.apply { this.setAlignment(Align.center) }
|
||||
.surroundWithCircle(30f).apply { circle.color= Color.RED.cpy().lerp(Color.BLACK,0.1f) }
|
||||
.surroundWithCircle(30f).apply { circle.color= Color.RED.darken(0.1f) }
|
||||
unassignButton.onClick {
|
||||
cityInfo.population.specialistAllocations.add(specialistName, -1)
|
||||
cityInfo.cityStats.update()
|
||||
|
@ -131,7 +131,7 @@ class PlayerPickerTable(
|
||||
fun getPlayerTable(player: Player): Table {
|
||||
val playerTable = Table()
|
||||
playerTable.pad(5f)
|
||||
playerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.8f))
|
||||
playerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.8f))
|
||||
|
||||
val nationTable = getNationTable(player)
|
||||
playerTable.add(nationTable).left()
|
||||
|
@ -33,8 +33,8 @@ class TechButton(techName:String, private val techManager: TechManager, isWorldS
|
||||
val percentWillBeComplete = (techCost - (remainingTech-techThisTurn)) / techCost.toFloat()
|
||||
val progressBar = ImageGetter.VerticalProgressBar(2f, 50f)
|
||||
.addColor(Color.WHITE, 1f)
|
||||
.addColor(Color.BLUE.cpy().lerp(Color.WHITE, 0.3f), percentWillBeComplete)
|
||||
.addColor(Color.BLUE.cpy().lerp(Color.BLACK, 0.5f), percentComplete)
|
||||
.addColor(Color.BLUE.brighten(0.3f), percentWillBeComplete)
|
||||
.addColor(Color.BLUE.darken(0.5f), percentComplete)
|
||||
add(progressBar.addBorder(1f, Color.GRAY)).pad(10f)
|
||||
rightSide.add(text).padBottom(5f).row()
|
||||
} else rightSide.add(text).height(25f).padBottom(5f).row()
|
||||
|
@ -164,7 +164,7 @@ class TechPickerScreen(
|
||||
var text = techName.tr()
|
||||
|
||||
if (techName == selectedTech?.name && techButton.color != currentTechColor) {
|
||||
techButton.color = techButton.color.cpy().lerp(Color.BLACK, 0.5f)
|
||||
techButton.color = techButton.color.darken(0.5f)
|
||||
}
|
||||
|
||||
techButton.orderIndicator?.remove()
|
||||
|
@ -398,7 +398,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
||||
val constructionPercentage = cityConstructions.getWorkDone(cityCurrentConstruction.name) /
|
||||
(cityCurrentConstruction as INonPerpetualConstruction).getProductionCost(cityConstructions.cityInfo.civInfo).toFloat()
|
||||
val productionBar = ImageGetter.getProgressBarVertical(2f, groupHeight, constructionPercentage,
|
||||
Color.BROWN.cpy().lerp(Color.WHITE, 0.5f), Color.BLACK)
|
||||
Color.BROWN.brighten(0.5f), Color.BLACK)
|
||||
productionBar.x = 10f
|
||||
label.x = productionBar.x - label.width - 3
|
||||
group.addActor(productionBar)
|
||||
|
@ -636,9 +636,9 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
||||
var color =
|
||||
if (tileSetStrings.tileSetConfig.useColorAsBaseTerrain)
|
||||
tileInfo.getBaseTerrain().getColor()
|
||||
else Color.WHITE // no need to color it, it's already colored
|
||||
else Color.WHITE.cpy() // no need to color it, it's already colored
|
||||
|
||||
if (!isViewable) color = color.cpy().lerp(tileSetStrings.tileSetConfig.fogOfWarColor, 0.6f)
|
||||
if (!isViewable) color = color.lerp(tileSetStrings.tileSetConfig.fogOfWarColor, 0.6f)
|
||||
for(image in tileBaseImages) image.color = color
|
||||
}
|
||||
|
||||
@ -677,6 +677,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
|
||||
.tryImage { if (baseUnit.replaces != null) "$unitsLocation${baseUnit.replaces}" else null }
|
||||
.tryImages(
|
||||
militaryUnit.civInfo.gameInfo.ruleSet.units.values.asSequence().map {
|
||||
@Suppress("unused") // yes receiver unused but we want the signature to match ImageAttempter instance
|
||||
fun MapUnit.() = if (it.unitType == militaryUnit.type.name)
|
||||
"$unitsLocation${it.name}"
|
||||
else
|
||||
|
@ -35,7 +35,7 @@ class TileGroupIcons(val tileGroup: TileGroup) {
|
||||
}
|
||||
|
||||
fun addPopulationIcon(icon: Image = ImageGetter.getStatIcon("Population")
|
||||
.apply { color = Color.GREEN.cpy().lerp(Color.BLACK, 0.5f) }) {
|
||||
.apply { color = Color.GREEN.darken(0.5f) }) {
|
||||
populationIcon?.remove()
|
||||
populationIcon = icon
|
||||
populationIcon!!.run {
|
||||
|
@ -40,8 +40,17 @@ var Button.isEnabled: Boolean
|
||||
get() = touchable == Touchable.enabled
|
||||
set(value) = if (value) enable() else disable()
|
||||
|
||||
/** Create a new [Color] instance from [r]/[g]/[b] given as Integers in the range 0..255 */
|
||||
fun colorFromRGB(r: Int, g: Int, b: Int) = Color(r / 255f, g / 255f, b / 255f, 1f)
|
||||
fun colorFromRGB(rgb:List<Int>) = colorFromRGB(rgb[0], rgb[1], rgb[2])
|
||||
/** Create a new [Color] instance from r/g/b given as Integers in the range 0..255 in the form of a 3-element List [rgb] */
|
||||
fun colorFromRGB(rgb: List<Int>) = colorFromRGB(rgb[0], rgb[1], rgb[2])
|
||||
/** Linearly interpolates between this [Color] and [BLACK][Color.BLACK] by [t] which is in the range [[0,1]].
|
||||
* The result is returned as a new instance. */
|
||||
fun Color.darken(t: Float): Color = Color(this).lerp(Color.BLACK, t)
|
||||
/** Linearly interpolates between this [Color] and [WHITE][Color.WHITE] by [t] which is in the range [[0,1]].
|
||||
* The result is returned as a new instance. */
|
||||
fun Color.brighten(t: Float): Color = Color(this).lerp(Color.WHITE, t)
|
||||
|
||||
fun Actor.centerX(parent: Actor){ x = parent.width/2 - width/2 }
|
||||
fun Actor.centerY(parent: Actor){ y = parent.height/2- height/2}
|
||||
fun Actor.center(parent: Actor){ centerX(parent); centerY(parent)}
|
||||
|
@ -246,10 +246,10 @@ object ImageGetter {
|
||||
fun getWonderImage(wonderName: String) = getImage("WonderImages/$wonderName")
|
||||
|
||||
val foodCircleColor = colorFromRGB(129, 199, 132)
|
||||
private val productionCircleColor = Color.BROWN.cpy().lerp(Color.WHITE, 0.5f)
|
||||
private val goldCircleColor = Color.GOLD.cpy().lerp(Color.WHITE, 0.5f)
|
||||
private val cultureCircleColor = Color.PURPLE.cpy().lerp(Color.WHITE, 0.5f)
|
||||
private val scienceCircleColor = Color.BLUE.cpy().lerp(Color.WHITE, 0.5f)
|
||||
private val productionCircleColor = Color.BROWN.brighten(0.5f)
|
||||
private val goldCircleColor = Color.GOLD.brighten(0.5f)
|
||||
private val cultureCircleColor = Color.PURPLE.brighten(0.5f)
|
||||
private val scienceCircleColor = Color.BLUE.brighten(0.5f)
|
||||
private fun getColorFromStats(stats: Stats) = when {
|
||||
stats.food > 0 -> foodCircleColor
|
||||
stats.production > 0 -> productionCircleColor
|
||||
@ -368,7 +368,7 @@ object ImageGetter {
|
||||
fun getTechIcon(techName: String): Image {
|
||||
val techIconColor = ruleset.eras[ruleset.technologies[techName]?.era()]?.getColor()
|
||||
?: return getWhiteDot()
|
||||
return getImage("TechIcons/$techName").apply { color = techIconColor.lerp(Color.BLACK, 0.6f) }
|
||||
return getImage("TechIcons/$techName").apply { color = techIconColor.darken(0.6f) }
|
||||
}
|
||||
|
||||
fun getProgressBarVertical(width: Float, height: Float, percentComplete: Float, progressColor: Color, backgroundColor: Color): Group {
|
||||
|
@ -11,7 +11,7 @@ import java.util.ArrayList
|
||||
/** Represents a row in the Language picker, used both in OptionsPopup and in LanguagePickerScreen */
|
||||
internal class LanguageTable(val language:String, val percentComplete: Int): Table(){
|
||||
private val blue = ImageGetter.getBlue()
|
||||
private val darkBlue = blue.cpy().lerp(Color.BLACK,0.5f)!!
|
||||
private val darkBlue = blue.darken(0.5f)!!
|
||||
|
||||
init{
|
||||
pad(10f)
|
||||
|
@ -27,7 +27,7 @@ open class Popup(val screen: BaseScreen): Table(BaseScreen.skin) {
|
||||
name = javaClass.simpleName
|
||||
|
||||
background = ImageGetter.getBackground(Color.GRAY.cpy().apply { a=.5f })
|
||||
innerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||
innerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f))
|
||||
|
||||
innerTable.pad(20f)
|
||||
innerTable.defaults().pad(5f)
|
||||
|
@ -41,7 +41,7 @@ class TabbedPager(
|
||||
private val headerFontSize: Int = Constants.defaultFontSize,
|
||||
private val headerFontColor: Color = Color.WHITE,
|
||||
private val highlightColor: Color = Color.BLUE,
|
||||
backgroundColor: Color = ImageGetter.getBlue().lerp(Color.BLACK, 0.5f),
|
||||
backgroundColor: Color = ImageGetter.getBlue().darken(0.5f),
|
||||
private val headerPadding: Float = 10f,
|
||||
capacity: Int = 4
|
||||
) : Table() {
|
||||
|
@ -374,7 +374,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
|
||||
val numberCircle = dto.unitToTurnsToDestination.values.maxOrNull()!!.toString().toLabel(fontSize = 14)
|
||||
.apply { setAlignment(Align.center) }
|
||||
.surroundWithCircle(smallerCircleSizes-2, color = ImageGetter.getBlue().lerp(Color.BLACK, 0.3f))
|
||||
.surroundWithCircle(smallerCircleSizes-2, color = ImageGetter.getBlue().darken(0.3f))
|
||||
.surroundWithCircle(smallerCircleSizes,false)
|
||||
|
||||
moveHereButton.addActor(numberCircle)
|
||||
|
@ -82,7 +82,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
|
||||
private val fogOfWarButton = createFogOfWarButton()
|
||||
private val nextTurnButton = createNextTurnButton()
|
||||
private var nextTurnAction: () -> Unit = {}
|
||||
private val tutorialTaskTable = Table().apply { background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) }
|
||||
private val tutorialTaskTable = Table().apply { background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f)) }
|
||||
|
||||
private val notificationsScroll: NotificationsScroll
|
||||
var shouldUpdate = false
|
||||
|
@ -47,7 +47,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
||||
private val happinessGroup = ImageGetter.getStatIcon("Happiness")
|
||||
|
||||
init {
|
||||
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||
background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f))
|
||||
|
||||
add(getStatsTable()).row()
|
||||
add(getResourceTable())
|
||||
|
@ -9,14 +9,11 @@ import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.ui.civilopedia.CivilopediaScreen
|
||||
import com.unciv.ui.civilopedia.FormattedLine.IconDisplay
|
||||
import com.unciv.ui.civilopedia.MarkupRenderer
|
||||
import com.unciv.ui.utils.BaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.addBorderAllowOpacity
|
||||
import com.unciv.ui.utils.toLabel
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
class TileInfoTable(private val viewingCiv :CivilizationInfo) : Table(BaseScreen.skin) {
|
||||
init {
|
||||
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||
background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f))
|
||||
}
|
||||
|
||||
internal fun updateTileTable(tile: TileInfo?) {
|
||||
|
@ -186,7 +186,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
||||
|
||||
val continuousRenderingDescription = "When disabled, saves battery life but certain animations will be suspended"
|
||||
val continuousRenderingLabel = WrappableLabel(continuousRenderingDescription,
|
||||
tabs.prefWidth, Color.ORANGE.cpy().lerp(Color.WHITE, 0.7f), 14)
|
||||
tabs.prefWidth, Color.ORANGE.brighten(0.7f), 14)
|
||||
continuousRenderingLabel.wrap = true
|
||||
add(continuousRenderingLabel).colspan(2).padTop(10f).row()
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
||||
init {
|
||||
pad(5f)
|
||||
touchable = Touchable.enabled
|
||||
background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
|
||||
background = ImageGetter.getBackground(ImageGetter.getBlue().darken(0.5f))
|
||||
|
||||
promotionsTable.touchable=Touchable.enabled
|
||||
|
||||
|
Reference in New Issue
Block a user