Ticket #2087: loading2.patch

File loading2.patch, 11.6 KB (added by metis, 9 years ago)

Further editing

  • binaries/data/config/default.cfg

     
    322322hotkey.chat = Return                        ; Toggle chat window
    323323hotkey.teamchat = "T"                       ; Toggle chat window in team chat mode
    324324
     325; > LOADING SCREEN TOOLTIP HOTKEYS
     326hotkey.loading.previoustip = "LeftArrow"
     327hotkey.loading.nexttip = "RightArrow"
     328
    325329; > GUI TEXTBOX HOTKEYS
    326330hotkey.text.delete.left = "Ctrl+Backspace"    ; Delete word to the left of cursor
    327331hotkey.text.delete.right = "Ctrl+Del"         ; Delete word to the right of cursor
     
    379383
    380384; MOD SETTINGS
    381385mod.enabledmods = "mod public"
     386
     387; LOADING SCREEN TIP CONTROLS
     388gui.loadingtips.enabled = true
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    10041004        Engine.SwitchGuiPage("page_loading.xml", {
    10051005            "attribs": g_GameAttributes,
    10061006            "isNetworked" : g_IsNetworked,
    1007             "playerAssignments": g_PlayerAssignments
     1007            "playerAssignments": g_PlayerAssignments,
     1008            "isController": g_IsController
    10081009        });
    10091010    }
    10101011}
  • binaries/data/mods/public/gui/loading/loading.js

     
    1 var g_Data;
     1let g_Data;
     2let tipControlsEnabled;
     3let tips;
     4let tipIndex;
     5
    26const END_PIECE_WIDTH = 16;
    37
    48function init(data)
    59{
    610    g_Data = data;
     11    if (!data)
     12        return;
    713
    8     // Set to "hourglass" cursor.
    9     Engine.SetCursor("cursor-wait");
     14    // janwas: main loop now sets progress / description, but that won't
     15    // happen until the first timeslice completes, so set initial values.
     16    Engine.GetGUIObjectByName("loadingMapName").caption = translate(sprintf(
     17        data.attribs.mapType === "random" ? "Generating “%(map)s”" : "Loading “%(map)s”",
     18        {"map": translate(data.attribs.settings.Name)}));
    1019
    11     // Get tip image and corresponding tip text
    12     var tipTextLoadingArray = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
     20    // Pick a random quote of the day (one quote per line).
     21    let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
     22    Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
    1323
    14     if (tipTextLoadingArray.length > 0)
    15     {
    16         // Set tip text
    17         var tipTextFilePath = tipTextLoadingArray[getRandom (0, tipTextLoadingArray.length-1)];
    18         var tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
     24    tips = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
     25    tipControlsEnabled = !data.isNetworked
     26        && Engine.ConfigDB_GetValue("user", "gui.loadingtips.enabled") === "true"
     27        && tips && tips.length > 0;
    1928
    20         if (tipText)
    21         {
    22             var index = tipText.indexOf("\n");
    23             var tipTextTitle = tipText.substring(0, index);
    24             var tipTextMessage = tipText.substring(index);
    25             Engine.GetGUIObjectByName("tipTitle").caption = tipTextTitle? tipTextTitle : "";
    26             Engine.GetGUIObjectByName("tipText").caption = tipTextMessage? tipTextMessage : "";
    27         }
     29    Engine.GetGUIObjectByName("prevTipButton").hidden = !tipControlsEnabled;
     30    Engine.GetGUIObjectByName("nextTipButton").hidden = !tipControlsEnabled;
    2831
    29         // Set tip image
    30         var fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
    31         var tipImageFilePath = "loading/tips/" + fileName;
    32         var sprite = "stretched:" + tipImageFilePath;
    33         Engine.GetGUIObjectByName("tipImage").sprite = sprite? sprite : "";
    34     }
    35     else
    36     {
    37         error("Failed to find any matching tips for the loading screen.")
    38     }
     32    if (tips && tips.length > 0)
     33        updateTip(getRandom(0, tips.length - 1));
     34}
    3935
    40     // janwas: main loop now sets progress / description, but that won't
    41     // happen until the first timeslice completes, so set initial values.
    42     var loadingMapName = Engine.GetGUIObjectByName ("loadingMapName");
     36function nextTip()
     37{
     38    updateTip((tipIndex + 1) % tips.length);
     39}
    4340
    44     if (data)
     41function prevTip()
     42{
     43    updateTip((tips.length + tipIndex - 1) % tips.length);
     44}
     45
     46function updateTip(nextTipIndex)
     47{
     48    // Set tip text
     49    tipIndex = nextTipIndex;
     50    let tipTextFilePath = tips[tipIndex];
     51    let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
     52    if (!tipText)
    4553    {
    46         var mapName = translate(data.attribs.settings.Name);
    47         switch (data.attribs.mapType)
    48         {
    49         case "skirmish":
    50         case "scenario":
    51             loadingMapName.caption = sprintf(translate("Loading “%(map)s”"), {map: mapName});
    52             break;
    53 
    54         case "random":
    55             loadingMapName.caption = sprintf(translate("Generating “%(map)s”"), {map: mapName});
    56             break;
    57 
    58         default:
    59             error(sprintf("Unknown map type: %(mapType)s", { mapType: data.attribs.mapType }));
    60         }
     54        error("Failed to read tip text for the loading screen.");
     55        return;
    6156    }
    6257
    63     Engine.GetGUIObjectByName("progressText").caption = "";
    64     Engine.GetGUIObjectByName("progressbar").caption = 0;
     58    let index = tipText.indexOf("\n");
     59    let fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
    6560
    66     // Pick a random quote of the day (each line is a separate tip).
    67     var quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
    68     Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
     61    Engine.GetGUIObjectByName("tipTitle").caption = tipText.substring(0, index);
     62    Engine.GetGUIObjectByName("tipText").caption = tipText.substring(index);
     63    Engine.GetGUIObjectByName("tipImage").sprite = "stretched:" + "loading/tips/" + fileName;
    6964}
    7065
    71 // ====================================================================
    7266function displayProgress()
    7367{
    7468    // Make the progessbar finish a little early so that the user can actually see it finish
    75     if (g_Progress < 100)
    76     {
    77         // Show 100 when it is really 99
    78         var progress = g_Progress + 1;
     69    if (g_Progress >= 100)
     70        return;
    7971
    80         Engine.GetGUIObjectByName("progressbar").caption = progress; // display current progress
    81         Engine.GetGUIObjectByName("progressText").caption = progress + "%";
     72    // Show 100 when it is really 99
     73    let progress = g_Progress + 1;
    8274
    83         // Displays detailed loading info rather than a percent
    84         // Engine.GetGUIObjectByName("progressText").caption = g_LoadDescription; // display current progess details
     75    Engine.GetGUIObjectByName("progressbar").caption = progress; // display current progress
     76    Engine.GetGUIObjectByName("progressText").caption = progress + "%";
    8577
    86         // Keep curved right edge of progress bar in sync with the rest of the progress bar
    87         var middle = Engine.GetGUIObjectByName("progressbar");
    88         var rightSide = Engine.GetGUIObjectByName("progressbar_right");
     78    // Keep curved right edge of progress bar in sync with the rest of the progress bar
     79    let middle = Engine.GetGUIObjectByName("progressbar");
     80    let rightSide = Engine.GetGUIObjectByName("progressbar_right");
    8981
    90         var middleLength = (middle.size.right - middle.size.left) - (END_PIECE_WIDTH / 2);
    91         var increment = Math.round(progress * middleLength / 100);
     82    let middleLength = (middle.size.right - middle.size.left) - (END_PIECE_WIDTH / 2);
     83    let increment = Math.round(progress * middleLength / 100);
    9284
    93         var size = rightSide.size;
    94         size.left = increment;
    95         size.right = increment + END_PIECE_WIDTH;
    96         rightSide.size = size;
    97     }
     85    let size = rightSide.size;
     86    size.left = increment;
     87    size.right = increment + END_PIECE_WIDTH;
     88    rightSide.size = size;
    9889}
    9990
    100 // ====================================================================
    10191function reallyStartGame()
    10292{
    103     // Stop the music
    104 //  if (global.curr_music)
    105 //      global.curr_music.fade(-1, 0.0, 5.0); // fade to 0 over 5 seconds
    106 
    107 
    10893    // This is a reserved function name that is executed by the engine when it is ready
    10994    // to start the game (i.e. loading progress has reached 100%).
    11095
    111     // Switch GUI from loading screen to game session.
     96    if (!tipControlsEnabled)
     97    {
     98        startGame();
     99        return;
     100    }
     101
     102    // Pause the game so it doesn't run while we read tips
     103    Engine.SetPaused(true);
     104    Engine.GetGUIObjectByName("startGameButton").hidden = false;
     105}
     106
     107function startGame()
     108{
     109    Engine.SetPaused(false);
     110
     111    // Switch GUI from loading screen to game session
    112112    Engine.SwitchGuiPage("page_session.xml", g_Data);
     113}
    113114
    114     // Restore default cursor.
    115     Engine.SetCursor("arrow-default");
    116 }
  • binaries/data/mods/public/gui/loading/loading.xml

     
    4040        <object size="50%+128 50%-193 50%+448 50%+193" type="image" sprite="LoadingTipText">
    4141            <object name="tipTitle" size="30 30 100% 50" type="text" style="LoadingTipTitleText"/>
    4242            <object name="tipText" size="30 50 100%-30 100%" type="text" style="LoadingTipText"/>
     43           
     44            <!-- LOADING SCREEN TIP SHOW PREVIOUS -->
     45            <object name="prevTipButton" type="button" size="30 100%-80 90 100%-40" z="99" hotkey="loading.previoustip" style="StoneButton">
     46                <translatableAttribute id="caption">Previous</translatableAttribute>
     47                <action on="Press">prevTip();</action>
     48            </object>
     49
     50            <!-- LOADING SCREEN TIP SHOW NEXT -->
     51            <object name="nextTipButton" type="button" size="100%-90 100%-80 100%-30 100%-40" z="99" hotkey="loading.nexttip" style="StoneButton">
     52                <translatableAttribute id="caption">Next</translatableAttribute>
     53                <action on="Press">nextTip();</action>
     54            </object>
     55
    4356        </object>
    4457
    4558        <!-- LOADING SCREEN QUOTE (needs increased z value to overcome the transparent area of the tip image above it -->
     
    4962            </object>
    5063            <object name="quoteText" size="0 30 100% 100%" type="text" style="LoadingText"></object>
    5164        </object>
     65   
    5266    </object>
     67
     68    <!-- LOADING SCREEN READY (needs increased z value to overcome the quote area -->
     69    <object name="startGameButton" type="button" size="50%-200 75%+80 50%+200 75%+120" z="99" hidden="true" hotkey="confirm" style="StoneButton">
     70        <translatableAttribute id="caption">I'm ready</translatableAttribute>
     71        <action on="Press">startGame();</action>
     72    </object>
     73
    5374</objects>
  • binaries/data/mods/public/gui/options/options.js

     
    1313        [translate("FPS Overlay"), translate("Show frames per second in top right corner."), {"config":"overlay.fps"}, "boolean"],
    1414        [translate("Realtime Overlay"), translate("Show current system time in top right corner."), {"config":"overlay.realtime"}, "boolean"],
    1515        [translate("Gametime Overlay"), translate("Show current simulation time in top right corner."), {"config":"gui.session.timeelapsedcounter"}, "boolean"],
     16        [translate("Tip Controls"), translate("Allow navigating through loading screen tips and wait for the user before entering game."), {"config":"gui.loadingtips.enabled"}, "boolean"],
    1617    ],
    1718    "graphicsSetting":
    1819    [
     
    108109                    case "config":
    109110                        // Load initial value if not yet loaded.
    110111                        if (!checked || typeof checked != "boolean")
    111                             checked = Engine.ConfigDB_GetValue("user", option[2][action]) === "true" ? true : false;
     112                            checked = Engine.ConfigDB_GetValue("user", option[2][action]) === "true";
    112113                        // Hacky macro to create the callback.
    113114                        var callback = function(key)
    114115                        {