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

71 lines
2.4 KiB
Kotlin

package com.unciv.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.scenes.scene2d.ui.TextField
import com.badlogic.gdx.utils.Json
import com.unciv.UnCivGame
import com.unciv.logic.GameSaver
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.getRandom
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.tr
class SaveScreen : PickerScreen() {
val textField = TextField("", skin)
init {
val currentSaves = Table()
currentSaves.add(Label("Current saves".tr(),skin)).row()
val saves = GameSaver().getSaves()
saves.forEach {
val textButton = TextButton(it, skin)
textButton.onClick {
textField.text = it
}
currentSaves.add(textButton).pad(5f).row()
}
topTable.add(currentSaves)
val newSave = Table()
val adjectives = listOf("Prancing","Obese","Junior","Senior","Abstract","Discombobulating","Simple","Awkward","Holy",
"Dangerous","Greasy","Stinky","Purple","Majestic","Incomprehensible","Cardboard","Chocolate","Robot","Ninja",
"Fluffy","Magical","Invisible")
val nouns = listOf("Moose","Pigeon","Weasel","Ferret","Onion","Marshmallow","Crocodile","Unicorn",
"Sandwich","Elephant","Kangaroo","Marmot","Beagle","Dolphin","Fish","Tomato","Duck","Dinosaur")
val defaultSaveName = adjectives.getRandom()+" "+nouns.getRandom()
textField.text = defaultSaveName
newSave.add(Label("Saved game name".tr(),skin)).row()
newSave.add(textField).width(300f).pad(10f).row()
val copyJsonButton = TextButton("Copy game info".tr(),skin)
copyJsonButton.onClick {
val json = Json().toJson(game.gameInfo)
val base64Gzip = Gzip.encoder(Gzip.compress(json))
Gdx.app.clipboard.contents = base64Gzip
}
newSave.add(copyJsonButton)
topTable.add(newSave)
topTable.pack()
rightSideButton.setText("Save game".tr())
rightSideButton.onClick {
GameSaver().saveGame(UnCivGame.Current.gameInfo, textField.text)
UnCivGame.Current.setWorldScreen()
}
rightSideButton.enable()
}
}