Dispose main menu screen when exiting to save space

This commit is contained in:
Yair Morgenstern 2020-07-06 23:25:11 +03:00
parent 58a8e358ea
commit 0516810571
3 changed files with 24 additions and 12 deletions

View File

@ -8,6 +8,8 @@ Fixed main menu crash when returning from certain modded games
Resolved #2794 - Save games and maps cannot have slashes/backslashes, to avoid foldername/filename confusion Resolved #2794 - Save games and maps cannot have slashes/backslashes, to avoid foldername/filename confusion
Civ is properly destroyed when liberating the last city of the civ
By alkorolyov: By alkorolyov:
- Basic spectator functionality - POC - Basic spectator functionality - POC
- Console mode for multiple game automation - POC - Console mode for multiple game automation - POC

View File

@ -46,9 +46,9 @@ class MainMenuScreen: CameraStageBaseScreen() {
ImageGetter.ruleset = RulesetCache.getBaseRuleset() ImageGetter.ruleset = RulesetCache.getBaseRuleset()
ImageGetter.refreshAtlas() ImageGetter.refreshAtlas()
thread(name="ShowMapBackground") { thread(name = "ShowMapBackground") {
val newMap = MapGenerator(RulesetCache.getBaseRuleset()) val newMap = MapGenerator(RulesetCache.getBaseRuleset())
.generateMap(MapParameters().apply { size = MapSize.Small; type=MapType.default }) .generateMap(MapParameters().apply { size = MapSize.Small; type = MapType.default })
Gdx.app.postRunnable { // for GL context Gdx.app.postRunnable { // for GL context
val mapHolder = EditorMapHolder(MapEditorScreen(), newMap) val mapHolder = EditorMapHolder(MapEditorScreen(), newMap)
backgroundTable.addAction(Actions.sequence( backgroundTable.addAction(Actions.sequence(
@ -72,35 +72,40 @@ class MainMenuScreen: CameraStageBaseScreen() {
val table = Table().apply { defaults().pad(10f) } val table = Table().apply { defaults().pad(10f) }
val autosaveGame = GameSaver.getSave(autosave, false) val autosaveGame = GameSaver.getSave(autosave, false)
if (autosaveGame.exists()) { if (autosaveGame.exists()) {
val resumeTable = getTableBlock("Resume","OtherIcons/Resume") { autoLoadGame() } val resumeTable = getTableBlock("Resume", "OtherIcons/Resume") { autoLoadGame() }
table.add(resumeTable).row() table.add(resumeTable).row()
} }
val quickstartTable = getTableBlock("Quickstart","OtherIcons/Quickstart") { QuickstartNewGame() } val quickstartTable = getTableBlock("Quickstart", "OtherIcons/Quickstart") { QuickstartNewGame() }
table.add(quickstartTable).row() table.add(quickstartTable).row()
val newGameButton = getTableBlock("Start new game","OtherIcons/New") { val newGameButton = getTableBlock("Start new game", "OtherIcons/New") {
game.setScreen(NewGameScreen(this)) game.setScreen(NewGameScreen(this))
dispose()
} }
table.add(newGameButton).row() table.add(newGameButton).row()
if (GameSaver.getSaves(false).any()) { if (GameSaver.getSaves(false).any()) {
val loadGameTable = getTableBlock("Load game","OtherIcons/Load") { game.setScreen(LoadGameScreen(this)) } val loadGameTable = getTableBlock("Load game", "OtherIcons/Load")
{ game.setScreen(LoadGameScreen(this)) }
table.add(loadGameTable).row() table.add(loadGameTable).row()
} }
val multiplayerTable = getTableBlock("Multiplayer","OtherIcons/Multiplayer") { game.setScreen(MultiplayerScreen(this)) } val multiplayerTable = getTableBlock("Multiplayer", "OtherIcons/Multiplayer")
{ game.setScreen(MultiplayerScreen(this)) }
table.add(multiplayerTable).row() table.add(multiplayerTable).row()
val mapEditorScreenTable = getTableBlock("Map editor","OtherIcons/MapEditor") { openMapEditorPopup() } val mapEditorScreenTable = getTableBlock("Map editor", "OtherIcons/MapEditor")
{ openMapEditorPopup() }
table.add(mapEditorScreenTable) table.add(mapEditorScreenTable)
// set the same width for all buttons // set the same width for all buttons
table.pack() table.pack()
table.children.filterIsInstance<Table>().forEach { table.children.filterIsInstance<Table>().forEach {
it.align(Align.left) it.align(Align.left)
it.moveBy( (it.width - table.width) / 2, 0f) it.moveBy((it.width - table.width) / 2, 0f)
it.width = table.width } it.width = table.width
}
table.pack() table.pack()
val scroll = ScrollPane(table) val scroll = ScrollPane(table)
@ -119,7 +124,10 @@ class MainMenuScreen: CameraStageBaseScreen() {
val tableBackground = ImageGetter.getBackground(colorFromRGB(29, 102, 107)) val tableBackground = ImageGetter.getBackground(colorFromRGB(29, 102, 107))
val newMapButton = getTableBlock("New map", "OtherIcons/New") { game.setScreen(NewMapScreen()) } val newMapButton = getTableBlock("New map", "OtherIcons/New") {
game.setScreen(NewMapScreen())
dispose()
}
newMapButton.background = tableBackground newMapButton.background = tableBackground
mapEditorPopup.add(newMapButton).row() mapEditorPopup.add(newMapButton).row()
@ -131,6 +139,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
loadMapScreen.dispose() loadMapScreen.dispose()
} }
game.setScreen(loadMapScreen) game.setScreen(loadMapScreen)
dispose()
} }
loadMapButton.background = tableBackground loadMapButton.background = tableBackground
@ -145,6 +154,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
loadScenarioScreen.dispose() loadScenarioScreen.dispose()
} }
game.setScreen(loadScenarioScreen) game.setScreen(loadScenarioScreen)
dispose()
} }
loadScenarioButton.background = tableBackground loadScenarioButton.background = tableBackground
@ -160,6 +170,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
private fun autoLoadGame() { private fun autoLoadGame() {
try { try {
game.loadGame(autosave) game.loadGame(autosave)
dispose()
} }
catch (outOfMemory:OutOfMemoryError){ catch (outOfMemory:OutOfMemoryError){
ResponsePopup("Not enough memory on phone to load game!", this) ResponsePopup("Not enough memory on phone to load game!", this)

View File

@ -437,7 +437,6 @@ class CityInfo {
return return
} }
val oldCiv = civInfo val oldCiv = civInfo
diplomaticRepercussionsForLiberatingCity(conqueringCiv) diplomaticRepercussionsForLiberatingCity(conqueringCiv)