mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
gdx font: working locale switch
This commit is contained in:
@@ -27,6 +27,7 @@ class TestTestTest : ApplicationAdapter() {
|
|||||||
|
|
||||||
gameFont = GameFontBase(false)
|
gameFont = GameFontBase(false)
|
||||||
//gameFont = BitmapFont()
|
//gameFont = BitmapFont()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val text = arrayOf(
|
val text = arrayOf(
|
||||||
@@ -67,6 +68,8 @@ class TestTestTest : ApplicationAdapter() {
|
|||||||
|
|
||||||
Gdx.graphics.setTitle("$GAME_NAME — F: ${Gdx.graphics.framesPerSecond}")
|
Gdx.graphics.setTitle("$GAME_NAME — F: ${Gdx.graphics.framesPerSecond}")
|
||||||
|
|
||||||
|
(gameFont as GameFontBase).reload("bg")
|
||||||
|
|
||||||
batch.inBatch {
|
batch.inBatch {
|
||||||
|
|
||||||
text.forEachIndexed { index, s ->
|
text.forEachIndexed { index, s ->
|
||||||
|
|||||||
@@ -156,6 +156,8 @@ class GameFontBase(val noShadow: Boolean) : BitmapFont() {
|
|||||||
"thai_variable.tga",
|
"thai_variable.tga",
|
||||||
"puae000-e0ff.tga"
|
"puae000-e0ff.tga"
|
||||||
)
|
)
|
||||||
|
private val cyrilic_bg = "cyrilic_bulgarian_variable.tga"
|
||||||
|
private val cyrilic_sr = "cyrilic_serbian_variable.tga"
|
||||||
private val codeRange = arrayOf( // MUST BE MATCHING WITH SHEET INDICES!!
|
private val codeRange = arrayOf( // MUST BE MATCHING WITH SHEET INDICES!!
|
||||||
0..0xFF,
|
0..0xFF,
|
||||||
0xAC00..0xD7A3,
|
0xAC00..0xD7A3,
|
||||||
@@ -256,6 +258,31 @@ class GameFontBase(val noShadow: Boolean) : BitmapFont() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun reload(locale: String) {
|
||||||
|
if (locale.startsWith("ru")) {
|
||||||
|
val pixmap = Pixmap(Gdx.files.internal(fontParentDir + fileList[SHEET_CYRILIC_VARW]))
|
||||||
|
val texture = Texture(pixmap)
|
||||||
|
sheets[SHEET_CYRILIC_VARW].dispose()
|
||||||
|
sheets[SHEET_CYRILIC_VARW] = TextureRegionPack(texture, W_VAR_INIT, H, HGAP_VAR, 0)
|
||||||
|
pixmap.dispose()
|
||||||
|
}
|
||||||
|
else if (locale.startsWith("bg")) {
|
||||||
|
val pixmap = Pixmap(Gdx.files.internal(fontParentDir + cyrilic_bg))
|
||||||
|
val texture = Texture(pixmap)
|
||||||
|
sheets[SHEET_CYRILIC_VARW].dispose()
|
||||||
|
sheets[SHEET_CYRILIC_VARW] = TextureRegionPack(texture, W_VAR_INIT, H, HGAP_VAR, 0)
|
||||||
|
pixmap.dispose()
|
||||||
|
}
|
||||||
|
else if (locale.startsWith("sr")) {
|
||||||
|
val pixmap = Pixmap(Gdx.files.internal(fontParentDir + cyrilic_sr))
|
||||||
|
val texture = Texture(pixmap)
|
||||||
|
sheets[SHEET_CYRILIC_VARW].dispose()
|
||||||
|
sheets[SHEET_CYRILIC_VARW] = TextureRegionPack(texture, W_VAR_INIT, H, HGAP_VAR, 0)
|
||||||
|
pixmap.dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun getLineHeight(): Float = H.toFloat()
|
override fun getLineHeight(): Float = H.toFloat()
|
||||||
|
|
||||||
override fun getXHeight() = lineHeight
|
override fun getXHeight() = lineHeight
|
||||||
@@ -320,7 +347,7 @@ class GameFontBase(val noShadow: Boolean) : BitmapFont() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
else { // JOHAB (assemble) HANGUL
|
else { // JOHAB (assemble) HANGUL
|
||||||
val hangulSheet = sheets[1]
|
val hangulSheet = sheets[SHEET_HANGUL]
|
||||||
val hIndex = c.toInt() - 0xAC00
|
val hIndex = c.toInt() - 0xAC00
|
||||||
|
|
||||||
val indexCho = getHanChosung(hIndex)
|
val indexCho = getHanChosung(hIndex)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class TextureRegionPack(
|
|||||||
private val verticalCount = (texture.height - 2 * vFrame + vGap) / (tileH + vGap)
|
private val verticalCount = (texture.height - 2 * vFrame + vGap) / (tileH + vGap)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
println("texture: $texture, dim: ${texture.width} x ${texture.height}, grid: $horizontalCount x $verticalCount, cellDim: $tileW x $tileH")
|
//println("texture: $texture, dim: ${texture.width} x ${texture.height}, grid: $horizontalCount x $verticalCount, cellDim: $tileW x $tileH")
|
||||||
|
|
||||||
regions = Array<TextureRegion>(horizontalCount * verticalCount, {
|
regions = Array<TextureRegion>(horizontalCount * verticalCount, {
|
||||||
val region = TextureRegion()
|
val region = TextureRegion()
|
||||||
|
|||||||
Reference in New Issue
Block a user