Changeset View
Standalone View
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" }, | |||||
"nameSpecificSmall": { "font": "sans-bold-12" }, | |||||
"nameGeneric": { "font": "sans-bold-16" } | |||||
}; | }; | ||||
var g_AttackTypes = { | var g_AttackTypes = { | ||||
"Melee": translate("Melee Attack:"), | "Melee": translate("Melee Attack:"), | ||||
"Ranged": translate("Ranged Attack:"), | "Ranged": translate("Ranged Attack:"), | ||||
"Capture": translate("Capture Attack:") | "Capture": translate("Capture Attack:") | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
function getSecondsString(seconds) | function getSecondsString(seconds) | ||||
{ | { | ||||
return sprintf(translatePlural("%(time)s %(second)s", "%(time)s %(second)s", seconds), { | return sprintf(translatePlural("%(time)s %(second)s", "%(time)s %(second)s", seconds), { | ||||
"time": seconds, | "time": seconds, | ||||
"second": unitFont(translatePlural("second", "seconds", seconds)) | "second": unitFont(translatePlural("second", "seconds", seconds)) | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Entity templates have a `Tooltip` tag in the Identity component. | |||||
elexis: `s/XML-based/entity`
+Identity componetn somewhere
(
Well, aura files had been json, then xml… | |||||
* (The contents of which are copied to a `tooltip` attribute in globalscripts.) | |||||
*/ | |||||
function getEntityTooltip(template) | function getEntityTooltip(template) | ||||
{ | { | ||||
if (!template.tooltip) | if (!template.tooltip) | ||||
return ""; | return ""; | ||||
return bodyFont(template.tooltip); | return bodyFont(template.tooltip); | ||||
} | } | ||||
Not Done Inline ActionsRenaming this to getIdentityTooltip would transport the same message with 2 lines less elexis: Renaming this to getIdentityTooltip would transport the same message with 2 lines less | |||||
Not Done Inline Actions
So no, I'm not renaming the function to that. s0600204: 1. Other tooltip functions have names that reflect what they return. `getCurrentHealthTooltip`… | |||||
Not Done Inline ActionsOk to keep the name now as it's not this patch introducing it, but getEntityFoo being used for techs and aruas is misleading. elexis: Ok to keep the name now as it's not this patch introducing it, but `getEntityFoo` being used… | |||||
/** | |||||
Not Done Inline ActionsI have trouble figuring out where that description field comes from. Tech? Aura? If so, put it into the function name. elexis: I have trouble figuring out where that description field comes from. Tech? Aura? If so, put it… | |||||
Not Done Inline ActionsHave added a descriptive comment instead. Currently, this only returns a value other than "" for technologies. This is because xml-based templates lack a "Description" tag, and Auras are only ever shown in the tooltip of the structure or unit that manifests it. However, at some point we might wish to show certain auras directly. For instance, civ/team bonuses (which are not shown anywhere in any gui page at the moment) could be shown directly with their own tooltips in the civinfo page. Also, there is the discussed possibility to add a Description tag to entity templates to provide non-historical context to entities. In both of these cases, this would be the function to get/format the text. So for this reason, renaming this function to imply that it only works for technologies would be incorrect. s0600204: Have added a descriptive comment instead.
Currently, this only returns a value other than `""`… | |||||
* Technologies have a `description` attribute, and Auras have an `auraDescription` | |||||
* attribute, which becomes `description`. | |||||
Done Inline Actionsduring the loading/parsing process. should be replaced with directory or filename informing the reader where to look them up. Why describe that the code does something unintentional rather than making it more clear to read? Better have getAuraDescription and getTechnologyDescription. But if this isn't like all the other tooltip functions in this file, then it shouldn't be in this file. (The other ones can only parse entity templates or entity states). elexis: `during the loading/parsing process.` should be replaced with directory or filename informing… | |||||
* | |||||
* (For technologies, this happens in globalscripts.) | |||||
* | |||||
* (For auras, this happens either in the Auras component (for session gui) or | |||||
* reference/common/load.js (for Reference Suite gui)) | |||||
*/ | |||||
function getDescriptionTooltip(template) | |||||
{ | |||||
if (!template.description) | |||||
return ""; | |||||
return bodyFont(template.description); | |||||
} | |||||
Not Done Inline ActionsAuras, technologies and entity components have different features, so making a function that returns something for more than one type means that the reader of the call to this function has to lookup this function to see what it supports. GetAuraDescription(Tooltip), GetTechnologyDescription and GetIdentityDescription seems better distinguishable and more conform with the rest to me. Works for now though and saves some redundancy as the description property coincidentally has the same name in all 3 cases. But IMO it's an ambiguity which should be rectified. Function comments should be condensed into 1-2 lines if possible. elexis: Auras, technologies and entity components have different features, so making a function that… | |||||
Not Done Inline ActionsIf we were to have GetAuraDescription() and GetTechnologyDescription(), the logic of the two functions would be identical and you'd be asking me to remove the duplication. We also don't have GetTechnologyNames or GetAuraName - they all use GetEntityNames, so why would we need separate functions to return the same attribute from techs, auras and entities just because they come from different sources? The approach used here is consistent with the rest of the file. s0600204: If we were to have `GetAuraDescription()` and `GetTechnologyDescription()`, the logic of the… | |||||
Not Done Inline ActionsThe function introduced here is okay elexis: The function introduced here is okay
I'm just not happy about that mapping auraDescription ->… | |||||
/** | |||||
* Entity templates have a `History` tag in the Identity component. | |||||
* (The contents of which are copied to a `history` attribute in globalscripts.) | |||||
*/ | |||||
function getHistoryTooltip(template) | |||||
{ | |||||
if (!template.history) | |||||
return ""; | |||||
return bodyFont(template.history); | |||||
} | |||||
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 | ||||
▲ Show 20 Lines • Show All 419 Lines • ▼ Show 20 Lines | if (template.wallSet) | ||||
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, entity, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch).join(" "); | { | ||||
let costs = getEntityCostComponentsTooltipString(template, entity, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch).join(" "); | |||||
if (costs) | |||||
// Translation: Label in tooltip showing cost of a unit, structure or technology. | |||||
return sprintf(translate("%(label)s %(costs)s"), { | |||||
"label": headerFont(translate("Cost:")), | |||||
"costs": costs | |||||
}); | |||||
} | |||||
return ""; | return ""; | ||||
} | } | ||||
function getRequiredTechnologyTooltip(technologyEnabled, requiredTechnology, civ) | function getRequiredTechnologyTooltip(technologyEnabled, requiredTechnology, civ) | ||||
{ | { | ||||
if (technologyEnabled) | if (technologyEnabled) | ||||
return ""; | return ""; | ||||
return sprintf(translate("Requires %(technology)s"), { | return sprintf(translate("Requires %(technology)s"), { | ||||
"technology": getEntityNames(GetTechnologyData(requiredTechnology, civ)) | "technology": getEntityNames(GetTechnologyData(requiredTechnology, civ)) | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Returns the population bonus information to display in the specified entity's construction button tooltip. | * Returns the population bonus information to display in the specified entity's construction button tooltip. | ||||
*/ | */ | ||||
function getPopulationBonusTooltip(template) | function getPopulationBonusTooltip(template) | ||||
Done Inline ActionsRequested change: Contrary to the other tooltip functions in this file, this one cannot operate on a simulation entity state or template data from Templates.js, so it is very misleading to camouflage that and name the argument template. This function should either comply with the constraints that the surrounding functions have, or be moved to the reference code which is currently the only place that can use it, or rename template and add a warning that people can't use it like they would expect from the surrounding code. elexis: Requested change:
Contrary to the other tooltip functions in this file, this one cannot… | |||||
Done Inline ActionsRelocated. Consolidating/merging the resource supply tooltip functions (this one, now in reference/common/load.js, and the relevant code in session/selection_details.js), and standardising the different object formats those functions expect, can take place in a follow-up revision. s0600204: Relocated.
Consolidating/merging the resource supply tooltip functions (this one, now in… | |||||
{ | { | ||||
let popBonus = ""; | let popBonus = ""; | ||||
if (template.cost && template.cost.populationBonus) | if (template.cost && template.cost.populationBonus) | ||||
popBonus = sprintf(translate("%(label)s %(populationBonus)s"), { | popBonus = sprintf(translate("%(label)s %(populationBonus)s"), { | ||||
"label": headerFont(translate("Population Bonus:")), | "label": headerFont(translate("Population Bonus:")), | ||||
"populationBonus": template.cost.populationBonus | "populationBonus": template.cost.populationBonus | ||||
Done Inline Actionsunneeded parentheses and strict comparison elexis: unneeded parentheses and strict comparison | |||||
}); | }); | ||||
return popBonus; | return popBonus; | ||||
Done Inline ActionsheaderFont elexis: headerFont | |||||
} | } | ||||
/** | /** | ||||
* Returns a message with the amount of each resource needed to create an entity. | * Returns a message with the amount of each resource needed to create an entity. | ||||
Done Inline ActionsShould likely use translation context or a translation comment explaining the transifex people where that is used and so that they can possibly use something other than the infinity symbol that fits more to their language. elexis: Should likely use translation context or a translation comment explaining the transifex people… | |||||
*/ | */ | ||||
function getNeededResourcesTooltip(resources) | function getNeededResourcesTooltip(resources) | ||||
{ | { | ||||
if (!resources) | if (!resources) | ||||
return ""; | return ""; | ||||
let formatted = []; | let formatted = []; | ||||
for (let resource in resources) | for (let resource in resources) | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | return sprintf(translate("%(specificName)s (%(genericName)s)"), { | ||||
"specificName": template.name.specific, | "specificName": template.name.specific, | ||||
"genericName": template.name.generic | "genericName": template.name.generic | ||||
}); | }); | ||||
} | } | ||||
function getEntityNamesFormatted(template) | function getEntityNamesFormatted(template) | ||||
{ | { | ||||
if (!template.name.specific) | if (!template.name.specific) | ||||
return '[font="sans-bold-16"]' + template.name.generic + "[/font]"; | return setStringTags(template.name.generic, g_TooltipTextFormats.nameSpecificBig); | ||||
// Translation: Example: "Epibátēs Athēnaîos [font="sans-bold-16"](Athenian Marine)[/font]" | // Translation: Example: "Epibátēs Athēnaîos [font="sans-bold-16"](Athenian Marine)[/font]" | ||||
return sprintf(translate("%(specificName)s %(fontStart)s(%(genericName)s)%(fontEnd)s"), { | return sprintf(translate("%(specificName)s %(fontStart)s(%(genericName)s)%(fontEnd)s"), { | ||||
"specificName": | "specificName": | ||||
'[font="sans-bold-16"]' + template.name.specific[0] + '[/font]' + | setStringTags(template.name.specific[0], g_TooltipTextFormats.nameSpecificBig) + | ||||
'[font="sans-bold-12"]' + template.name.specific.slice(1).toUpperCase() + '[/font]', | setStringTags(template.name.specific.slice(1).toUpperCase(), g_TooltipTextFormats.nameSpecificSmall), | ||||
"genericName": template.name.generic, | "genericName": template.name.generic, | ||||
"fontStart": '[font="sans-bold-16"]', | "fontStart": '[font="' + g_TooltipTextFormats.nameGeneric.font + '"]', | ||||
"fontEnd": '[/font]' | "fontEnd": '[/font]' | ||||
elexisUnsubmitted Not Done Inline ActionsI must have eaten something wrong when committing rP18454, fontStart and fontEnd shouldn't be part of the string. To be fixed elsewhere. (I don't think it was a precedent) elexis: I must have eaten something wrong when committing rP18454, fontStart and fontEnd shouldn't be… | |||||
}); | }); | ||||
} | } | ||||
function getVisibleEntityClassesFormatted(template) | function getVisibleEntityClassesFormatted(template) | ||||
{ | { | ||||
if (!template.visibleIdentityClasses || !template.visibleIdentityClasses.length) | if (!template.visibleIdentityClasses || !template.visibleIdentityClasses.length) | ||||
return ""; | return ""; | ||||
Show All 33 Lines | function getLootTooltip(template) | ||||
if (!lootLabels.length) | if (!lootLabels.length) | ||||
return ""; | 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(" ") | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
Done Inline ActionsShould end with Tooltip instead of message, as that's the norm of this file. templateViewerTooltip? elexis: Should end with Tooltip instead of message, as that's the norm of this file. | |||||
* @param {boolean} rightClickOnly | |||||
*/ | |||||
elexisUnsubmitted Done Inline ActionsDon't see the benefit in the comment elexis: Don't see the benefit in the comment | |||||
function templateViewerOnClickMessage(rightClickOnly) | |||||
{ | |||||
if (rightClickOnly) | |||||
// Translation: Appears in a tooltip to indicate that right-clicking the corresponding GUI element will open the Template Details GUI page. | |||||
return translate("Right-click to view more information."); | |||||
// Translation: Appears in a tooltip to indicate that clicking the corresponding GUI element will open the Template Details GUI page. | |||||
return translate("Click to view more information."); | |||||
} |
s/XML-based/entity
+Identity componetn somewhere
(
Well, aura files had been json, then xml again, then json again. Who knows what's next? :P
"entity templates" is the correct phrasing according to ComponentManager.cpp.
The Tooltip is a property of the Identity component afaics, so perhaps its more valuable to mention that, so that people that want to only change the style in this file know what they actually change.
(According to the "XML-based" comment, the function is not used for auras and technologies. The function name already seems to reflect that, so no need to rename)
)