Ticket #2373: resignation_v6.patch

File resignation_v6.patch, 10.6 KB (added by Michael, 10 years ago)

Moved timer back to leaveGame. Timer is not executed after SwitchGuiPage()

  • binaries/data/mods/public/gui/common/functions_global_object.js

     
    2222{
    2323    if (btnCode !== undefined && g_messageBoxBtnFunctions[btnCode])
    2424    {
    25         if (g_messageBoxCallbackArgs[btnCode])
    26             g_messageBoxBtnFunctions[btnCode](g_messageBoxCallbackArgs[btnCode]);
     25        // cache the vales to make it possible to call a messageBox from a callback function.
     26        var callbackFunction = g_messageBoxBtnFunctions[btnCode];
     27        var callbackArgs = g_messageBoxCallbackArgs[btnCode]
     28        g_messageBoxBtnFunctions  = [];
     29        g_messageBoxCallbackArgs = [];
     30
     31        if (callbackArgs !== undefined)
     32            callbackFunction(callbackArgs);
    2733        else
    28             g_messageBoxBtnFunctions[btnCode]();
     34            callbackFunction();
     35           
     36        return;
    2937    }
    30 
    3138    g_messageBoxBtnFunctions  = [];
    3239    g_messageBoxCallbackArgs = [];
    3340}
  • binaries/data/mods/public/gui/session/menu.js

     
    147147    closeOpenDialogs();
    148148    pauseGame();
    149149    var btCaptions = ["Yes", "No"];
    150     var btCode = [leaveGame, resumeGame];
     150    var btCode = [prepareLeaveGame, resumeGame];
     151    if (g_IsNetworked && !g_GameEnded)
     152        btCode = [g_IsController ? abortNetworkGameQuestion : networkReturnQuestion, resumeGame];
    151153    messageBox(400, 200, "Are you sure you want to quit?", "Confirmation", 0, btCaptions, btCode);
    152154}
    153155
     156function networkReturnQuestion()
     157{
     158    var btCaptions = ["I resign", "I will return"];
     159    var btCode = [prepareLeaveGame, prepareLeaveGame];
     160    var btArgs = [false, true];
     161    messageBox(400, 200, "You are exiting the game. Will you return soon or do you want to resign?", "Confirmation", 0, btCaptions, btCode, btArgs);
     162}
    154163
     164function abortNetworkGameQuestion()
     165{
     166    var btCaptions = ["Exit the game", "Resume"];
     167    var btCode = [prepareLeaveGame, resumeGame];
     168    messageBox(400, 200, "Because you are the host the game will end for all players if you leave.\n\nAre you sure you want to do that?", "Confirmation", 0, btCaptions, btCode);
     169}
     170
    155171function openDeleteDialog(selection)
    156172{
    157173    closeMenu();
  • binaries/data/mods/public/gui/session/session.js

     
     1const TIME_UNTIL_ENGINE_ENDS_GAME = 3000; // time in ms until the engine quits the game (in MP with resign)
     2
    13// Network Mode
    24var g_IsNetworked = false;
    35
     
    3739// Whether the player has lost/won and reached the end of their game
    3840var g_GameEnded = false;
    3941
     42// true, if prepareLeaveGame() was called
     43var g_leaveGameInProcess = false;
     44
    4045var g_Disconnected = false; // Lost connection to server
    4146
    4247// Holds player states from the last tick
     
    234239    Engine.SubmitUserReport("profile", 3, JSON.stringify(data));
    235240}
    236241
    237 function resignGame()
     242/**
     243 * let's a player resign
     244 * leaveGameAfterResign: if true, game is quit, after resign
     245 */
     246function resignGame(leaveGameAfterResign)
    238247{
    239248    var simState = GetSimState();
    240249
     
    248257        "playerId": Engine.GetPlayerID()
    249258    });
    250259
    251     global.music.setState(global.music.states.DEFEAT);
    252     resumeGame();
     260    // resume to the game, if the resign button was used
     261    if (!leaveGameAfterResign)
     262    {
     263        global.music.setState(global.music.states.DEFEAT);
     264        resumeGame();
     265    }
    253266}
    254267
    255 function leaveGame()
     268/**
     269 * prepare to leave the game
     270 * willRejoin: can be set to true, in case of network game, if the player just has to reboot or restart the game
     271 */
     272function prepareLeaveGame(willRejoin)
    256273{
    257274    var extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState");
    258275    var playerState = extendedSimState.players[Engine.GetPlayerID()];
     
    274291    else // "active"
    275292    {
    276293        gameResult = "You have abandoned the game.";
    277 
    278         // Tell other players that we have given up and been defeated
    279         Engine.PostNetworkCommand({
    280             "type": "defeat-player",
    281             "playerId": Engine.GetPlayerID()
    282         });
    283 
    284294        global.music.setState(global.music.states.DEFEAT);
     295       
     296        // resign, if player click on "No, I resign"
     297        if (!willRejoin)
     298        {
     299            gameResult = "You have been defeated...";
     300            resignGame(true);
     301        }
    285302    }
     303    g_leaveGameInProcess = true;
     304    // exit the game
     305    if(g_IsNetworked)
     306        setTimeout(function() { leaveGame({"gameResult": gameResult, "extendedSimState": extendedSimState, "mapSettings": mapSettings}); }, TIME_UNTIL_ENGINE_ENDS_GAME);
     307    else
     308        leaveGame({"gameResult": gameResult, "extendedSimState": extendedSimState, "mapSettings": mapSettings});
     309}
    286310
     311/**
     312 * leaves the game; is needed to give network messages time to reach their destination
     313 * data: must contain gameResult, extendedSimState and mapSettings
     314 */
     315function leaveGame(data)
     316{
    287317    stopAmbient();
    288318    Engine.EndGame();
    289319
     
    291321        Engine.SendUnregisterGame();
    292322
    293323    Engine.SwitchGuiPage("page_summary.xml", {
    294                             "gameResult"  : gameResult,
    295                             "timeElapsed" : extendedSimState.timeElapsed,
    296                             "playerStates": extendedSimState.players,
     324                            "gameResult"  : data.gameResult,
     325                            "timeElapsed" : data.extendedSimState.timeElapsed,
     326                            "playerStates": data.extendedSimState.players,
    297327                            "players": g_Players,
    298                             "mapSettings": mapSettings
     328                            "mapSettings": data.mapSettings
    299329                         });
    300330}
    301331
     
    427457        var btCode = [null];
    428458        var message = "Press OK to continue";
    429459    }
    430     else
     460    else if (!g_leaveGameInProcess)
    431461    {
    432462        var btCaptions = ["Yes", "No"];
    433         var btCode = [leaveGame, null];
     463        var btCode = [prepareLeaveGame, null];
    434464        var message = "Do you want to quit?";
    435465    }
     466    else
     467    {
     468        var btCaptions = ["Ok"];
     469        var btCode = [null];
     470        var message = "You have been defeated. Game will exit now.";
     471    }
    436472
    437473    if (playerState.state == "defeated")
    438474    {
  • binaries/data/mods/public/gui/session/session.xml

     
    3939    <!--
    4040        <action on="Press"><![CDATA[
    4141            messageBox(400, 200, "Do you really want to quit?", "Confirmation", 0,
    42                 ["Yes", "No!"], [leaveGame, null]);
     42                ["Yes", "No!"], [prepareLeaveGame, null]);
    4343        ]]></action>
    4444    -->
    4545
     
    776776        z="40"
    777777    >
    778778        <object size="4 36 100%-4 50%+20">
     779       
     780            <!-- Manual button -->
     781            <object type="button"
     782                name="manualButton"
     783                style="StoneButtonFancy"
     784                size="0 0 100% 28"
     785                tooltip_style="sessionToolTip"
     786            >
     787                Manual
     788                <action on="Press">openManual();</action>
     789            </object>
     790           
     791            <!-- Chat button -->
     792            <object type="button"
     793                name="chatButton"
     794                style="StoneButtonFancy"
     795                size="0 32 100% 60"
     796                tooltip_style="sessionToolTip"
     797            >
     798                Chat
     799                <action on="Press">chatMenuButton();</action>
     800            </object>
    779801
    780         <!-- Settings button -->
    781         <object type="button"
    782             name="settingsButton"
    783             style="StoneButtonFancy"
    784             size="0 0 100% 28"
    785             tooltip_style="sessionToolTip"
    786         >
    787             Settings
    788             <action on="Press">settingsMenuButton();</action>
    789         </object>
     802            <!-- Save game button -->
     803            <object type="button"
     804                name="saveGameButton"
     805                style="StoneButtonFancy"
     806                size="0 64 100% 92"
     807                tooltip_style="sessionToolTip"
     808            >
     809                Save
     810                <action on="Press">
     811                openSave();
     812                </action>
     813            </object>
     814           
     815            <!-- Settings button -->
     816            <object type="button"
     817                name="settingsButton"
     818                style="StoneButtonFancy"
     819                size="0 96 100% 124"
     820                tooltip_style="sessionToolTip"
     821            >
     822                Settings
     823                <action on="Press">settingsMenuButton();</action>
     824            </object>
    790825
    791 
    792         <!-- Save game button -->
    793         <object type="button"
    794             name="saveGameButton"
    795             style="StoneButtonFancy"
    796             size="0 32 100% 60"
    797             tooltip_style="sessionToolTip"
    798         >
    799             Save
    800             <action on="Press">
    801             openSave();
    802             </action>
     826            <!-- Pause / Resume Button -->
     827            <object type="button"
     828                name="pauseButton"
     829                style="StoneButtonFancy"
     830                size="0 128 100% 156"
     831                tooltip_style="sessionToolTip"
     832            >
     833                <object name="pauseButtonText" type="text" style="CenteredButtonText" ghost="true">Pause</object>
     834                <action on="Press">togglePause();</action>
     835            </object>
     836           
     837            <!-- Resign button -->
     838            <object type="button"
     839                name="menuResignButton"
     840                style="StoneButtonFancy"
     841                size="0 160 100% 188"
     842                tooltip_style="sessionToolTip"
     843            >
     844                Resign
     845                <action on="Press">resignMenuButton();</action>
     846            </object>
     847           
     848            <!-- Exit button -->
     849            <object type="button"
     850                name="menuExitButton"
     851                style="StoneButtonFancy"
     852                size="0 192 100% 220"
     853                tooltip_style="sessionToolTip"
     854            >
     855                Exit
     856                <action on="Press">exitMenuButton();</action>
     857            </object>
    803858        </object>
    804 
    805         <!-- Chat button -->
    806         <object type="button"
    807             name="chatButton"
    808             style="StoneButtonFancy"
    809             size="0 64 100% 92"
    810             tooltip_style="sessionToolTip"
    811         >
    812             Chat
    813             <action on="Press">chatMenuButton();</action>
    814         </object>
    815 
    816         <!-- Resign button -->
    817         <object type="button"
    818             name="menuResignButton"
    819             style="StoneButtonFancy"
    820             size="0 96 100% 124"
    821             tooltip_style="sessionToolTip"
    822         >
    823             Resign
    824             <action on="Press">resignMenuButton();</action>
    825         </object>
    826 
    827         <!-- Exit button -->
    828         <object type="button"
    829             name="menuExitButton"
    830             style="StoneButtonFancy"
    831             size="0 128 100% 156"
    832             tooltip_style="sessionToolTip"
    833         >
    834             Exit
    835             <action on="Press">exitMenuButton();</action>
    836         </object>
    837 
    838         <!-- Pause / Resume Button -->
    839         <object type="button"
    840             name="pauseButton"
    841             style="StoneButtonFancy"
    842             size="0 160 100% 188"
    843             tooltip_style="sessionToolTip"
    844         >
    845             <object name="pauseButtonText" type="text" style="CenteredButtonText" ghost="true">Pause</object>
    846             <action on="Press">togglePause();</action>
    847         </object>
    848 
    849         <!-- Manual button -->
    850         <object type="button"
    851             name="manualButton"
    852             style="StoneButtonFancy"
    853             size="0 192 100% 220"
    854             tooltip_style="sessionToolTip"
    855         >
    856             Manual
    857             <action on="Press">openManual();</action>
    858         </object>
    859         </object>
    860859    </object>
    861860
    862861    <!-- In-progress research -->
     
    13541353        tooltip_style="sessionToolTip"
    13551354    >
    13561355        <object size="0 0 100% 100%" type="text" style="CenteredButtonText" name="disconnectedExitButtonText" ghost="true">Exit</object>
    1357         <action on="Press">leaveGame()</action>
     1356        <action on="Press">prepareLeaveGame()</action>
    13581357    </object>
    13591358
    13601359    </object>