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

89 lines
3.1 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
2018-07-26 20:46:14 +00:00
import com.badlogic.gdx.scenes.scene2d.ui.Table
2019-11-23 20:28:23 +00:00
import com.unciv.UncivGame
import com.unciv.models.translations.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
import com.unciv.ui.utils.toLabel
2018-07-26 20:46:14 +00:00
class LanguageTable(val language:String, val percentComplete: Int):Table(){
2018-07-26 20:46:14 +00:00
private val blue = ImageGetter.getBlue()
private val darkBlue = blue.cpy().lerp(Color.BLACK,0.5f)!!
init{
pad(10f)
defaults().pad(10f)
if(ImageGetter.imageExists("FlagIcons/$language"))
add(ImageGetter.getImage("FlagIcons/$language")).size(40f)
val spaceSplitLang = language.replace("_"," ")
add("$spaceSplitLang ($percentComplete%)".toLabel())
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
/// trimMargin is overhead, but easier to maintain and see when it might get trimmed without wrap:
val translationDisclaimer = """
|Please note that translations are a community-based work in progress and are INCOMPLETE!
|The percentage shown is how much of the language is translated in-game.
|If you want to help translating the game into your language,
| instructions are in the Github readme! (Menu > Community > Github)
""".trimMargin()
topTable.add(translationDisclaimer.toLabel()).pad(10f).row()
val languageCompletionPercentage = UncivGame.Current.translations
.percentCompleteOfLanguages
languageTables.addAll(languageCompletionPercentage
.map { LanguageTable(it.key,if(it.key=="English") 100 else it.value) }
.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.isFreshlyCreated = false // mark so the picker isn't called next launch
2019-11-23 20:28:23 +00:00
UncivGame.Current.settings.save()
UncivGame.Current.translations.tryReadTranslationForCurrentLanguage()
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
}