From 33b331f9fa38d1fe7b696f477f6ce1d787dc2418 Mon Sep 17 00:00:00 2001 From: elexis Date: Sun, 11 Jun 2017 00:17:59 +0000 Subject: [PATCH] Correct resource order in the GUI. Differential Revision: https://code.wildfiregames.com/D23 Reviewed By: s0600204 This was SVN commit r19762. --- binaries/data/mods/public/gui/common/l10n.js | 4 ++-- .../data/mods/public/gui/common/tooltips.js | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/binaries/data/mods/public/gui/common/l10n.js b/binaries/data/mods/public/gui/common/l10n.js index 740db62193..4f22715e54 100644 --- a/binaries/data/mods/public/gui/common/l10n.js +++ b/binaries/data/mods/public/gui/common/l10n.js @@ -8,8 +8,8 @@ function getLocalizedResourceName(resourceName, context) */ function getLocalizedResourceAmounts(resources) { - let amounts = Object.keys(resources) - .filter(type => resources[type] > 0) + let amounts = g_ResourceData.GetCodes() + .filter(type => resources[type]) .map(type => sprintf(translate("%(amount)s %(resourceType)s"), { "amount": resources[type], "resourceType": getLocalizedResourceName(g_ResourceData.GetResource(type).name, "withinSentence") diff --git a/binaries/data/mods/public/gui/common/tooltips.js b/binaries/data/mods/public/gui/common/tooltips.js index 338411cb67..b775c9b09e 100644 --- a/binaries/data/mods/public/gui/common/tooltips.js +++ b/binaries/data/mods/public/gui/common/tooltips.js @@ -37,6 +37,11 @@ var g_RangeTooltipString = { } }; +function getCostTypes() +{ + return g_ResourceData.GetCodes().concat(["population", "populationBonus", "time"]); +} + function resourceIcon(resource) { return '[icon="icon_' + resource + '"]'; @@ -344,8 +349,9 @@ function getBuildRateTooltip(template) function multiplyEntityCosts(template, trainNum) { let totalCosts = {}; - for (let r in template.cost) - totalCosts[r] = Math.floor(template.cost[r] * trainNum); + for (let r of getCostTypes()) + if (template.cost[r]) + totalCosts[r] = Math.floor(template.cost[r] * trainNum); return totalCosts; } @@ -363,7 +369,7 @@ function getEntityCostComponentsTooltipString(template, entity, buildingsCountTo }) : 1)); let costs = []; - for (let type in template.cost) + for (let type of getCostTypes()) // Population bonus is shown in the tooltip if (type != "populationBonus" && totalCosts[type]) costs.push(sprintf(translate("%(component)s %(cost)s"), { @@ -418,7 +424,7 @@ function getResourceTrickleTooltip(template) if (!template.resourceTrickle) return ""; - let resCodes = Object.keys(template.resourceTrickle.rates).filter(res => template.resourceTrickle.rates[res]); + let resCodes = g_ResourceData.GetCodes().filter(res => template.resourceTrickle.rates[res]); if (!resCodes.length) return ""; @@ -446,9 +452,7 @@ function getWallPieceTooltip(wallTypes) { let out = []; let resourceCount = {}; - - // Initialize the acceptable types for '$x to $y $resource' mode. - for (let resource in wallTypes[0].cost) + for (let resource of getCostTypes()) if (wallTypes[0].cost[resource]) resourceCount[resource] = [wallTypes[0].cost[resource]];