Stat colors unified - for use in notifications, improvements, yield icons, etc

This commit is contained in:
Yair Morgenstern
2022-07-15 12:36:39 +03:00
parent d9389b3c4e
commit 0716350a3e
3 changed files with 23 additions and 23 deletions

View File

@ -1,21 +1,24 @@
package com.unciv.models.stats
import com.badlogic.gdx.graphics.Color
import com.unciv.logic.civilization.NotificationIcon
import com.unciv.models.UncivSound
import com.unciv.ui.utils.Fonts
import com.unciv.ui.utils.extensions.colorFromHex
enum class Stat(
val notificationIcon: String,
val purchaseSound: UncivSound,
val character: Char
val character: Char,
val color:Color
) {
Production(NotificationIcon.Production, UncivSound.Click, Fonts.production),
Food(NotificationIcon.Food, UncivSound.Click, Fonts.food),
Gold(NotificationIcon.Gold, UncivSound.Coin, Fonts.gold),
Science(NotificationIcon.Science, UncivSound.Chimes, Fonts.science),
Culture(NotificationIcon.Culture, UncivSound.Paper, Fonts.culture),
Happiness(NotificationIcon.Happiness, UncivSound.Click, Fonts.happiness),
Faith(NotificationIcon.Faith, UncivSound.Choir, Fonts.faith);
Production(NotificationIcon.Production, UncivSound.Click, Fonts.production, colorFromHex(0xc14d00)),
Food(NotificationIcon.Food, UncivSound.Click, Fonts.food, colorFromHex(0x24A348)),
Gold(NotificationIcon.Gold, UncivSound.Coin, Fonts.gold, colorFromHex(0xffeb7f)),
Science(NotificationIcon.Science, UncivSound.Chimes, Fonts.science, colorFromHex(0x8c9dff)),
Culture(NotificationIcon.Culture, UncivSound.Paper, Fonts.culture, colorFromHex(0x8b60ff)),
Happiness(NotificationIcon.Happiness, UncivSound.Click, Fonts.happiness, colorFromHex(0xffd800)),
Faith(NotificationIcon.Faith, UncivSound.Choir, Fonts.faith, colorFromHex(0xcbdfff));
companion object {
val statsUsableToBuy = setOf(Gold, Food, Science, Culture, Faith)
@ -26,6 +29,3 @@ enum class Stat(
val statsWithCivWideField = setOf(Gold, Science, Culture, Faith)
}
}
// Should the well-known colours for these be needed:
// Production = "#c14d00", Food = "#38ff70", Gold = "#ffeb7f", Science = "#8c9dff", Culture = "#8b60ff", Happiness = "#ffd800", Faith = "#cbdfff"

View File

@ -247,18 +247,10 @@ object ImageGetter {
fun wonderImageExists(wonderName: String) = imageExists("WonderImages/$wonderName")
fun getWonderImage(wonderName: String) = getImage("WonderImages/$wonderName")
private val foodCircleColor = colorFromRGB(129, 199, 132)
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
stats.gold > 0 -> goldCircleColor
stats.culture > 0 -> cultureCircleColor
stats.science > 0 -> scienceCircleColor
else -> Color.WHITE
private fun getColorFromStats(stats: Stats): Color? {
if (stats.asSequence().none { it.value > 0 }) return Color.WHITE
val highestStat = stats.asSequence().maxByOrNull { it.value }!!
return highestStat.key.color
}

View File

@ -71,6 +71,14 @@ var Button.isEnabled: Boolean
get() = touchable == Touchable.enabled
set(value) = if (value) enable() else disable()
fun colorFromHex(hexColor: Int): Color {
val colorSize = 16 * 16 // 2 hexadecimal digits
val r = hexColor / (colorSize * colorSize)
val g = (hexColor / colorSize) % colorSize
val b = hexColor % colorSize
return colorFromRGB(r, g, b)
}
/** 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)
/** 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] */