Fix #2373. Have player resign if not returning to a networked game. Also notify host of networked game that by leaving all other players will be disconnected. Based off patch by boeseRaupe

This was SVN commit r14772.
This commit is contained in:
JoshuaJB 2014-02-21 20:02:23 +00:00
parent 8c21ec4dfd
commit a3e1c68b9a
4 changed files with 131 additions and 95 deletions

View File

@ -22,10 +22,17 @@ var g_messageBoxCallbackFunction = function(btnCode)
{ {
if (btnCode !== undefined && g_messageBoxBtnFunctions[btnCode]) if (btnCode !== undefined && g_messageBoxBtnFunctions[btnCode])
{ {
if (g_messageBoxCallbackArgs[btnCode]) // Cache the variables to make it possible to call a messageBox from a callback function.
g_messageBoxBtnFunctions[btnCode](g_messageBoxCallbackArgs[btnCode]); var callbackFunction = g_messageBoxBtnFunctions[btnCode];
var callbackArgs = g_messageBoxCallbackArgs[btnCode]
g_messageBoxBtnFunctions = [];
g_messageBoxCallbackArgs = [];
if (callbackArgs !== undefined)
callbackFunction(callbackArgs);
else else
g_messageBoxBtnFunctions[btnCode](); callbackFunction();
return;
} }
g_messageBoxBtnFunctions = []; g_messageBoxBtnFunctions = [];

View File

@ -146,11 +146,31 @@ function exitMenuButton()
closeMenu(); closeMenu();
closeOpenDialogs(); closeOpenDialogs();
pauseGame(); pauseGame();
var btCaptions = ["Yes", "No"]; if (g_IsNetworked && g_IsController)
var btCode = [leaveGame, resumeGame]; {
messageBox(400, 200, "Are you sure you want to quit?", "Confirmation", 0, btCaptions, btCode); var btCode = [leaveGame, resumeGame];
var message = "Are you sure you want to quit? Leaving will disconnect all other players.";
}
else if (g_IsNetworked && !g_GameEnded)
{
var btCode = [networkReturnQuestion, resumeGame];
var message = "Are you sure you want to quit?";
}
else
{
var btCode = [leaveGame, resumeGame];
var message = "Are you sure you want to quit?";
}
messageBox(400, 200, message, "Confirmation", 0, ["Yes", "No"], btCode);
} }
function networkReturnQuestion()
{
var btCaptions = ["I resign", "I will return"];
var btCode = [leaveGame, leaveGame];
var btArgs = [false, true];
messageBox(400, 200, "Do you want to resign or will you return soon?", "Confirmation", 0, btCaptions, btCode, btArgs);
}
function openDeleteDialog(selection) function openDeleteDialog(selection)
{ {

View File

@ -234,7 +234,11 @@ function reportPerformance(time)
Engine.SubmitUserReport("profile", 3, JSON.stringify(data)); Engine.SubmitUserReport("profile", 3, JSON.stringify(data));
} }
function resignGame() /**
* Resign a player.
* @param leaveGameAfterResign If player is quitting after resignation.
*/
function resignGame(leaveGameAfterResign)
{ {
var simState = GetSimState(); var simState = GetSimState();
@ -249,10 +253,17 @@ function resignGame()
}); });
global.music.setState(global.music.states.DEFEAT); global.music.setState(global.music.states.DEFEAT);
resumeGame();
// Resume the game if not resigning.
if (!leaveGameAfterResign)
resumeGame();
} }
function leaveGame() /**
* Leave the game
* @param willRejoin If player is going to be rejoining a networked game.
*/
function leaveGame(willRejoin)
{ {
var extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState"); var extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState");
var playerState = extendedSimState.players[Engine.GetPlayerID()]; var playerState = extendedSimState.players[Engine.GetPlayerID()];
@ -273,15 +284,14 @@ function leaveGame()
} }
else // "active" 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); global.music.setState(global.music.states.DEFEAT);
if (willRejoin)
gameResult = "You have left the game.";
else
{
gameResult = "You have abandoned the game.";
resignGame(true);
}
} }
stopAmbient(); stopAmbient();

