Ticket #1090: loadsave-v2.patch

File loadsave-v2.patch, 6.4 KB (added by mimo, 2 years ago)

new version with map preview

  • binaries/data/mods/public/gui/savedgames/load.js

     
    88    if (!savedGames.length)
    99    {
    1010        gameSelection.list = [translate("No saved games found")];
    11         gameSelection.selected = 0;
     11        gameSelection.selected = -1;
     12        selectionChanged();
    1213        Engine.GetGUIObjectByName("loadGameButton").enabled = false;
    1314        Engine.GetGUIObjectByName("deleteGameButton").enabled = false;
    1415        return;
     
    2627        gameSelection.selected = 0;
    2728    else if (gameSelection.selected >= savedGames.length) // happens when deleting the last saved game
    2829        gameSelection.selected = savedGames.length - 1;
     30    selectionChanged();
    2931}
    3032
     33function selectionChanged()
     34{
     35    let gameSelection = Engine.GetGUIObjectByName("gameSelection");
     36    let selectionEmpty = gameSelection.selected == -1;
     37    Engine.GetGUIObjectByName("gameInfoLogo").hidden = !selectionEmpty;
     38    Engine.GetGUIObjectByName("gameInfoText").hidden = selectionEmpty;
     39    Engine.GetGUIObjectByName("gameInfoPreview").hidden = selectionEmpty;
     40
     41    if (selectionEmpty)
     42        return;
     43
     44    let metadata = g_SavedGamesMetadata[gameSelection.selected];
     45    let gameInfoText = Engine.GetGUIObjectByName("gameInfoText");
     46    gameInfoText.caption = sprintf(translate(" %(players)s \n %(playedTime)s \n %(mapType)s \n %(victory)s \n %(mods)s"), {
     47        "players": translate("Players: ") + (metadata.initAttributes.settings.PlayerData.length - 1),
     48        "playedTime": translate("Played time: ") + timeToString(metadata.gui.timeElapsed ? metadata.gui.timeElapsed : 0),
     49        "mapType": translate("Map type: ") + translateMapType(metadata.initAttributes.mapType),
     50        "victory": translate("Victory: ") + translateVictoryCondition(metadata.initAttributes.settings.GameType),
     51        "mods": sprintf(translate("Mods: %(mods)s"), { "mods": metadata.mods.join(translate(", ")) })
     52    });
     53
     54    let mapData = getMapDescriptionAndPreview(metadata.initAttributes.mapType, metadata.initAttributes.map);
     55    setMapPreviewImage("gameInfoPreview", mapData.preview);
     56}
     57
    3158function loadGame()
    3259{
    3360    var gameSelection = Engine.GetGUIObjectByName("gameSelection");
  • binaries/data/mods/public/gui/savedgames/load.xml

     
    44
    55    <script file="gui/common/functions_global_object.js" />
    66    <script file="gui/common/functions_utility.js" />
     7    <script file="gui/common/settings.js" />
    78    <script file="gui/common/functions_utility_loadsave.js" />
    89    <script file="gui/savedgames/load.js" />
    910
     
    1011    <!-- Add a translucent black background to fade out the menu page -->
    1112    <object type="image" z="0" sprite="BackgroundTranslucent"/>
    1213
    13     <object type="image" style="ModernDialog" size="50%-300 50%-200 50%+300 50%+200">
     14    <object type="image" style="ModernDialog" size="50%-400 50%-250 50%+400 50%+250">
    1415
    1516        <object type="text" style="TitleText" size="50%-128 -18 50%+128 14">
    1617            <translatableAttribute id="caption">Load Game</translatableAttribute>
    1718        </object>
    1819
    19         <object name="gameSelection"
    20             style="ModernList"
    21             type="list"
    22             size="24 24 100%-24 100%-100">
    23         </object>
     20        <object type="image" size="0 20 550 100%">
     21            <object name="gameSelection"
     22                style="ModernList"
     23                type="list"
     24                size="24 24 100%-24 100%-100">
     25                <action on="SelectionChange">selectionChanged();</action>
     26            </object>
    2427
    25         <object type="button" size="0%+25 100%-60 33%+10 100%-32" style="StoneButton" hotkey="cancel">
    26             <translatableAttribute id="caption">Cancel</translatableAttribute>
    27             <action on="Press">Engine.PopGuiPage();</action>
    28         </object>
     28            <object type="button" size="0%+25 100%-60 33%+10 100%-32" style="StoneButton" hotkey="cancel">
     29                <translatableAttribute id="caption">Cancel</translatableAttribute>
     30                <action on="Press">Engine.PopGuiPage();</action>
     31            </object>
    2932
    30         <object name="deleteGameButton" type="button" size="33%+20 100%-60 66%-15 100%-32" style="StoneButton" hotkey="session.savedgames.delete">
    31             <translatableAttribute id="caption">Delete</translatableAttribute>
    32             <action on="Press">
    33                 if (!this.enabled)
    34                     return;
    35                 if (Engine.HotkeyIsPressed("session.savedgames.noconfirmation"))
    36                     deleteGameWithoutConfirmation();
    37                 else
    38                     deleteGame();
    39             </action>
     33            <object name="deleteGameButton" type="button" size="33%+20 100%-60 66%-15 100%-32" style="StoneButton" hotkey="session.savedgames.delete">
     34                <translatableAttribute id="caption">Delete</translatableAttribute>
     35                <action on="Press">
     36                    if (!this.enabled)
     37                        return;
     38                    if (Engine.HotkeyIsPressed("session.savedgames.noconfirmation"))
     39                        deleteGameWithoutConfirmation();
     40                    else
     41                        deleteGame();
     42                </action>
     43            </object>
     44
     45            <object name="loadGameButton" type="button" style="StoneButton" size="66%-5 100%-60 100%-25 100%-32">
     46                <translatableAttribute id="caption">Load</translatableAttribute>
     47                <action on="Press">loadGame();</action>
     48            </object>
     49
    4050        </object>
    4151
    42         <object name="loadGameButton" type="button" style="StoneButton" size="66%-5 100%-60 100%-25 100%-32">
    43             <translatableAttribute id="caption">Load</translatableAttribute>
    44             <action on="Press">loadGame();</action>
     52        <object type="image" size="550 20 100%-20 100%">
     53            <object name="gameInfoLogo" size="0 65 220 165" type="image" sprite="logo"/>
     54            <object name="gameInfoPreview" size="0 24 220 244"  type="image" sprite=""/>
     55            <object name="gameInfoText" type="text" style="ModernLeftLabelText" text_valign="top" size="0 260 100%-20 100%-5" />
    4556        </object>
    46 
    4757    </object>
    4858
    49     </objects>
     59</objects>
  • binaries/data/mods/public/gui/savedgames/save.js

     
    1414
    1515function init(data)
    1616{
    17     g_SavedGameData = data && data.savedGameData || undefined;
     17    g_SavedGameData = data && data.savedGameData || {};
     18    g_SavedGameData.timeElapsed = Engine.GuiInterfaceCall("GetSimulationState").timeElapsed;
    1819
    1920    var gameSelection = Engine.GetGUIObjectByName("gameSelection");
    2021    Engine.GetGUIObjectByName("deleteGameButton").enabled = false;