mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-24 10:01:39 +07:00
EventHub removal - 'add multiplayer game' no longer works through EventHub
This commit is contained in:
parent
0dbc9b0bce
commit
e7f4c4dd1d
@ -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)
|
||||
|
@ -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<String, GameDisplay>()
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user