Added various styles for displaying resource icons (#8298)

* Added various styles for displaying resource icons

* Removed options, implemented background type color-coding + amount indicator

Co-authored-by: tunerzinc@gmail.com <vfylfhby>
This commit is contained in:
vegeta1k95 2023-01-04 14:42:51 +01:00 committed by GitHub
parent 0be1794e94
commit 5aca35c244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 20 deletions

View File

@ -1,7 +1,13 @@
package com.unciv.models.ruleset.tile
import com.badlogic.gdx.graphics.Color
enum class ResourceType(val color:String) {
Luxury("#ffeb7f"),
Strategic("#c5a189"),
Bonus("#81c784")
Luxury("#ffd800"),
Strategic("#c14d00"),
Bonus("#24A348");
fun getColor() : Color {
return Color.valueOf(color)
}
}

View File

@ -22,7 +22,6 @@ import com.unciv.json.json
import com.unciv.logic.city.PerpetualConstruction
import com.unciv.models.ruleset.Nation
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.skins.SkinCache
import com.unciv.models.stats.Stats
import com.unciv.models.tilesets.TileSetCache
@ -355,24 +354,29 @@ object ImageGetter {
return image
}
fun getResourceImage(resourceName: String, size: Float): IconCircleGroup {
fun getResourceImage(resourceName: String, size: Float, amount: Int = 0): IconCircleGroup {
val iconGroup = getImage("ResourceIcons/$resourceName").surroundWithCircle(size)
val resource = ruleset.tileResources[resourceName]
?: return iconGroup // This is the result of a bad modding setup, just give em an empty circle. Their problem.
iconGroup.circle.color = getColorFromStats(resource)
if (resource.resourceType == ResourceType.Luxury) {
val happiness = getStatIcon("Happiness")
happiness.setSize(size / 2, size / 2)
happiness.x = iconGroup.width - happiness.width
iconGroup.addActor(happiness)
}
if (resource.resourceType == ResourceType.Strategic) {
val production = getStatIcon("Production")
production.setSize(size / 2, size / 2)
production.x = iconGroup.width - production.width
iconGroup.addActor(production)
val color = resource.resourceType.getColor()
iconGroup.circle.color = color
// Show amount indicator for strategic resources (bottom-right)
if (amount > 0) {
val label = amount.toString().toLabel(
fontSize = 8,
fontColor = Color.WHITE,
alignment = Align.center)
val group = label.surroundWithCircle(size/2, true, Color.BLACK)
label.y -= 0.5f
group.x = iconGroup.width - group.width * 2 / 3
group.y = -group.height / 3
iconGroup.addActor(group)
}
return iconGroup.surroundWithThinCircle()
}

View File

@ -170,7 +170,7 @@ class TileGroupIcons(val tileGroup: TileGroup) {
tileGroup.resourceImage?.remove()
if (tileGroup.resource == null) tileGroup.resourceImage = null
else {
val newResourceIcon = ImageGetter.getResourceImage(tileGroup.tileInfo.resource!!, 20f)
val newResourceIcon = ImageGetter.getResourceImage(tileGroup.tileInfo.resource!!, 20f, tileGroup.tileInfo.resourceAmount)
newResourceIcon.center(tileGroup)
newResourceIcon.x = newResourceIcon.x - 22 // left
newResourceIcon.y = newResourceIcon.y + 10 // top

View File

@ -444,7 +444,9 @@ fun String.toLabel() = Label(this.tr(), BaseScreen.skin)
fun Int.toLabel() = this.toString().toLabel()
/** Translate a [String] and make a [Label] widget from it with a specified font color and size */
fun String.toLabel(fontColor: Color = Color.WHITE, fontSize: Int = Constants.defaultFontSize): Label {
fun String.toLabel(fontColor: Color = Color.WHITE,
fontSize: Int = Constants.defaultFontSize,
alignment: Int = Align.left ): Label {
// We don't want to use setFontSize and setFontColor because they set the font,
// which means we need to rebuild the font cache which means more memory allocation.
var labelStyle = BaseScreen.skin.get(Label.LabelStyle::class.java)
@ -453,7 +455,10 @@ fun String.toLabel(fontColor: Color = Color.WHITE, fontSize: Int = Constants.def
labelStyle.fontColor = fontColor
if (fontSize != Constants.defaultFontSize) labelStyle.font = Fonts.font
}
return Label(this.tr(), labelStyle).apply { setFontScale(fontSize / Fonts.ORIGINAL_FONT_SIZE) }
return Label(this.tr(), labelStyle).apply {
setFontScale(fontSize / Fonts.ORIGINAL_FONT_SIZE)
setAlignment(alignment)
}
}
/**