New game screen clearly split into "Map options" and "Game options"

This commit is contained in:
Yair Morgenstern 2019-12-09 22:48:54 +02:00
parent 9493ce1a2e
commit 54bbd5d8a2
4 changed files with 150 additions and 99 deletions

View file

@ -53,6 +53,12 @@
Ukrainian:"Почати!"
}
"Map options":{
}
"Game options":{
}
"Map type":{
Italian:"Tipo di mappa"
Russian:"Тип карты"
@ -68,7 +74,11 @@
Korean:"지도 유형"
Czech:"Typ mapy"
Ukrainian:"Тип мапи"
}
}
"Map generation type": {
}
"Number of city-states":{
Italian:"Numero di Città-Stato"

View file

@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.Json
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.MapSaver
import com.unciv.logic.map.MapType
import com.unciv.logic.map.RoadStatus
import com.unciv.models.gamebasics.tr
import com.unciv.ui.saves.Gzip
@ -44,6 +45,8 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
val saveMapButton = TextButton("Save map".tr(), skin)
saveMapButton.onClick {
mapEditorScreen.tileMap.mapParameters.name=mapEditorScreen.mapName
mapEditorScreen.tileMap.mapParameters.type=MapType.custom
MapSaver().saveMap(mapEditorScreen.mapName,mapEditorScreen.tileMap)
UncivGame.Current.setWorldScreen()
}

View file

@ -0,0 +1,71 @@
package com.unciv.ui.newgamescreen
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.unciv.logic.map.MapParameters
import com.unciv.logic.map.MapType
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.toLabel
// This is a separate class, because it should be in use both in the New Game screen and the Map Editor screen
class MapParametersTable(val mapParameters: MapParameters): Table(){
init {
addMapTypeSelectBox()
addWorldSizeSelectBox()
addNoRuinsCheckbox()
}
private fun addMapTypeSelectBox() {
add("{Map generation type}:".toLabel())
val mapTypes = listOf(MapType.default, MapType.pangaea, MapType.continents, MapType.perlin)
val mapTypeSelectBox = TranslatedSelectBox(mapTypes, mapParameters.type, CameraStageBaseScreen.skin)
mapTypeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
mapParameters.type=mapTypeSelectBox.selected.value
}
})
add(mapTypeSelectBox).row()
}
private fun addWorldSizeSelectBox(){
val worldSizeLabel = "{World size}:".toLabel()
val worldSizeToRadius = LinkedHashMap<String, Int>()
worldSizeToRadius["Tiny"] = 10
worldSizeToRadius["Small"] = 15
worldSizeToRadius["Medium"] = 20
worldSizeToRadius["Large"] = 30
worldSizeToRadius["Huge"] = 40
val currentWorldSizeName = worldSizeToRadius.entries
.first { it.value == mapParameters.radius }.key
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, currentWorldSizeName, CameraStageBaseScreen.skin)
worldSizeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
mapParameters.radius = worldSizeToRadius[worldSizeSelectBox.selected.value]!!
}
})
add(worldSizeLabel)
add(worldSizeSelectBox).pad(10f).row()
}
private fun addNoRuinsCheckbox() {
val noRuinsCheckbox = CheckBox("No ancient ruins".tr(), CameraStageBaseScreen.skin)
noRuinsCheckbox.isChecked = mapParameters.noRuins
noRuinsCheckbox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
mapParameters.noRuins = noRuinsCheckbox.isChecked
}
})
add(noRuinsCheckbox).colspan(2).row()
}
}

View file

