mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 18:59:15 +07:00
Performance improvements for NativeFont - separated chinese and other charsForFonts,
since the chinese have hundreds of chars and it makes the font loading time really long
This commit is contained in:
@ -11,10 +11,10 @@ import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.ui.worldscreen.optionstable.PopupTable
|
||||
import core.java.nativefont.NativeFont
|
||||
import core.java.nativefont.NativeFontPaint
|
||||
import java.io.FileOutputStream
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URL
|
||||
import java.security.*
|
||||
import java.security.MessageDigest
|
||||
|
||||
class Fonts {
|
||||
companion object {
|
||||
@ -52,7 +52,8 @@ class Fonts {
|
||||
return true
|
||||
return false
|
||||
}
|
||||
fun getCharsForFont(): String {
|
||||
|
||||
fun getCharsForFont(withChinese:Boolean): String {
|
||||
val defaultText = "ABCČĆDĐEFGHIJKLMNOPQRSŠTUVWXYZŽaäàâăbcčćçdđeéfghiîjklmnoöpqrsșštțuüvwxyzž" +
|
||||
"АБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюя" +
|
||||
"ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάßΆέΈέΉίϊΐΊόΌύΰϋΎΫΏ" +
|
||||
@ -61,19 +62,21 @@ class Fonts {
|
||||
val charSet = HashSet<Char>()
|
||||
charSet.addAll(defaultText.asIterable())
|
||||
|
||||
if(Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").exists())
|
||||
charSet.addAll(Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").readString().asIterable())
|
||||
if (Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").exists())
|
||||
charSet.addAll(Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").readString().asIterable())
|
||||
if (Gdx.files.internal("jsons/Tutorials/Tutorials_Simplified_Chinese.json").exists())
|
||||
charSet.addAll(Gdx.files.internal("jsons/Tutorials/Tutorials_Simplified_Chinese.json").readString().asIterable())
|
||||
if(withChinese) {
|
||||
if (Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").exists())
|
||||
charSet.addAll(Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").readString().asIterable())
|
||||
if (Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").exists())
|
||||
charSet.addAll(Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").readString().asIterable())
|
||||
if (Gdx.files.internal("jsons/Tutorials/Tutorials_Simplified_Chinese.json").exists())
|
||||
charSet.addAll(Gdx.files.internal("jsons/Tutorials/Tutorials_Simplified_Chinese.json").readString().asIterable())
|
||||
|
||||
for (entry in GameBasics.Translations.entries) {
|
||||
for (lang in entry.value) {
|
||||
if (lang.key.contains("Chinese")) charSet.addAll(lang.value.asIterable())
|
||||
for (entry in GameBasics.Translations.entries) {
|
||||
for (lang in entry.value) {
|
||||
if (lang.key.contains("Chinese")) charSet.addAll(lang.value.asIterable())
|
||||
}
|
||||
}
|
||||
}
|
||||
return charSet.joinToString()
|
||||
return charSet.joinToString("")
|
||||
}
|
||||
fun getFont(size: Int): BitmapFont {
|
||||
if(UnCivGame.Current.settings.fontSet=="WenQuanYiMicroHei"){
|
||||
@ -97,17 +100,19 @@ class Fonts {
|
||||
parameter.size = size
|
||||
parameter.minFilter = Texture.TextureFilter.Linear
|
||||
parameter.magFilter = Texture.TextureFilter.Linear
|
||||
parameter.characters = getCharsForFont()
|
||||
parameter.characters = getCharsForFont(true)
|
||||
val font = generator.generateFont(parameter)
|
||||
fontCache[keyForFont] = font
|
||||
return font
|
||||
}
|
||||
}
|
||||
val fontForLanguage ="Nativefont"
|
||||
val keyForFont = "$fontForLanguage $size"
|
||||
if (fontCache.containsKey(keyForFont))return fontCache[keyForFont]!!
|
||||
val withChinese = UnCivGame.Current.settings.language.contains("Chinese")
|
||||
val keyForFont = if(!withChinese) "$fontForLanguage $size" else "$fontForLanguage $size withChinese" // different cache for chinese
|
||||
if (fontCache.containsKey(keyForFont)) return fontCache[keyForFont]!!
|
||||
val font=NativeFont(NativeFontPaint(size))
|
||||
font.appendText(getCharsForFont())
|
||||
val charsForFont = getCharsForFont(withChinese)
|
||||
font.appendText(charsForFont)
|
||||
fontCache[keyForFont] = font
|
||||
return font
|
||||
}
|
||||
|
@ -3,7 +3,10 @@ package com.unciv.ui.worldscreen.optionstable
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.UnCivGame
|
||||
@ -280,13 +283,15 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
|
||||
GameBasics.Translations.filter { !it.value.containsKey(currentLanguage) }.forEach { missingTextArray.add(it.key) }
|
||||
missingTextSelectBox.items = missingTextArray
|
||||
missingTextSelectBox.selected = "Untranslated texts"
|
||||
innerTable.add(missingTextSelectBox).pad(10f).width(UnCivGame.Current.worldScreen.stage.width / 2).colspan(2).row()
|
||||
innerTable.add(missingTextSelectBox).pad(10f)
|
||||
.width(screen.stage.width / 2).colspan(2).row()
|
||||
}
|
||||
}
|
||||
|
||||
fun selectLanguage(){
|
||||
UnCivGame.Current.settings.language = selectedLanguage
|
||||
UnCivGame.Current.settings.save()
|
||||
CameraStageBaseScreen.resetFonts() // to load chinese characters if necessary
|
||||
UnCivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv)
|
||||
UnCivGame.Current.setWorldScreen()
|
||||
WorldScreenOptionsTable(UnCivGame.Current.worldScreen)
|
||||
|
Reference in New Issue
Block a user