mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-13 11:30:31 +07:00
Added base for translations - we should now be able to add fan translations for different languages!
This commit is contained in:
parent
e0f97e584d
commit
d81768047f
6
android/assets/jsons/Translations.json
Normal file
6
android/assets/jsons/Translations.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"Next turn":
|
||||
{
|
||||
Spanish:"июня"
|
||||
}
|
||||
}
|
@ -10,12 +10,13 @@ import com.unciv.ui.worldscreen.WorldScreen
|
||||
|
||||
class UnCivGame : Game() {
|
||||
var gameInfo: GameInfo = GameInfo()
|
||||
var settings = GameSettings()
|
||||
lateinit var settings : GameSettings
|
||||
|
||||
lateinit var worldScreen: WorldScreen
|
||||
|
||||
override fun create() {
|
||||
GameBasics.run { } // just to initialize
|
||||
settings = GameSaver().getGeneralSettings()
|
||||
Current = this
|
||||
if (GameSaver().getSave("Autosave").exists()) {
|
||||
try {
|
||||
@ -27,12 +28,16 @@ class UnCivGame : Game() {
|
||||
else startNewGame()
|
||||
}
|
||||
|
||||
fun loadGame(gameName:String){
|
||||
gameInfo = GameSaver().loadGame( gameName)
|
||||
fun loadGame(gameInfo:GameInfo){
|
||||
this.gameInfo = gameInfo
|
||||
worldScreen = WorldScreen()
|
||||
setWorldScreen()
|
||||
}
|
||||
|
||||
fun loadGame(gameName:String){
|
||||
loadGame(GameSaver().loadGame( gameName))
|
||||
}
|
||||
|
||||
fun startNewGame(saveTutorialState:Boolean = false) {
|
||||
val newGame = GameStarter().startNewGame(20, 3, "Babylon")
|
||||
if(saveTutorialState) {
|
||||
@ -56,5 +61,4 @@ class UnCivGame : Game() {
|
||||
lateinit var Current: UnCivGame
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -30,11 +30,17 @@ class GameSaver {
|
||||
getSave(GameName).delete()
|
||||
}
|
||||
|
||||
fun getGeneralSettingsFile(): FileHandle {
|
||||
return Gdx.files.local("GameSettings.json")
|
||||
}
|
||||
|
||||
fun getGeneralSettings():GameSettings{
|
||||
return Json().fromJson(GameSettings::class.java, Gdx.files.local("GameSettings.json"))
|
||||
val settingsFile = getGeneralSettingsFile()
|
||||
if(!settingsFile.exists()) return GameSettings()
|
||||
return Json().fromJson(GameSettings::class.java, settingsFile)
|
||||
}
|
||||
|
||||
fun setGeneralSettings(gameSettings: GameSettings){
|
||||
Gdx.files.local("GameSettings.json").writeString(Json().toJson(gameSettings), false)
|
||||
getGeneralSettingsFile().writeString(Json().toJson(gameSettings), false)
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.unciv.models.gamebasics
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.models.stats.INamed
|
||||
import kotlin.collections.set
|
||||
|
||||
object GameBasics {
|
||||
val Buildings = LinkedHashMap<String, Building>()
|
||||
@ -15,8 +16,9 @@ object GameBasics {
|
||||
val Civilizations = LinkedHashMap<String, Civilization>()
|
||||
val PolicyBranches = LinkedHashMap<String, PolicyBranch>()
|
||||
val Tutorials = LinkedHashMap<String, List<String>>()
|
||||
val Translations = Translations(Gdx.files.internal("jsons/Translations.json").readString())
|
||||
|
||||
private fun <T> getFromJson(tClass: Class<T>, name: String): T {
|
||||
fun <T> getFromJson(tClass: Class<T>, name: String): T {
|
||||
val jsonText = Gdx.files.internal("jsons/$name.json").readString()
|
||||
return Json().fromJson(tClass, jsonText)
|
||||
}
|
||||
@ -69,4 +71,5 @@ object GameBasics {
|
||||
branch.policies.last().name = branch.name + " Complete"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
39
core/src/com/unciv/models/gamebasics/Translations.kt
Normal file
39
core/src/com/unciv/models/gamebasics/Translations.kt
Normal file
@ -0,0 +1,39 @@
|
||||
package com.unciv.models.gamebasics
|
||||
|
||||
import com.badlogic.gdx.utils.JsonReader
|
||||
import java.util.*
|
||||
|
||||
class Translations() : HashMap<String, HashMap<String, String>>(){
|
||||
|
||||
constructor(json:String):this(){
|
||||
val jsonValue = JsonReader().parse(json)!!
|
||||
|
||||
// """
|
||||
// {
|
||||
// "a": {"k1":"v1",k2:"v2"},
|
||||
// b:{k3:"v3"}
|
||||
// }"""
|
||||
|
||||
var currentEntry = jsonValue.child
|
||||
while(currentEntry!=null){
|
||||
val entryMap = HashMap<String,String>()
|
||||
this[currentEntry.name!!]=entryMap
|
||||
|
||||
var currentLanguage = currentEntry.child
|
||||
while(currentLanguage!=null){
|
||||
entryMap[currentLanguage.name!!]=currentLanguage.asString()
|
||||
currentLanguage = currentLanguage.next
|
||||
}
|
||||
currentEntry = currentEntry.next
|
||||
}
|
||||
}
|
||||
|
||||
fun get(text:String,language:String): String {
|
||||
if(!containsKey(text) || !get(text)!!.containsKey(language)) return text
|
||||
return get(text)!![language]!!
|
||||
}
|
||||
|
||||
fun getLanguages(): List<String> {
|
||||
return mutableListOf("English").apply { addAll(values.flatMap { it.keys }) }
|
||||
}
|
||||
}
|
@ -19,4 +19,13 @@ class GameSettings : LinkedHashMap<String, String>() {
|
||||
set(value) {
|
||||
this["ShowResourcesAndImprovements"]=value.toString()
|
||||
}
|
||||
|
||||
var language:String
|
||||
get() {
|
||||
if(this.containsKey("Language")) return get("Language")!!
|
||||
else return "English"
|
||||
}
|
||||
set(value) {
|
||||
this["Language"]=value
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.unciv.ui.pickerscreens
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
@ -8,11 +10,7 @@ import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.Policy
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.disable
|
||||
import com.unciv.ui.utils.enable
|
||||
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
|
||||
class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen() {
|
||||
|
@ -13,6 +13,7 @@ import com.unciv.ui.pickerscreens.TechPickerScreen
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.disable
|
||||
import com.unciv.ui.utils.enable
|
||||
import com.unciv.ui.utils.tr
|
||||
import com.unciv.ui.worldscreen.unit.UnitActionsTable
|
||||
|
||||
class WorldScreen : CameraStageBaseScreen() {
|
||||
|
@ -1,9 +1,14 @@
|
||||
package com.unciv.ui.worldscreen
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.LoadScreen
|
||||
import com.unciv.ui.NewGameScreen
|
||||
import com.unciv.ui.SaveScreen
|
||||
@ -70,16 +75,30 @@ class WorldScreenDisplayOptionsTable() : OptionsTable(){
|
||||
update()
|
||||
}
|
||||
|
||||
fun update(){
|
||||
fun update() {
|
||||
clear()
|
||||
val tileMapHolder=UnCivGame.Current.worldScreen.tileMapHolder
|
||||
val tileMapHolder = UnCivGame.Current.worldScreen.tileMapHolder
|
||||
val settings = UnCivGame.Current.settings
|
||||
if(settings.showWorkedTiles) addButton("Hide worked tiles") {settings.showWorkedTiles=false; update()}
|
||||
else addButton("Show worked tiles") {settings.showWorkedTiles=true; update()}
|
||||
if (settings.showWorkedTiles) addButton("Hide worked tiles") { settings.showWorkedTiles = false; update() }
|
||||
else addButton("Show worked tiles") { settings.showWorkedTiles = true; update() }
|
||||
|
||||
if (settings.showResourcesAndImprovements)
|
||||
addButton("Hide resources and improvements") { settings.showResourcesAndImprovements = false; update() }
|
||||
else addButton("Show resources and improvements") { settings.showResourcesAndImprovements = true; update() }
|
||||
|
||||
val languageSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
|
||||
val languageArray = com.badlogic.gdx.utils.Array<String>()
|
||||
GameBasics.Translations.getLanguages().forEach { languageArray.add(it) }
|
||||
languageSelectBox.setItems(languageArray)
|
||||
languageSelectBox.selected = UnCivGame.Current.settings.language
|
||||
add(languageSelectBox).pad(10f).row()
|
||||
languageSelectBox.addListener(object : ChangeListener() {
|
||||
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||
UnCivGame.Current.settings.language = languageSelectBox.selected;
|
||||
GameSaver().setGeneralSettings(UnCivGame.Current.settings)
|
||||
}
|
||||
})
|
||||
|
||||
if(settings.showResourcesAndImprovements)
|
||||
addButton("Hide resources and improvements") {settings.showResourcesAndImprovements=false; update()}
|
||||
else addButton("Show resources and improvements") {settings.showResourcesAndImprovements=true; update()}
|
||||
|
||||
addButton("Close"){ remove() }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user