mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-27 08:09:21 +07:00
Added display option to change screen resolution
This commit is contained in:
@ -28,4 +28,13 @@ class GameSettings : LinkedHashMap<String, String>() {
|
|||||||
set(value) {
|
set(value) {
|
||||||
this["Language"]=value
|
this["Language"]=value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resolution:String
|
||||||
|
get() {
|
||||||
|
if(this.containsKey("Resolution")) return get("Resolution")!!
|
||||||
|
else return "900x600"
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
this["Resolution"]=value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ open class CameraStageBaseScreen : Screen {
|
|||||||
private var isTutorialShowing = false
|
private var isTutorialShowing = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
stage = Stage(ExtendViewport(1000f, 600f), batch)// FitViewport(1000,600)
|
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
|
||||||
|
stage = Stage(ExtendViewport(resolutions[0], resolutions[1]), batch)// FitViewport(1000,600)
|
||||||
Gdx.input.inputProcessor = stage
|
Gdx.input.inputProcessor = stage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
|||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
import com.unciv.ui.utils.addClickListener
|
import com.unciv.ui.utils.addClickListener
|
||||||
|
import com.unciv.ui.utils.tr
|
||||||
|
|
||||||
open class OptionsTable: Table(){
|
open class OptionsTable: Table(){
|
||||||
init {
|
init {
|
||||||
@ -18,7 +19,7 @@ open class OptionsTable: Table(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addButton(text:String, action:()->Unit){
|
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)
|
button.addClickListener(action)
|
||||||
add(button).row()
|
add(button).row()
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import com.unciv.logic.GameSaver
|
|||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.center
|
import com.unciv.ui.utils.center
|
||||||
import com.unciv.ui.utils.tr
|
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
|
|
||||||
class WorldScreenDisplayOptionsTable() : OptionsTable(){
|
class WorldScreenDisplayOptionsTable() : OptionsTable(){
|
||||||
@ -20,12 +19,12 @@ class WorldScreenDisplayOptionsTable() : OptionsTable(){
|
|||||||
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)
|
if (settings.showResourcesAndImprovements)
|
||||||
addButton("Hide resources and improvements") { settings.showResourcesAndImprovements = false; update() }
|
addButton("{Hide} {resources and improvements}") { settings.showResourcesAndImprovements = false; update() }
|
||||||
else addButton("Show resources and improvements") { settings.showResourcesAndImprovements = true; update() }
|
else addButton("{Show} {resources and improvements}") { settings.showResourcesAndImprovements = true; update() }
|
||||||
|
|
||||||
val languageSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
|
val languageSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
|
||||||
val languageArray = com.badlogic.gdx.utils.Array<String>()
|
val languageArray = com.badlogic.gdx.utils.Array<String>()
|
||||||
@ -39,11 +38,28 @@ class WorldScreenDisplayOptionsTable() : OptionsTable(){
|
|||||||
GameSaver().setGeneralSettings(UnCivGame.Current.settings)
|
GameSaver().setGeneralSettings(UnCivGame.Current.settings)
|
||||||
UnCivGame.Current.worldScreen = WorldScreen()
|
UnCivGame.Current.worldScreen = WorldScreen()
|
||||||
UnCivGame.Current.setWorldScreen()
|
UnCivGame.Current.setWorldScreen()
|
||||||
|
UnCivGame.Current.worldScreen.stage.addActor(WorldScreenDisplayOptionsTable())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
val resolutionSelectBox= SelectBox<String>(CameraStageBaseScreen.skin)
|
||||||
|
val resolutionArray = com.badlogic.gdx.utils.Array<String>()
|
||||||
|
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.
|
pack() // Needed to show the background.
|
||||||
center(UnCivGame.Current.worldScreen.stage)
|
center(UnCivGame.Current.worldScreen.stage)
|
||||||
|
Reference in New Issue
Block a user