diff --git a/binaries/data/mods/public/gui/common/functions_global_object.js b/binaries/data/mods/public/gui/common/functions_global_object.js index e7a4194e44..eb7e1860a7 100644 --- a/binaries/data/mods/public/gui/common/functions_global_object.js +++ b/binaries/data/mods/public/gui/common/functions_global_object.js @@ -6,7 +6,7 @@ // ******************************************* // messageBox // ******************************************* -// @params: int mbWidth, int mbHeight, string mbMessage, string mbTitle, int mbMode, arr mbButtonCaptions +// @params: int mbWidth, int mbHeight, string mbMessage, string mbTitle, int mbMode, arr mbButtonCaptions, arr mbButtonsCode // @return: void // @desc: Displays a new modal message box. // ******************************************* diff --git a/binaries/data/mods/public/gui/page_summary.xml b/binaries/data/mods/public/gui/page_summary.xml new file mode 100644 index 0000000000..0239814247 --- /dev/null +++ b/binaries/data/mods/public/gui/page_summary.xml @@ -0,0 +1,9 @@ + + + common/setup.xml + common/styles.xml + common/sprite1.xml + common/init.xml + summary/summary.xml + common/global.xml + diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js index fb7feff786..274b0b6edc 100644 --- a/binaries/data/mods/public/gui/session_new/session.js +++ b/binaries/data/mods/public/gui/session_new/session.js @@ -17,6 +17,9 @@ var g_IsTrainingQueueBlocked = false; // Cache EntityStates var g_EntityStates = {}; // {id:entState} +// Whether the player has lost/won and reached the end of their game +var g_GameEnded = false; + function GetEntityState(entId) { if (!(entId in g_EntityStates)) @@ -75,9 +78,36 @@ function init(initData, hotloadData) function leaveGame() { + var simState = Engine.GuiInterfaceCall("GetSimulationState"); + var playerState = simState.players[Engine.GetPlayerID()]; + + var gameResult; + if (playerState.state == "won") + { + gameResult = "You have won the battle!"; + } + else if (playerState.state == "defeated") + { + gameResult = "You have been defeated..."; + } + 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() + }); + + } + stopMusic(); endGame(); - Engine.SwitchGuiPage("page_pregame.xml"); + + Engine.SwitchGuiPage("page_summary.xml", { "gameResult" : gameResult }); + } // Return some data that we'll use when hotloading this file after changes @@ -88,6 +118,8 @@ function getHotloadData() function onTick() { + checkPlayerState(); + while (true) { var message = Engine.PollNetworkClient(); @@ -121,6 +153,28 @@ function onTick() getGUIObjectByName("resourcePop").textcolor = "white"; } +function checkPlayerState() +{ + var simState = Engine.GuiInterfaceCall("GetSimulationState"); + var playerState = simState.players[Engine.GetPlayerID()]; + + if (!g_GameEnded) + { + if (playerState.state == "defeated") + { + g_GameEnded = true; + messageBox(400, 200, "You have been defeated... Do you want to leave the game now?", + "Defeat", 0, ["Yes", "No!"], [leaveGame, null]); + } + else if (playerState.state == "won") + { + g_GameEnded = true; + messageBox(400, 200, "You have won the battle! Do you want to leave the game now?", + "Victory", 0, ["Yes", "No!"], [leaveGame, null]); + } + } +} + function onSimulationUpdate() { g_Selection.dirty = false; diff --git a/binaries/data/mods/public/gui/summary/summary.js b/binaries/data/mods/public/gui/summary/summary.js new file mode 100644 index 0000000000..61c1f405d2 --- /dev/null +++ b/binaries/data/mods/public/gui/summary/summary.js @@ -0,0 +1,4 @@ +function init(data) +{ + getGUIObjectByName("summaryText").caption = data.gameResult; +} diff --git a/binaries/data/mods/public/gui/summary/summary.xml b/binaries/data/mods/public/gui/summary/summary.xml new file mode 100644 index 0000000000..fff69b7104 --- /dev/null +++ b/binaries/data/mods/public/gui/summary/summary.xml @@ -0,0 +1,38 @@ + + + + + +