mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 23:40:01 +07:00
Added base for translations - we should now be able to add fan translations for different languages!
This commit is contained in:
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() {
|
class UnCivGame : Game() {
|
||||||
var gameInfo: GameInfo = GameInfo()
|
var gameInfo: GameInfo = GameInfo()
|
||||||
var settings = GameSettings()
|
lateinit var settings : GameSettings
|
||||||
|
|
||||||
lateinit var worldScreen: WorldScreen
|
lateinit var worldScreen: WorldScreen
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
GameBasics.run { } // just to initialize
|
GameBasics.run { } // just to initialize
|
||||||
|
settings = GameSaver().getGeneralSettings()
|
||||||
Current = this
|
Current = this
|
||||||
if (GameSaver().getSave("Autosave").exists()) {
|
if (GameSaver().getSave("Autosave").exists()) {
|
||||||
try {
|
try {
|
||||||
@ -27,12 +28,16 @@ class UnCivGame : Game() {
|
|||||||
else startNewGame()
|
else startNewGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadGame(gameName:String){
|
fun loadGame(gameInfo:GameInfo){
|
||||||
gameInfo = GameSaver().loadGame( gameName)
|
this.gameInfo = gameInfo
|
||||||
worldScreen = WorldScreen()
|
worldScreen = WorldScreen()
|
||||||
setWorldScreen()
|
setWorldScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun loadGame(gameName:String){
|
||||||
|
loadGame(GameSaver().loadGame( gameName))
|
||||||
|
}
|
||||||
|
|
||||||
fun startNewGame(saveTutorialState:Boolean = false) {
|
fun startNewGame(saveTutorialState:Boolean = false) {
|
||||||
val newGame = GameStarter().startNewGame(20, 3, "Babylon")
|
val newGame = GameStarter().startNewGame(20, 3, "Babylon")
|
||||||
if(saveTutorialState) {
|
if(saveTutorialState) {
|
||||||
@ -57,4 +62,3 @@ class UnCivGame : Game() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,11 +30,17 @@ class GameSaver {
|
|||||||
getSave(GameName).delete()
|
getSave(GameName).delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getGeneralSettingsFile(): FileHandle {
|
||||||
|
return Gdx.files.local("GameSettings.json")
|
||||||
|
}
|
||||||
|
|
||||||
fun getGeneralSettings():GameSettings{
|
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){
|
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.Gdx
|
||||||
import com.badlogic.gdx.utils.Json
|
import com.badlogic.gdx.utils.Json
|
||||||
import com.unciv.models.stats.INamed
|
import com.unciv.models.stats.INamed
|
||||||
|
import kotlin.collections.set
|
||||||
|
|
||||||
object GameBasics {
|
object GameBasics {
|
||||||
val Buildings = LinkedHashMap<String, Building>()
|
val Buildings = LinkedHashMap<String, Building>()
|
||||||
@ -15,8 +16,9 @@ object GameBasics {
|
|||||||
val Civilizations = LinkedHashMap<String, Civilization>()
|
val Civilizations = LinkedHashMap<String, Civilization>()
|
||||||
val PolicyBranches = LinkedHashMap<String, PolicyBranch>()
|
val PolicyBranches = LinkedHashMap<String, PolicyBranch>()
|
||||||
val Tutorials = LinkedHashMap<String, List<String>>()
|
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()
|
val jsonText = Gdx.files.internal("jsons/$name.json").readString()
|
||||||
return Json().fromJson(tClass, jsonText)
|
return Json().fromJson(tClass, jsonText)
|
||||||
}
|
}
|
||||||
@ -70,3 +72,4 @@ object GameBasics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
set(value) {
|
||||||
this["ShowResourcesAndImprovements"]=value.toString()
|
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
|
package com.unciv.ui.pickerscreens
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Button
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
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.GameBasics
|
||||||
import com.unciv.models.gamebasics.Policy
|
import com.unciv.models.gamebasics.Policy
|
||||||
import com.unciv.ui.cityscreen.addClickListener
|
import com.unciv.ui.cityscreen.addClickListener
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.*
|
||||||
import com.unciv.ui.utils.ImageGetter
|
|
||||||
import com.unciv.ui.utils.disable
|
|
||||||
import com.unciv.ui.utils.enable
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen() {
|
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.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.disable
|
import com.unciv.ui.utils.disable
|
||||||
import com.unciv.ui.utils.enable
|
import com.unciv.ui.utils.enable
|
||||||
|
import com.unciv.ui.utils.tr
|
||||||
import com.unciv.ui.worldscreen.unit.UnitActionsTable
|
import com.unciv.ui.worldscreen.unit.UnitActionsTable
|
||||||
|
|
||||||
class WorldScreen : CameraStageBaseScreen() {
|
class WorldScreen : CameraStageBaseScreen() {
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package com.unciv.ui.worldscreen
|
package com.unciv.ui.worldscreen
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
|
import com.unciv.logic.GameSaver
|
||||||
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import com.unciv.ui.LoadScreen
|
import com.unciv.ui.LoadScreen
|
||||||
import com.unciv.ui.NewGameScreen
|
import com.unciv.ui.NewGameScreen
|
||||||
import com.unciv.ui.SaveScreen
|
import com.unciv.ui.SaveScreen
|
||||||
@ -70,16 +75,30 @@ class WorldScreenDisplayOptionsTable() : OptionsTable(){
|
|||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update(){
|
fun update() {
|
||||||
clear()
|
clear()
|
||||||
val tileMapHolder=UnCivGame.Current.worldScreen.tileMapHolder
|
val tileMapHolder = UnCivGame.Current.worldScreen.tileMapHolder
|
||||||
val settings = UnCivGame.Current.settings
|
val settings = UnCivGame.Current.settings
|
||||||
if(settings.showWorkedTiles) addButton("Hide worked tiles") {settings.showWorkedTiles=false; update()}
|
if (settings.showWorkedTiles) addButton("Hide worked tiles") { settings.showWorkedTiles = false; update() }
|
||||||
else addButton("Show worked tiles") {settings.showWorkedTiles=true; 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() }
|
addButton("Close"){ remove() }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user