Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/tooltips.js
Show First 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | |||||
function getProjectilesTooltip(template) | function getProjectilesTooltip(template) | ||||
{ | { | ||||
if (!template.garrisonHolder || !template.buildingAI) | if (!template.garrisonHolder || !template.buildingAI) | ||||
return ""; | return ""; | ||||
let limit = Math.min( | let limit = Math.min( | ||||
template.buildingAI.maxArrowCount || Infinity, | template.buildingAI.maxArrowCount || Infinity, | ||||
template.buildingAI.defaultArrowCount + | template.buildingAI.defaultArrowCount + | ||||
template.buildingAI.garrisonArrowMultiplier * | Math.round(template.buildingAI.garrisonArrowMultiplier * | ||||
template.garrisonHolder.capacity | template.garrisonHolder.capacity) | ||||
); | ); | ||||
if (!limit) | if (!limit) | ||||
return ""; | return ""; | ||||
return [ | return [ | ||||
sprintf(translate("%(label)s: %(value)s"), { | sprintf(translate("%(label)s: %(value)s"), { | ||||
"label": headerFont(translate("Projectile Limit")), | "label": headerFont(translate("Projectile Limit")), | ||||
"value": limit | "value": limit | ||||
}), | }), | ||||
sprintf(translate("%(label)s: %(value)s"), { | sprintf(translate("%(label)s: %(value)s"), { | ||||
"label": headerFont(translateWithContext("projectiles", "Default")), | "label": headerFont(translateWithContext("projectiles", "Default")), | ||||
"value": template.buildingAI.defaultArrowCount | "value": template.buildingAI.defaultArrowCount | ||||
}), | }), | ||||
sprintf(translate("%(label)s: %(value)s"), { | sprintf(translate("%(label)s: %(value)s"), { | ||||
"label": headerFont(translateWithContext("projectiles", "Per Unit")), | "label": headerFont(translateWithContext("projectiles", "Per Unit")), | ||||
"value": template.buildingAI.garrisonArrowMultiplier | "value": +template.buildingAI.garrisonArrowMultiplier.toFixed(2) | ||||
}) | }) | ||||
].join(commaFont(translate(", "))); | ].join(commaFont(translate(", "))); | ||||
} | } | ||||
function getRepairRateTooltip(template) | function getRepairRateTooltip(template) | ||||
{ | { | ||||
if (!template.repairRate) | if (!template.repairRate) | ||||
return ""; | return ""; | ||||
Show All 31 Lines | for (let r in template.cost) | ||||
totalCosts[r] = Math.floor(template.cost[r] * trainNum); | totalCosts[r] = Math.floor(template.cost[r] * trainNum); | ||||
return totalCosts; | return totalCosts; | ||||
} | } | ||||
/** | /** | ||||
* Helper function for getEntityCostTooltip. | * Helper function for getEntityCostTooltip. | ||||
*/ | */ | ||||
function getEntityCostComponentsTooltipString(template, trainNum, entity) | function getEntityCostComponentsTooltipString(template, entity, buildingsCountToTrainFullBatch = 1, fullBatchSize = 1, remainderBatch = 0) | ||||
{ | { | ||||
if (!trainNum) | let totalCosts = multiplyEntityCosts(template, buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch); | ||||
trainNum = 1; | |||||
let totalCosts = multiplyEntityCosts(template, trainNum); | |||||
if (template.cost.time) | if (template.cost.time) | ||||
totalCosts.time = Math.ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1)); | totalCosts.time = Math.ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { | ||||
"entity": entity, | |||||
"batchSize": buildingsCountToTrainFullBatch > 0 ? fullBatchSize : remainderBatch | |||||
}) : 1)); | |||||
let costs = []; | let costs = []; | ||||
for (let type in template.cost) | for (let type in template.cost) | ||||
// Population bonus is shown in the tooltip | // Population bonus is shown in the tooltip | ||||
if (type != "populationBonus" && totalCosts[type]) | if (type != "populationBonus" && totalCosts[type]) | ||||
costs.push(sprintf(translate("%(component)s %(cost)s"), { | costs.push(sprintf(translate("%(component)s %(cost)s"), { | ||||
"component": resourceIcon(type), | "component": resourceIcon(type), | ||||
"cost": totalCosts[type] | "cost": totalCosts[type] | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | for (let i = 0; i < wallTypes.length; ++i) | ||||
out.push(getEntityCostComponentsTooltipString(wallTypes[i]).join(", ")); | out.push(getEntityCostComponentsTooltipString(wallTypes[i]).join(", ")); | ||||
return out; | return out; | ||||
} | } | ||||
/** | /** | ||||
* Returns the cost information to display in the specified entity's construction button tooltip. | * Returns the cost information to display in the specified entity's construction button tooltip. | ||||
*/ | */ | ||||
function getEntityCostTooltip(template, trainNum, entity) | function getEntityCostTooltip(template, entity, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch) | ||||
{ | { | ||||
// Entities with a wallset component are proxies for initiating wall placement and as such do not have a cost of | // Entities with a wallset component are proxies for initiating wall placement and as such do not have a cost of | ||||
// their own; the individual wall pieces within it do. | // their own; the individual wall pieces within it do. | ||||
if (template.wallSet) | if (template.wallSet) | ||||
{ | { | ||||
let templateLong = GetTemplateData(template.wallSet.templates.long); | let templateLong = GetTemplateData(template.wallSet.templates.long); | ||||
let templateMedium = GetTemplateData(template.wallSet.templates.medium); | let templateMedium = GetTemplateData(template.wallSet.templates.medium); | ||||
let templateShort = GetTemplateData(template.wallSet.templates.short); | let templateShort = GetTemplateData(template.wallSet.templates.short); | ||||
let templateTower = GetTemplateData(template.wallSet.templates.tower); | let templateTower = GetTemplateData(template.wallSet.templates.tower); | ||||
let wallCosts = getWallPieceTooltip([templateShort, templateMedium, templateLong]); | let wallCosts = getWallPieceTooltip([templateShort, templateMedium, templateLong]); | ||||
let towerCosts = getEntityCostComponentsTooltipString(templateTower); | let towerCosts = getEntityCostComponentsTooltipString(templateTower); | ||||
return sprintf(translate("Walls: %(costs)s"), { "costs": wallCosts.join(" ") }) + "\n" + | return sprintf(translate("Walls: %(costs)s"), { "costs": wallCosts.join(" ") }) + "\n" + | ||||
sprintf(translate("Towers: %(costs)s"), { "costs": towerCosts.join(" ") }); | sprintf(translate("Towers: %(costs)s"), { "costs": towerCosts.join(" ") }); | ||||
} | } | ||||
if (template.cost) | if (template.cost) | ||||
return getEntityCostComponentsTooltipString(template, trainNum, entity).join(" "); | return getEntityCostComponentsTooltipString(template, entity, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch).join(" "); | ||||
return ""; | return ""; | ||||
} | } | ||||
function getRequiredTechnologyTooltip(technologyEnabled, requiredTechnology, civ) | function getRequiredTechnologyTooltip(technologyEnabled, requiredTechnology, civ) | ||||
{ | { | ||||
if (technologyEnabled) | if (technologyEnabled) | ||||
return ""; | return ""; | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | function getHealerTooltip(template) | ||||
].join(translate(", ")); | ].join(translate(", ")); | ||||
} | } | ||||
function getAurasTooltip(template) | function getAurasTooltip(template) | ||||
{ | { | ||||
if (!template.auras) | if (!template.auras) | ||||
return ""; | return ""; | ||||
let tooltips = Object.keys(template.auras).map( | let tooltips = []; | ||||
aura => sprintf(translate("%(auralabel)s %(aurainfo)s"), { | for (let auraID in template.auras) | ||||
{ | |||||
let tooltip = sprintf(translate("%(auralabel)s %(aurainfo)s"), { | |||||
"auralabel": headerFont(sprintf(translate("%(auraname)s:"), { | "auralabel": headerFont(sprintf(translate("%(auraname)s:"), { | ||||
"auraname": translate(template.auras[aura].name) | "auraname": translate(template.auras[auraID].name) | ||||
})), | })), | ||||
"aurainfo": bodyFont(translate(template.auras[aura].description)) | "aurainfo": bodyFont(translate(template.auras[auraID].description)) | ||||
})); | }); | ||||
let radius = +template.auras[auraID].radius; | |||||
if (radius) | |||||
tooltip += " " + sprintf(translatePlural("%(label)s %(val)s %(unit)s", "%(label)s %(val)s %(unit)s", radius), { | |||||
"label": translateWithContext("aura", "Range:"), | |||||
"val": radius, | |||||
"unit": unitFont(translatePlural("meter", "meters", radius)) | |||||
}); | |||||
tooltips.push(tooltip); | |||||
} | |||||
return tooltips.join("\n"); | return tooltips.join("\n"); | ||||
} | } | ||||
function getEntityNames(template) | function getEntityNames(template) | ||||
{ | { | ||||
if (!template.name.specific) | if (!template.name.specific) | ||||
return template.name.generic; | return template.name.generic; | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator