Desktop window size restore (#2319)

* Bring Incas into the main game
(also changes slinger withdraw ability to inheritable)

* Update Nations.json

* Small version: remember window size only, and leave positioning to Gdx
This commit is contained in:
proteus-anguinus 2020-04-03 09:33:46 +02:00 committed by GitHub
parent 8f583732aa
commit 10762a3873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -51,6 +51,7 @@ class UncivGame(
var music: Music? = null
val musicLocation = "music/thatched-villagers.mp3"
private var isSizeRestored = false
var isInitialized = false
@ -93,9 +94,18 @@ class UncivGame(
crashController = CrashController.Impl(crashReportSender)
}
private fun restoreSize() {
if (!isSizeRestored && Gdx.app.type == Application.ApplicationType.Desktop && settings.windowState.height>39 && settings.windowState.width>39) {
isSizeRestored = true
Gdx.graphics.setWindowedMode(settings.windowState.width, settings.windowState.height)
}
}
fun autoLoadGame() {
if (!GameSaver().getSave("Autosave").exists())
if (!GameSaver().getSave("Autosave").exists()) {
restoreSize()
return setScreen(LanguagePickerScreen())
}
try {
loadGame("Autosave")
} catch (ex: Exception) { // silent fail if we can't read the autosave
@ -124,6 +134,7 @@ class UncivGame(
this.gameInfo = gameInfo
ImageGetter.ruleset = gameInfo.ruleSet
ImageGetter.refreshAtlas()
restoreSize()
worldScreen = WorldScreen(gameInfo.getPlayerToViewAs())
setWorldScreen()
}
@ -166,8 +177,10 @@ class UncivGame(
}
override fun dispose() {
if (::gameInfo.isInitialized)
if (::gameInfo.isInitialized) {
GameSaver().autoSave(gameInfo)
settings.save()
}
}
companion object {

View File

@ -4,6 +4,8 @@ import com.badlogic.gdx.Application
import com.badlogic.gdx.Gdx
import com.unciv.logic.GameSaver
data class WindowState (val width:Int=0, val height:Int=0)
class GameSettings {
var showWorkedTiles: Boolean = false
var showResourcesAndImprovements: Boolean = true
@ -30,6 +32,7 @@ class GameSettings {
var multiplayerTurnCheckerPersistentNotificationEnabled = true
var multiplayerTurnCheckerDelayInMinutes = 5
var orderTradeOffersByAmount = true
var windowState = WindowState()
init {
// 26 = Android Oreo. Versions below may display permanent icon in notification bar.
@ -39,6 +42,9 @@ class GameSettings {
}
fun save(){
if (Gdx.app.type == Application.ApplicationType.Desktop) {
windowState = WindowState( Gdx.graphics.width, Gdx.graphics.height)
}
GameSaver().setGeneralSettings(this)
}