mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
All UI changes in threads are now run in a postRunnable - should hopefully get rid of IndexOutOfBoundsExceptions
This commit is contained in:
parent
507c677d08
commit
7330daff48
@ -65,7 +65,6 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
||||
Actions.fadeIn(0.3f)
|
||||
))
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,14 +143,16 @@ class MultiplayerScreen(previousScreen: CameraStageBaseScreen) : PickerScreen()
|
||||
else
|
||||
GameSaver.saveGame(game, gameName, true)
|
||||
|
||||
reloadGameListUI()
|
||||
Gdx.app.postRunnable { reloadGameListUI() }
|
||||
} catch (ex: Exception) {
|
||||
Gdx.app.postRunnable {
|
||||
val errorPopup = Popup(this)
|
||||
errorPopup.addGoodSizedLabel("Could not download game!".tr())
|
||||
errorPopup.row()
|
||||
errorPopup.addCloseButton()
|
||||
errorPopup.open()
|
||||
}
|
||||
}
|
||||
addGameButton.setText(addGameText)
|
||||
addGameButton.enable()
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) {
|
||||
open()
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
addGoodSizedLabel("Could not get list of maps!").row()
|
||||
Gdx.app.postRunnable { addGoodSizedLabel("Could not get list of maps!").row() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ class NewMapScreen : PickerScreen() {
|
||||
}
|
||||
|
||||
} catch (exception: Exception) {
|
||||
Gdx.app.postRunnable {
|
||||
rightButtonSetEnabled(true)
|
||||
val cantMakeThatMapPopup = Popup(this)
|
||||
cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr())
|
||||
@ -63,6 +64,7 @@ class NewMapScreen : PickerScreen() {
|
||||
Gdx.input.inputProcessor = stage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -98,12 +98,14 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
|
||||
//Save gameId to clipboard because you have to do it anyway.
|
||||
Gdx.app.clipboard.contents = newGame!!.gameId
|
||||
//Popup to notify the User that the gameID got copied to the clipboard
|
||||
ResponsePopup("gameID copied to clipboard".tr(), UncivGame.Current.worldScreen, 2500)
|
||||
Gdx.app.postRunnable { ResponsePopup("gameID copied to clipboard".tr(), UncivGame.Current.worldScreen, 2500) }
|
||||
} catch (ex: Exception) {
|
||||
Gdx.app.postRunnable {
|
||||
val cantUploadNewGamePopup = Popup(this)
|
||||
cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!")
|
||||
cantUploadNewGamePopup.addCloseButton()
|
||||
cantUploadNewGamePopup.open()
|
||||
}
|
||||
newGame = null
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class SaveGameScreen : PickerScreen() {
|
||||
rightSideButton.setText("Saving...".tr())
|
||||
thread(name="SaveGame") {
|
||||
GameSaver.saveGame(UncivGame.Current.gameInfo, textField.text)
|
||||
UncivGame.Current.setWorldScreen()
|
||||
Gdx.app.postRunnable { UncivGame.Current.setWorldScreen() }
|
||||
}
|
||||
}
|
||||
rightSideButton.enable()
|
||||
|
@ -461,17 +461,19 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
try {
|
||||
OnlineMultiplayer().tryUploadGame(gameInfoClone)
|
||||
} catch (ex: Exception) {
|
||||
Gdx.app.postRunnable { // Since we're changing the UI, that should be done on the main thread
|
||||
val cantUploadNewGamePopup = Popup(this)
|
||||
cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!").row()
|
||||
cantUploadNewGamePopup.addCloseButton()
|
||||
cantUploadNewGamePopup.open()
|
||||
}
|
||||
isPlayersTurn = true // Since we couldn't push the new game clone, then it's like we never clicked the "next turn" button
|
||||
shouldUpdate = true
|
||||
return@thread
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
game.crashController.crashOccurred()
|
||||
Gdx.app.postRunnable { game.crashController.crashOccurred() }
|
||||
throw ex
|
||||
}
|
||||
|
||||
|
@ -220,17 +220,21 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
|
||||
innerTable.add(errorTable).colspan(2).row()
|
||||
|
||||
downloadMusicButton.onClick {
|
||||
// So the whole game doesn't get stuck while downloading the file
|
||||
thread(name = "Music") {
|
||||
try {
|
||||
downloadMusicButton.disable()
|
||||
errorTable.clear()
|
||||
errorTable.add("Downloading...".toLabel())
|
||||
|
||||
// So the whole game doesn't get stuck while downloading the file
|
||||
thread(name = "Music") {
|
||||
try {
|
||||
val file = DropBox.downloadFile("/Music/thatched-villagers.mp3")
|
||||
musicLocation.write(file, false)
|
||||
Gdx.app.postRunnable {
|
||||
rebuildInnerTable()
|
||||
worldScreen.game.startMusic()
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
Gdx.app.postRunnable {
|
||||
errorTable.clear()
|
||||
errorTable.add("Could not download music!".toLabel(Color.RED))
|
||||
}
|
||||
@ -238,6 +242,7 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addResolutionSelectBox() {
|
||||
innerTable.add("Resolution".toLabel())
|
||||
|
@ -66,7 +66,9 @@ class UnitContextMenu(val tileMapHolder: WorldMapHolder, val selectedUnit: MapUn
|
||||
val tileToMoveTo: TileInfo
|
||||
try {
|
||||
tileToMoveTo = selectedUnit.movement.getTileToMoveToThisTurn(targetTile)
|
||||
}catch (ex:Exception){ return@thread } // can't move here
|
||||
} catch (ex: Exception) {
|
||||
return@thread
|
||||
} // can't move here
|
||||
|
||||
Gdx.app.postRunnable {
|
||||
try {
|
||||
@ -86,8 +88,7 @@ class UnitContextMenu(val tileMapHolder: WorldMapHolder, val selectedUnit: MapUn
|
||||
|
||||
tileMapHolder.worldScreen.shouldUpdate = true
|
||||
tileMapHolder.unitActionOverlay?.remove()
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
} catch (e: Exception) {}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user