mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-25 23:29:47 +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 com.unciv.ui.worldscreen.optionstable.PopupTable
|
||||||
import core.java.nativefont.NativeFont
|
import core.java.nativefont.NativeFont
|
||||||
import core.java.nativefont.NativeFontPaint
|
import core.java.nativefont.NativeFontPaint
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.security.*
|
import java.security.MessageDigest
|
||||||
|
|
||||||
class Fonts {
|
class Fonts {
|
||||||
companion object {
|
companion object {
|
||||||
@ -52,7 +52,8 @@ class Fonts {
|
|||||||
return true
|
return true
|
||||||
return false
|
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ž" +
|
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>()
|
val charSet = HashSet<Char>()
|
||||||
charSet.addAll(defaultText.asIterable())
|
charSet.addAll(defaultText.asIterable())
|
||||||
|
|
||||||
if(Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").exists())
|
if(withChinese) {
|
||||||
charSet.addAll(Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").readString().asIterable())
|
if (Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").exists())
|
||||||
if (Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").exists())
|
charSet.addAll(Gdx.files.internal("jsons/BasicHelp/BasicHelp_Simplified_Chinese.json").readString().asIterable())
|
||||||
charSet.addAll(Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").readString().asIterable())
|
if (Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").exists())
|
||||||
if (Gdx.files.internal("jsons/Tutorials/Tutorials_Simplified_Chinese.json").exists())
|
charSet.addAll(Gdx.files.internal("jsons/Nations_Simplified_Chinese.json").readString().asIterable())
|
||||||
charSet.addAll(Gdx.files.internal("jsons/Tutorials/Tutorials_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 (entry in GameBasics.Translations.entries) {
|
||||||
for (lang in entry.value) {
|
for (lang in entry.value) {
|
||||||
if (lang.key.contains("Chinese")) charSet.addAll(lang.value.asIterable())
|
if (lang.key.contains("Chinese")) charSet.addAll(lang.value.asIterable())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return charSet.joinToString()
|
return charSet.joinToString("")
|
||||||
}
|
}
|
||||||
fun getFont(size: Int): BitmapFont {
|
fun getFont(size: Int): BitmapFont {
|
||||||
if(UnCivGame.Current.settings.fontSet=="WenQuanYiMicroHei"){
|
if(UnCivGame.Current.settings.fontSet=="WenQuanYiMicroHei"){
|
||||||
@ -97,17 +100,19 @@ class Fonts {
|
|||||||
parameter.size = size
|
parameter.size = size
|
||||||
parameter.minFilter = Texture.TextureFilter.Linear
|
parameter.minFilter = Texture.TextureFilter.Linear
|
||||||
parameter.magFilter = Texture.TextureFilter.Linear
|
parameter.magFilter = Texture.TextureFilter.Linear
|
||||||
parameter.characters = getCharsForFont()
|
parameter.characters = getCharsForFont(true)
|
||||||
val font = generator.generateFont(parameter)
|
val font = generator.generateFont(parameter)
|
||||||
fontCache[keyForFont] = font
|
fontCache[keyForFont] = font
|
||||||
return font
|
return font
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val fontForLanguage ="Nativefont"
|
val fontForLanguage ="Nativefont"
|
||||||
val keyForFont = "$fontForLanguage $size"
|
val withChinese = UnCivGame.Current.settings.language.contains("Chinese")
|
||||||
if (fontCache.containsKey(keyForFont))return fontCache[keyForFont]!!
|
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))
|
val font=NativeFont(NativeFontPaint(size))
|
||||||
font.appendText(getCharsForFont())
|
val charsForFont = getCharsForFont(withChinese)
|
||||||
|
font.appendText(charsForFont)
|
||||||
fontCache[keyForFont] = font
|
fontCache[keyForFont] = font
|
||||||
return font
|
return font
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ package com.unciv.ui.worldscreen.optionstable
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
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.scenes.scene2d.utils.ChangeListener
|
||||||
import com.badlogic.gdx.utils.Array
|
import com.badlogic.gdx.utils.Array
|
||||||
import com.unciv.UnCivGame
|
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) }
|
GameBasics.Translations.filter { !it.value.containsKey(currentLanguage) }.forEach { missingTextArray.add(it.key) }
|
||||||
missingTextSelectBox.items = missingTextArray
|
missingTextSelectBox.items = missingTextArray
|
||||||
missingTextSelectBox.selected = "Untranslated texts"
|
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(){
|
fun selectLanguage(){
|
||||||
UnCivGame.Current.settings.language = selectedLanguage
|
UnCivGame.Current.settings.language = selectedLanguage
|
||||||
UnCivGame.Current.settings.save()
|
UnCivGame.Current.settings.save()
|
||||||
|
CameraStageBaseScreen.resetFonts() // to load chinese characters if necessary
|
||||||
UnCivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv)
|
UnCivGame.Current.worldScreen = WorldScreen(worldScreen.viewingCiv)
|
||||||
UnCivGame.Current.setWorldScreen()
|
UnCivGame.Current.setWorldScreen()
|
||||||
WorldScreenOptionsTable(UnCivGame.Current.worldScreen)
|
WorldScreenOptionsTable(UnCivGame.Current.worldScreen)
|
||||||
|
Reference in New Issue
Block a user