From 1bbc11cc47125c794ff8578c4a265dad5e79e9cd Mon Sep 17 00:00:00 2001 From: Timo T Date: Wed, 15 Jun 2022 19:01:02 +0200 Subject: [PATCH] Fix option change not reloading main menu properly (#7170) --- core/src/com/unciv/UncivGame.kt | 4 ++-- core/src/com/unciv/ui/options/OptionsPopup.kt | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index b8c85b3d6a..7b2ec9d9ac 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -204,12 +204,12 @@ class UncivGame(parameters: UncivGameParameters) : Game() { } /** Re-creates the current [worldScreen], if there is any. */ - fun reloadWorldscreen() { + suspend fun reloadWorldscreen() { val curWorldScreen = worldScreen val curGameInfo = gameInfo if (curWorldScreen == null || curGameInfo == null) return - Concurrency.run { loadGame(curGameInfo) } + loadGame(curGameInfo) } private data class NewScreens(val screenToShow: BaseScreen, val worldScreen: WorldScreen) { diff --git a/core/src/com/unciv/ui/options/OptionsPopup.kt b/core/src/com/unciv/ui/options/OptionsPopup.kt index 949e8fa0ea..e708b1f1e7 100644 --- a/core/src/com/unciv/ui/options/OptionsPopup.kt +++ b/core/src/com/unciv/ui/options/OptionsPopup.kt @@ -28,6 +28,9 @@ import com.unciv.ui.utils.extensions.toCheckBox import com.unciv.ui.utils.extensions.toGdxArray import com.unciv.ui.utils.extensions.toLabel import com.unciv.ui.worldscreen.WorldScreen +import com.unciv.utils.concurrency.Concurrency +import com.unciv.utils.concurrency.Dispatcher +import com.unciv.utils.concurrency.withGLContext import kotlin.reflect.KMutableProperty0 /** @@ -133,8 +136,20 @@ class OptionsPopup( /** Reload this Popup after major changes (resolution, tileset, language, font) */ private fun reloadWorldAndOptions() { - settings.save() - UncivGame.Current.reloadWorldscreen() + Concurrency.run("Reload from options") { + settings.save() + val screen = UncivGame.Current.screen + if (screen is WorldScreen) { + UncivGame.Current.reloadWorldscreen() + } else if (screen is MainMenuScreen) { + withGLContext { + UncivGame.Current.setScreen(MainMenuScreen()) + } + } + withGLContext { + UncivGame.Current.screen?.openOptionsPopup(tabs.activePage) + } + } } fun addCheckbox(table: Table, text: String, initialState: Boolean, updateWorld: Boolean = false, action: ((Boolean) -> Unit)) {