From 36a8b368c855c3376d84359e1f6c8387a4512ada Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 13 Apr 2023 16:00:50 +0300 Subject: [PATCH] Arbitrary images in font!!! (#9167) * Arbitrary images in font!!! * Added unit, promotion, and improvement icons to text * Fixed icons in notifications * Removed icons from formatted lines to avoid double-icons * Removed nation icon from next to menu to not have double-icons * Removed nation icon from next to menu to not have double-icons * Icons do not appear in Civilopedia twice * Better Nation texts --- .../com/unciv/models/ruleset/nation/Nation.kt | 5 +- .../unciv/models/translations/Translations.kt | 14 ++-- .../unciv/ui/components/ColorMarkupLabel.kt | 2 +- core/src/com/unciv/ui/components/Fonts.kt | 76 +++++++++++++++++++ .../com/unciv/ui/components/WrappableLabel.kt | 5 +- .../extensions/Scene2dExtensions.kt | 12 ++- core/src/com/unciv/ui/images/ImageGetter.kt | 5 +- core/src/com/unciv/ui/images/Portrait.kt | 2 +- .../TechnologyDescriptions.kt | 12 +-- .../civilopediascreen/CivilopediaScreen.kt | 5 +- .../civilopediascreen/FormattedLine.kt | 5 +- .../civilopediascreen/ICivilopediaText.kt | 2 +- .../ui/screens/newgamescreen/NationTable.kt | 12 +-- .../newgamescreen/PlayerPickerTable.kt | 2 +- .../screens/pickerscreens/TechPickerScreen.kt | 10 +-- .../worldscreen/NotificationsScroll.kt | 16 ++-- .../worldscreen/TechPolicyDiplomacyButtons.kt | 2 +- .../screens/worldscreen/WorldScreenTopBar.kt | 12 +-- 18 files changed, 138 insertions(+), 61 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/nation/Nation.kt b/core/src/com/unciv/models/ruleset/nation/Nation.kt index 13113501bb..7cfcef3fd3 100644 --- a/core/src/com/unciv/models/ruleset/nation/Nation.kt +++ b/core/src/com/unciv/models/ruleset/nation/Nation.kt @@ -191,6 +191,7 @@ class Nation : RulesetObject() { building.hasUnique(UniqueType.HiddenFromCivilopedia) -> continue !religionEnabled && building.hasUnique(UniqueType.HiddenWithoutReligion) -> continue } + yield(FormattedLine(separator = true)) yield(FormattedLine("{${building.name}} -", link=building.makeLink())) if (building.replaces != null && ruleset.buildings.containsKey(building.replaces!!)) { val originalBuilding = ruleset.buildings[building.replaces!!]!! @@ -222,6 +223,7 @@ class Nation : RulesetObject() { private fun getUniqueUnitsText(ruleset: Ruleset) = sequence { for (unit in ruleset.units.values) { if (unit.uniqueTo != name || unit.hasUnique(UniqueType.HiddenFromCivilopedia)) continue + yield(FormattedLine(separator = true)) yield(FormattedLine("{${unit.name}} -", link="Unit/${unit.name}")) if (unit.replaces != null && ruleset.units.containsKey(unit.replaces!!)) { val originalUnit = ruleset.units[unit.replaces!!]!! @@ -260,7 +262,7 @@ class Nation : RulesetObject() { // "{$promotion} ({$effect})" won't work as effect may contain [] and tr() does not support that kind of nesting yield( FormattedLine( - "${promotion.tr()} (${effect.joinToString(",") { it.tr() }})", + "${promotion.tr(true)} (${effect.joinToString(",") { it.tr() }})", link = "Promotion/$promotion", indent = 1 ) ) } @@ -280,6 +282,7 @@ class Nation : RulesetObject() { for (improvement in ruleset.tileImprovements.values) { if (improvement.uniqueTo != name || improvement.hasUnique(UniqueType.HiddenFromCivilopedia)) continue + yield(FormattedLine(separator = true)) yield(FormattedLine(improvement.name, link = "Improvement/${improvement.name}")) yield(FormattedLine(improvement.cloneStats().toString(), indent = 1)) // = (improvement as Stats).toString minus import plus copy overhead if (improvement.terrainsCanBeBuiltOn.isNotEmpty()) { diff --git a/core/src/com/unciv/models/translations/Translations.kt b/core/src/com/unciv/models/translations/Translations.kt index 846931adb7..04d039cae3 100644 --- a/core/src/com/unciv/models/translations/Translations.kt +++ b/core/src/com/unciv/models/translations/Translations.kt @@ -7,6 +7,7 @@ import com.unciv.models.ruleset.RulesetCache import com.unciv.models.ruleset.unique.Unique import com.unciv.models.stats.Stat import com.unciv.models.stats.Stats +import com.unciv.ui.components.Fonts import com.unciv.utils.Log import com.unciv.utils.debug import java.util.* @@ -291,7 +292,7 @@ object TranslationActiveModsCache { * defaults to the input string if no translation is available, * but with placeholder or sentence brackets removed. */ -fun String.tr(): String { +fun String.tr(hideIcons:Boolean = false): String { val language:String = UncivGame.Current.settings.language if (contains('<') && contains('>')) { // Conditionals! /** @@ -307,13 +308,13 @@ fun String.tr(): String { * together into the final fully translated string. */ - var translatedBaseUnique = this.removeConditionals().tr() + var translatedBaseUnique = this.removeConditionals().tr(hideIcons) val conditionals = this.getConditionals().map { it.placeholderText } val conditionsWithTranslation: LinkedHashMap = linkedMapOf() for (conditional in this.getConditionals()) - conditionsWithTranslation[conditional.placeholderText] = conditional.text.tr() + conditionsWithTranslation[conditional.placeholderText] = conditional.text.tr(hideIcons) val translatedConditionals: MutableList = mutableListOf() @@ -401,14 +402,14 @@ fun String.tr(): String { for (i in termsInMessage.indices) { languageSpecificPlaceholder = languageSpecificPlaceholder.replace( "[${termsInTranslationPlaceholder[i]}]", // re-add square brackets to placeholder terms - termsInMessage[i].tr() + termsInMessage[i].tr(hideIcons) ) } return languageSpecificPlaceholder // every component is already translated } if (processCurly) { // Translating partial sentences - return curlyBraceRegex.replace(this) { it.groups[1]!!.value.tr() } + return curlyBraceRegex.replace(this) { it.groups[1]!!.value.tr(hideIcons) } } if (Stats.isStats(this)) return Stats.parse(this).toString() @@ -418,6 +419,9 @@ fun String.tr(): String { val stat = Stat.safeValueOf(this) if (stat != null) return stat.character + translation + if (!hideIcons && Fonts.rulesetObjectNameToChar.containsKey(this)) + return Fonts.rulesetObjectNameToChar[this]!! + translation + return translation } diff --git a/core/src/com/unciv/ui/components/ColorMarkupLabel.kt b/core/src/com/unciv/ui/components/ColorMarkupLabel.kt index cb0901e723..72cc1dcdb2 100644 --- a/core/src/com/unciv/ui/components/ColorMarkupLabel.kt +++ b/core/src/com/unciv/ui/components/ColorMarkupLabel.kt @@ -114,7 +114,7 @@ class ColorMarkupLabel private constructor( val sb = StringBuilder(translated.length + 42) var currentColor = ' ' for (char in translated) { - val newColor = if (char in Fonts.allSymbols) 'S' else 'T' + val newColor = if (char in Fonts.allSymbols || char in Fonts.charToRulesetImageActor) 'S' else 'T' if (newColor != currentColor) { if (currentColor != ' ') sb.append("[]") sb.append('[') diff --git a/core/src/com/unciv/ui/components/Fonts.kt b/core/src/com/unciv/ui/components/Fonts.kt index 183c1f2771..627782a88d 100644 --- a/core/src/com/unciv/ui/components/Fonts.kt +++ b/core/src/com/unciv/ui/components/Fonts.kt @@ -1,6 +1,8 @@ package com.unciv.ui.components +import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.BitmapFont @@ -8,12 +10,16 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData import com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph import com.badlogic.gdx.graphics.g2d.GlyphLayout import com.badlogic.gdx.graphics.g2d.PixmapPacker +import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion +import com.badlogic.gdx.graphics.glutils.FrameBuffer +import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Disposable import com.unciv.Constants import com.unciv.GUI import com.unciv.UncivGame +import com.unciv.models.ruleset.Ruleset import com.unciv.models.translations.tr import com.unciv.ui.images.ImageGetter @@ -154,6 +160,8 @@ class NativeBitmapFontData( MayaCalendar.katun -> getPixmap(MayaCalendar.katunIcon) MayaCalendar.baktun -> getPixmap(MayaCalendar.baktunIcon) in MayaCalendar.digits -> getPixmap(MayaCalendar.digitIcon(ch)) + in Fonts.charToRulesetImageActor -> Fonts.getPixmapFromActor( + Fonts.charToRulesetImageActor[ch]!!) else -> fontImplementation.getCharPixmap(ch) } } @@ -191,6 +199,7 @@ object Fonts { val settings = GUI.getSettings() fontImplementation.setFontFamily(settings.fontFamilyData, settings.getFontSize()) font = fontImplementation.getBitmapFont() + font.data.markupEnabled = true } /** Reduce the font list returned by platform-specific code to font families (plain variant if possible) */ @@ -231,6 +240,73 @@ object Fonts { return pixmap } + val rulesetObjectNameToChar =HashMap() + val charToRulesetImageActor = HashMap() + // See https://en.wikipedia.org/wiki/Private_Use_Areas - char encodings 57344 63743 are not assigned + var nextUnusedCharacterNumber = 57344 + fun addRulesetImages(ruleset:Ruleset) { + rulesetObjectNameToChar.clear() + charToRulesetImageActor.clear() + nextUnusedCharacterNumber = 57344 + + fun addChar(objectName:String, objectActor: Actor){ + val char = Char(nextUnusedCharacterNumber) + nextUnusedCharacterNumber++ + rulesetObjectNameToChar[objectName] = char + charToRulesetImageActor[char] = objectActor + } + + for (resourceName in ruleset.tileResources.keys) + addChar(resourceName, ImageGetter.getResourcePortrait(resourceName, ORIGINAL_FONT_SIZE)) + + for (buildingName in ruleset.buildings.keys) + addChar(buildingName, ImageGetter.getConstructionPortrait(buildingName, ORIGINAL_FONT_SIZE)) + + for (unitName in ruleset.units.keys) + addChar(unitName, ImageGetter.getConstructionPortrait(unitName, ORIGINAL_FONT_SIZE)) + + for (promotionName in ruleset.unitPromotions.keys) + addChar(promotionName, ImageGetter.getPromotionPortrait(promotionName, ORIGINAL_FONT_SIZE)) + + for (improvementName in ruleset.tileImprovements.keys) + addChar(improvementName, ImageGetter.getImprovementPortrait(improvementName, ORIGINAL_FONT_SIZE)) + + for (techName in ruleset.technologies.keys) + addChar(techName, ImageGetter.getTechIconPortrait(techName, ORIGINAL_FONT_SIZE)) + + for (nation in ruleset.nations.values) + addChar(nation.name, ImageGetter.getNationPortrait(nation, ORIGINAL_FONT_SIZE)) + } + + fun getPixmapFromActor(actor: Actor): Pixmap { + val spriteBatch = SpriteBatch() + + val frameBuffer = + FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false) + frameBuffer.begin() + + spriteBatch.begin() + actor.draw(spriteBatch, 1f) + spriteBatch.end() + + val w = actor.width.toInt() + val h = actor.height.toInt() + val pixmap = Pixmap(w, h, Pixmap.Format.RGBA8888) + Gdx.gl.glReadPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixmap.pixels) + frameBuffer.end() + + // Pixmap is now *upside down* so we need to flip it around the y axis + for (i in 0..w) + for (j in 0..h/2) { + val topPixel = pixmap.getPixel(i,j) + val bottomPixel = pixmap.getPixel(i, h-j) + pixmap.drawPixel(i,j,bottomPixel) + pixmap.drawPixel(i,h-j,topPixel) + } + + return pixmap + } + const val turn = '⏳' // U+23F3 'hourglass' const val strength = '†' // U+2020 'dagger' const val rangedStrength = '‡' // U+2021 'double dagger' diff --git a/core/src/com/unciv/ui/components/WrappableLabel.kt b/core/src/com/unciv/ui/components/WrappableLabel.kt index b0c3e78e55..d7f042e6b7 100644 --- a/core/src/com/unciv/ui/components/WrappableLabel.kt +++ b/core/src/com/unciv/ui/components/WrappableLabel.kt @@ -17,8 +17,9 @@ class WrappableLabel( text: String, private val expectedWidth: Float, fontColor: Color = Color.WHITE, - private val fontSize: Int = Constants.defaultFontSize -) : Label(text.tr(), BaseScreen.skin) { + private val fontSize: Int = Constants.defaultFontSize, + hideIcons: Boolean = false +) : Label(text.tr(hideIcons), BaseScreen.skin) { private var _measuredWidth = 0f private var optimizedWidth = Float.MAX_VALUE diff --git a/core/src/com/unciv/ui/components/extensions/Scene2dExtensions.kt b/core/src/com/unciv/ui/components/extensions/Scene2dExtensions.kt index ac7f77515b..0b0d7502c8 100644 --- a/core/src/com/unciv/ui/components/extensions/Scene2dExtensions.kt +++ b/core/src/com/unciv/ui/components/extensions/Scene2dExtensions.kt @@ -30,13 +30,16 @@ import com.unciv.Constants import com.unciv.models.UncivSound import com.unciv.models.translations.tr import com.unciv.ui.audio.SoundPlayer -import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.Fonts import com.unciv.ui.components.KeyCharAndCode import com.unciv.ui.components.KeyShortcutDispatcher import com.unciv.ui.components.KeyboardBinding +import com.unciv.ui.components.extensions.GdxKeyCodeFixes.DEL +import com.unciv.ui.components.extensions.GdxKeyCodeFixes.toString +import com.unciv.ui.components.extensions.GdxKeyCodeFixes.valueOf import com.unciv.ui.images.IconCircleGroup import com.unciv.ui.images.ImageGetter +import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.utils.concurrency.Concurrency /** @@ -493,8 +496,9 @@ 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, - alignment: Int = Align.left ): Label { + fontSize: Int = Constants.defaultFontSize, + alignment: Int = Align.left, + hideIcons: Boolean = false): 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) @@ -503,7 +507,7 @@ fun String.toLabel(fontColor: Color = Color.WHITE, labelStyle.fontColor = fontColor if (fontSize != Constants.defaultFontSize) labelStyle.font = Fonts.font } - return Label(this.tr(), labelStyle).apply { + return Label(this.tr(hideIcons), labelStyle).apply { setFontScale(fontSize / Fonts.ORIGINAL_FONT_SIZE) setAlignment(alignment) } diff --git a/core/src/com/unciv/ui/images/ImageGetter.kt b/core/src/com/unciv/ui/images/ImageGetter.kt index 4977bae14b..de8e292024 100644 --- a/core/src/com/unciv/ui/images/ImageGetter.kt +++ b/core/src/com/unciv/ui/images/ImageGetter.kt @@ -20,8 +20,8 @@ import com.unciv.Constants import com.unciv.UncivGame import com.unciv.json.json import com.unciv.logic.city.PerpetualConstruction -import com.unciv.models.ruleset.nation.Nation import com.unciv.models.ruleset.Ruleset +import com.unciv.models.ruleset.nation.Nation import com.unciv.models.skins.SkinCache import com.unciv.models.tilesets.TileSetCache import com.unciv.ui.components.* @@ -74,6 +74,9 @@ object ImageGetter { TileSetCache.assembleTileSetConfigs(ruleset.mods) SkinCache.assembleSkinConfigs(ruleset.mods) + + Fonts.resetFont() + Fonts.addRulesetImages(ruleset) } /** Loads all atlas/texture files from a folder, as controlled by an Atlases.json */ diff --git a/core/src/com/unciv/ui/images/Portrait.kt b/core/src/com/unciv/ui/images/Portrait.kt index 6980bad505..ef84ea2bdb 100644 --- a/core/src/com/unciv/ui/images/Portrait.kt +++ b/core/src/com/unciv/ui/images/Portrait.kt @@ -70,7 +70,7 @@ open class Portrait(val type: Type, val imageName: String, val size: Float, val } /** Inner image */ - private fun getMainImage() : Image { + fun getMainImage() : Image { return when { ImageGetter.imageExists(pathPortrait) -> { isPortrait = true diff --git a/core/src/com/unciv/ui/objectdescriptions/TechnologyDescriptions.kt b/core/src/com/unciv/ui/objectdescriptions/TechnologyDescriptions.kt index e460d10319..7b785d32f1 100644 --- a/core/src/com/unciv/ui/objectdescriptions/TechnologyDescriptions.kt +++ b/core/src/com/unciv/ui/objectdescriptions/TechnologyDescriptions.kt @@ -42,7 +42,7 @@ object TechnologyDescriptions { if (enabledUnits.any()) { lineList += "{Units enabled}: " for (unit in enabledUnits) - lineList += " • " + unit.name.tr() + " (" + unit.getShortDescription() + ")" + lineList += " • ${unit.name.tr()} (${unit.getShortDescription()})\n" } val (wonders, regularBuildings) = getEnabledBuildings(name, ruleset, viewingCiv) @@ -51,13 +51,13 @@ object TechnologyDescriptions { if (regularBuildings.isNotEmpty()) { lineList += "{Buildings enabled}: " for (building in regularBuildings) - lineList += " • " + building.name.tr() + " (" + building.getShortDescription() + ")" + lineList += " • ${building.name.tr()} (${building.getShortDescription()})\n" } if (wonders.isNotEmpty()) { lineList += "{Wonders enabled}: " for (wonder in wonders) - lineList += " • " + wonder.name.tr() + " (" + wonder.getShortDescription() + ")" + lineList += " • ${wonder.name.tr()} (${wonder.getShortDescription()})\n" } for (obj in getObsoletedObjects(name, ruleset, viewingCiv)) @@ -204,7 +204,7 @@ object TechnologyDescriptions { lineList += FormattedLine() lineList += FormattedLine("{Units enabled}:") for (unit in enabledUnits) - lineList += FormattedLine(unit.name.tr() + " (" + unit.getShortDescription() + ")", link = unit.makeLink()) + lineList += FormattedLine(unit.name.tr(true) + " (" + unit.getShortDescription() + ")", link = unit.makeLink()) } val (wonders, regularBuildings) = getEnabledBuildings(name, ruleset, null) @@ -214,14 +214,14 @@ object TechnologyDescriptions { lineList += FormattedLine() lineList += FormattedLine("{Wonders enabled}:") for (wonder in wonders) - lineList += FormattedLine(wonder.name.tr() + " (" + wonder.getShortDescription() + ")", link = wonder.makeLink()) + lineList += FormattedLine(wonder.name.tr(true) + " (" + wonder.getShortDescription() + ")", link = wonder.makeLink()) } if (regularBuildings.isNotEmpty()) { lineList += FormattedLine() lineList += FormattedLine("{Buildings enabled}:") for (building in regularBuildings) - lineList += FormattedLine(building.name.tr() + " (" + building.getShortDescription() + ")", link = building.makeLink()) + lineList += FormattedLine(building.name.tr(true) + " (" + building.getShortDescription() + ")", link = building.makeLink()) } val obsoletedObjects = getObsoletedObjects(name, ruleset, null).toList() diff --git a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt index 012d5bab82..37bdfe7153 100644 --- a/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/screens/civilopediascreen/CivilopediaScreen.kt @@ -122,7 +122,7 @@ class CivilopediaScreen( compareBy{ it.sortBy } .thenBy (UncivGame.Current.settings.getCollatorFromLocale()) { // In order for the extra icons on Happiness and Faith to not affect sort order - it.name.tr().replace(Fonts.happiness.toString(),"").replace(Fonts.faith.toString(),"") }) + it.name.tr(true).replace(Fonts.happiness.toString(),"").replace(Fonts.faith.toString(),"") }) var currentY = -1f @@ -139,7 +139,8 @@ class CivilopediaScreen( entryButton.add(entry.image).padLeft(20f).padRight(10f) else entryButton.add(entry.image).padLeft(10f) - entryButton.left().add(entry.name.toLabel(Color.WHITE, 25)).pad(10f) + entryButton.left().add(entry.name + .toLabel(Color.WHITE, 25, hideIcons=true)).pad(10f) entryButton.onClick { selectEntry(entry) } entryButton.name = entry.name // make button findable val cell = entrySelectTable.add(entryButton).height(75f).expandX().fillX() diff --git a/core/src/com/unciv/ui/screens/civilopediascreen/FormattedLine.kt b/core/src/com/unciv/ui/screens/civilopediascreen/FormattedLine.kt index 53f53016a0..43b0490ffc 100644 --- a/core/src/com/unciv/ui/screens/civilopediascreen/FormattedLine.kt +++ b/core/src/com/unciv/ui/screens/civilopediascreen/FormattedLine.kt @@ -11,9 +11,9 @@ import com.unciv.models.metadata.BaseRuleset import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.RulesetCache import com.unciv.models.ruleset.unique.Unique +import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.images.ImageGetter import com.unciv.ui.screens.basescreen.BaseScreen -import com.unciv.ui.components.extensions.toLabel import com.unciv.utils.Log import kotlin.math.max @@ -285,8 +285,7 @@ class FormattedLine ( else -> (indent-1) * indentPad + indentOneAtNumIcons * (minIconSize + iconPad) + iconPad - usedWidth } - val label = if (fontSize == Constants.defaultFontSize && labelColor == defaultColor) textToDisplay.toLabel() - else textToDisplay.toLabel(labelColor,fontSize) + val label = textToDisplay.toLabel(labelColor, fontSize, hideIcons = iconCount!=0) label.wrap = !centered && labelWidth > 0f label.setAlignment(align) if (labelWidth == 0f) diff --git a/core/src/com/unciv/ui/screens/civilopediascreen/ICivilopediaText.kt b/core/src/com/unciv/ui/screens/civilopediascreen/ICivilopediaText.kt index 76d00cb0c8..1ed8e632aa 100644 --- a/core/src/com/unciv/ui/screens/civilopediascreen/ICivilopediaText.kt +++ b/core/src/com/unciv/ui/screens/civilopediascreen/ICivilopediaText.kt @@ -1,9 +1,9 @@ package com.unciv.ui.screens.civilopediascreen import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.unciv.UncivGame import com.unciv.models.ruleset.Ruleset import com.unciv.models.stats.INamed -import com.unciv.UncivGame // Kdoc only /** Addon common to most ruleset game objects managing civilopedia display diff --git a/core/src/com/unciv/ui/screens/newgamescreen/NationTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/NationTable.kt index f231160d75..5acdc480bc 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/NationTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/NationTable.kt @@ -6,14 +6,14 @@ import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align import com.unciv.Constants -import com.unciv.models.ruleset.nation.Nation import com.unciv.models.ruleset.Ruleset -import com.unciv.ui.screens.civilopediascreen.FormattedLine.IconDisplay -import com.unciv.ui.screens.civilopediascreen.MarkupRenderer -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.screens.basescreen.BaseScreen +import com.unciv.models.ruleset.nation.Nation import com.unciv.ui.components.WrappableLabel import com.unciv.ui.components.extensions.pad +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.screens.basescreen.BaseScreen +import com.unciv.ui.screens.civilopediascreen.FormattedLine.IconDisplay +import com.unciv.ui.screens.civilopediascreen.MarkupRenderer // The ruleset also acts as a secondary parameter to determine if this is the right or self side of the player picker class NationTable(val nation: Nation, width: Float, minHeight: Float, ruleset: Ruleset? = null) @@ -40,7 +40,7 @@ class NationTable(val nation: Nation, width: Float, minHeight: Float, ruleset: R val titleText = if (ruleset == null || nation.name == Constants.random || nation.name == Constants.spectator) nation.name else nation.getLeaderDisplayName() val leaderDisplayNameMaxWidth = internalWidth - 70f // for the nation indicator with padding - val leaderDisplayLabel = WrappableLabel(titleText, leaderDisplayNameMaxWidth, innerColor, Constants.headingFontSize) + val leaderDisplayLabel = WrappableLabel(titleText, leaderDisplayNameMaxWidth, innerColor, Constants.headingFontSize, hideIcons = true) if (leaderDisplayLabel.prefWidth > leaderDisplayNameMaxWidth - 2f) { leaderDisplayLabel.wrap = true titleTable.add(leaderDisplayLabel).width(leaderDisplayNameMaxWidth) diff --git a/core/src/com/unciv/ui/screens/newgamescreen/PlayerPickerTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/PlayerPickerTable.kt index b0bd115030..5a94f8d499 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/PlayerPickerTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/PlayerPickerTable.kt @@ -280,7 +280,7 @@ class PlayerPickerTable( ImageGetter.getRandomNationPortrait(40f) else ImageGetter.getNationPortrait(nationImageName, 40f) nationTable.add(nationImage).pad(5f) - nationTable.add(player.chosenCiv.toLabel()).pad(5f) + nationTable.add(player.chosenCiv.toLabel(hideIcons = true)).pad(5f) nationTable.touchable = Touchable.enabled return nationTable } diff --git a/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt index 062f7d9e85..a892c2f657 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/TechPickerScreen.kt @@ -15,10 +15,6 @@ import com.unciv.models.UncivSound import com.unciv.models.ruleset.tech.Technology import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.translations.tr -import com.unciv.ui.screens.civilopediascreen.CivilopediaCategories -import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.popups.ToastPopup import com.unciv.ui.components.Fonts import com.unciv.ui.components.extensions.colorFromRGB import com.unciv.ui.components.extensions.darken @@ -27,6 +23,10 @@ import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.onDoubleClick import com.unciv.ui.components.extensions.surroundWithCircle import com.unciv.ui.components.extensions.toLabel +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.popups.ToastPopup +import com.unciv.ui.screens.civilopediascreen.CivilopediaCategories +import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen import com.unciv.utils.concurrency.Concurrency import kotlin.math.abs @@ -220,7 +220,7 @@ class TechPickerScreen( techButton.turns.setText(turnsToTech[techName] + "${Fonts.turn}".tr()) } - techButton.text.setText(techName.tr()) + techButton.text.setText(techName.tr(true)) } addConnectingLines() diff --git a/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt b/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt index 4f4de4a0ff..9a12e3c7bb 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/NotificationsScroll.kt @@ -14,13 +14,12 @@ import com.unciv.GUI import com.unciv.logic.civilization.Notification import com.unciv.logic.civilization.NotificationCategory import com.unciv.ui.components.ColorMarkupLabel -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.screens.basescreen.BaseScreen -import com.unciv.ui.components.WrappableLabel import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.packIfNeeded import com.unciv.ui.components.extensions.surroundWithCircle import com.unciv.ui.images.IconCircleGroup +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.AutoScrollPane as ScrollPane /*TODO @@ -251,14 +250,11 @@ class NotificationsScroll( listItem.background = backgroundDrawable val maxLabelWidth = maxEntryWidth - (iconSize + 5f) * notification.icons.size - 10f - val label = WrappableLabel(notification.text, maxLabelWidth, Color.BLACK, fontSize) + val label = ColorMarkupLabel(notification.text, Color.BLACK, fontSize= fontSize) + label.width = maxLabelWidth + label.wrap = true label.setAlignment(Align.center) - if (label.prefWidth > maxLabelWidth * scaleFactor) { // can't explain why the comparison needs scaleFactor - label.wrap = true - listItem.add(label).maxWidth(label.optimizePrefWidth()).padRight(10f) - } else { - listItem.add(label).padRight(10f) - } + listItem.add(label).padRight(10f) notification.addNotificationIconsTo(listItem, worldScreen.gameInfo.ruleset, iconSize) diff --git a/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt b/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt index b02bbf452d..5b579e972e 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt @@ -105,7 +105,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree innerButton.setButtonColor(colorFromRGB(7, 46, 43)) techButtonHolder.actor = innerButton val turnsToTech = viewingCiv.tech.turnsToTech(currentTech) - innerButton.text.setText(currentTech.tr()) + innerButton.text.setText(currentTech.tr(true)) innerButton.turns.setText(turnsToTech + Fonts.turn) } else { val canResearch = viewingCiv.tech.canResearchTech() diff --git a/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt b/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt index 4c32c123f4..580d354085 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt @@ -5,7 +5,6 @@ import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Cell -import com.badlogic.gdx.scenes.scene2d.ui.Container import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align @@ -203,7 +202,6 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() { private class SelectedCivilizationTable(worldScreen: WorldScreen) : Table(BaseScreen.skin) { private var selectedCiv = "" private val selectedCivLabel = "".toLabel() - private val selectedCivIconHolder = Container() private val menuButton = ImageGetter.getImage("OtherIcons/MenuIcon") init { @@ -227,13 +225,8 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() { worldScreen.game.pushScreen(civilopediaScreen) } - selectedCivIconHolder.onClick { - worldScreen.openEmpireOverview() - } - add(menuButton).size(50f).padRight(0f) - add(selectedCivLabel).padRight(0f) - add(selectedCivIconHolder).size(35f) + add(selectedCivLabel).padRight(10f) pack() } @@ -243,9 +236,6 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() { this.selectedCiv = newCiv selectedCivLabel.setText(newCiv.tr()) - val nation = worldScreen.gameInfo.ruleset.nations[worldScreen.selectedCiv.civName]!! - val selectedCivIcon = ImageGetter.getNationPortrait(nation, 35f) - selectedCivIconHolder.actor = selectedCivIcon invalidate() pack() }