Organized new game screen functions

This commit is contained in:
Yair Morgenstern 2019-04-12 16:59:56 +03:00
parent 9bb4d988a3
commit d86672b0c0
2 changed files with 35 additions and 26 deletions

View file

@ -20,7 +20,7 @@ class UnCivGame(val version: String) : Game() {
val viewEntireMapForDebug = false val viewEntireMapForDebug = false
// For when you need to test something in an advanced game and don't have time to faff around // For when you need to test something in an advanced game and don't have time to faff around
val superchargedForDebug = true val superchargedForDebug = false
lateinit var worldScreen: WorldScreen lateinit var worldScreen: WorldScreen

View file

@ -74,17 +74,40 @@ class NewGameScreen: PickerScreen(){
val newGameOptionsTable = Table() val newGameOptionsTable = Table()
newGameOptionsTable.skin = skin newGameOptionsTable.skin = skin
addMapTypeSizeAndFile(newGameOptionsTable)
addNumberOfHumansAndEnemies(newGameOptionsTable)
addDifficultySelectBox(newGameOptionsTable)
rightSideButton.enable()
rightSideButton.setText("Start game!".tr())
rightSideButton.onClick {
Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked!
rightSideButton.disable()
rightSideButton.setText("Working...".tr())
thread { // Creating a new game can take a while and we don't want ANRs
newGame = GameStarter().startNewGame(newGameParameters)
}
}
newGameOptionsTable.pack()
return newGameOptionsTable
}
private fun addMapTypeSizeAndFile(newGameOptionsTable: Table) {
newGameOptionsTable.add("{Map type}:".tr()) newGameOptionsTable.add("{Map type}:".tr())
val mapTypes = LinkedHashMap<String, MapType>() val mapTypes = LinkedHashMap<String, MapType>()
for (type in MapType.values()) { for (type in MapType.values()) {
if(type==MapType.File && GameSaver().getMaps().isEmpty()) continue if (type == MapType.File && GameSaver().getMaps().isEmpty()) continue
mapTypes[type.toString()] = type mapTypes[type.toString()] = type
} }
val mapFileLabel = "{Map file}:".toLabel() val mapFileLabel = "{Map file}:".toLabel()
val mapFileSelectBox = getMapFileSelectBox() val mapFileSelectBox = getMapFileSelectBox()
mapFileLabel.isVisible=false mapFileLabel.isVisible = false
mapFileSelectBox.isVisible=false mapFileSelectBox.isVisible = false
val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin) val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin)
@ -98,13 +121,13 @@ class NewGameScreen: PickerScreen(){
worldSizeSelectBox.isVisible = false worldSizeSelectBox.isVisible = false
worldSizeLabel.isVisible = false worldSizeLabel.isVisible = false
mapFileSelectBox.isVisible = true mapFileSelectBox.isVisible = true
mapFileLabel.isVisible=true mapFileLabel.isVisible = true
newGameParameters.mapFileName = mapFileSelectBox.selected newGameParameters.mapFileName = mapFileSelectBox.selected
} else { } else {
worldSizeSelectBox.isVisible = true worldSizeSelectBox.isVisible = true
worldSizeLabel.isVisible = true worldSizeLabel.isVisible = true
mapFileSelectBox.isVisible = false mapFileSelectBox.isVisible = false
mapFileLabel.isVisible=false mapFileLabel.isVisible = false
newGameParameters.mapFileName = null newGameParameters.mapFileName = null
} }
} }
@ -117,8 +140,9 @@ class NewGameScreen: PickerScreen(){
newGameOptionsTable.add(mapFileLabel) newGameOptionsTable.add(mapFileLabel)
newGameOptionsTable.add(mapFileSelectBox).pad(10f).row() newGameOptionsTable.add(mapFileSelectBox).pad(10f).row()
}
private fun addNumberOfHumansAndEnemies(newGameOptionsTable: Table) {
newGameOptionsTable.add("{Number of human players}:".tr()) newGameOptionsTable.add("{Number of human players}:".tr())
val humanPlayers = SelectBox<Int>(skin) val humanPlayers = SelectBox<Int>(skin)
val humanPlayersArray = Array<Int>() val humanPlayersArray = Array<Int>()
@ -131,7 +155,7 @@ class NewGameScreen: PickerScreen(){
newGameOptionsTable.add("{Number of enemies}:".tr()) newGameOptionsTable.add("{Number of enemies}:".tr())
val enemiesSelectBox = SelectBox<Int>(skin) val enemiesSelectBox = SelectBox<Int>(skin)
val enemiesArray = Array<Int>() val enemiesArray = Array<Int>()
(0..GameBasics.Nations.size-1).forEach { enemiesArray.add(it) } (0..GameBasics.Nations.size - 1).forEach { enemiesArray.add(it) }
enemiesSelectBox.items = enemiesArray enemiesSelectBox.items = enemiesArray
enemiesSelectBox.selected = newGameParameters.numberOfEnemies enemiesSelectBox.selected = newGameParameters.numberOfEnemies
newGameOptionsTable.add(enemiesSelectBox).pad(10f).row() newGameOptionsTable.add(enemiesSelectBox).pad(10f).row()
@ -153,32 +177,17 @@ class NewGameScreen: PickerScreen(){
removeExtraHumanNations(humanPlayers) removeExtraHumanNations(humanPlayers)
} }
}) })
}
private fun addDifficultySelectBox(newGameOptionsTable: Table) {
newGameOptionsTable.add("{Difficulty}:".tr()) newGameOptionsTable.add("{Difficulty}:".tr())
val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty , skin) val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty, skin)
difficultySelectBox.addListener(object : ChangeListener() { difficultySelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) { override fun changed(event: ChangeEvent?, actor: Actor?) {
newGameParameters.difficulty = difficultySelectBox.selected.value newGameParameters.difficulty = difficultySelectBox.selected.value
} }
}) })
newGameOptionsTable.add(difficultySelectBox).pad(10f).row() newGameOptionsTable.add(difficultySelectBox).pad(10f).row()
rightSideButton.enable()
rightSideButton.setText("Start game!".tr())
rightSideButton.onClick {
Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked!
rightSideButton.disable()
rightSideButton.setText("Working...".tr())
thread {
// Creating a new game can tke a while and we don't want ANRs
newGame = GameStarter().startNewGame(newGameParameters)
}
}
newGameOptionsTable.pack()
return newGameOptionsTable
} }
private fun getMapFileSelectBox(): SelectBox<String> { private fun getMapFileSelectBox(): SelectBox<String> {