diff --git a/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt index 5d26cc4f12..6a83bf0d62 100644 --- a/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt @@ -9,17 +9,17 @@ import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.onChange import com.unciv.ui.utils.toLabel -class MapOptionsTable(val newGameScreen: NewGameScreen): Table(){ +class MapOptionsTable(val newGameScreen: NewGameScreen): Table() { val mapParameters = newGameScreen.gameSetupInfo.mapParameters private var mapTypeSpecificTable = Table() private val generatedMapOptionsTable = MapParametersTable(mapParameters) private val savedMapOptionsTable = Table() - init{ + init { defaults().pad(5f) - add("Map options".toLabel(fontSize = 24)).colspan(2).row() + add("Map options".toLabel(fontSize = 24)).top().colspan(2).row() addMapTypeSelection() } diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt index 4cfeb8d729..9a97f9ff8f 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt @@ -27,19 +27,24 @@ class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var m constructor(gameInfo: GameInfo) : this("", gameInfo.gameParameters.clone(), gameInfo.tileMap.mapParameters) } -class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): PickerScreen(){ +class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): PickerScreen() { - var gameSetupInfo:GameSetupInfo= _gameSetupInfo ?: GameSetupInfo() + var gameSetupInfo: GameSetupInfo = _gameSetupInfo ?: GameSetupInfo() val ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods) init { setDefaultCloseAction(previousScreen) - scrollPane.setScrollingDisabled(true,true) + scrollPane.setScrollingDisabled(true, true) val playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters) val newGameScreenOptionsTable = NewGameScreenOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) } - topTable.add(ScrollPane(newGameScreenOptionsTable).apply{setOverscroll(false,false)}).height(topTable.parent.height) - topTable.add(playerPickerTable).height(topTable.parent.height) + topTable.add(ScrollPane(MapOptionsTable(this)).apply { setOverscroll(false, false) }) + .maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top() + topTable.addSeparatorVertical() + topTable.add(playerPickerTable).maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top() + topTable.addSeparatorVertical() + topTable.add(ScrollPane(newGameScreenOptionsTable).apply { setOverscroll(false, false) }) + .maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top() topTable.pack() topTable.setFillParent(true) @@ -72,7 +77,7 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe rightSideButton.disable() rightSideButton.setText("Working...".tr()) - thread(name="NewGame") { + thread(name = "NewGame") { // Creating a new game can take a while and we don't want ANRs newGameThread() } @@ -115,16 +120,16 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe Gdx.graphics.requestRendering() } - fun setNewGameButtonEnabled(bool:Boolean){ - if(bool) rightSideButton.enable() + fun setNewGameButtonEnabled(bool: Boolean) { + if (bool) rightSideButton.enable() else rightSideButton.disable() } - var newGame:GameInfo?=null + var newGame: GameInfo? = null override fun render(delta: Float) { - if (newGame != null){ + if (newGame != null) { game.loadGame(newGame!!) } super.render(delta) @@ -144,5 +149,4 @@ class TranslatedSelectBox(values : Collection, default:String, skin: Ski val defaultItem = array.firstOrNull { it.value == default } selected = if (defaultItem != null) defaultItem else array.first() } -} - +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt index 9dffca5835..d7184c85f6 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt @@ -23,11 +23,8 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi top() defaults().pad(5f) - val mapOptionsColumn = MapOptionsTable(newGameScreen) - add(mapOptionsColumn).row() - val gameOptionsColumn = Table().apply { defaults().pad(5f) } - gameOptionsColumn.add("Game options".toLabel(fontSize = 24)).colspan(2).row() + gameOptionsColumn.add("Game options".toLabel(fontSize = 24)).padTop(0f).colspan(2).row() gameOptionsColumn.addDifficultySelectBox() gameOptionsColumn.addGameSpeedSelectBox() gameOptionsColumn.addEraSelectBox() @@ -43,23 +40,23 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi pack() } - private fun Table.addCheckbox(text:String, initialState:Boolean, onChange:(newValue:Boolean)->Unit){ + private fun Table.addCheckbox(text: String, initialState: Boolean, onChange: (newValue: Boolean) -> Unit) { val checkbox = CheckBox(text.tr(), CameraStageBaseScreen.skin) checkbox.isChecked = initialState checkbox.onChange { onChange(checkbox.isChecked) } add(checkbox).colspan(2).row() } - private fun Table.addBarbariansCheckbox() = - addCheckbox("No barbarians", newGameParameters.noBarbarians) + private fun Table.addBarbariansCheckbox() = + addCheckbox("No barbarians", newGameParameters.noBarbarians) { newGameParameters.noBarbarians = it } private fun Table.addOneCityChallengeCheckbox() = - addCheckbox("One City Challenge", newGameParameters.oneCityChallenge) + addCheckbox("One City Challenge", newGameParameters.oneCityChallenge) { newGameParameters.oneCityChallenge = it } private fun Table.addNuclearWeaponsCheckbox() = - addCheckbox("Enable nuclear weapons", newGameParameters.nuclearWeaponsEnabled) + addCheckbox("Enable nuclear weapons", newGameParameters.nuclearWeaponsEnabled) { newGameParameters.nuclearWeaponsEnabled = it } @@ -80,7 +77,7 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi val numberOfCityStates = ruleset.nations.filter { it.value.isCityState() }.size - val cityStatesArray = Array(numberOfCityStates+1) + val cityStatesArray = Array(numberOfCityStates + 1) (0..numberOfCityStates).forEach { cityStatesArray.add(it) } cityStatesSelectBox.items = cityStatesArray @@ -91,7 +88,7 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi } } - fun Table.addSelectBox(text:String, values:Collection, initialState:String, onChange: (newValue: String) -> Unit){ + fun Table.addSelectBox(text: String, values: Collection, initialState: String, onChange: (newValue: String) -> Unit) { add(text.toLabel()) val selectBox = TranslatedSelectBox(values, initialState, CameraStageBaseScreen.skin) selectBox.onChange { onChange(selectBox.selected.value) } @@ -100,18 +97,18 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi private fun Table.addDifficultySelectBox() { addSelectBox("{Difficulty}:", ruleset.difficulties.keys, newGameParameters.difficulty) - {newGameParameters.difficulty = it} + { newGameParameters.difficulty = it } } private fun Table.addGameSpeedSelectBox() { addSelectBox("{Game Speed}:", GameSpeed.values().map { it.name }, newGameParameters.gameSpeed.name) - {newGameParameters.gameSpeed = GameSpeed.valueOf(it)} + { newGameParameters.gameSpeed = GameSpeed.valueOf(it) } } private fun Table.addEraSelectBox() { val eras = ruleset.technologies.values.map { it.era() }.distinct() addSelectBox("{Starting Era}:", eras, newGameParameters.startingEra) - { newGameParameters.startingEra = it } + { newGameParameters.startingEra = it } } @@ -142,8 +139,8 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi fun Table.addModCheckboxes() { - val modRulesets = RulesetCache.filter { it.key!="" }.values - if(modRulesets.isEmpty()) return + val modRulesets = RulesetCache.filter { it.key != "" }.values + if (modRulesets.isEmpty()) return fun reloadMods() { ruleset.clear() @@ -158,8 +155,8 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi add("Mods:".toLabel(fontSize = 24)).padTop(16f).colspan(2).row() val modCheckboxTable = Table().apply { defaults().pad(5f) } - for(mod in modRulesets){ - val checkBox = CheckBox(mod.name.tr(),CameraStageBaseScreen.skin) + for (mod in modRulesets) { + val checkBox = CheckBox(mod.name.tr(), CameraStageBaseScreen.skin) if (mod.name in newGameParameters.mods) checkBox.isChecked = true checkBox.onChange { if (checkBox.isChecked) newGameParameters.mods.add(mod.name) @@ -180,5 +177,4 @@ class NewGameScreenOptionsTable(newGameScreen: NewGameScreen, val updatePlayerPi add(modCheckboxTable).colspan(2).row() } -} - +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt index fad7ad8060..8e6070c0f4 100644 --- a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt @@ -22,10 +22,12 @@ import java.util.* class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: GameParameters): Table() { val playerListTable = Table() val nationsPopupWidth = newGameScreen.stage.width / 2f + val civBlocksWidth = newGameScreen.stage.width / 3 init { top() - add(ScrollPane(playerListTable).apply{setOverscroll(false,false)}).width(newGameScreen.stage.width/2) + add("Civilizations".toLabel(fontSize = 24)).padBottom(20f).row() + add(ScrollPane(playerListTable).apply { setOverscroll(false, false) }).width(civBlocksWidth) update() } @@ -34,19 +36,19 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: val gameBasics = newGameScreen.ruleset // the mod picking changes this ruleset reassignRemovedModReferences() - val newRulesetPlayableCivs = newGameScreen.ruleset.nations.count { it.key!=Constants.barbarians } - if(newGameParameters.players.size > newRulesetPlayableCivs) - newGameParameters.players=ArrayList(newGameParameters.players.subList(0,newRulesetPlayableCivs)) + val newRulesetPlayableCivs = newGameScreen.ruleset.nations.count { it.key != Constants.barbarians } + if (newGameParameters.players.size > newRulesetPlayableCivs) + newGameParameters.players = ArrayList(newGameParameters.players.subList(0, newRulesetPlayableCivs)) if (desiredCiv.isNotEmpty()) assignDesiredCiv(desiredCiv) for (player in newGameParameters.players) { - playerListTable.add(getPlayerTable(player, gameBasics)).pad(10f).row() + playerListTable.add(getPlayerTable(player, gameBasics)).width(civBlocksWidth).padBottom(20f).row() } - if(newGameParameters.players.count() < gameBasics.nations.values.count { it.isMajorCiv() }) { - playerListTable.add("+".toLabel(Color.BLACK,30).apply { this.setAlignment(Align.center) } + if (newGameParameters.players.count() < gameBasics.nations.values.count { it.isMajorCiv() }) { + playerListTable.add("+".toLabel(Color.BLACK, 30).apply { this.setAlignment(Align.center) } .surroundWithCircle(50f).onClick { newGameParameters.players.add(Player()); update() }).pad(10f) } - newGameScreen.setNewGameButtonEnabled(newGameParameters.players.size>1) + newGameScreen.setNewGameButtonEnabled(newGameParameters.players.size > 1) } private fun reassignRemovedModReferences() { @@ -58,9 +60,9 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: private fun assignDesiredCiv(desiredCiv: String) { // No auto-select if desiredCiv already used - if (newGameParameters.players.any {it.chosenCiv == desiredCiv}) return + if (newGameParameters.players.any { it.chosenCiv == desiredCiv }) return // Do auto-select, silently no-op if no suitable slot (human with 'random' choice) - newGameParameters.players.firstOrNull { it.chosenCiv == "Random" && it.playerType==PlayerType.Human }?.chosenCiv = desiredCiv + newGameParameters.players.firstOrNull { it.chosenCiv == "Random" && it.playerType == PlayerType.Human }?.chosenCiv = desiredCiv } fun getPlayerTable(player: Player, ruleset: Ruleset): Table { @@ -69,7 +71,7 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: playerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.8f)) val nationTable = getNationTable(player) - playerTable.add(nationTable) + playerTable.add(nationTable).left() val playerTypeTextbutton = player.playerType.name.toTextButton() playerTypeTextbutton.onClick { @@ -78,11 +80,11 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: else player.playerType = PlayerType.AI update() } - playerTable.add(playerTypeTextbutton).width(100f).pad(5f) - playerTable.add("-".toLabel(Color.BLACK,30).apply { this.setAlignment(Align.center) } + playerTable.add(playerTypeTextbutton).width(100f).pad(5f).right() + playerTable.add("-".toLabel(Color.BLACK, 30).apply { this.setAlignment(Align.center) } .surroundWithCircle(40f) - .onClick { newGameParameters.players.remove(player); update() }).pad(5f).row() - if(newGameParameters.isOnlineMultiplayer && player.playerType==PlayerType.Human) { + .onClick { newGameParameters.players.remove(player); update() }).pad(5f).right().row() + if (newGameParameters.isOnlineMultiplayer && player.playerType == PlayerType.Human) { val playerIdTextfield = TextField(player.playerId, CameraStageBaseScreen.skin) playerIdTextfield.messageText = "Please input Player ID!".tr() @@ -90,7 +92,7 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: var errorLabel = "✘".toLabel(Color.RED) playerTable.add(errorLabel).pad(5f).row() - fun onPlayerIdTextUpdated(){ + fun onPlayerIdTextUpdated() { try { UUID.fromString(IdChecker.checkAndReturnPlayerUuid(playerIdTextfield.text)) player.playerId = playerIdTextfield.text.trim() @@ -122,13 +124,13 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: private fun getNationTable(player: Player): Table { val nationTable = Table() - val nationImage = if (player.chosenCiv == "Random") "?".toLabel(Color.WHITE,25) + val nationImage = if (player.chosenCiv == "Random") "?".toLabel(Color.WHITE, 25) .apply { this.setAlignment(Align.center) } .surroundWithCircle(36f).apply { circle.color = Color.BLACK } - .surroundWithCircle(40f,false).apply { circle.color = Color.WHITE } + .surroundWithCircle(40f, false).apply { circle.color = Color.WHITE } else ImageGetter.getNationIndicator(newGameScreen.ruleset.nations[player.chosenCiv]!!, 40f) nationTable.add(nationImage).pad(5f) - nationTable.add(player.chosenCiv.toLabel()).width(230f).pad(5f) + nationTable.add(player.chosenCiv.toLabel()).pad(5f) nationTable.touchable = Touchable.enabled nationTable.onClick { popupNationPicker(player) @@ -146,7 +148,7 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: randomPlayerTable.add("?".toLabel(Color.WHITE, 30) .apply { this.setAlignment(Align.center) } .surroundWithCircle(45f).apply { circle.color = Color.BLACK } - .surroundWithCircle(50f,false).apply { circle.color = Color.WHITE }).pad(10f) + .surroundWithCircle(50f, false).apply { circle.color = Color.WHITE }).pad(10f) randomPlayerTable.add("Random".toLabel()) randomPlayerTable.touchable = Touchable.enabled randomPlayerTable.onClick { @@ -162,7 +164,7 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: if (player.chosenCiv != nation.name && newGameParameters.players.any { it.chosenCiv == nation.name }) continue - nationListTable.add(NationTable(nation, nationsPopupWidth,newGameScreen.ruleset).onClick { + nationListTable.add(NationTable(nation, nationsPopupWidth, newGameScreen.ruleset).onClick { player.chosenCiv = nation.name nationsPopup.close() update() @@ -172,6 +174,4 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: nationsPopup.open() update() } -} - - +} \ No newline at end of file