Unciv/core/src/com/unciv/ui/LanguagePickerScreen.kt

90 lines
3 KiB
Kotlin
Raw Normal View History

2018-07-26 20:46:14 +00:00
package com.unciv.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Label
2018-07-26 20:46:14 +00:00
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table
2019-11-23 20:28:23 +00:00
import com.unciv.UncivGame
import com.unciv.models.gamebasics.tr
2018-07-26 20:46:14 +00:00
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick
2018-07-26 20:46:14 +00:00
class LanguageTable(val language:String,skin: Skin):Table(skin){
private val blue = ImageGetter.getBlue()
private val darkBlue = blue.cpy().lerp(Color.BLACK,0.5f)!!
val percentComplete: Int
2018-07-26 20:46:14 +00:00
init{
pad(10f)
defaults().pad(10f)
if(ImageGetter.imageExists("FlagIcons/$language"))
add(ImageGetter.getImage("FlagIcons/$language")).size(40f)
val translations = UncivGame.Current.ruleSet.Translations
val availableTranslations = translations.filter { it.value.containsKey(language) }
if(language=="English") percentComplete = 100
else percentComplete = (availableTranslations.size*100 / translations.size) - 5
val spaceSplitLang = language.replace("_"," ")
add("$spaceSplitLang ($percentComplete%)")
update("")
touchable = Touchable.enabled // so click listener is activated when any part is clicked, not only children
2018-07-26 20:46:14 +00:00
pack()
}
2018-07-26 20:46:14 +00:00
fun update(chosenLanguage:String){
background = ImageGetter.getBackground( if(chosenLanguage==language) blue else darkBlue)
}
2018-07-26 20:46:14 +00:00
}
class LanguagePickerScreen: PickerScreen(){
var chosenLanguage = "English"
private val languageTables = ArrayList<LanguageTable>()
fun update(){
languageTables.forEach { it.update(chosenLanguage) }
}
init {
closeButton.isVisible = false
topTable.add(Label(
"Please note that translations are a " +
"community-based work in progress and are INCOMPLETE! \n" +
"The percentage shown is how much of the language is translated in-game.\n" +
"If you want to help translating the game into your language, \n"+
" instructions are in the Github readme! (Menu > Community > Github)",skin)).pad(10f).row()
languageTables.addAll(UncivGame.Current.ruleSet.Translations.getLanguages().map { LanguageTable(it,skin) }
.sortedByDescending { it.percentComplete } )
languageTables.forEach {
2018-09-23 07:39:56 +00:00
it.onClick {
chosenLanguage = it.language
2018-07-26 20:46:14 +00:00
rightSideButton.enable()
update()
}
topTable.add(it).pad(10f).row()
2018-07-26 20:46:14 +00:00
}
rightSideButton.setText("Pick language".tr())
2018-09-23 07:39:56 +00:00
rightSideButton.onClick {
pickLanguage()
2018-07-26 20:46:14 +00:00
}
}
fun pickLanguage(){
2019-11-23 20:28:23 +00:00
UncivGame.Current.settings.language = chosenLanguage
UncivGame.Current.settings.save()
2019-04-25 07:37:46 +00:00
resetFonts()
2019-11-23 20:28:23 +00:00
UncivGame.Current.startNewGame()
dispose()
}
2018-07-26 20:46:14 +00:00
}