mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -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]
|
* 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)
|
debug("Changing name of game %s to", game.name, newName)
|
||||||
val oldPreview = game.preview ?: throw game.error!!
|
val oldPreview = game.preview ?: throw game.error!!
|
||||||
val oldLastUpdate = game.lastUpdate
|
val oldLastUpdate = game.lastUpdate
|
||||||
val oldName = game.name
|
val oldName = game.name
|
||||||
|
|
||||||
savedGames.remove(game.fileHandle)
|
val newFileHandle = files.saveGame(oldPreview, newName, onException)
|
||||||
files.deleteSave(game.fileHandle)
|
|
||||||
val newFileHandle = files.saveGame(oldPreview, newName)
|
|
||||||
|
|
||||||
val newGame = OnlineMultiplayerGame(newFileHandle, oldPreview, oldLastUpdate)
|
val newGame = OnlineMultiplayerGame(newFileHandle, oldPreview, oldLastUpdate)
|
||||||
savedGames[newFileHandle] = newGame
|
savedGames[newFileHandle] = newGame
|
||||||
|
|
||||||
|
savedGames.remove(game.fileHandle)
|
||||||
|
files.deleteSave(game.fileHandle)
|
||||||
EventBus.send(MultiplayerGameNameChanged(oldName, newName))
|
EventBus.send(MultiplayerGameNameChanged(oldName, newName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,12 @@ class EditMultiplayerGameInfoScreen(val multiplayerGame: OnlineMultiplayerGame)
|
|||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
rightSideButton.setText("Saving...".tr())
|
rightSideButton.setText("Saving...".tr())
|
||||||
val newName = textField.text.trim()
|
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()
|
val newScreen = game.popScreen()
|
||||||
if (newScreen is MultiplayerScreen) {
|
if (newScreen is MultiplayerScreen) {
|
||||||
newScreen.selectGame(newName)
|
newScreen.selectGame(newName)
|
||||||
|
@ -159,7 +159,7 @@ open class Popup(
|
|||||||
action: (()->Unit)? = null
|
action: (()->Unit)? = null
|
||||||
): Cell<TextButton> {
|
): Cell<TextButton> {
|
||||||
val cell = addButton(text, additionalKey, style) { close(); if(action!=null) action() }
|
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
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user