diff --git a/binaries/data/mods/public/gui/session/NetworkStatusOverlay.js b/binaries/data/mods/public/gui/session/NetworkStatusOverlay.js index 223d0660e7..8c4b3826f2 100644 --- a/binaries/data/mods/public/gui/session/NetworkStatusOverlay.js +++ b/binaries/data/mods/public/gui/session/NetworkStatusOverlay.js @@ -11,7 +11,7 @@ class NetworkStatusOverlay Engine.GetGUIObjectByName("disconnectedExitButton").onPress = () => { - closePageCallback({ [Engine.openRequest]: endGame(true) }); + closePageCallback({ [Engine.openRequest]: getNextPageOpenRequest(true) }); }; registerNetworkStatusChangeHandler(this.onNetStatusMessage.bind(this)); diff --git a/binaries/data/mods/public/gui/session/message_box/QuitConfirmation.js b/binaries/data/mods/public/gui/session/message_box/QuitConfirmation.js index 9b0e60acc0..ae59794349 100644 --- a/binaries/data/mods/public/gui/session/message_box/QuitConfirmation.js +++ b/binaries/data/mods/public/gui/session/message_box/QuitConfirmation.js @@ -18,12 +18,12 @@ QuitConfirmation.prototype.Buttons = { // Translation: Shown in the Dialog that shows up when the game finishes "caption": translate("Quit and View Summary"), - "onPress": () => endGame(true) + "onPress": () => getNextPageOpenRequest(true) }, { // Translation: Shown in the Dialog that shows up when the game finishes "caption": translate("Quit"), - "onPress": () => endGame(false) + "onPress": () => getNextPageOpenRequest(false) } ]; diff --git a/binaries/data/mods/public/gui/session/message_box/QuitConfirmationMenu.js b/binaries/data/mods/public/gui/session/message_box/QuitConfirmationMenu.js index 92efb80c44..23efdb4788 100644 --- a/binaries/data/mods/public/gui/session/message_box/QuitConfirmationMenu.js +++ b/binaries/data/mods/public/gui/session/message_box/QuitConfirmationMenu.js @@ -6,7 +6,7 @@ ReturnQuestion.prototype.Caption = translate("Do you want to resign or will you ReturnQuestion.prototype.Buttons = [ { "caption": translate("I will return"), - "onPress": () => endGame(false) + "onPress": () => getNextPageOpenRequest(false) }, { "caption": translate("I resign"), diff --git a/binaries/data/mods/public/gui/session/message_box/QuitConfirmationReplay.js b/binaries/data/mods/public/gui/session/message_box/QuitConfirmationReplay.js index b629a8857b..033d8b9a61 100644 --- a/binaries/data/mods/public/gui/session/message_box/QuitConfirmationReplay.js +++ b/binaries/data/mods/public/gui/session/message_box/QuitConfirmationReplay.js @@ -26,11 +26,11 @@ QuitConfirmationReplay.prototype.Buttons = { // Translation: Shown in the Dialog that shows up when a replay finishes "caption": translate("Quit and View Summary"), - "onPress": () => endGame(true) + "onPress": () => getNextPageOpenRequest(true) }, { // Translation: Shown in the Dialog that shows up when a replay finishes "caption": translate("Quit"), - "onPress": () => endGame(false) + "onPress": () => getNextPageOpenRequest(false) } ]; diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 4e20db8229..d7f3aebe0e 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -368,7 +368,17 @@ async function init(initData, hotloadData) setTimeout(displayGamestateNotifications, 1000); - return promise; + const closeResult = await promise; + + Engine.EndGame(); + // After the replay file was closed in EndGame + // Done here to keep EndGame small + if (!g_IsReplay) + Engine.AddReplayToCache(Engine.GetCurrentReplayDirectory()); + if (g_IsController && Engine.HasXmppClient()) + Engine.SendUnregisterGame(); + + return closeResult; } function registerPlayersInitHandler(handler) @@ -528,31 +538,20 @@ function closeOpenDialogs() g_TradeDialog.close(); } -function endGame(showSummary) +/** + * Put together an open request for the next GUI page to show after closing the session. + * This could be, depending on the situation, the the summary screen, the main menu, the lobby, etc. + */ +function getNextPageOpenRequest(showSummary) { - // Before ending the game - const replayDirectory = Engine.GetCurrentReplayDirectory(); - const simData = Engine.GuiInterfaceCall("GetReplayMetadata"); - const playerID = Engine.GetPlayerID(); - - Engine.EndGame(); - - // After the replay file was closed in EndGame - // Done here to keep EndGame small - if (!g_IsReplay) - Engine.AddReplayToCache(replayDirectory); - - if (g_IsController && Engine.HasXmppClient()) - Engine.SendUnregisterGame(); - const summaryData = { - "sim": simData, + "sim": Engine.GuiInterfaceCall("GetReplayMetadata"), "gui": { "dialog": false, - "assignedPlayer": playerID, + "assignedPlayer": Engine.GetPlayerID(), "disconnected": g_Disconnected, "isReplay": g_IsReplay, - "replayDirectory": !g_HasRejoined && replayDirectory, + "replayDirectory": !g_HasRejoined && Engine.GetCurrentReplayDirectory(), "replaySelectionData": g_ReplaySelectionData } }; @@ -561,9 +560,8 @@ function endGame(showSummary) { const menu = g_CampaignSession.getMenu(); if (g_InitAttributes.campaignData.skipSummary) - { return { "page": menu }; - } + summaryData.campaignData = { "filename": g_InitAttributes.campaignData.run }; summaryData.nextPage = menu; } diff --git a/binaries/data/mods/public/gui/session/tutorial/TutorialManager.js b/binaries/data/mods/public/gui/session/tutorial/TutorialManager.js index 9c2b93d450..d59c9a2c3b 100644 --- a/binaries/data/mods/public/gui/session/tutorial/TutorialManager.js +++ b/binaries/data/mods/public/gui/session/tutorial/TutorialManager.js @@ -140,7 +140,7 @@ class TutorialManager continue() { if (this.isFinished) - this.closePageCallback({ [Engine.openRequest]: endGame(true) }); + this.closePageCallback({ [Engine.openRequest]: getNextPageOpenRequest(true) }); else if (this.pendingSteps.length) this.displayNextPendingStep(); else