From c20944469d1c4bddeb47576fb42ba6ab0fced66b Mon Sep 17 00:00:00 2001 From: yairm210 Date: Thu, 15 Aug 2024 12:47:56 +0300 Subject: [PATCH] UI: Show terrain icons in text --- .../unciv/ui/components/fonts/FontRulesetIcons.kt | 13 +++++++++++++ .../civilopediascreen/CivilopediaImageGetters.kt | 7 +++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/ui/components/fonts/FontRulesetIcons.kt b/core/src/com/unciv/ui/components/fonts/FontRulesetIcons.kt index 5586ab2fa3..bcfde403a1 100644 --- a/core/src/com/unciv/ui/components/fonts/FontRulesetIcons.kt +++ b/core/src/com/unciv/ui/components/fonts/FontRulesetIcons.kt @@ -9,10 +9,12 @@ import com.badlogic.gdx.math.Matrix4 import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group import com.unciv.models.ruleset.Ruleset +import com.unciv.ui.components.extensions.center import com.unciv.ui.components.extensions.setSize import com.unciv.ui.components.fonts.FontRulesetIcons.getPixmapFromActor import com.unciv.ui.images.ImageGetter import com.unciv.ui.images.Portrait +import com.unciv.ui.screens.civilopediascreen.CivilopediaImageGetters import kotlin.math.ceil /** Map all or most Ruleset icons as Actors to unused Char codepoints, @@ -72,6 +74,17 @@ object FontRulesetIcons { if (!ImageGetter.imageExists(fileLocation)) continue addChar(policy.name, ImageGetter.getImage(fileLocation).apply { setSize(Fonts.ORIGINAL_FONT_SIZE) }) } + + for (terrain in ruleset.terrains.values) { + // These ensure that the font icons are correctly sized - tilegroup rendering works differently than others, to account for clickability vs rendered areas + val tileGroup = CivilopediaImageGetters.terrainImage(terrain, ruleset, Fonts.ORIGINAL_FONT_SIZE) + tileGroup.width *= 1.5f + tileGroup.height *= 1.5f + for (layer in tileGroup.children) layer.center(tileGroup) + + addChar(terrain.name, tileGroup) + } + } private val frameBuffer by lazy { diff --git a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt index e0a9ad36e9..d2f23983e2 100644 --- a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt +++ b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaImageGetters.kt @@ -1,8 +1,7 @@ package com.unciv.ui.screens.civilopediascreen import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.scenes.scene2d.Actor -import com.badlogic.gdx.scenes.scene2d.ui.Container +import com.badlogic.gdx.scenes.scene2d.Group import com.unciv.UncivGame import com.unciv.logic.map.tile.Tile import com.unciv.models.ruleset.Ruleset @@ -23,7 +22,7 @@ internal object CivilopediaImageGetters { private const val policyInnerSize = 0.25f // Todo: potential synergy with map editor - private fun terrainImage(terrain: Terrain, ruleset: Ruleset, imageSize: Float): Actor { + internal fun terrainImage(terrain: Terrain, ruleset: Ruleset, imageSize: Float): Group { val tile = Tile() tile.ruleset = ruleset val baseTerrainFromOccursOn = @@ -48,7 +47,7 @@ internal object CivilopediaImageGetters { group.isForceVisible = true group.isForMapEditorIcon = true group.update() - return Container(group) + return group } val construction = { name: String, size: Float ->