Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/common/tooltips.js
var g_TooltipTextFormats = { | var g_TooltipTextFormats = { | ||||
"unit": { "font": "sans-10", "color": "orange" }, | "unit": { "font": "sans-10", "color": "orange" }, | ||||
"header": { "font": "sans-bold-13" }, | "header": { "font": "sans-bold-13" }, | ||||
"body": { "font": "sans-13" }, | "body": { "font": "sans-13" }, | ||||
"comma": { "font": "sans-12" }, | "comma": { "font": "sans-12" }, | ||||
"nameSpecificBig": { "font": "sans-bold-16" }, | "nameSpecificBig": { "font": "sans-bold-16" }, | ||||
"nameSpecificSmall": { "font": "sans-bold-12" }, | "nameSpecificSmall": { "font": "sans-bold-12" }, | ||||
"nameGeneric": { "font": "sans-bold-16" } | "nameGeneric": { "font": "sans-bold-16" } | ||||
}; | }; | ||||
function getCostTypes() | /** | ||||
{ | * String of four spaces to be used as indentation in gui strings. | ||||
return g_ResourceData.GetCodes().concat(["population", "populationBonus", "time"]); | */ | ||||
} | var g_Indent = " "; | ||||
var g_DamageTypesMetadata = new DamageTypesMetadata(); | var g_DamageTypesMetadata = new DamageTypesMetadata(); | ||||
var g_StatusEffectsMetadata = new StatusEffectsMetadata(); | var g_StatusEffectsMetadata = new StatusEffectsMetadata(); | ||||
/** | /** | ||||
* If true, always shows whether the splash damage deals friendly fire. | * If true, always shows whether the splash damage deals friendly fire. | ||||
* Otherwise display the friendly fire tooltip only if it does. | * Otherwise display the friendly fire tooltip only if it does. | ||||
*/ | */ | ||||
var g_AlwaysDisplayFriendlyFire = false; | var g_AlwaysDisplayFriendlyFire = false; | ||||
function getCostTypes() | |||||
{ | |||||
return g_ResourceData.GetCodes().concat(["population", "populationBonus", "time"]); | |||||
} | |||||
function resourceIcon(resource) | function resourceIcon(resource) | ||||
{ | { | ||||
return '[icon="icon_' + resource + '"]'; | return '[icon="icon_' + resource + '"]'; | ||||
} | } | ||||
function resourceNameFirstWord(type) | function resourceNameFirstWord(type) | ||||
{ | { | ||||
return translateWithContext("firstWord", g_ResourceData.GetNames()[type]); | return translateWithContext("firstWord", g_ResourceData.GetNames()[type]); | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | function getResistanceTooltip(template) | ||||
let details = []; | let details = []; | ||||
if (template.resistance.Damage) | if (template.resistance.Damage) | ||||
details.push(getDamageResistanceTooltip(template.resistance.Damage)); | details.push(getDamageResistanceTooltip(template.resistance.Damage)); | ||||
if (template.resistance.Capture) | if (template.resistance.Capture) | ||||
details.push(getCaptureResistanceTooltip(template.resistance.Capture)); | details.push(getCaptureResistanceTooltip(template.resistance.Capture)); | ||||
// ToDo: Status effects resistance. | // TODO: Status effects resistance. | ||||
return sprintf(translate("%(label)s\n %(details)s"), { | return sprintf(translate("%(label)s\n" + g_Indent + "%(details)s"), { | ||||
"label": headerFont(translate("Resistance:")), | "label": headerFont(translate("Resistance:")), | ||||
"details": details.join("\n ") | "details": details.join("\n" + g_Indent) | ||||
}); | }); | ||||
} | } | ||||
function getDamageResistanceTooltip(resistanceTypeTemplate) | function getDamageResistanceTooltip(resistanceTypeTemplate) | ||||
{ | { | ||||
if (!resistanceTypeTemplate) | if (!resistanceTypeTemplate) | ||||
return ""; | return ""; | ||||
return sprintf(translate("%(label)s %(details)s"), { | return sprintf(translate("%(label)s %(details)s"), { | ||||
"label": headerFont(translate("Damage Resistance:")), | "label": headerFont(translate("Damage:")), | ||||
"details": | "details": | ||||
g_DamageTypesMetadata.sort(Object.keys(resistanceTypeTemplate)).map( | g_DamageTypesMetadata.sort(Object.keys(resistanceTypeTemplate)).map( | ||||
dmgType => sprintf(translate("%(damage)s %(damageType)s %(resistancePercentage)s"), { | dmgType => sprintf(translate("%(damage)s %(damageType)s %(resistancePercentage)s"), { | ||||
"damage": resistanceTypeTemplate[dmgType].toFixed(1), | "damage": resistanceTypeTemplate[dmgType].toFixed(1), | ||||
"damageType": unitFont(translateWithContext("damage type", g_DamageTypesMetadata.getName(dmgType))), | "damageType": unitFont(translateWithContext("damage type", g_DamageTypesMetadata.getName(dmgType))), | ||||
"resistancePercentage": | "resistancePercentage": | ||||
'[font="sans-10"]' + | '[font="sans-10"]' + | ||||
sprintf(translate("(%(resistancePercentage)s)"), { | sprintf(translate("(%(resistancePercentage)s)"), { | ||||
"resistancePercentage": resistanceLevelToPercentageString(resistanceTypeTemplate[dmgType]) | "resistancePercentage": resistanceLevelToPercentageString(resistanceTypeTemplate[dmgType]) | ||||
}) + '[/font]' | }) + '[/font]' | ||||
}) | }) | ||||
).join(commaFont(translate(", "))) | ).join(commaFont(translate(", "))) | ||||
}); | }); | ||||
} | } | ||||
function getCaptureResistanceTooltip(resistanceTypeTemplate) | function getCaptureResistanceTooltip(resistanceTypeTemplate) | ||||
{ | { | ||||
if (!resistanceTypeTemplate) | if (!resistanceTypeTemplate) | ||||
return ""; | return ""; | ||||
return sprintf(translate("%(label)s %(details)s"), { | return sprintf(translate("%(label)s %(details)s"), { | ||||
"label": headerFont(translate("Capture Resistance:")), | "label": headerFont(translate("Capture:")), | ||||
"details": | "details": | ||||
sprintf(translate("%(damage)s %(damageType)s %(resistancePercentage)s"), { | sprintf(translate("%(damage)s %(damageType)s %(resistancePercentage)s"), { | ||||
"damage": resistanceTypeTemplate.toFixed(1), | "damage": resistanceTypeTemplate.toFixed(1), | ||||
"damageType": unitFont(translateWithContext("damage type", "Capture")), | "damageType": unitFont(translateWithContext("damage type", "Capture")), | ||||
"resistancePercentage": | "resistancePercentage": | ||||
'[font="sans-10"]' + | '[font="sans-10"]' + | ||||
sprintf(translate("(%(resistancePercentage)s)"), { | sprintf(translate("(%(resistancePercentage)s)"), { | ||||
"resistancePercentage": resistanceLevelToPercentageString(resistanceTypeTemplate) | "resistancePercentage": resistanceLevelToPercentageString(resistanceTypeTemplate) | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if (!captureTemplate) | ||||
return ""; | return ""; | ||||
return sprintf(translate("%(amount)s %(name)s"), { | return sprintf(translate("%(amount)s %(name)s"), { | ||||
"amount": (+captureTemplate).toFixed(1), | "amount": (+captureTemplate).toFixed(1), | ||||
"name": unitFont(translateWithContext("damage type", "Capture")) | "name": unitFont(translateWithContext("damage type", "Capture")) | ||||
}); | }); | ||||
} | } | ||||
function splashDetails(splashTemplate) | |||||
{ | |||||
let splashLabel = sprintf(headerFont(translate("%(splashShape)s Splash")), { | |||||
"splashShape": splashTemplate.shape | |||||
}); | |||||
let splashDamageTooltip = sprintf(translate("%(label)s: %(effects)s"), { | |||||
"label": splashLabel, | |||||
"effects": attackEffectsDetails(splashTemplate) | |||||
}); | |||||
if (g_AlwaysDisplayFriendlyFire || splashTemplate.friendlyFire) | |||||
splashDamageTooltip += commaFont(translate(", ")) + sprintf(translate("Friendly Fire: %(enabled)s"), { | |||||
"enabled": splashTemplate.friendlyFire ? translate("Yes") : translate("No") | |||||
}); | |||||
return splashDamageTooltip; | |||||
} | |||||
function applyStatusDetails(applyStatusTemplate) | function applyStatusDetails(applyStatusTemplate) | ||||
{ | { | ||||
if (!applyStatusTemplate) | if (!applyStatusTemplate) | ||||
return ""; | return ""; | ||||
return sprintf(translate("gives %(name)s"), { | return sprintf(translate("gives %(name)s"), { | ||||
"name": Object.keys(applyStatusTemplate).map(x => { | "name": Object.keys(applyStatusTemplate).map(x => { | ||||
let template = g_StatusEffectsMetadata.augment(x, applyStatusTemplate[x]); | let template = g_StatusEffectsMetadata.augment(x, applyStatusTemplate[x]); | ||||
Show All 22 Lines | function getAttackTooltip(template) | ||||
let tooltips = []; | let tooltips = []; | ||||
for (let attackType in template.attack) | for (let attackType in template.attack) | ||||
{ | { | ||||
// Slaughter is used to kill animals, so do not show it. | // Slaughter is used to kill animals, so do not show it. | ||||
if (attackType == "Slaughter") | if (attackType == "Slaughter") | ||||
continue; | continue; | ||||
let attackLabel = sprintf(headerFont(translate("%(attackType)s Attack")), { | let attackLabel = sprintf(headerFont(translate("%(attackType)s")), { | ||||
"attackType": attackType | "attackType": attackType | ||||
}); | }); | ||||
let attackTypeTemplate = template.attack[attackType]; | let attackTypeTemplate = template.attack[attackType]; | ||||
let projectiles; | let projectiles; | ||||
// Use either current rate from simulation or default count if the sim is not running. | // Use either current rate from simulation or default count if the sim is not running. | ||||
// ToDo: This ought to be extended to include units which fire multiple projectiles. | // TODO: This ought to be extended to include units which fire multiple projectiles. | ||||
if (template.buildingAI) | if (template.buildingAI) | ||||
projectiles = template.buildingAI.arrowCount || template.buildingAI.defaultArrowCount; | projectiles = template.buildingAI.arrowCount || template.buildingAI.defaultArrowCount; | ||||
// Show the effects of status effects below | let splashTemplate = attackTypeTemplate.splash; | ||||
// Show the effects of status effects below. | |||||
let statusEffectsDetails = []; | let statusEffectsDetails = []; | ||||
if (attackTypeTemplate.ApplyStatus) | if (attackTypeTemplate.ApplyStatus) | ||||
for (let status in attackTypeTemplate.ApplyStatus) | for (let status in attackTypeTemplate.ApplyStatus) | ||||
{ | { | ||||
let status_template = g_StatusEffectsMetadata.augment(status, attackTypeTemplate.ApplyStatus[status]); | let status_template = g_StatusEffectsMetadata.augment(status, attackTypeTemplate.ApplyStatus[status]); | ||||
statusEffectsDetails.push("\n " + getStatusEffectsTooltip(status_template, true)); | statusEffectsDetails.push("\n" + g_Indent + g_Indent + getStatusEffectsTooltip(status_template, true)); | ||||
} | } | ||||
statusEffectsDetails = statusEffectsDetails.join(""); | statusEffectsDetails = statusEffectsDetails.join(""); | ||||
tooltips.push(sprintf(translate("%(attackLabel)s: %(effects)s, %(range)s, %(rate)s%(statusEffects)s"), { | tooltips.push(sprintf(translate("%(attackLabel)s: %(effects)s, %(range)s, %(rate)s%(statusEffects)s%(splash)s"), { | ||||
"attackLabel": attackLabel, | "attackLabel": attackLabel, | ||||
"effects": attackEffectsDetails(attackTypeTemplate), | "effects": attackEffectsDetails(attackTypeTemplate), | ||||
"range": rangeDetails(attackTypeTemplate), | "range": rangeDetails(attackTypeTemplate), | ||||
"rate": attackRateDetails(attackTypeTemplate.repeatTime, projectiles), | "rate": attackRateDetails(attackTypeTemplate.repeatTime, projectiles), | ||||
"splash": splashTemplate ? "\n" + g_Indent + g_Indent + splashDetails(splashTemplate) : "", | |||||
"statusEffects": statusEffectsDetails | "statusEffects": statusEffectsDetails | ||||
})); | })); | ||||
} | } | ||||
return tooltips.join("\n"); | |||||
} | |||||
function getSplashDamageTooltip(template) | |||||
{ | |||||
if (!template.attack) | |||||
return ""; | |||||
let tooltips = []; | |||||
for (let attackType in template.attack) | |||||
{ | |||||
let splashTemplate = template.attack[attackType].splash; | |||||
if (!splashTemplate) | |||||
continue; | |||||
let splashLabel = sprintf(headerFont(translate("%(splashShape)s Splash Damage")), { | |||||
"splashShape": splashTemplate.shape | |||||
}); | |||||
let splashDamageTooltip = sprintf(translate("%(label)s: %(effects)s"), { | |||||
"label": splashLabel, | |||||
"effects": attackEffectsDetails(splashTemplate) | |||||
}); | |||||
if (g_AlwaysDisplayFriendlyFire || splashTemplate.friendlyFire) | return sprintf(translate("%(label)s\n" + g_Indent + "%(details)s"), { | ||||
splashDamageTooltip += commaFont(translate(", ")) + sprintf(translate("Friendly Fire: %(enabled)s"), { | "label": headerFont(translate("Attack:")), | ||||
"enabled": splashTemplate.friendlyFire ? translate("Yes") : translate("No") | "details": tooltips.join("\n" + g_Indent) | ||||
}); | }); | ||||
tooltips.push(splashDamageTooltip); | |||||
} | |||||
// If multiple attack types deal splash damage, the attack type should be shown to differentiate. | |||||
return tooltips.join("\n"); | |||||
} | } | ||||
/** | /** | ||||
* @param applier - if true, return the tooltip for the Applier. If false, Receiver is returned. | * @param applier - if true, return the tooltip for the Applier. If false, Receiver is returned. | ||||
*/ | */ | ||||
function getStatusEffectsTooltip(template, applier) | function getStatusEffectsTooltip(template, applier) | ||||
{ | { | ||||
let tooltipAttributes = []; | let tooltipAttributes = []; | ||||
▲ Show 20 Lines • Show All 578 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator