Fix option change not reloading main menu properly (#7170)

This commit is contained in:
Timo T 2022-06-15 19:01:02 +02:00 committed by GitHub
parent 89a7cc7246
commit 1bbc11cc47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -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) {

View File

@ -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() {
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)) {