Index: ps/trunk/binaries/data/config/default.cfg =================================================================== --- ps/trunk/binaries/data/config/default.cfg +++ ps/trunk/binaries/data/config/default.cfg @@ -361,6 +361,9 @@ aibehavior = "random" ; Default behavior of the AI (random, balanced, aggressive or defensive) settingsslide = true ; Enable/Disable settings panel slide +[gui.loadingscreen] +progressdescription = false ; Whether to display the progress percent or a textual description + [gui.session] camerajump.threshold = 40 ; How close do we have to be to the actual location in order to jump back to the previous one? timeelapsedcounter = false ; Show the game duration in the top right corner Index: ps/trunk/binaries/data/mods/public/gui/loading/ProgressBar.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/ProgressBar.js +++ ps/trunk/binaries/data/mods/public/gui/loading/ProgressBar.js @@ -0,0 +1,51 @@ +/** + * This class will display the progress of the map loading by animating a progress bar. + * Optionally it displays the current stage of the loading screen. + */ +class ProgressBar +{ + constructor() + { + this.progressbar_right = Engine.GetGUIObjectByName("progressbar_right"); + this.progressbar_right_width = this.progressbar_right.size.right - this.progressbar_right.size.left; + + this.progressbar = Engine.GetGUIObjectByName("progressbar"); + this.progressbar.onGameLoadProgress = this.onGameLoadProgress.bind(this); + this.progressBarSize = this.progressbar.size.right - this.progressbar.size.left - this.progressbar_right_width / 2; + + this.progressText = Engine.GetGUIObjectByName("progressText"); + this.showDescription = Engine.ConfigDB_GetValue("user", this.ConfigKey) == "true"; + this.percentArgs = !this.showDescription && {}; + } + + onGameLoadProgress(progression, description) + { + // Make the progessbar finish a little early so that the player can see it finish + if (progression >= 100) + return; + + // Show 100 when it is really 99 + let progress = progression + 1; + this.progressbar.caption = progress; + + if (this.showDescription) + this.progressText.caption = description; + else + { + this.percentArgs.percentage = progress; + this.progressText.caption = sprintf(this.CaptionFormat, this.percentArgs); + } + + let increment = Math.round(progress * this.progressBarSize / 100); + let size = this.progressbar_right.size; + size.left = increment; + size.right = increment + this.progressbar_right_width; + this.progressbar_right.size = size; + } +} + +ProgressBar.prototype.CaptionFormat = + translateWithContext("loading screen progress", "%(percentage)s%%"); + +ProgressBar.prototype.ConfigKey = + "gui.loadingscreen.progressdescription"; Index: ps/trunk/binaries/data/mods/public/gui/loading/ProgressBar.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/ProgressBar.xml +++ ps/trunk/binaries/data/mods/public/gui/loading/ProgressBar.xml @@ -0,0 +1,8 @@ + + + + + + + + Index: ps/trunk/binaries/data/mods/public/gui/loading/QuoteDisplay.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/QuoteDisplay.js +++ ps/trunk/binaries/data/mods/public/gui/loading/QuoteDisplay.js @@ -0,0 +1,14 @@ +/** + * This class is concerned with chosing and displaying quotes from historical figures. + */ +class QuoteDisplay +{ + constructor() + { + Engine.GetGUIObjectByName("quoteText").caption = + translate(pickRandom( + Engine.ReadFileLines(this.File).filter(line => line))); + } +} + +QuoteDisplay.prototype.File = "gui/text/quotes.txt"; Index: ps/trunk/binaries/data/mods/public/gui/loading/QuoteDisplay.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/QuoteDisplay.xml +++ ps/trunk/binaries/data/mods/public/gui/loading/QuoteDisplay.xml @@ -0,0 +1,2 @@ + + Index: ps/trunk/binaries/data/mods/public/gui/loading/TipDisplay.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/TipDisplay.js +++ ps/trunk/binaries/data/mods/public/gui/loading/TipDisplay.js @@ -0,0 +1,52 @@ +/** + * This class is concerned with chosing and displaying hints about how to play the game. + * This includes a text and an image. + */ +class TipDisplay +{ + constructor() + { + this.tipImage = Engine.GetGUIObjectByName("tipImage"); + this.tipTitle = Engine.GetGUIObjectByName("tipTitle"); + this.tipText = Engine.GetGUIObjectByName("tipText"); + + this.tipFiles = listFiles(this.TextPath, ".txt", false); + this.displayRandomTip(); + } + + displayRandomTip() + { + let tipFile = pickRandom(this.tipFiles); + if (tipFile) + this.displayTip(tipFile); + else + error("Failed to find any matching tips for the loading screen."); + } + + displayTip(tipFile) + { + this.tipImage.sprite = + "stretched:" + this.ImagePath + tipFile + ".png"; + + let tipText = Engine.TranslateLines(Engine.ReadFile( + this.TextPath + tipFile + ".txt")).split("\n"); + + this.tipTitle.caption = tipText.shift(); + + this.tipText.caption = tipText.map(text => + text && sprintf(this.BulletFormat, { "tiptext": text })).join("\n\n"); + } +} + +/** + * Directory storing txt files containing the gameplay tips. + */ +TipDisplay.prototype.TextPath = "gui/text/tips/"; + +/** + * Directory storing the PNG images with filenames corresponding to the tip text files. + */ +TipDisplay.prototype.ImagePath = "loading/tips/"; + +// Translation: A bullet point used before every item of list of tips displayed on loading screen +TipDisplay.prototype.BulletFormat = translate("• %(tiptext)s"); Index: ps/trunk/binaries/data/mods/public/gui/loading/TipDisplay.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/TipDisplay.xml +++ ps/trunk/binaries/data/mods/public/gui/loading/TipDisplay.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + Index: ps/trunk/binaries/data/mods/public/gui/loading/TitleDisplay.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/TitleDisplay.js +++ ps/trunk/binaries/data/mods/public/gui/loading/TitleDisplay.js @@ -0,0 +1,17 @@ +/** + * This class choses the title of the loading screen page. + */ +class TitleDisplay +{ + constructor(data) + { + let loadingMapName = Engine.GetGUIObjectByName("loadingMapName"); + loadingMapName.caption = sprintf( + data.attribs.mapType == "random" ? this.Generating : this.Loading, + { "map": translate(data.attribs.settings.Name) }); + } +} + +TitleDisplay.prototype.Generating = translate("Generating “%(map)s”"); + +TitleDisplay.prototype.Loading = translate("Loading “%(map)s”"); Index: ps/trunk/binaries/data/mods/public/gui/loading/TitleDisplay.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/TitleDisplay.xml +++ ps/trunk/binaries/data/mods/public/gui/loading/TitleDisplay.xml @@ -0,0 +1,2 @@ + + Index: ps/trunk/binaries/data/mods/public/gui/loading/loading.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/loading.js +++ ps/trunk/binaries/data/mods/public/gui/loading/loading.js @@ -1,97 +1,16 @@ -/** - * Path to a file containing quotes of historical figures. - */ -var g_QuotesFile = "gui/text/quotes.txt"; - -/** - * Directory storing txt files containing the gameplay tips. - */ -var g_TipsTextPath = "gui/text/tips/"; - -/** - * Directory storing the PNG images with filenames corresponding to the tip text files. - */ -var g_TipsImagePath = "loading/tips/"; - -var g_Data; -var g_EndPieceWidth = 16; +var g_LoadingPage; function init(data) { - g_Data = data; + g_LoadingPage = { + "initData": data, + "progressBar": new ProgressBar(), + "quoteDisplay": new QuoteDisplay(), + "tipDisplay": new TipDisplay(), + "titleDisplay": new TitleDisplay(data) + }; Engine.SetCursor("cursor-wait"); - - let tipFile = pickRandom(listFiles(g_TipsTextPath, ".txt", false)); - - if (tipFile) - { - let tipText = Engine.TranslateLines(Engine.ReadFile(g_TipsTextPath + tipFile + ".txt")).split("\n"); - Engine.GetGUIObjectByName("tipTitle").caption = tipText.shift(); - Engine.GetGUIObjectByName("tipText").caption = tipText.map( - // Translation: A bullet point used before every item of list of tips displayed on loading screen - text => text && sprintf(translate("• %(tiptext)s"), { "tiptext": text }) - ).join("\n\n"); - Engine.GetGUIObjectByName("tipImage").sprite = "stretched:" + g_TipsImagePath + tipFile + ".png"; - } - else - error("Failed to find any matching tips for the loading screen."); - - // janwas: main loop now sets progress / description, but that won't - // happen until the first timeslice completes, so set initial values. - let loadingMapName = Engine.GetGUIObjectByName("loadingMapName"); - - if (data) - { - let mapName = translate(data.attribs.settings.Name); - switch (data.attribs.mapType) - { - case "skirmish": - case "scenario": - loadingMapName.caption = sprintf(translate("Loading “%(map)s”"), { "map": mapName }); - break; - - case "random": - loadingMapName.caption = sprintf(translate("Generating “%(map)s”"), { "map": mapName }); - break; - } - } - - Engine.GetGUIObjectByName("progressText").caption = ""; - - let progressbar = Engine.GetGUIObjectByName("progressbar"); - progressbar.caption = 0; - progressbar.onGameLoadProgress = displayProgress; - - Engine.GetGUIObjectByName("quoteText").caption = translate(pickRandom(Engine.ReadFileLines(g_QuotesFile).filter(line => line))); -} - -function displayProgress(progression, description) -{ - // Make the progessbar finish a little early so that the user can actually see it finish - if (progression >= 100) - return; - - // Show 100 when it is really 99 - let progress = progression + 1; - - Engine.GetGUIObjectByName("progressbar").caption = progress; // display current progress - Engine.GetGUIObjectByName("progressText").caption = progress + "%"; - - // Displays detailed loading info rather than a percent - // Engine.GetGUIObjectByName("progressText").caption = description; - - // Keep curved right edge of progress bar in sync with the rest of the progress bar - let middle = Engine.GetGUIObjectByName("progressbar"); - let rightSide = Engine.GetGUIObjectByName("progressbar_right"); - - let middleLength = (middle.size.right - middle.size.left) - (g_EndPieceWidth / 2); - let increment = Math.round(progress * middleLength / 100); - - let size = rightSide.size; - size.left = increment; - size.right = increment + g_EndPieceWidth; - rightSide.size = size; } /** @@ -100,7 +19,6 @@ */ function reallyStartGame() { - Engine.SwitchGuiPage("page_session.xml", g_Data); - + Engine.SwitchGuiPage("page_session.xml", g_LoadingPage.initData); Engine.ResetCursor(); } Index: ps/trunk/binaries/data/mods/public/gui/loading/loading.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loading/loading.xml +++ ps/trunk/binaries/data/mods/public/gui/loading/loading.xml @@ -1,10 +1,4 @@ - -