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
|
2018-12-07 09:24:55 +00:00
|
|
|
import com.unciv.models.gamebasics.tr
|
2018-07-26 20:46:14 +00:00
|
|
|
import com.unciv.ui.pickerscreens.PickerScreen
|
2018-12-10 08:41:13 +00:00
|
|
|
import com.unciv.ui.utils.*
|
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)!!
|
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-12-01 20:22:30 +00:00
|
|
|
if(ImageGetter.imageExists("FlagIcons/$language"))
|
|
|
|
add(ImageGetter.getImage("FlagIcons/$language")).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-12-01 20:22:30 +00:00
|
|
|
else percentComplete = (availableTranslations.size*100 / GameBasics.Translations.size) - 5
|
2018-12-10 09:19:35 +00:00
|
|
|
|
|
|
|
val spaceSplitLang = language.replace("_"," ")
|
|
|
|
add("$spaceSplitLang ($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 " +
|
2018-12-01 20:22:30 +00:00
|
|
|
"into your language, send me an email to yairm210@hotmail.com!",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-12-10 08:41:13 +00:00
|
|
|
|
|
|
|
|
2018-09-23 07:39:56 +00:00
|
|
|
rightSideButton.onClick {
|
2019-09-01 10:01:37 +00:00
|
|
|
pickLanguage()
|
2018-07-26 20:46:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 08:41:13 +00:00
|
|
|
fun pickLanguage(){
|
|
|
|
UnCivGame.Current.settings.language = chosenLanguage
|
|
|
|
UnCivGame.Current.settings.save()
|
2019-04-25 07:37:46 +00:00
|
|
|
resetFonts()
|
2018-12-10 08:41:13 +00:00
|
|
|
UnCivGame.Current.startNewGame()
|
|
|
|
dispose()
|
|
|
|
}
|
2018-07-26 20:46:14 +00:00
|
|
|
}
|