From 5aef49955a3990826377eb98875402012db1a8c9 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 19 Jun 2018 18:36:04 +0300 Subject: [PATCH] Added display option to change screen resolution --- core/src/com/unciv/ui/GameSettings.kt | 9 ++++++ .../unciv/ui/utils/CameraStageBaseScreen.kt | 3 +- .../worldscreen/optionstable/OptionsTable.kt | 3 +- .../WorldScreenDisplayOptionsTable.kt | 28 +++++++++++++++---- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/GameSettings.kt b/core/src/com/unciv/ui/GameSettings.kt index da9d2fb2e1..3719da3ab6 100644 --- a/core/src/com/unciv/ui/GameSettings.kt +++ b/core/src/com/unciv/ui/GameSettings.kt @@ -28,4 +28,13 @@ class GameSettings : LinkedHashMap() { set(value) { this["Language"]=value } + + var resolution:String + get() { + if(this.containsKey("Resolution")) return get("Resolution")!! + else return "900x600" + } + set(value) { + this["Resolution"]=value + } } diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 6b28438a43..9aeb280967 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -30,7 +30,8 @@ open class CameraStageBaseScreen : Screen { private var isTutorialShowing = false init { - stage = Stage(ExtendViewport(1000f, 600f), batch)// FitViewport(1000,600) + val resolutions: List = game.settings.resolution.split("x").map { it.toInt().toFloat() } + stage = Stage(ExtendViewport(resolutions[0], resolutions[1]), batch)// FitViewport(1000,600) Gdx.input.inputProcessor = stage } diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt index 6eace425e1..bf6c34e0b6 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.addClickListener +import com.unciv.ui.utils.tr open class OptionsTable: Table(){ init { @@ -18,7 +19,7 @@ open class OptionsTable: Table(){ } fun addButton(text:String, action:()->Unit){ - val button = TextButton(text, CameraStageBaseScreen.skin).apply { color= ImageGetter.getBlue() } + val button = TextButton(text.tr(), CameraStageBaseScreen.skin).apply { color= ImageGetter.getBlue() } button.addClickListener(action) add(button).row() } diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt index 1330162efc..dfa4d783fb 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt @@ -8,7 +8,6 @@ import com.unciv.logic.GameSaver import com.unciv.models.gamebasics.GameBasics import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.center -import com.unciv.ui.utils.tr import com.unciv.ui.worldscreen.WorldScreen class WorldScreenDisplayOptionsTable() : OptionsTable(){ @@ -20,12 +19,12 @@ class WorldScreenDisplayOptionsTable() : OptionsTable(){ clear() 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() } + addButton("{Hide} {resources and improvements}") { settings.showResourcesAndImprovements = false; update() } + else addButton("{Show} {resources and improvements}") { settings.showResourcesAndImprovements = true; update() } val languageSelectBox = SelectBox(CameraStageBaseScreen.skin) val languageArray = com.badlogic.gdx.utils.Array() @@ -39,11 +38,28 @@ class WorldScreenDisplayOptionsTable() : OptionsTable(){ GameSaver().setGeneralSettings(UnCivGame.Current.settings) UnCivGame.Current.worldScreen = WorldScreen() UnCivGame.Current.setWorldScreen() + UnCivGame.Current.worldScreen.stage.addActor(WorldScreenDisplayOptionsTable()) } }) + val resolutionSelectBox= SelectBox(CameraStageBaseScreen.skin) + val resolutionArray = com.badlogic.gdx.utils.Array() + resolutionArray.addAll("900x600","1200x800","1500x1000") + resolutionSelectBox.setItems(resolutionArray) + resolutionSelectBox.selected = UnCivGame.Current.settings.resolution + add(resolutionSelectBox).pad(10f).row() - addButton("Close".tr()){ remove() } + resolutionSelectBox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + UnCivGame.Current.settings.resolution = resolutionSelectBox.selected + GameSaver().setGeneralSettings(UnCivGame.Current.settings) + UnCivGame.Current.worldScreen = WorldScreen() + UnCivGame.Current.setWorldScreen() + UnCivGame.Current.worldScreen.stage.addActor(WorldScreenDisplayOptionsTable()) + } + }) + + addButton("Close"){ remove() } pack() // Needed to show the background. center(UnCivGame.Current.worldScreen.stage)