Display the carried resources when selecting a group of units. Patch by Imarok, fixes #3113.

Shows the information for all selected units and for all units of a
given type.
Rename g_CostDisplayNames to g_CostDisplayIcons.

This was SVN commit r18154.
This commit is contained in:
elexis 2016-05-11 00:07:38 +00:00
parent 2a830fdb6a
commit f5dccae966
5 changed files with 28 additions and 28 deletions

View File

@ -1,4 +1,4 @@
const g_CostDisplayNames = {
const g_CostDisplayIcons = {
"food": '[icon="iconFood"]',
"wood": '[icon="iconWood"]',
"stone": '[icon="iconStone"]',
@ -258,10 +258,10 @@ function getBuildRateTooltip(rate)
* Translates a cost component identifier as they are used internally
* (e.g. "population", "food", etc.) to proper display names.
*/
function getCostComponentDisplayName(costComponentName)
function getCostComponentDisplayIcon(costComponentName)
{
if (costComponentName in g_CostDisplayNames)
return g_CostDisplayNames[costComponentName];
if (costComponentName in g_CostDisplayIcons)
return g_CostDisplayIcons[costComponentName];
warn(sprintf("The specified cost component, ‘%(component)s’, is not currently supported.", { "component": costComponentName }));
return "";
@ -292,10 +292,10 @@ function getEntityCostComponentsTooltipString(template, trainNum, entity)
let costs = [];
for (let type in g_CostDisplayNames)
for (let type in g_CostDisplayIcons)
if (totalCosts[type])
costs.push(sprintf(translate("%(component)s %(cost)s"), {
"component": getCostComponentDisplayName(type),
"component": getCostComponentDisplayIcon(type),
"cost": totalCosts[type]
}));
@ -353,7 +353,7 @@ function getWallPieceTooltip(wallTypes)
// Translation: This string is part of the resources cost string on
// the tooltip for wall structures.
out.push(sprintf(translate("%(resourceIcon)s %(minimum)s to %(resourceIcon)s %(maximum)s"), {
"resourceIcon": getCostComponentDisplayName(resource),
"resourceIcon": getCostComponentDisplayIcon(resource),
"minimum": resourceMin,
"maximum": resourceMax
}));
@ -415,7 +415,7 @@ function getNeededResourcesTooltip(resources)
let formatted = [];
for (let resource in resources)
formatted.push(sprintf(translate("%(component)s %(cost)s"), {
"component": '[font="sans-12"]' + getCostComponentDisplayName(resource) + '[/font]',
"component": '[font="sans-12"]' + getCostComponentDisplayIcon(resource) + '[/font]',
"cost": resources[resource]
}));

View File

@ -338,6 +338,7 @@ function displayMultiple(selection)
let maxCapturePoints = 0;
let capturePoints = (new Array(g_MaxPlayers + 1)).fill(0);
let playerID = 0;
let totalResourcesCarried = {};
for (let i = 0; i < selection.length; ++i)
{
@ -355,6 +356,12 @@ function displayMultiple(selection)
maxCapturePoints += entState.maxCapturePoints;
capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]);
}
if (entState.resourceCarrying && entState.resourceCarrying.length)
{
let carrying = entState.resourceCarrying[0];
totalResourcesCarried[carrying.type] = (totalResourcesCarried[carrying.type] || 0) + carrying.amount;
}
}
Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0;
@ -404,7 +411,11 @@ function displayMultiple(selection)
});
}
Engine.GetGUIObjectByName("numberOfUnits").caption = selection.length;
let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits");
numberOfUnits.caption = selection.length;
numberOfUnits.tooltip = Object.keys(totalResourcesCarried).map(res =>
getCostComponentDisplayIcon(res) + totalResourcesCarried[res]
).join(" ");
// Unhide Details Area
Engine.GetGUIObjectByName("detailsAreaMultiple").hidden = false;

View File

@ -737,7 +737,7 @@ g_SelectionPanels.Queue = {
{
tooltip += "\n[color=\"red\"]" + translate("Insufficient population capacity:") + "\n[/color]";
tooltip += sprintf(translate("%(population)s %(neededSlots)s"), {
"population": getCostComponentDisplayName("population"),
"population": getCostComponentDisplayIcon("population"),
"neededSlots": data.item.neededSlots
});
}
@ -977,23 +977,12 @@ g_SelectionPanels.Selection = {
},
"setTooltip": function(data)
{
let tooltip = data.name;
if (data.carried)
{
var str = data.name + "\n";
var ress = ["food", "wood", "stone", "metal"];
for (var i = 0; i < 4; ++i)
{
if (data.carried[ress[i]])
{
str += getCostComponentDisplayName(ress[i]) + data.carried[ress[i]];
if (i !== 3)
str += " ";
}
}
data.button.tooltip = str;
}
else
data.button.tooltip = data.name;
tooltip += "\n" + Object.keys(data.carried).map(res =>
getCostComponentDisplayIcon(res) + data.carried[res]
).join(" ");
data.button.tooltip = tooltip;
},
"setCountDisplay": function(data)
{

View File

@ -19,7 +19,7 @@
<!-- Total -->
<object size="100%-42 12 100%-8 46" type="image" sprite="groupsIcon">
<object size="0 0 100% 100%" type="text" style="largeCenteredOutlinedText" name="numberOfUnits"/>
<object size="0 0 100% 100%" type="text" style="largeCenteredOutlinedText" name="numberOfUnits" tooltip_style="sessionToolTipBold"/>
</object>
<!-- Stats Bars -->

View File

@ -366,7 +366,7 @@ function assembleTooltip(template)
let rates = [];
for (let type in template.gather)
rates.push(sprintf(translate("%(resourceIcon)s %(rate)s"), {
"resourceIcon": getCostComponentDisplayName(type),
"resourceIcon": getCostComponentDisplayIcon(type),
"rate": template.gather[type]
}));