Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/common/tooltips.js
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | function unitFont(text) | ||||
return g_TooltipTextFormats.unit[0] + text + g_TooltipTextFormats.unit[1]; | return g_TooltipTextFormats.unit[0] + text + g_TooltipTextFormats.unit[1]; | ||||
} | } | ||||
function commaFont(text) | function commaFont(text) | ||||
{ | { | ||||
return g_TooltipTextFormats.comma[0] + text + g_TooltipTextFormats.comma[1]; | return g_TooltipTextFormats.comma[0] + text + g_TooltipTextFormats.comma[1]; | ||||
} | } | ||||
function getSecondsString(seconds) | |||||
{ | |||||
return sprintf(translatePlural("%(time)s %(second)s", "%(time)s %(second)s", seconds), { | |||||
"time": seconds, | |||||
"second": unitFont(translatePlural("second", "seconds", seconds)) | |||||
}); | |||||
} | |||||
function getEntityTooltip(template) | function getEntityTooltip(template) | ||||
{ | { | ||||
if (!template.tooltip) | if (!template.tooltip) | ||||
return ""; | return ""; | ||||
return bodyFont(template.tooltip); | return bodyFont(template.tooltip); | ||||
} | } | ||||
function getHealthTooltip(template) | function getHealthTooltip(template) | ||||
{ | { | ||||
if (!template.health) | if (!template.health) | ||||
return ""; | return ""; | ||||
return sprintf(translate("%(label)s %(details)s"), { | return sprintf(translate("%(label)s %(details)s"), { | ||||
"label": headerFont(translate("Health:")), | "label": headerFont(translate("Health:")), | ||||
"details": template.health | "details": template.health | ||||
}); | }); | ||||
} | } | ||||
function attackRateDetails(template, type) | function attackRateDetails(template, type) | ||||
{ | { | ||||
// Either one arrow shot by UnitAI, | // Either one arrow shot by UnitAI, | ||||
let time = template.attack[type].repeatTime / 1000; | let timeString = getSecondsString(template.attack[type].repeatTime / 1000); | ||||
let timeString = sprintf(translatePlural("%(time)s %(second)s", "%(time)s %(second)s", time), { | |||||
"time": time, | |||||
"second": unitFont(translatePlural("second", "seconds", time)) | |||||
}); | |||||
// or multiple arrows shot by BuildingAI | // or multiple arrows shot by BuildingAI | ||||
if (!template.buildingAI || type != "Ranged") | if (!template.buildingAI || type != "Ranged") | ||||
return timeString; | return timeString; | ||||
// Show either current rate from simulation or default count if the sim is not running | // Show either current rate from simulation or default count if the sim is not running | ||||
let arrows = template.buildingAI.arrowCount || template.buildingAI.defaultArrowCount; | let arrows = template.buildingAI.arrowCount || template.buildingAI.defaultArrowCount; | ||||
let arrowString = sprintf(translatePlural("%(arrowcount)s %(arrows)s", "%(arrowcount)s %(arrows)s", arrows), { | let arrowString = sprintf(translatePlural("%(arrowcount)s %(arrows)s", "%(arrowcount)s %(arrows)s", arrows), { | ||||
▲ Show 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | "details": | ||||
type => sprintf(translate("%(resourceIcon)s %(rate)s"), { | type => sprintf(translate("%(resourceIcon)s %(rate)s"), { | ||||
"resourceIcon": resourceIcon(type), | "resourceIcon": resourceIcon(type), | ||||
"rate": rates[type] | "rate": rates[type] | ||||
}) | }) | ||||
).join(" ") | ).join(" ") | ||||
}); | }); | ||||
} | } | ||||
function getResourceTrickleTooltip(template) | |||||
{ | |||||
if (!template.resourceTrickle) | |||||
return ""; | |||||
let resCodes = Object.keys(template.resourceTrickle.rates).filter(res => template.resourceTrickle.rates[res]); | |||||
if (!resCodes.length) | |||||
return ""; | |||||
return sprintf(translate("%(label)s %(details)s"), { | |||||
"label": headerFont(translate("Resource Trickle:")), | |||||
"details": sprintf(translate("%(resources)s / %(time)s"), { | |||||
"resources": | |||||
resCodes.map( | |||||
res => sprintf(translate("%(resourceIcon)s %(rate)s"), { | |||||
"resourceIcon": resourceIcon(res), | |||||
"rate": template.resourceTrickle.rates[res] | |||||
}) | |||||
).join(" "), | |||||
"time": getSecondsString(template.resourceTrickle.interval / 1000) | |||||
}) | |||||
}); | |||||
} | |||||
/** | /** | ||||
* Returns an array of strings for a set of wall pieces. If the pieces share | * Returns an array of strings for a set of wall pieces. If the pieces share | ||||
* resource type requirements, output will be of the form '10 to 30 Stone', | * resource type requirements, output will be of the form '10 to 30 Stone', | ||||
* otherwise output will be, e.g. '10 Stone, 20 Stone, 30 Stone'. | * otherwise output will be, e.g. '10 Stone, 20 Stone, 30 Stone'. | ||||
*/ | */ | ||||
function getWallPieceTooltip(wallTypes) | function getWallPieceTooltip(wallTypes) | ||||
{ | { | ||||
let out = []; | let out = []; | ||||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | for (let type of lootTypes) | ||||
// Translation: %(component) will be the icon for the loot type and %(loot) will be the value. | // Translation: %(component) will be the icon for the loot type and %(loot) will be the value. | ||||
lootLabels.push(sprintf(translate("%(component)s %(loot)s"), { | lootLabels.push(sprintf(translate("%(component)s %(loot)s"), { | ||||
"component": resourceIcon(type), | "component": resourceIcon(type), | ||||
"loot": loot | "loot": loot | ||||
})); | })); | ||||
} | } | ||||
if (!lootLabels.length) | |||||
return ""; | |||||
return sprintf(translate("%(label)s %(details)s"), { | return sprintf(translate("%(label)s %(details)s"), { | ||||
"label": headerFont(translate("Loot:")), | "label": headerFont(translate("Loot:")), | ||||
"details": lootLabels.join(" ") | "details": lootLabels.join(" ") | ||||
}); | }); | ||||
} | } |
Wildfire Games · Phabricator