diff --git a/core/src/com/unciv/models/ruleset/tile/ResourceType.kt b/core/src/com/unciv/models/ruleset/tile/ResourceType.kt index 6c644af174..df464945b1 100644 --- a/core/src/com/unciv/models/ruleset/tile/ResourceType.kt +++ b/core/src/com/unciv/models/ruleset/tile/ResourceType.kt @@ -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) + } } diff --git a/core/src/com/unciv/ui/images/ImageGetter.kt b/core/src/com/unciv/ui/images/ImageGetter.kt index 3e310d78e4..91aae66928 100644 --- a/core/src/com/unciv/ui/images/ImageGetter.kt +++ b/core/src/com/unciv/ui/images/ImageGetter.kt @@ -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() } diff --git a/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt b/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt index e357aed4ef..bd4dcd3ec7 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroupIcons.kt @@ -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 diff --git a/core/src/com/unciv/ui/utils/extensions/Scene2dExtensions.kt b/core/src/com/unciv/ui/utils/extensions/Scene2dExtensions.kt index 5a21460b7d..6f5894e804 100644 --- a/core/src/com/unciv/ui/utils/extensions/Scene2dExtensions.kt +++ b/core/src/com/unciv/ui/utils/extensions/Scene2dExtensions.kt @@ -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) + } } /**