mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
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:
parent
72a26857e9
commit
eb09c2a8c5
1 changed files with 21 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue