diff --git a/core/src/com/unciv/ui/screens/multiplayerscreens/AddMultiplayerGameScreen.kt b/core/src/com/unciv/ui/screens/multiplayerscreens/AddMultiplayerGameScreen.kt index 576b944cca..dbfe5395d1 100644 --- a/core/src/com/unciv/ui/screens/multiplayerscreens/AddMultiplayerGameScreen.kt +++ b/core/src/com/unciv/ui/screens/multiplayerscreens/AddMultiplayerGameScreen.kt @@ -18,7 +18,7 @@ import com.unciv.utils.Concurrency import com.unciv.utils.launchOnGLThread import java.util.UUID -class AddMultiplayerGameScreen : PickerScreen() { +class AddMultiplayerGameScreen(multiplayerScreen: MultiplayerScreen) : PickerScreen() { init { val gameNameTextField = UncivTextField.create("Game name") val gameIDTextField = UncivTextField.create("GameID") @@ -63,6 +63,7 @@ class AddMultiplayerGameScreen : PickerScreen() { launchOnGLThread { popup.close() game.popScreen() + multiplayerScreen.gameList.update() } } catch (ex: Exception) { val (message) = LoadGameScreen.getLoadExceptionMessage(ex) diff --git a/core/src/com/unciv/ui/screens/multiplayerscreens/GameList.kt b/core/src/com/unciv/ui/screens/multiplayerscreens/GameList.kt index a586461bfe..7763e74624 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.MultiplayerGameAdded import com.unciv.logic.multiplayer.MultiplayerGameDeleted import com.unciv.logic.multiplayer.MultiplayerGameNameChanged import com.unciv.logic.multiplayer.MultiplayerGameUpdateEnded @@ -25,7 +24,7 @@ import com.unciv.ui.components.input.onClick import com.unciv.ui.components.extensions.setSize class GameList( - onSelected: (String) -> Unit + val onSelected: (String) -> Unit ) : VerticalGroup() { private val gameDisplays = mutableMapOf() @@ -36,33 +35,24 @@ class GameList( padTop(10f) padBottom(10f) - events.receive(MultiplayerGameAdded::class) { - val multiplayerGame = UncivGame.Current.onlineMultiplayer.getGameByName(it.name) - if (multiplayerGame == null) return@receive - addGame(it.name, multiplayerGame.preview, multiplayerGame.error, onSelected) - } events.receive(MultiplayerGameNameChanged::class) { - val gameDisplay = gameDisplays.remove(it.name) - if (gameDisplay == null) return@receive - gameDisplay.changeName(it.newName) - gameDisplays[it.newName] = gameDisplay - children.sort() + update() } events.receive(MultiplayerGameDeleted::class) { - val gameDisplay = gameDisplays.remove(it.name) - if (gameDisplay == null) return@receive - gameDisplay.remove() + update() } - for (game in UncivGame.Current.onlineMultiplayer.games) { - addGame(game.name, game.preview, game.error, onSelected) - } + update() } - private fun addGame(name: String, preview: GameInfoPreview?, error: Exception?, onSelected: (String) -> Unit) { - val gameDisplay = GameDisplay(name, preview, error, onSelected) - gameDisplays[name] = gameDisplay - addActor(gameDisplay) + fun update(){ + clearChildren() + gameDisplays.clear() + for (game in UncivGame.Current.onlineMultiplayer.games) { + val gameDisplay = GameDisplay(game.name, game.preview, game.error, onSelected) + gameDisplays[game.name] = gameDisplay + addActor(gameDisplay) + } children.sort() } } diff --git a/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt b/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt index efda9193b4..723992becb 100644 --- a/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt +++ b/core/src/com/unciv/ui/screens/multiplayerscreens/MultiplayerScreen.kt @@ -38,7 +38,7 @@ class MultiplayerScreen : PickerScreen() { private val refreshButton = createRefreshButton() private val rightSideTable = createRightSideTable() - private val leftSideTable = GameList(::selectGame) + val gameList = GameList(::selectGame) private val events = EventBus.EventReceiver() @@ -91,7 +91,7 @@ class MultiplayerScreen : PickerScreen() { fun createAddGameButton(): TextButton { val btn = addGameText.toTextButton() btn.onClick { - game.pushScreen(AddMultiplayerGameScreen()) + game.pushScreen(AddMultiplayerGameScreen(this)) } return btn } @@ -135,7 +135,7 @@ class MultiplayerScreen : PickerScreen() { private fun createMainContent(): Table { val mainTable = Table() - mainTable.add(ScrollPane(leftSideTable).apply { setScrollingDisabled(true, false) }).center() + mainTable.add(ScrollPane(gameList).apply { setScrollingDisabled(true, false) }).center() mainTable.add(rightSideTable) return mainTable }