2 const g_EndPieceWidth = 16;
8 Engine.SetCursor("cursor-wait");
10 // Get tip image and corresponding tip text
11 let tipTextLoadingArray = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
13 if (tipTextLoadingArray.length > 0)
16 let tipTextFilePath = tipTextLoadingArray[getRandom(0, tipTextLoadingArray.length-1)];
17 let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
21 let index = tipText.indexOf("\n");
22 let tipTextTitle = tipText.substring(0, index);
23 let tipTextMessage = tipText.substring(index);
24 Engine.GetGUIObjectByName("tipTitle").caption = tipTextTitle? tipTextTitle : "";
25 Engine.GetGUIObjectByName("tipText").caption = tipTextMessage? tipTextMessage : "";
29 let fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
30 let tipImageFilePath = "loading/tips/" + fileName;
31 let sprite = "stretched:" + tipImageFilePath;
32 Engine.GetGUIObjectByName("tipImage").sprite = sprite? sprite : "";
35 error("Failed to find any matching tips for the loading screen.");
37 // janwas: main loop now sets progress / description, but that won't
38 // happen until the first timeslice completes, so set initial values.
39 let loadingMapName = Engine.GetGUIObjectByName("loadingMapName");
43 let mapName = translate(data.attribs.settings.Name);
44 switch (data.attribs.mapType)
48 loadingMapName.caption = sprintf(translate("Loading ā%(map)sā"), { "map": mapName });
52 loadingMapName.caption = sprintf(translate("Generating ā%(map)sā"), { "map": mapName });
56 error("Unknown map type: " + data.attribs.mapType);
60 Engine.GetGUIObjectByName("progressText").caption = "";
61 Engine.GetGUIObjectByName("progressbar").caption = 0;
63 // Pick a random quote of the day (each line is a separate tip).
64 let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
65 Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
68 function displayProgress()
70 // Make the progessbar finish a little early so that the user can actually see it finish
71 if (g_Progress >= 100)
74 // Show 100 when it is really 99
75 let progress = g_Progress + 1;
77 Engine.GetGUIObjectByName("progressbar").caption = progress; // display current progress
78 Engine.GetGUIObjectByName("progressText").caption = progress + "%";
80 // Displays detailed loading info rather than a percent
81 // Engine.GetGUIObjectByName("progressText").caption = g_LoadDescription; // display current progess details
83 // Keep curved right edge of progress bar in sync with the rest of the progress bar
84 let middle = Engine.GetGUIObjectByName("progressbar");
85 let rightSide = Engine.GetGUIObjectByName("progressbar_right");
87 let middleLength = (middle.size.right - middle.size.left) - (g_EndPieceWidth / 2);
88 let increment = Math.round(progress * middleLength / 100);
90 let size = rightSide.size;
91 size.left = increment;
92 size.right = increment + g_EndPieceWidth;
93 rightSide.size = size;
97 * This is a reserved function name that is executed by the engine when it is ready
98 * to start the game (i.e. loading progress has reached 100%).
100 function reallyStartGame()
102 Engine.SwitchGuiPage("page_session.xml", g_Data);
104 Engine.ResetCursor();