mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Resolved #7878 - Handle errors when renaming multiplayer games
This commit is contained in:
parent
b8d1f1d801
commit
c4bac19bb2
@ -284,18 +284,18 @@ class OnlineMultiplayer {
|
||||
/**
|
||||
* Fires [MultiplayerGameNameChanged]
|
||||
*/
|
||||
fun changeGameName(game: OnlineMultiplayerGame, newName: String) {
|
||||
fun changeGameName(game: OnlineMultiplayerGame, newName: String, onException:(Exception?)->Unit) {
|
||||
debug("Changing name of game %s to", game.name, newName)
|
||||
val oldPreview = game.preview ?: throw game.error!!
|
||||
val oldLastUpdate = game.lastUpdate
|
||||
val oldName = game.name
|
||||
|
||||
savedGames.remove(game.fileHandle)
|
||||
files.deleteSave(game.fileHandle)
|
||||
val newFileHandle = files.saveGame(oldPreview, newName)
|
||||
|
||||
val newFileHandle = files.saveGame(oldPreview, newName, onException)
|
||||
val newGame = OnlineMultiplayerGame(newFileHandle, oldPreview, oldLastUpdate)
|
||||
savedGames[newFileHandle] = newGame
|
||||
|
||||
savedGames.remove(game.fileHandle)
|
||||
files.deleteSave(game.fileHandle)
|
||||
EventBus.send(MultiplayerGameNameChanged(oldName, newName))
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,12 @@ class EditMultiplayerGameInfoScreen(val multiplayerGame: OnlineMultiplayerGame)
|
||||
rightSideButton.onClick {
|
||||
rightSideButton.setText("Saving...".tr())
|
||||
val newName = textField.text.trim()
|
||||
game.onlineMultiplayer.changeGameName(multiplayerGame, newName)
|
||||
game.onlineMultiplayer.changeGameName(multiplayerGame, newName){
|
||||
val popup = Popup(this)
|
||||
popup.addGoodSizedLabel("Could not save game!")
|
||||
popup.addCloseButton()
|
||||
popup.open()
|
||||
}
|
||||
val newScreen = game.popScreen()
|
||||
if (newScreen is MultiplayerScreen) {
|
||||
newScreen.selectGame(newName)
|
||||
|
@ -159,7 +159,7 @@ open class Popup(
|
||||
action: (()->Unit)? = null
|
||||
): Cell<TextButton> {
|
||||
val cell = addButton(text, additionalKey, style) { close(); if(action!=null) action() }
|
||||
cell.getActor().keyShortcuts.add(KeyCharAndCode.BACK)
|
||||
cell.actor.keyShortcuts.add(KeyCharAndCode.BACK)
|
||||
return cell
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user