Show the portrait of the most common (or most costly) unit type in the selection group buttons on the left hand side. Patch by Imarok, fixes #2163.

This was SVN commit r18728.
This commit is contained in:
elexis 2016-09-16 10:47:00 +00:00
parent 72a26857e9
commit eb09c2a8c5

View file

@ -880,6 +880,13 @@ function updateGroups()
{
g_Groups.update();
// Determine the sum of the costs of a given template
let getCostSum = (template) =>
{
let cost = GetTemplateData(template).cost;
return Object.keys(cost).map(key => cost[key]).reduce((sum, cur) => sum + cur);
};
for (let i in Engine.GetGUIObjectByName("unitGroupPanel").children)
{
Engine.GetGUIObjectByName("unitGroupLabel[" + i + "]").caption = i;
@ -889,6 +896,20 @@ function updateGroups()
button.onpress = (function(i) { return function() { performGroup((Engine.HotkeyIsPressed("selection.add") ? "add" : "select"), i); }; })(i);
button.ondoublepress = (function(i) { return function() { performGroup("snap", i); }; })(i);
button.onpressright = (function(i) { return function() { performGroup("breakUp", i); }; })(i);
// Chose icon of the most common template (or the most costly if it's not unique)
if (g_Groups.groups[i].getTotalCount() > 0)
{
let icon = GetTemplateData(g_Groups.groups[i].getEntsGrouped().reduce((pre, cur) => {
if (pre.ents.length == cur.ents.length)
return getCostSum(pre.template) > getCostSum(cur.template) ? pre : cur;
return pre.ents.length > cur.ents.length ? pre : cur;
}).template).icon;
Engine.GetGUIObjectByName("unitGroupIcon[" + i + "]").sprite =
icon ? ("stretched:session/portraits/" + icon) : "groupsIcon";
}
setPanelObjectPosition(button, i, 1);
}
}