mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-18 14:23:56 -07:00
Add config option to display the loading screen stage description. Add tip functions for future use, refs D1730. Harmonize coordinates. Differential Revision: https://code.wildfiregames.com/D2418 This was SVN commit r23150.
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/**
|
|
* 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");
|