2018-07-26 20:46:14 +00:00
|
|
|
package com.unciv.ui
|
|
|
|
|
|
|
|
import com.badlogic.gdx.graphics.Color
|
2018-08-04 18:36:08 +00:00
|
|
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
2018-08-04 18:50:56 +00:00
|
|
|
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
|
|
|
|
import com.unciv.UnCivGame
|
|
|
|
import com.unciv.models.gamebasics.GameBasics
|
|
|
|
import com.unciv.ui.pickerscreens.PickerScreen
|
|
|
|
import com.unciv.ui.utils.ImageGetter
|
2018-09-23 07:39:56 +00:00
|
|
|
import com.unciv.ui.utils.onClick
|
2018-07-26 20:46:14 +00:00
|
|
|
import com.unciv.ui.utils.enable
|
|
|
|
import com.unciv.ui.utils.tr
|
|
|
|
|
|
|
|
|
|
|
|
class LanguageTable(val language:String,skin: Skin):Table(skin){
|
|
|
|
private val blue = ImageGetter.getBlue()
|
|
|
|
private val darkBlue = blue.cpy().lerp(Color.BLACK,0.5f)!!
|
2018-08-05 13:12:46 +00:00
|
|
|
val percentComplete: Int
|
2018-07-26 20:46:14 +00:00
|
|
|
|
|
|
|
init{
|
|
|
|
pad(10f)
|
|
|
|
defaults().pad(10f)
|
2018-08-04 18:36:08 +00:00
|
|
|
add(ImageGetter.getImage("FlagIcons/$language.png")).size(40f)
|
2018-08-04 18:50:56 +00:00
|
|
|
val availableTranslations = GameBasics.Translations.filter { it.value.containsKey(language) }
|
2018-08-05 13:12:46 +00:00
|
|
|
|
2018-08-04 18:50:56 +00:00
|
|
|
if(language=="English") percentComplete = 100
|
2018-08-05 13:12:46 +00:00
|
|
|
else percentComplete = (availableTranslations.size*100 / GameBasics.Translations.size) - 10
|
2018-08-04 18:50:56 +00:00
|
|
|
add("$language ($percentComplete%)")
|
2018-08-04 18:36:08 +00:00
|
|
|
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-08-04 18:36:08 +00:00
|
|
|
|
2018-07-26 20:46:14 +00:00
|
|
|
fun update(chosenLanguage:String){
|
|
|
|
background = ImageGetter.getBackground( if(chosenLanguage==language) blue else darkBlue)
|
|
|
|
}
|
2018-08-04 18:36:08 +00:00
|
|
|
|
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
|
2018-08-04 18:50:56 +00:00
|
|
|
topTable.add(Label(
|
|
|
|
"Please note that translations are a " +
|
2018-08-05 13:12:46 +00:00
|
|
|
"community-based work in progress and are INCOMPLETE! \n" +
|
2018-08-05 20:08:50 +00:00
|
|
|
"The percentage shown is how much of the language is translated in-game.\n" +
|
2018-08-04 18:50:56 +00:00
|
|
|
"If you want to help translating the game " +
|
|
|
|
"into your language, contact me!",skin)).pad(10f).row()
|
2018-08-05 13:12:46 +00:00
|
|
|
|
|
|
|
languageTables.addAll(GameBasics.Translations.getLanguages().map { LanguageTable(it,skin) }
|
|
|
|
.sortedByDescending { it.percentComplete } )
|
|
|
|
|
|
|
|
languageTables.forEach {
|
2018-09-23 07:39:56 +00:00
|
|
|
it.onClick {
|
2018-08-05 13:12:46 +00:00
|
|
|
chosenLanguage = it.language
|
2018-07-26 20:46:14 +00:00
|
|
|
rightSideButton.enable()
|
|
|
|
update()
|
|
|
|
}
|
2018-08-05 13:12:46 +00:00
|
|
|
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 {
|
2018-07-26 20:46:14 +00:00
|
|
|
UnCivGame.Current.settings.language = chosenLanguage
|
2018-07-26 21:07:32 +00:00
|
|
|
UnCivGame.Current.settings.save()
|
2018-07-26 20:46:14 +00:00
|
|
|
UnCivGame.Current.startNewGame()
|
|
|
|
dispose()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|