Ticket #2087: 2087.3.diff

File 2087.3.diff, 10.2 KB (added by Stan, 8 years ago)

Rebased patch, should fix the style issues. Things remaining are the big button (Which I like the way it is as you can press enter anyways) and the camera movement.

  • 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/loading/loading.js

     
    11let g_Data;
     2let g_TipIndex;
     3let g_Tips;
    24const g_EndPieceWidth = 16;
    35
    46function init(data)
     
    57{
    68    g_Data = data;
    79
    8     // Set to "hourglass" cursor.
    9     Engine.SetCursor("cursor-wait");
     10    if (!g_Data)
     11        return;
    1012
    11     // Get tip image and corresponding tip text
    12     let tipTextLoadingArray = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
     13    // Main loop now sets progress/description, but that won't
     14    // happen until the first timeslice completes, so set initial values.
     15    Engine.GetGUIObjectByName("loadingMapName").caption = sprintf(
     16        data.attribs.mapType === "random" ? translate("Generating “%(map)s”") : translate("Loading “%(map)s”"),
     17        { "map": translate(data.attribs.settings.Name) });
    1318
    14     if (tipTextLoadingArray.length > 0)
    15     {
    16         // Set tip text
    17         let tipTextFilePath = tipTextLoadingArray[getRandom (0, tipTextLoadingArray.length-1)];
    18         let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
     19    // Pick a random quote of the day (one quote per line).
     20    let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
     21    Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
    1922
    20         if (tipText)
    21         {
    22             let index = tipText.indexOf("\n");
    23             let tipTextTitle = tipText.substring(0, index);
    24             let tipTextMessage = tipText.substring(index);
    25             Engine.GetGUIObjectByName("tipTitle").caption = tipTextTitle? tipTextTitle : "";
    26             Engine.GetGUIObjectByName("tipText").caption = tipTextMessage? tipTextMessage : "";
    27         }
     23    g_Tips = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
     24    let tipControlsEnabled = !data.isNetworked &&
     25        Engine.ConfigDB_GetValue("user", "gui.loadingtips.enabled") === "true" &&
     26        g_Tips && g_Tips.length > 0;
    2827
    29         // Set tip image
    30         let fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
    31         let tipImageFilePath = "loading/tips/" + fileName;
    32         let 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.");
     28    Engine.GetGUIObjectByName("prevTipButton").hidden = !tipControlsEnabled;
     29    Engine.GetGUIObjectByName("nextTipButton").hidden = !tipControlsEnabled;
    3730
    38     // janwas: main loop now sets progress / description, but that won't
    39     // happen until the first timeslice completes, so set initial values.
    40     let loadingMapName = Engine.GetGUIObjectByName("loadingMapName");
     31    if (g_Tips && g_Tips.length > 0)
     32        updateTip(getRandom(0, g_Tips.length - 1));
     33}
    4134
    42     if (data)
    43     {
    44         let 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;
     35function nextTip()
     36{
     37    updateTip((g_TipIndex + 1) % g_Tips.length);
     38}
    5139
    52         case "random":
    53             loadingMapName.caption = sprintf(translate("Generating “%(map)s”"), { "map": mapName });
    54             break;
     40function prevTip()
     41{
     42    updateTip((g_Tips.length + g_TipIndex - 1) % g_Tips.length);
     43}
    5544
    56         default:
    57             error("Unknown map type: " + data.attribs.mapType);
    58         }
     45function updateTip(nextTipIndex)
     46{
     47    // Set tip text
     48    g_TipIndex = nextTipIndex;
     49    let tipTextFilePath = g_Tips[g_TipIndex];
     50    let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
     51    if (!tipText)
     52    {
     53        error("Failed to read tip text for the loading screen.");
     54        return;
    5955    }
    6056
    61     Engine.GetGUIObjectByName("progressText").caption = "";
    62     Engine.GetGUIObjectByName("progressbar").caption = 0;
     57    let index = tipText.indexOf("\n");
     58    let fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
    6359
    64     // Pick a random quote of the day (each line is a separate tip).
    65     let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
    66     Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
     60    Engine.GetGUIObjectByName("tipTitle").caption = tipText.substring(0, index);
     61    Engine.GetGUIObjectByName("tipText").caption = tipText.substring(index);
     62    Engine.GetGUIObjectByName("tipImage").sprite = "stretched:" + "loading/tips/" + fileName;
    6763}
    6864
    6965function displayProgress()
     
    7874    Engine.GetGUIObjectByName("progressbar").caption = progress; // display current progress
    7975    Engine.GetGUIObjectByName("progressText").caption = progress + "%";
    8076
    81     // Displays detailed loading info rather than a percent
    82     // Engine.GetGUIObjectByName("progressText").caption = g_LoadDescription; // display current progess details
    83 
    8477    // Keep curved right edge of progress bar in sync with the rest of the progress bar
    8578    let middle = Engine.GetGUIObjectByName("progressbar");
    8679    let rightSide = Engine.GetGUIObjectByName("progressbar_right");
     
    10093 */
    10194function reallyStartGame()
    10295{
    103     // Switch GUI from loading screen to game session.
     96    if (Engine.GetGUIObjectByName("prevTipButton").hidden && Engine.GetGUIObjectByName("nextTipButton"))
     97    {
     98        startGame();
     99        return;
     100    }
     101
     102    // Save the Camera Data
     103    // TODO : Currently there is no function that returns the full camera position so if you zoom that will not be reset.
     104    // We cannot prevent hotkeys from working because else the changing tooltip hotkeys wouldn't work.
     105    g_Data.posZ = Engine.CameraGetZ();
     106    g_Data.posX = Engine.CameraGetX();
     107    // Pause the game so it doesn't run while we read tips
     108    Engine.SetPaused(true);
     109    Engine.GetGUIObjectByName("startGameButton").hidden = false;
     110}
     111
     112function startGame()
     113{
     114    Engine.SetPaused(false);
     115    Engine.CameraMoveTo(g_Data.posX,g_Data.posZ);
     116    // Switch GUI from loading screen to game session
    104117    Engine.SwitchGuiPage("page_session.xml", g_Data);
    105118
    106     // Restore default cursor.
    107     Engine.SetCursor("arrow-default");
    108 
    109119    // Notify the other clients that we have finished the loading screen
    110120    if (g_Data.isNetworked && g_Data.isRejoining)
    111121        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>
    4355        </object>
    4456
    4557        <!-- LOADING SCREEN QUOTE (needs increased z value to overcome the transparent area of the tip image above it -->
     
    5062            <object name="quoteText" size="0 30 100% 100%" type="text" style="LoadingText"></object>
    5163        </object>
    5264    </object>
     65
     66    <!-- LOADING SCREEN READY (needs increased z value to overcome the quote area -->
     67    <object name="startGameButton" type="button" size="50%-200 80%+80 50%+200 80%+120" z="99" hidden="true" hotkey="confirm" style="ModernButtonRed">
     68        <translatableAttribute id="caption">I'm ready</translatableAttribute>
     69        <action on="Press">startGame();</action>
     70    </object>
     71
    5372</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                        {