From be216d8e6bef68c52797d54cca9560de363b731b Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 15 Aug 2020 21:58:02 +0300 Subject: [PATCH] Game no longer crashes on new game screen when no scenarios are available --- .../unciv/ui/newgamescreen/MapOptionsTable.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt index 61156a0e..44d0f9c9 100644 --- a/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt @@ -80,16 +80,19 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() { override fun toString() = fileHandle.name() } + val scenarioFiles = getScenarioFiles() val scenarioSelectBox = SelectBox(CameraStageBaseScreen.skin) - for (savedGame in getScenarioFiles()) { - scenarioSelectBox.items.add(FileHandleWrapper(savedGame)) + if (scenarioFiles.any()) { + for (savedGame in getScenarioFiles()) { + scenarioSelectBox.items.add(FileHandleWrapper(savedGame)) + } + scenarioSelectBox.items = scenarioSelectBox.items // it doesn't register them until you do this. + scenarioSelectBox.selected = scenarioSelectBox.items.first() + // needs to be after the item change, so it doesn't activate before we choose the Scenario maptype + scenarioSelectBox.onChange { selectSavedGameAsScenario(scenarioSelectBox.selected.fileHandle) } + scenarioOptionsTable.add("{Scenario file}:".toLabel()).left() + scenarioOptionsTable.add(scenarioSelectBox) } - scenarioSelectBox.items = scenarioSelectBox.items // it doesn't register them until you do this. - scenarioSelectBox.selected = scenarioSelectBox.items.first() - // needs to be after the item change, so it doesn't activate before we choose the Scenario maptype - scenarioSelectBox.onChange { selectSavedGameAsScenario(scenarioSelectBox.selected.fileHandle) } - scenarioOptionsTable.add("{Scenario file}:".toLabel()).left() - scenarioOptionsTable.add(scenarioSelectBox) fun updateOnMapTypeChange() { mapTypeSpecificTable.clear()