Skip to content

Commit

Permalink
Suppress onlineMultiplayer checkbox clicks in game options (APIv2), f…
Browse files Browse the repository at this point in the history
…ixed NPE in popup
  • Loading branch information
CrsiX committed May 10, 2023
1 parent 1ec7429 commit 642aaf8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions core/src/com/unciv/logic/multiplayer/OnlineMultiplayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class OnlineMultiplayer: Disposable {
Concurrency.runOnNonDaemonThreadPool {
try {
val gameInfo = UncivFiles.gameInfoFromString(it.gameData)
gameInfo.setTransients()
addGame(gameInfo)
val gameDetails = api.game.head(it.gameUUID, suppress = true)
Concurrency.runOnGLThread {
Expand Down
24 changes: 13 additions & 11 deletions core/src/com/unciv/ui/popups/RegisterLoginPopup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class RegisterLoginPopup(private val base: BaseScreen, confirmUsage: Boolean = f
private val registerButton = "Register".toTextButton()
private val listener: EventListener

private var confirmationPopup: Popup? = null

init {
/** Simple listener class for key presses on ENTER keys to trigger the login button */
class SimpleEnterListener : InputListener() {
Expand Down Expand Up @@ -75,9 +77,10 @@ class RegisterLoginPopup(private val base: BaseScreen, confirmUsage: Boolean = f
}

if (confirmUsage) {
askConfirmUsage {
confirmationPopup = askConfirmUsage {
build()
}
confirmationPopup?.open()
} else {
build()
}
Expand Down Expand Up @@ -116,24 +119,23 @@ class RegisterLoginPopup(private val base: BaseScreen, confirmUsage: Boolean = f
}
}

private fun askConfirmUsage(block: () -> Unit) {
private fun askConfirmUsage(block: () -> Unit): Popup {
val playerId = UncivGame.Current.settings.multiplayer.userId
addGoodSizedLabel("By using the new multiplayer servers, you overwrite your existing player ID. Games on other servers will not be accessible anymore, unless the player ID is properly restored. Keep your player ID safe before proceeding:").colspan(2)
row()
addGoodSizedLabel(playerId)
addButton("Copy user ID") {
val popup = Popup(base)
popup.addGoodSizedLabel("By using the new multiplayer servers, you overwrite your existing player ID. Games on other servers will not be accessible anymore, unless the player ID is properly restored. Keep your player ID safe before proceeding:").colspan(2)
popup.row()
popup.addGoodSizedLabel(playerId)
popup.addButton("Copy user ID") {
Gdx.app.clipboard.contents = base.game.settings.multiplayer.userId
ToastPopup("UserID copied to clipboard", base).open(force = true)
}
row()
val cell = addButton(Constants.OK) {
innerTable.clear()
block.invoke()
}
popup.row()
val cell = popup.addCloseButton(Constants.OK, action = block)
cell.colspan(2)
cell.actor.keyShortcuts.add(KeyCharAndCode.ESC)
cell.actor.keyShortcuts.add(KeyCharAndCode.BACK)
cell.actor.keyShortcuts.add(KeyCharAndCode.RETURN)
return popup
}

private fun createPopup(msg: String? = null, force: Boolean = false): Popup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SocialMenuTable(
private var lastSelectedChat: UUID? = null

init {
debugAll()
add(friendList).growX().minWidth(base.stage.width * 0.45f).padRight(5f)
add(chatContainer).minWidth(base.stage.width * 0.45f).maxHeight(maxChatHeight).growX()
Concurrency.run {
Expand Down
24 changes: 17 additions & 7 deletions core/src/com/unciv/ui/screens/newgamescreen/GameOptionsTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.Align
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.civilization.PlayerType
import com.unciv.logic.multiplayer.ApiVersion
import com.unciv.models.metadata.GameParameters
import com.unciv.models.metadata.Player
import com.unciv.models.ruleset.RulesetCache
Expand Down Expand Up @@ -165,14 +166,23 @@ class GameOptionsTable(
{ gameParameters.nuclearWeaponsEnabled = it }

private fun Table.addIsOnlineMultiplayerCheckbox() =
addCheckbox("Online Multiplayer", gameParameters.isOnlineMultiplayer)
{ shouldUseMultiplayer ->
gameParameters.isOnlineMultiplayer = shouldUseMultiplayer
updatePlayerPickerTable("")
if (shouldUseMultiplayer) {
MultiplayerHelpers.showDropboxWarning(previousScreen as BaseScreen)
if (UncivGame.Current.onlineMultiplayer.isInitialized() && UncivGame.Current.onlineMultiplayer.apiVersion != ApiVersion.APIv2) {
addCheckbox("Online Multiplayer", gameParameters.isOnlineMultiplayer)
{ shouldUseMultiplayer ->
gameParameters.isOnlineMultiplayer = shouldUseMultiplayer
updatePlayerPickerTable("")
if (shouldUseMultiplayer) {
MultiplayerHelpers.showDropboxWarning(previousScreen as BaseScreen)
}
update()
}
} else {
val checkBox = addCheckbox("Online Multiplayer", initialState = false) {}
checkBox.onChange {
checkBox.isChecked = false
ToastPopup("To use new multiplayer games, go back to the main menu and create a lobby from the multiplayer menu instead.", stage).open()
}
update()
checkBox
}

private fun Table.addAnyoneCanSpectateCheckbox() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class MapParametersTable(

fun addTextButton(text: String, shouldAddToTable: Boolean = false, action: ((Boolean) -> Unit)) {
val button = text.toTextButton()
button.onClick { action.invoke(true) }
button.onClick { action(true) }
if (shouldAddToTable)
table.add(button).colspan(2).padTop(10f).row()
}
Expand Down

0 comments on commit 642aaf8

Please sign in to comment.