Ticket #4284: restart-menu.diff

File restart-menu.diff, 3.2 KB (added by Jon Baer, 8 years ago)
  • session/menu.js

     
    22const MARGIN = 4;
    33
    44// Includes the main menu button
    5 const NUM_BUTTONS = 9;
     5const NUM_BUTTONS = 10;
    66
    77// Regular menu buttons
    88const BUTTON_HEIGHT = 32;
     
    105105    togglePause();
    106106}
    107107
     108function restartMenuButton()
     109{
     110    closeOpenDialogs();
     111    pauseGame();
     112
     113    if (g_GameAttributes.settings.mapType == "random")
     114        messageBox(
     115            400, 200,
     116            translate("Are you sure you want to restart the game?"),
     117            translate("Confirmation"),
     118            [translate("No"), translate("Yes"), translate("Reseed")],
     119            [resumeGame, restartGame, restartGame],
     120            [null,false,true]
     121        );
     122    else
     123        messageBox(
     124            400, 200,
     125            translate("Are you sure you want to restart the game?"),
     126            translate("Confirmation"),
     127            [translate("No"), translate("Yes")],
     128            [resumeGame, restartGame]
     129        );
     130}
     131
    108132function resignMenuButton()
    109133{
    110134    closeOpenDialogs();
  • session/menu.xml

     
    7777            <action on="Press">togglePause();</action>
    7878        </object>
    7979
     80        <!-- Restart button -->
     81        <object type="button"
     82            name="menuRestartButton"
     83            style="StoneButtonFancy"
     84            size="0 192 100% 220"
     85            tooltip_style="sessionToolTip" enabled="false"
     86        >
     87            <translatableAttribute id="caption">Restart</translatableAttribute>
     88            <action on="Press">restartMenuButton();</action>
     89        </object>
     90
    8091        <!-- Resign button -->
    8192        <object type="button"
    8293            name="menuResignButton"
    8394            style="StoneButtonFancy"
    84             size="0 192 100% 220"
     95            size="0 224 100% 252"
    8596            tooltip_style="sessionToolTip"
    8697        >
    8798            <translatableAttribute id="caption">Resign</translatableAttribute>
     
    92103        <object type="button"
    93104            name="menuExitButton"
    94105            style="StoneButtonFancy"
    95             size="0 224 100% 252"
     106            size="0 256 100% 284"
    96107            tooltip_style="sessionToolTip"
    97108        >
    98109            <translatableAttribute id="caption">Exit</translatableAttribute>
  • session/session.js

     
    248248            restoreSavedGameData(initData.savedGUIData);
    249249
    250250        Engine.GetGUIObjectByName("gameSpeedButton").hidden = g_IsNetworked;
     251        Engine.GetGUIObjectByName("menuRestartButton").enabled = !g_IsNetworked;
     252
    251253    }
    252254    else // Needed for autostart loading option
    253255    {
     
    517519}
    518520
    519521/**
    520  * Resign a player.
    521  * @param leaveGameAfterResign If player is quitting after resignation.
     522 * Restart the game
     523 * @param reseed If the random map should be re-seeded.
    522524 */
     525function restartGame(reseed)
     526{
     527    let playerId = Engine.GetPlayerID();
     528    let gameAttributes = g_GameAttributes;
     529
     530    if (reseed)
     531        gameAttributes.settings.Seed = Math.floor(Math.random() * Math.pow(2, 32));
     532
     533    Engine.EndGame();
     534    Engine.StartGame(gameAttributes, playerId);
     535    Engine.SwitchGuiPage("page_loading.xml", {
     536        "attribs": gameAttributes,
     537        "isNetworked" : g_IsNetworked,
     538        "playerAssignments": g_PlayerAssignments
     539    });
     540}
     541
    523542function resignGame(leaveGameAfterResign)
    524543{
    525544    if (g_IsObserver || g_Disconnected)