diff --git a/core/src/com/unciv/logic/multiplayer/OnlineMultiplayer.kt b/core/src/com/unciv/logic/multiplayer/OnlineMultiplayer.kt index 09ddc2c9e5..e178e49a9c 100644 --- a/core/src/com/unciv/logic/multiplayer/OnlineMultiplayer.kt +++ b/core/src/com/unciv/logic/multiplayer/OnlineMultiplayer.kt @@ -112,7 +112,7 @@ class OnlineMultiplayer { } } - private suspend fun updateSavesFromFiles() { + private fun updateSavesFromFiles() { val saves = files.getMultiplayerSaves() val removedSaves = savedGames.keys - saves.toSet() @@ -152,12 +152,12 @@ class OnlineMultiplayer { addGame(gamePreview, saveFileName) } - private suspend fun addGame(newGame: GameInfo) { + private fun addGame(newGame: GameInfo) { val newGamePreview = newGame.asPreview() addGame(newGamePreview, newGamePreview.gameId) } - private suspend fun addGame(preview: GameInfoPreview, saveFileName: String) { + private fun addGame(preview: GameInfoPreview, saveFileName: String) { val fileHandle = files.saveGame(preview, saveFileName) return addGame(fileHandle, preview) } @@ -271,8 +271,6 @@ class OnlineMultiplayer { /** * Deletes the game from disk, does not delete it remotely. - * - * Fires [MultiplayerGameDeleted] */ fun deleteGame(multiplayerGame: OnlineMultiplayerGame) { deleteGame(multiplayerGame.fileHandle) @@ -285,7 +283,6 @@ class OnlineMultiplayer { debug("Deleting game %s with id %s", fileHandle.name(), game.preview?.gameId) savedGames.remove(game.fileHandle) - Concurrency.runOnGLThread { EventBus.send(MultiplayerGameDeleted(game.name)) } } /** diff --git a/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerEvents.kt b/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerEvents.kt index d9d974004b..0ad0c62ba3 100644 --- a/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerEvents.kt +++ b/core/src/com/unciv/logic/multiplayer/OnlineMultiplayerEvents.kt @@ -49,10 +49,3 @@ class MultiplayerGameNameChanged( override val name: String, val newName: String ) : Event, HasMultiplayerGameName - -/** - * Gets sent when a game is deleted - */ -class MultiplayerGameDeleted( - override val name: String -) : Event, HasMultiplayerGameName diff --git a/core/src/com/unciv/ui/screens/multiplayerscreens/EditMultiplayerGameInfoScreen.kt b/core/src/com/unciv/ui/screens/multiplayerscreens/EditMultiplayerGameInfoScreen.kt index 9808c43aeb..bde551a021 100644 --- a/core/src/com/unciv/ui/screens/multiplayerscreens/EditMultiplayerGameInfoScreen.kt +++ b/core/src/com/unciv/ui/screens/multiplayerscreens/EditMultiplayerGameInfoScreen.kt @@ -41,7 +41,7 @@ class EditMultiplayerGameInfoScreen(val multiplayerGame: OnlineMultiplayerGame) ) { try { game.onlineMultiplayer.deleteGame(multiplayerGame) - game.popScreen() + (game.popScreen() as? MultiplayerScreen)?.onGameDeleted(multiplayerGame.name) } catch (ex: Exception) { Log.error("Could not delete game!", ex) ToastPopup("Could not delete game!", this) diff --git a/core/src/com/unciv/ui/screens/multiplayerscreens/GameList.kt b/core/src/com/unciv/ui/screens/multiplayerscreens/GameList.kt index 7763e74624..3b2a69013f 100644 --- a/core/src/com/unciv/ui/screens/multiplayerscreens/GameList.kt +++ b/core/src/com/unciv/ui/screens/multiplayerscreens/GameList.kt @@ -10,7 +10,6 @@ import com.unciv.UncivGame import com.unciv.logic.GameInfoPreview import com.unciv.logic.event.EventBus import com.unciv.logic.multiplayer.HasMultiplayerGameName -import com.unciv.logic.multiplayer.MultiplayerGameDeleted import com.unciv.logic.multiplayer.MultiplayerGameNameChanged import com.unciv.logic.multiplayer.MultiplayerGameUpdateEnded import com.unciv.logic.multiplayer.MultiplayerGameUpdateFailed @@ -38,9 +37,6 @@ class GameList( events.receive(MultiplayerGameNameChanged::class) { update() } - events.receive(MultiplayerGameDeleted::class) { - update() - } update() } @@ -101,11 +97,6 @@ private class GameDisplay( } } - fun changeName(newName: String) { - gameName = newName - gameButton.setText(newName) - } - private fun updateTurnIndicator() { if (isPlayersTurn()) statusIndicators.addActor(turnIndicator) else turnIndicator.remove() diff --git a/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt b/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt index 723992becb..31ccf170fb 100644 --- a/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt +++ b/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt @@ -3,8 +3,6 @@ package com.unciv.ui.screens.multiplayerscreens import com.badlogic.gdx.Gdx import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton -import com.unciv.logic.event.EventBus -import com.unciv.logic.multiplayer.MultiplayerGameDeleted import com.unciv.logic.multiplayer.OnlineMultiplayerGame import com.unciv.models.translations.tr import com.unciv.ui.screens.pickerscreens.PickerScreen @@ -40,8 +38,6 @@ class MultiplayerScreen : PickerScreen() { private val rightSideTable = createRightSideTable() val gameList = GameList(::selectGame) - private val events = EventBus.EventReceiver() - init { setDefaultCloseAction() @@ -53,16 +49,17 @@ class MultiplayerScreen : PickerScreen() { setupRightSideButton() - events.receive(MultiplayerGameDeleted::class, { it.name == selectedGame?.name }) { - unselectGame() - } - game.onlineMultiplayer.requestUpdate() pickerPane.bottomTable.background = skinStrings.getUiBackground("MultiplayerScreen/BottomTable", tintColor = skinStrings.skinConfig.clearColor) pickerPane.topTable.background = skinStrings.getUiBackground("MultiplayerScreen/TopTable", tintColor = skinStrings.skinConfig.clearColor) } + fun onGameDeleted(gameName:String){ + if (selectedGame?.name == gameName) unselectGame() + gameList.update() + } + private fun setupRightSideButton() { rightSideButton.setText("Join game".tr()) rightSideButton.onClick { MultiplayerHelpers.loadMultiplayerGame(this, selectedGame!!) }