@ -9,7 +9,6 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.Array
import com.unciv.logic.MapSaver
import com.unciv.logic.map.MapParameters
import com.unciv.logic.map.MapType
import com.unciv.models.gamebasics.Ruleset
import com.unciv.models.gamebasics.VictoryType
import com.unciv.models.gamebasics.tech.TechEra
@ -24,7 +23,10 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
val ruleset: Ruleset, val onMultiplayerToggled:()->Unit)
: Table(CameraStageBaseScreen.skin){
init{
addMapTypeSizeAndFile()
add("Map options".toLabel(fontSize = 24)).colspan(2).row()
addMapTypeSelection()
add("Game options".toLabel(fontSize = 24)).padTop(20f).colspan(2).row()
addDifficultySelectBox()
addGameSpeedSelectBox()
addEraSelectBox()
@ -32,7 +34,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
addVictoryTypeCheckboxes()
addBarbariansCheckbox()
addOneCityChallengeCheckbox()
addNoRuinsCheckbox()
addIsOnlineMultiplayerCheckbox()
// addModCheckboxes()
@ -40,6 +41,67 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
pack()
}
private fun addMapTypeSelection() {
add("{Map type}:".toLabel())
val mapTypes = arrayListOf("Generated")
if(MapSaver().getMaps().isNotEmpty()) mapTypes.add("Existing")
val mapFileLabel = "{Map file}:".toLabel()
val mapFileSelectBox = getMapFileSelectBox()
mapFileLabel.isVisible = false
mapFileSelectBox.isVisible = false
val mapTypeSelectBox = TranslatedSelectBox(mapTypes, "Generated", CameraStageBaseScreen.skin)
val mapParameterTable = MapParametersTable(mapParameters)
fun updateOnMapTypeChange(){
mapParameters.type = mapTypeSelectBox.selected.value
if (mapParameters.type == "Existing") {
mapParameterTable.isVisible = false
mapFileSelectBox.isVisible = true
mapFileLabel.isVisible = true
mapParameters.name = mapFileSelectBox.selected
} else {
mapParameterTable.isVisible = true
mapFileSelectBox.isVisible = false
mapFileLabel.isVisible = false
mapParameters.name = ""
}
}
updateOnMapTypeChange() // activate once, so when we had a file map before we'll have the right things set for another one
mapTypeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
updateOnMapTypeChange()
}
})
add(mapTypeSelectBox).pad(10f).row()
add(mapParameterTable).colspan(2).row()
add(mapFileLabel)
add(mapFileSelectBox).pad(10f).row()
}
private fun getMapFileSelectBox(): SelectBox<String> {
val mapFileSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
val mapNames = Array<String>()
for (mapName in MapSaver().getMaps()) mapNames.add(mapName)
mapFileSelectBox.items = mapNames
if (mapParameters.name in mapNames) mapFileSelectBox.selected = mapParameters.name
mapFileSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
mapParameters.name = mapFileSelectBox.selected!!
}
})
return mapFileSelectBox
}
private fun addBarbariansCheckbox() {
val noBarbariansCheckbox = CheckBox("No barbarians".tr(), CameraStageBaseScreen.skin)
noBarbariansCheckbox.isChecked = newGameParameters.noBarbarians
@ -62,17 +124,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
add(oneCityChallengeCheckbox).colspan(2).row()
}
private fun addNoRuinsCheckbox() {
val noRuinsCheckbox = CheckBox("No ancient ruins".tr(), CameraStageBaseScreen.skin)
noRuinsCheckbox.isChecked = mapParameters.noRuins
noRuinsCheckbox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
mapParameters.noRuins = noRuinsCheckbox.isChecked
}
})
add(noRuinsCheckbox).colspan(2).row()
}
private fun addIsOnlineMultiplayerCheckbox() {
val isOnlineMultiplayerCheckbox = CheckBox("Online Multiplayer".tr(), CameraStageBaseScreen.skin)
@ -86,56 +137,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
add(isOnlineMultiplayerCheckbox).colspan(2).row()
}
private fun addMapTypeSizeAndFile() {
add("{Map type}:".tr())
val mapTypes = arrayListOf(MapType.default,MapType.continents,MapType.perlin,MapType.pangaea)
if(MapSaver().getMaps().isNotEmpty()) mapTypes.add(MapType.custom)
val mapFileLabel = "{Map file}:".toLabel()
val mapFileSelectBox = getMapFileSelectBox()
mapFileLabel.isVisible = false
mapFileSelectBox.isVisible = false
val mapTypeSelectBox = TranslatedSelectBox(mapTypes, mapParameters.type, CameraStageBaseScreen.skin)
val worldSizeSelectBox = getWorldSizeSelectBox()
val worldSizeLabel = "{World size}:".toLabel()
fun updateOnMapTypeChange(){
mapParameters.type = mapTypeSelectBox.selected.value
if (mapParameters.type == MapType.custom) {
worldSizeSelectBox.isVisible = false
worldSizeLabel.isVisible = false
mapFileSelectBox.isVisible = true
mapFileLabel.isVisible = true
mapParameters.name = mapFileSelectBox.selected
} else {
worldSizeSelectBox.isVisible = true
worldSizeLabel.isVisible = true
mapFileSelectBox.isVisible = false
mapFileLabel.isVisible = false
mapParameters.name = ""
}
}
updateOnMapTypeChange() // activate once, so when we had a file map before we'll have the right things set for another one
mapTypeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
updateOnMapTypeChange()
}
})
add(mapTypeSelectBox).pad(10f).row()
add(worldSizeLabel)
add(worldSizeSelectBox).pad(10f).row()
add(mapFileLabel)
add(mapFileSelectBox).pad(10f).row()
}
private fun addCityStatesSelectBox() {
add("{Number of city-states}:".tr())
val cityStatesSelectBox = SelectBox<Int>(CameraStageBaseScreen.skin)
@ -215,40 +216,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
add(victoryConditionsTable).colspan(2).row()
}
private fun getMapFileSelectBox(): SelectBox<String> {
val mapFileSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
val mapNames = Array<String>()
for (mapName in MapSaver().getMaps()) mapNames.add(mapName)
mapFileSelectBox.items = mapNames
if (mapParameters.name in mapNames) mapFileSelectBox.selected = mapParameters.name
mapFileSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
mapParameters.name = mapFileSelectBox.selected!!
}
})
return mapFileSelectBox
}
private fun getWorldSizeSelectBox(): TranslatedSelectBox {
val worldSizeToRadius = LinkedHashMap<String, Int>()
worldSizeToRadius["Tiny"] = 10
worldSizeToRadius["Small"] = 15
worldSizeToRadius["Medium"] = 20
worldSizeToRadius["Large"] = 30
worldSizeToRadius["Huge"] = 40
val currentWorldSizeName = worldSizeToRadius.entries
.first { it.value == mapParameters.radius }.key
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, currentWorldSizeName, CameraStageBaseScreen.skin)
worldSizeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
mapParameters.radius = worldSizeToRadius[worldSizeSelectBox.selected.value]!!
}
})
return worldSizeSelectBox
}
fun addModCheckboxes(){