Ticket #2087: 2087.2.diff

File 2087.2.diff, 11.2 KB (added by Stan, 8 years ago)

Reset the X,Z positions of the camera after loading, and move the default cfg to the right place.

  • binaries/data/config/default.cfg

     
    220220;9 =
    221221;10 =
    222222
     223[hotkey.loading]    ; > LOADING SCREEN TOOLTIP HOTKEYS
     224previoustip = "LeftArrow"
     225nexttip = "RightArrow"
     226
    223227[hotkey.profile]
    224228toggle = "F11"               ; Enable/disable real-time profiler
    225229save = "Shift+F11"           ; Save current profiler data to logs/profile.txt
     
    316320cursorblinkrate = 0.5             ; Cursor blink rate in seconds (0.0 to disable blinking)
    317321scale = 1.0                       ; GUI scaling factor, for improved compatibility with 4K displays
    318322
     323[gui.loadingtips]    ; > LOADING SCREEN TIP CONTROLS
     324enabled = true
     325
    319326[gui.menu]
    320327limitfps = true                   ; Limit FPS in the menus and loading screen
    321328
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    11681168        Engine.SwitchGuiPage("page_loading.xml", {
    11691169            "attribs": g_GameAttributes,
    11701170            "isNetworked" : g_IsNetworked,
    1171             "playerAssignments": g_PlayerAssignments
     1171            "playerAssignments": g_PlayerAssignments,
     1172            "isController": g_IsController
    11721173        });
    11731174    }
    11741175}
  • binaries/data/mods/public/gui/loading/loading.js

     
    1 var g_Data;
     1let g_Data;
     2let tipControlsEnabled;
     3let tips;
     4let tipIndex;
     5
     6
    27const END_PIECE_WIDTH = 16;
    38
    49function init(data)
     
    510{
    611    g_Data = data;
    712
    8     // Set to "hourglass" cursor.
    9     Engine.SetCursor("cursor-wait");
     13    if (!g_Data)
     14        return;
    1015
    11     // Get tip image and corresponding tip text
    12     var tipTextLoadingArray = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
     16    // janwas: main loop now sets progress / description, but that won't
     17    // happen until the first timeslice completes, so set initial values.
     18    Engine.GetGUIObjectByName("loadingMapName").caption = sprintf(
     19        data.attribs.mapType === "random" ? translate("Generating “%(map)s”") : translate("Loading “%(map)s”"),
     20        { "map": translate(data.attribs.settings.Name) });
    1321
    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));
     22    // Pick a random quote of the day (one quote per line).
     23    let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
     24    Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
    1925
    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         }
     26    tips = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
     27    tipControlsEnabled = !data.isNetworked
     28        && Engine.ConfigDB_GetValue("user", "gui.loadingtips.enabled") === "true"
     29        && tips && tips.length > 0;
    2830
    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         error("Failed to find any matching tips for the loading screen.");
     31    Engine.GetGUIObjectByName("prevTipButton").hidden = !tipControlsEnabled;
     32    Engine.GetGUIObjectByName("nextTipButton").hidden = !tipControlsEnabled;
    3733
    38     // janwas: main loop now sets progress / description, but that won't
    39     // happen until the first timeslice completes, so set initial values.
    40     var loadingMapName = Engine.GetGUIObjectByName("loadingMapName");
     34    if (tips && tips.length > 0)
     35        updateTip(getRandom(0, tips.length - 1));
     36}
    4137
    42     if (data)
    43     {
    44         var mapName = translate(data.attribs.settings.Name);
    45         switch (data.attribs.mapType)
    46         {
    47         case "skirmish":
    48         case "scenario":
    49             loadingMapName.caption = sprintf(translate("Loading “%(map)s”"), { "map": mapName });
    50             break;
     38function nextTip()
     39{
     40    updateTip((tipIndex + 1) % tips.length);
     41}
    5142
    52         case "random":
    53             loadingMapName.caption = sprintf(translate("Generating “%(map)s”"), { "map": mapName });
    54             break;
     43function prevTip()
     44{
     45    updateTip((tips.length + tipIndex - 1) % tips.length);
     46}
    5547
    56         default:
    57             error("Unknown map type: " + data.attribs.mapType);
    58         }
     48function updateTip(nextTipIndex)
     49{
     50    // Set tip text
     51    tipIndex = nextTipIndex;
     52    let tipTextFilePath = tips[tipIndex];
     53    let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
     54    if (!tipText)
     55    {
     56        error("Failed to read tip text for the loading screen.");
     57        return;
    5958    }
    6059
    61     Engine.GetGUIObjectByName("progressText").caption = "";
    62     Engine.GetGUIObjectByName("progressbar").caption = 0;
     60    let index = tipText.indexOf("\n");
     61    let fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
    6362
    64     // Pick a random quote of the day (each line is a separate tip).
    65     var quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
    66     Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
     63    Engine.GetGUIObjectByName("tipTitle").caption = tipText.substring(0, index);
     64    Engine.GetGUIObjectByName("tipText").caption = tipText.substring(index);
     65    Engine.GetGUIObjectByName("tipImage").sprite = "stretched:" + "loading/tips/" + fileName;
    6766}
    6867
    6968function displayProgress()
     
    7877    Engine.GetGUIObjectByName("progressbar").caption = progress; // display current progress
    7978    Engine.GetGUIObjectByName("progressText").caption = progress + "%";
    8079
    81     // Displays detailed loading info rather than a percent
    82     // Engine.GetGUIObjectByName("progressText").caption = g_LoadDescription; // display current progess details
    83 
    8480    // Keep curved right edge of progress bar in sync with the rest of the progress bar
    85     var middle = Engine.GetGUIObjectByName("progressbar");
    86     var rightSide = Engine.GetGUIObjectByName("progressbar_right");
     81    let middle = Engine.GetGUIObjectByName("progressbar");
     82    let rightSide = Engine.GetGUIObjectByName("progressbar_right");
    8783
    88     var middleLength = (middle.size.right - middle.size.left) - (END_PIECE_WIDTH / 2);
    89     var increment = Math.round(progress * middleLength / 100);
     84    let middleLength = (middle.size.right - middle.size.left) - (END_PIECE_WIDTH / 2);
     85    let increment = Math.round(progress * middleLength / 100);
    9086
    91     var size = rightSide.size;
     87    let size = rightSide.size;
    9288    size.left = increment;
    9389    size.right = increment + END_PIECE_WIDTH;
    9490    rightSide.size = size;
     
    10096 */
    10197function reallyStartGame()
    10298{
    103     // Switch GUI from loading screen to game session.
     99    if (!tipControlsEnabled)
     100    {
     101        startGame();
     102        return;
     103    }
     104
     105    // Save the Camera Data
     106    // TODO : Currently there is no function that returns the full camera position so if you zoom that will not be reset.
     107    // We cannot prevent hotkeys from working because else the changing tooltip hotkeys wouldn't work.
     108    g_Data.posZ = Engine.CameraGetZ();
     109    g_Data.posX = Engine.CameraGetX();
     110    // Pause the game so it doesn't run while we read tips
     111    Engine.SetPaused(true);
     112    Engine.GetGUIObjectByName("startGameButton").hidden = false;
     113}
     114
     115function startGame()
     116{
     117    Engine.SetPaused(false);
     118    Engine.CameraMoveTo(g_Data.posX,g_Data.posZ);
     119    // Switch GUI from loading screen to game session
    104120    Engine.SwitchGuiPage("page_session.xml", g_Data);
    105121
    106     // Restore default cursor.
    107     Engine.SetCursor("arrow-default");
    108    
    109122    // Notify the other clients that we have finished the loading screen
    110123    if (g_Data.isNetworked && g_Data.isRejoining)
    111124        Engine.SendNetworkRejoined();
  • 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="20 100% 100 100%+30" z="99" hotkey="loading.previoustip" style="ModernButtonRed">
     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% 100%-30 100%+30" z="99" hotkey="loading.nexttip" style="ModernButtonRed">
     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 80%+80 50%+200 80%+120" z="99" hidden="true" hotkey="confirm" style="ModernButtonRed">
     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

     
    1515        [translate("Gametime Overlay"), translate("Show current simulation time in top right corner."), {"config":"gui.session.timeelapsedcounter"}, "boolean"],
    1616        [translate("Ceasefire Time Overlay"), translate("Always show the remaining ceasefire time."), {"config":"gui.session.ceasefirecounter"}, "boolean"],
    1717        [translate("Persist Match Settings"), translate("Save and restore match settings for quick reuse when hosting another game"), {"config":"persistmatchsettings"}, "boolean"],
     18        [translate("Tip Controls"), translate("Allow navigating through loading screen tips and wait for the user before entering game."), {"config":"gui.loadingtips.enabled"}, "boolean"],
    1819    ],
    1920    "graphicsSetting":
    2021    [
     
    116117                    case "config":
    117118                        // Load initial value if not yet loaded.
    118119                        if (!checked || typeof checked != "boolean")
    119                             checked = Engine.ConfigDB_GetValue("user", option[2][action]) === "true" ? true : false;
     120                            checked = Engine.ConfigDB_GetValue("user", option[2][action]) === "true";
    120121                        // Hacky macro to create the callback.
    121122                        var callback = function(key)
    122123                        {