Index: binaries/data/mods/public/gui/common/functions_global_object.js
===================================================================
--- binaries/data/mods/public/gui/common/functions_global_object.js (revision 14644)
+++ binaries/data/mods/public/gui/common/functions_global_object.js (working copy)
@@ -22,12 +22,19 @@
{
if (btnCode !== undefined && g_messageBoxBtnFunctions[btnCode])
{
- if (g_messageBoxCallbackArgs[btnCode])
- g_messageBoxBtnFunctions[btnCode](g_messageBoxCallbackArgs[btnCode]);
+ // cache the vales to make it possible to call a messageBox from a callback function.
+ var callbackFunction = g_messageBoxBtnFunctions[btnCode];
+ var callbackArgs = g_messageBoxCallbackArgs[btnCode]
+ g_messageBoxBtnFunctions = [];
+ g_messageBoxCallbackArgs = [];
+
+ if (callbackArgs !== undefined)
+ callbackFunction(callbackArgs);
else
- g_messageBoxBtnFunctions[btnCode]();
+ callbackFunction();
+
+ return;
}
-
g_messageBoxBtnFunctions = [];
g_messageBoxCallbackArgs = [];
}
Index: binaries/data/mods/public/gui/session/menu.js
===================================================================
--- binaries/data/mods/public/gui/session/menu.js (revision 14644)
+++ binaries/data/mods/public/gui/session/menu.js (working copy)
@@ -147,10 +147,17 @@
closeOpenDialogs();
pauseGame();
var btCaptions = ["Yes", "No"];
- var btCode = [leaveGame, resumeGame];
+ var btCode = [g_IsNetworked && !g_GameEnded ? networkReturnQuestion : prepareLeaveGame, resumeGame];
messageBox(400, 200, "Are you sure you want to quit?", "Confirmation", 0, btCaptions, btCode);
}
+function networkReturnQuestion()
+{
+ var btCaptions = ["Yes, I will return", "No, I resign"];
+ var btCode = [prepareLeaveGame, prepareLeaveGame];
+ var btArgs = [true, false];
+ messageBox(400, 200, "You are exiting the game, will you return soon?", "Confirmation", 0, btCaptions, btCode, btArgs);
+}
function openDeleteDialog(selection)
{
Index: binaries/data/mods/public/gui/session/session.js
===================================================================
--- binaries/data/mods/public/gui/session/session.js (revision 14644)
+++ binaries/data/mods/public/gui/session/session.js (working copy)
@@ -1,3 +1,5 @@
+const TIME_UNTIL_ENGINE_ENDS_GAME = 5000; // time in ms until the engine quits the game (in MP with resign)
+
// Network Mode
var g_IsNetworked = false;
@@ -37,6 +39,9 @@
// Whether the player has lost/won and reached the end of their game
var g_GameEnded = false;
+// true, if prepareLeaveGame() was called
+var g_leaveGameInProcess = false;
+
var g_Disconnected = false; // Lost connection to server
// Holds player states from the last tick
@@ -234,7 +239,11 @@
Engine.SubmitUserReport("profile", 3, JSON.stringify(data));
}
-function resignGame()
+/**
+ * let's a player resign
+ * leaveGameAfterResign: if true, game is quit, after resign
+ */
+function resignGame(leaveGameAfterResign)
{
var simState = GetSimState();
@@ -248,16 +257,25 @@
"playerId": Engine.GetPlayerID()
});
- global.music.setState(global.music.states.DEFEAT);
- resumeGame();
+ // resume to the game, if the resign button was used
+ if (!leaveGameAfterResign)
+ {
+ global.music.setState(global.music.states.DEFEAT);
+ resumeGame();
+ }
}
-function leaveGame()
+/**
+ * prepare to leave the game
+ * willRejoin: can be set to true, in case of network game, if the player just has to reboot or restart the game
+ */
+function prepareLeaveGame(willRejoin)
{
var extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState");
var playerState = extendedSimState.players[Engine.GetPlayerID()];
var mapSettings = Engine.GetMapSettings();
var gameResult;
+ var timeUntilEngineEndsGame = 1;
if (g_Disconnected)
{
@@ -274,16 +292,27 @@
else // "active"
{
gameResult = "You have abandoned the game.";
-
- // Tell other players that we have given up and been defeated
- Engine.PostNetworkCommand({
- "type": "defeat-player",
- "playerId": Engine.GetPlayerID()
- });
-
global.music.setState(global.music.states.DEFEAT);
+
+ // resign, if player click on "No, I resign"
+ if (!willRejoin)
+ {
+ gameResult = "You have been defeated...";
+ resignGame(true);
+ if(g_IsNetworked)
+ timeUntilEngineEndsGame = TIME_UNTIL_ENGINE_ENDS_GAME; // give engine some time to deliver the network message (before the client disconnects...)
+ }
}
+ g_leaveGameInProcess = true;
+ setTimeout(function() { leaveGame({"gameResult": gameResult, "extendedSimState": extendedSimState, "mapSettings": mapSettings}); }, timeUntilEngineEndsGame);
+}
+/**
+ * leaves the game; is needed to give network messages time to reach their destination
+ * data: must contain gameResult, extendedSimState and mapSettings
+ */
+function leaveGame(data)
+{
stopAmbient();
Engine.EndGame();
@@ -291,11 +320,11 @@
Engine.SendUnregisterGame();
Engine.SwitchGuiPage("page_summary.xml", {
- "gameResult" : gameResult,
- "timeElapsed" : extendedSimState.timeElapsed,
- "playerStates": extendedSimState.players,
+ "gameResult" : data.gameResult,
+ "timeElapsed" : data.extendedSimState.timeElapsed,
+ "playerStates": data.extendedSimState.players,
"players": g_Players,
- "mapSettings": mapSettings
+ "mapSettings": data.mapSettings
});
}
@@ -427,12 +456,18 @@
var btCode = [null];
var message = "Press OK to continue";
}
- else
+ else if (!g_leaveGameInProcess)
{
var btCaptions = ["Yes", "No"];
- var btCode = [leaveGame, null];
+ var btCode = [prepareLeaveGame, null];
var message = "Do you want to quit?";
}
+ else
+ {
+ var btCaptions = ["Ok"];
+ var btCode = [null];
+ var message = "You have been defeated. Game will exit now.";
+ }
if (playerState.state == "defeated")
{
Index: binaries/data/mods/public/gui/session/session.xml
===================================================================
--- binaries/data/mods/public/gui/session/session.xml (revision 14644)
+++ binaries/data/mods/public/gui/session/session.xml (working copy)
@@ -39,7 +39,7 @@
@@ -776,87 +776,86 @@
z="40"
>
@@ -1354,7 +1353,7 @@
tooltip_style="sessionToolTip"
>
Exit
- leaveGame()
+ prepareLeaveGame()