View File

@ -776,86 +776,85 @@
z="40" z="40"
> >
<object size="4 36 100%-4 50%+20"> <object size="4 36 100%-4 50%+20">
<!-- Manual button -->
<object type="button"
name="manualButton"
style="StoneButtonFancy"
size="0 0 100% 28"
tooltip_style="sessionToolTip"
>
Manual
<action on="Press">openManual();</action>
</object>
<!-- Chat button -->
<object type="button"
name="chatButton"
style="StoneButtonFancy"
size="0 32 100% 60"
tooltip_style="sessionToolTip"
>
Chat
<action on="Press">chatMenuButton();</action>
</object>
<!-- Settings button --> <!-- Save game button -->
<object type="button" <object type="button"
name="settingsButton" name="saveGameButton"
style="StoneButtonFancy" style="StoneButtonFancy"
size="0 0 100% 28" size="0 64 100% 92"
tooltip_style="sessionToolTip" tooltip_style="sessionToolTip"
> >
Settings Save
<action on="Press">settingsMenuButton();</action> <action on="Press">
</object> openSave();
</action>
</object>
<!-- Settings button -->
<object type="button"
name="settingsButton"
style="StoneButtonFancy"
size="0 96 100% 124"
tooltip_style="sessionToolTip"
>
Settings
<action on="Press">settingsMenuButton();</action>
</object>
<!-- Pause / Resume Button -->
<!-- Save game button --> <object type="button"
<object type="button" name="pauseButton"
name="saveGameButton" style="StoneButtonFancy"
style="StoneButtonFancy" size="0 128 100% 156"
size="0 32 100% 60" tooltip_style="sessionToolTip"
tooltip_style="sessionToolTip" >
> <object name="pauseButtonText" type="text" style="CenteredButtonText" ghost="true">Pause</object>
Save <action on="Press">togglePause();</action>
<action on="Press"> </object>
openSave();
</action> <!-- Resign button -->
</object> <object type="button"
name="menuResignButton"
<!-- Chat button --> style="StoneButtonFancy"
<object type="button" size="0 160 100% 188"
name="chatButton" tooltip_style="sessionToolTip"
style="StoneButtonFancy" >
size="0 64 100% 92" Resign
tooltip_style="sessionToolTip" <action on="Press">resignMenuButton();</action>
> </object>
Chat
<action on="Press">chatMenuButton();</action> <!-- Exit button -->
</object> <object type="button"
name="menuExitButton"
<!-- Resign button --> style="StoneButtonFancy"
<object type="button" size="0 192 100% 220"
name="menuResignButton" tooltip_style="sessionToolTip"
style="StoneButtonFancy" >
size="0 96 100% 124" Exit
tooltip_style="sessionToolTip" <action on="Press">exitMenuButton();</action>
> </object>
Resign
<action on="Press">resignMenuButton();</action>
</object>
<!-- Exit button -->
<object type="button"
name="menuExitButton"
style="StoneButtonFancy"
size="0 128 100% 156"
tooltip_style="sessionToolTip"
>
Exit
<action on="Press">exitMenuButton();</action>
</object>
<!-- Pause / Resume Button -->
<object type="button"
name="pauseButton"
style="StoneButtonFancy"
size="0 160 100% 188"
tooltip_style="sessionToolTip"
>
<object name="pauseButtonText" type="text" style="CenteredButtonText" ghost="true">Pause</object>
<action on="Press">togglePause();</action>
</object>
<!-- Manual button -->
<object type="button"
name="manualButton"
style="StoneButtonFancy"
size="0 192 100% 220"
tooltip_style="sessionToolTip"
>
Manual
<action on="Press">openManual();</action>
</object>
</object> </object>
</object> </object>