diff --git a/core/src/com/unciv/models/gamebasics/Translations.kt b/core/src/com/unciv/models/gamebasics/Translations.kt index 8e6b5acf7a..5c60d260ac 100644 --- a/core/src/com/unciv/models/gamebasics/Translations.kt +++ b/core/src/com/unciv/models/gamebasics/Translations.kt @@ -42,7 +42,11 @@ class Translations : HashMap(){ fun getLanguages(): List { val toReturn = mutableListOf() - toReturn.addAll(values.flatMap { it.keys }.distinct()) + + for(value in values) + for(key in keys) + if(!toReturn.contains(key)) toReturn.add(key) + toReturn.remove("Japanese") // These were for tests but were never actually seriously translated toReturn.remove("Thai") return toReturn diff --git a/core/src/com/unciv/ui/EmpireOverviewScreen.kt b/core/src/com/unciv/ui/EmpireOverviewScreen.kt index 5676e02091..d569056f71 100644 --- a/core/src/com/unciv/ui/EmpireOverviewScreen.kt +++ b/core/src/com/unciv/ui/EmpireOverviewScreen.kt @@ -404,24 +404,25 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ companion object { fun getCivGroup(civ: CivilizationInfo, afterCivNameText:String,currentPlayer:CivilizationInfo): Table { val civGroup = Table() - val civGroupBackground = ImageGetter.getDrawable("OtherIcons/civTableBackground") var labelText = civ.civName.tr()+afterCivNameText var labelColor=Color.WHITE + val backgroundColor:Color if (civ.isDefeated()) { civGroup.add(ImageGetter.getImage("OtherIcons/DisbandUnit")).size(30f) - civGroup.background = civGroupBackground.tint(Color.LIGHT_GRAY) + backgroundColor = Color.LIGHT_GRAY labelColor = Color.BLACK } else if (currentPlayer==civ || UnCivGame.Current.viewEntireMapForDebug || currentPlayer.knows(civ)) { civGroup.add(ImageGetter.getNationIndicator(civ.nation, 30f)) - civGroup.background = civGroupBackground.tint(civ.nation.getOuterColor()) + backgroundColor = civ.nation.getOuterColor() labelColor = civ.nation.getInnerColor() } else { - civGroup.background = civGroupBackground.tint(Color.DARK_GRAY) + backgroundColor = Color.DARK_GRAY labelText = "???" } + civGroup.background = ImageGetter.getTableBackground(backgroundColor) val label = labelText.toLabel(labelColor) label.setAlignment(Align.center) diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt index c4a95ebb76..625ad7c6e5 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt @@ -1,10 +1,15 @@ package com.unciv.ui.cityscreen import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.scenes.scene2d.ui.* +import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.badlogic.gdx.scenes.scene2d.ui.TextField import com.badlogic.gdx.utils.Align import com.unciv.models.gamebasics.tr -import com.unciv.ui.utils.* +import com.unciv.ui.utils.CameraStageBaseScreen +import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.onClick +import com.unciv.ui.utils.toLabel import com.unciv.ui.worldscreen.optionstable.PopupTable class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ @@ -31,12 +36,12 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){ } if(city.isCapital()){ - val starImage = Image(ImageGetter.getDrawable("OtherIcons/Star").tint(Color.LIGHT_GRAY)) + val starImage = ImageGetter.getImage("OtherIcons/Star").apply { color= Color.LIGHT_GRAY } cityNameTable.add(starImage).size(20f).padRight(5f) } if(city.isPuppet){ - val starImage = Image(ImageGetter.getDrawable("OtherIcons/Puppet").tint(Color.LIGHT_GRAY)) + val starImage = ImageGetter.getImage("OtherIcons/Puppet").apply { color= Color.LIGHT_GRAY } cityNameTable.add(starImage).size(20f).padRight(5f) } diff --git a/core/src/com/unciv/ui/pickerscreens/TechButton.kt b/core/src/com/unciv/ui/pickerscreens/TechButton.kt index b57e30bec3..9540e848d7 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechButton.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechButton.kt @@ -17,7 +17,7 @@ class TechButton(techName:String, val techManager: TechManager, isWorldScreen: B init { touchable = Touchable.enabled defaults().pad(10f) - background = ImageGetter.getDrawable("OtherIcons/civTableBackground") + background = ImageGetter.getTableBackground() if (ImageGetter.techIconExists(techName)) add(ImageGetter.getTechIconGroup(techName, 60f)) diff --git a/core/src/com/unciv/ui/tilegroups/CityButton.kt b/core/src/com/unciv/ui/tilegroups/CityButton.kt index b533fb646a..87fcefa17d 100644 --- a/core/src/com/unciv/ui/tilegroups/CityButton.kt +++ b/core/src/com/unciv/ui/tilegroups/CityButton.kt @@ -47,8 +47,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski if (tileGroup.tileInfo.airUnits.isEmpty()) return val secondarycolor = city.civInfo.nation.getInnerColor() val airUnitTable = Table().apply { defaults().pad(5f) } - airUnitTable.background = ImageGetter.getDrawable("OtherIcons/civTableBackground") - .tint(city.civInfo.nation.getOuterColor()) + airUnitTable.background = ImageGetter.getTableBackground(city.civInfo.nation.getOuterColor()) val aircraftImage = ImageGetter.getImage("OtherIcons/Aircraft") aircraftImage.color = secondarycolor airUnitTable.add(aircraftImage).size(15f) @@ -93,8 +92,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski val secondaryColor = city.civInfo.nation.getInnerColor() val iconTable = Table() iconTable.touchable=Touchable.enabled - iconTable.background = ImageGetter.getDrawable("OtherIcons/civTableBackground") - .tint(city.civInfo.nation.getOuterColor()) + iconTable.background = ImageGetter.getTableBackground(city.civInfo.nation.getOuterColor()) if (city.resistanceCounter > 0) { val resistanceImage = ImageGetter.getImage("StatIcons/Resistance") diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index bf5c34b8b4..0bd2e37e5a 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -24,6 +24,29 @@ object ImageGetter { // So, we now use TexturePacker in the DesktopLauncher class to pack all the different images into single images, // and the atlas is what tells us what was packed where. var atlas = TextureAtlas("game.atlas") + + // We then shove all the drawables into a hashmap, because the atlas specifically tells us + // that the search on it is inefficient + val textureRegionDrawables = HashMap() + + init{ + setTextureRegionDrawables() + } + + fun setTextureRegionDrawables(){ + textureRegionDrawables.clear() + for(region in atlas.regions){ + val drawable =TextureRegionDrawable(region) + textureRegionDrawables[region.name] = drawable + } + } + + fun refreshAltas() { + atlas.dispose() // To avoid OutOfMemory exceptions + atlas = TextureAtlas("game.atlas") + setTextureRegionDrawables() + } + fun getWhiteDot() = getImage(whiteDotLocation) fun getDot(dotColor: Color) = getWhiteDot().apply { color = dotColor} @@ -32,29 +55,24 @@ object ImageGetter { } fun getImage(fileName: String): Image { - return Image(getTextureRegion(fileName)) + return Image(getDrawable(fileName)) } - fun getDrawable(fileName: String): TextureRegionDrawable { - val drawable = TextureRegionDrawable(getTextureRegion(fileName)) - drawable.minHeight = 0f - drawable.minWidth = 0f - return drawable + private fun getDrawable(fileName: String): TextureRegionDrawable { + if(textureRegionDrawables.containsKey(fileName)) return textureRegionDrawables[fileName]!! + else return textureRegionDrawables[whiteDotLocation]!! } - private fun getTextureRegion(fileName: String): TextureRegion { - try { - val region = atlas.findRegion(fileName) - - if(region==null) - throw Exception("Could not find $fileName") - return region - } catch (ex: Exception) { - return getTextureRegion(whiteDotLocation) - } + fun getTableBackground(tintColor: Color?=null): Drawable? { + val drawable = getDrawable("OtherIcons/civTableBackground") + drawable.minHeight=0f + drawable.minWidth=0f + if(tintColor==null) return drawable + return drawable.tint(tintColor) } - fun imageExists(fileName:String) = atlas.findRegion(fileName)!=null + + fun imageExists(fileName:String) = textureRegionDrawables.containsKey(fileName) fun techIconExists(techName:String) = imageExists("TechIcons/$techName") fun getStatIcon(statName: String): Image { @@ -153,10 +171,6 @@ object ImageGetter { return getDrawable(whiteDotLocation).tint(color) } - fun refreshAltas() { - atlas.dispose() // To avoid OutOfMemory exceptions - atlas = TextureAtlas("game.atlas") - } fun getResourceImage(resourceName: String, size:Float): Actor { val iconGroup = getImage("ResourceIcons/$resourceName").surroundWithCircle(size) diff --git a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt index 5b155bf8b2..128a14a710 100644 --- a/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt +++ b/core/src/com/unciv/ui/worldscreen/NotificationsScroll.kt @@ -35,7 +35,7 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu listItem.add(ImageGetter.getCircle() .apply { color=notification.color }).size(10f).pad(5f) - listItem.background(ImageGetter.getDrawable("OtherIcons/civTableBackground")) + listItem.background = ImageGetter.getTableBackground() listItem.add(label).pad(5f).padRight(10f) // using a large click area with no gap in between each message item. diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index a8312ea80f..5fc0553e8b 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -260,8 +260,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { if (viewingCiv.tech.currentTechnology() == null) { val buttonPic = Table() - buttonPic.background = ImageGetter.getDrawable("OtherIcons/civTableBackground") - .tint(colorFromRGB(7, 46, 43)) + buttonPic.background = ImageGetter.getTableBackground(colorFromRGB(7, 46, 43)) buttonPic.defaults().pad(20f) buttonPic.add("{Pick a tech}!".toLabel(Color.WHITE,30)) techButtonHolder.add(buttonPic)