From 479b3a02ad63da7f9eb5716b85cbfc7eab225169 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 12 Mar 2019 22:10:25 +0200 Subject: [PATCH] Resolved #383 - Configurable amount of turns between autosaves --- android/assets/jsons/Translations.json | 4 ++ core/src/com/unciv/GameSettings.kt | 1 + core/src/com/unciv/logic/trade/TradeLogic.kt | 2 +- .../com/unciv/ui/worldscreen/WorldScreen.kt | 3 +- .../optionstable/WorldScreenOptionsTable.kt | 66 ++++++++++++++----- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/android/assets/jsons/Translations.json b/android/assets/jsons/Translations.json index 7dc06e14e6..e808a4e507 100644 --- a/android/assets/jsons/Translations.json +++ b/android/assets/jsons/Translations.json @@ -685,6 +685,10 @@ Japanese:"表示オプション" } + "Turns between autosaves:":{} + + "Sound effects volume":{} + "Show":{ Italian:"Mostra" Russian:"Показать" diff --git a/core/src/com/unciv/GameSettings.kt b/core/src/com/unciv/GameSettings.kt index eb05dd7af2..4c15eb615c 100644 --- a/core/src/com/unciv/GameSettings.kt +++ b/core/src/com/unciv/GameSettings.kt @@ -10,6 +10,7 @@ class GameSettings { var tutorialsShown = ArrayList() var hasCrashedRecently = false var soundEffectsVolume = 0.5f + var turnsBetweenAutosaves = 1 fun save(){ GameSaver().setGeneralSettings(this) diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index db14f0513e..7aafd78830 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -87,7 +87,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci var value = 50*min(offer.amount,civsWithLuxToTrade.size) // they'll buy at 50 each only, and that's so they can trade it away if(!theirAvailableOffers.any { it.name==offer.name }) - value+=300 // only if they're lacking will they buy the first one at 300 + value+=200 // only if they're lacking will they buy the first one at 240 (Civ V standard, see https://www.reddit.com/r/civ/comments/1go7i9/luxury_and_strategic_resource_pricing/ & others) return value } } diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index e9581b8c94..2f3f345d57 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -253,7 +253,8 @@ class WorldScreen : CameraStageBaseScreen() { // the save takes a long time( up to a second!) and we can do it while the player continues his game. // On the other hand if we alter the game data while it's being serialized we could get a concurrent modification exception. // So what we do is we clone all the game data and serialize the clone. - GameSaver().saveGame(gameInfoClone, "Autosave") + if(gameInfo.turns % game.settings.turnsBetweenAutosaves == 0) + GameSaver().saveGame(gameInfoClone, "Autosave") nextTurnButton.enable() // only enable the user to next turn once we've saved the current one } diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 96534b5f48..31a495e0c5 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -5,10 +5,12 @@ import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.ui.SelectBox import com.badlogic.gdx.scenes.scene2d.ui.Slider +import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener import com.badlogic.gdx.utils.Array import com.unciv.UnCivGame import com.unciv.models.gamebasics.GameBasics +import com.unciv.models.gamebasics.tr import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.WorldScreen import kotlin.concurrent.thread @@ -47,12 +49,39 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){ addButton("{Hide} {resources and improvements}") { settings.showResourcesAndImprovements = false; update() } else addButton("{Show} {resources and improvements}") { settings.showResourcesAndImprovements = true; update() } - addLanguageSelectBox() - val resolutionSelectBox= SelectBox(skin) - val resolutionArray = com.badlogic.gdx.utils.Array() - resolutionArray.addAll("900x600","1050x700","1200x800","1500x1000") + addResolutionSelectBox() + + addAutosaveTurnsSelectBox() + + addSoundEffectsVolumeSlider() + + addButton("Close"){ remove() } + + pack() // Needed to show the background. + center(UnCivGame.Current.worldScreen.stage) + UnCivGame.Current.worldScreen.shouldUpdate=true + } + + private fun addSoundEffectsVolumeSlider() { + val soundEffectsVolumeSlider = Slider(0f, 1.0f, 0.1f, false, skin) + soundEffectsVolumeSlider.value = UnCivGame.Current.settings.soundEffectsVolume + soundEffectsVolumeSlider.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + UnCivGame.Current.settings.soundEffectsVolume = soundEffectsVolumeSlider.value + UnCivGame.Current.settings.save() + Sounds.play("click") + } + }) + add("Sound effects volume".tr()).row() + add(soundEffectsVolumeSlider).row() + } + + private fun addResolutionSelectBox() { + val resolutionSelectBox = SelectBox(skin) + val resolutionArray = Array() + resolutionArray.addAll("900x600", "1050x700", "1200x800", "1500x1000") resolutionSelectBox.items = resolutionArray resolutionSelectBox.selected = UnCivGame.Current.settings.resolution add(resolutionSelectBox).pad(10f).row() @@ -66,24 +95,27 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){ WorldScreenOptionsTable(UnCivGame.Current.worldScreen) } }) + } - val soundEffectsVolumeSlider = Slider(0f,1.0f,0.1f,false,skin) - soundEffectsVolumeSlider.value = UnCivGame.Current.settings.soundEffectsVolume - soundEffectsVolumeSlider.addListener(object: ChangeListener(){ + private fun addAutosaveTurnsSelectBox() { + val autosaveTurnsSelectBox = SelectBox(skin) + val autosaveTurnsArray = Array() + autosaveTurnsArray.addAll(1,2,5,10) + autosaveTurnsSelectBox.items = autosaveTurnsArray + autosaveTurnsSelectBox.selected = UnCivGame.Current.settings.turnsBetweenAutosaves + + val table = Table() + table.add("Turns between autosaves:".toLabel()) + table.add(autosaveTurnsSelectBox).pad(10f) + add(table).row() + + autosaveTurnsSelectBox.addListener(object : ChangeListener() { override fun changed(event: ChangeEvent?, actor: Actor?) { - UnCivGame.Current.settings.soundEffectsVolume= soundEffectsVolumeSlider.value + UnCivGame.Current.settings.turnsBetweenAutosaves= autosaveTurnsSelectBox.selected UnCivGame.Current.settings.save() - Sounds.play("click") + update() } }) - add("Sound effects volume").row() - add(soundEffectsVolumeSlider).row() - - addButton("Close"){ remove() } - - pack() // Needed to show the background. - center(UnCivGame.Current.worldScreen.stage) - UnCivGame.Current.worldScreen.shouldUpdate=true } private fun addLanguageSelectBox() {