mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 05:44:08 -07:00
Add helper function to apply arbitrary GUI tags (such as font and color).
This avoids the caller having to duplicate the GUI tag format over and over again (equal to54904b1750), detects syntax errors at compile time and applies the separation-of-concerns pattern (callers only have to specify the tag value agnosticly of the tag format). Differential Revision: https://code.wildfiregames.com/D1167 Patch By: fpre / ffffffff Comments By: bb Refse1b13dead9This was SVN commit r20697.
This commit is contained in:
parent
e4cc4da1d2
commit
3cfb8730a8
2 changed files with 23 additions and 9 deletions
|
|
@ -6,4 +6,18 @@ function coloredText(text, color)
|
|||
return '[color="' + color + '"]' + text + '[/color]';
|
||||
}
|
||||
|
||||
//TODO: font setter
|
||||
/**
|
||||
* Set GUI tags on text string.
|
||||
*
|
||||
* @param {string} string - String to apply tags to.
|
||||
* @param {object} tags - Object containing the tags, for instance { "color": "white" } or { "font": "sans-13" }.
|
||||
*/
|
||||
function setStringTags(text, tags)
|
||||
{
|
||||
let result = "";
|
||||
|
||||
for (let tag in tags)
|
||||
result = '[' + tag + '="' + tags[tag] + '"]' + text + '[/' + tag + ']';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
var g_TooltipTextFormats = {
|
||||
"unit": ['[font="sans-10"][color="orange"]', '[/color][/font]'],
|
||||
"header": ['[font="sans-bold-13"]', '[/font]'],
|
||||
"body": ['[font="sans-13"]', '[/font]'],
|
||||
"comma": ['[font="sans-12"]', '[/font]']
|
||||
"unit": { "font": "sans-10", "color": "orange" },
|
||||
"header": { "font": "sans-bold-13" },
|
||||
"body": { "font": "sans-13" },
|
||||
"comma": { "font": "sans-12" }
|
||||
};
|
||||
|
||||
var g_AttackTypes = {
|
||||
|
|
@ -84,22 +84,22 @@ function getLocalizedResourceAmounts(resources)
|
|||
|
||||
function bodyFont(text)
|
||||
{
|
||||
return g_TooltipTextFormats.body[0] + text + g_TooltipTextFormats.body[1];
|
||||
return setStringTags(text, g_TooltipTextFormats.body);
|
||||
}
|
||||
|
||||
function headerFont(text)
|
||||
{
|
||||
return g_TooltipTextFormats.header[0] + text + g_TooltipTextFormats.header[1];
|
||||
return setStringTags(text, g_TooltipTextFormats.header);
|
||||
}
|
||||
|
||||
function unitFont(text)
|
||||
{
|
||||
return g_TooltipTextFormats.unit[0] + text + g_TooltipTextFormats.unit[1];
|
||||
return setStringTags(text, g_TooltipTextFormats.unit);
|
||||
}
|
||||
|
||||
function commaFont(text)
|
||||
{
|
||||
return g_TooltipTextFormats.comma[0] + text + g_TooltipTextFormats.comma[1];
|
||||
return setStringTags(text, g_TooltipTextFormats.comma);
|
||||
}
|
||||
|
||||
function getSecondsString(seconds)
|
||||
|
|
|
|||
Loading…
Reference in a new issue