Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/session.js
Show First 20 Lines • Show All 932 Lines • ▼ Show 20 Lines | function displayHeroes() | ||||
} | } | ||||
} | } | ||||
function updateGroups() | function updateGroups() | ||||
{ | { | ||||
g_Groups.update(); | g_Groups.update(); | ||||
// Determine the sum of the costs of a given template | // Determine the sum of the costs of a given template | ||||
let getCostSum = (template) => | let getCostSum = (ent) => | ||||
{ | { | ||||
let cost = GetTemplateData(template).cost; | let cost = GetTemplateData(GetEntityState(ent).template).cost; | ||||
return cost ? Object.keys(cost).map(key => cost[key]).reduce((sum, cur) => sum + cur) : 0; | return cost ? Object.keys(cost).map(key => cost[key]).reduce((sum, cur) => sum + cur) : 0; | ||||
}; | }; | ||||
for (let i in Engine.GetGUIObjectByName("unitGroupPanel").children) | for (let i in Engine.GetGUIObjectByName("unitGroupPanel").children) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("unitGroupLabel[" + i + "]").caption = i; | Engine.GetGUIObjectByName("unitGroupLabel[" + i + "]").caption = i; | ||||
let button = Engine.GetGUIObjectByName("unitGroupButton["+i+"]"); | let button = Engine.GetGUIObjectByName("unitGroupButton["+i+"]"); | ||||
button.hidden = g_Groups.groups[i].getTotalCount() == 0; | button.hidden = g_Groups.groups[i].getTotalCount() == 0; | ||||
button.onpress = (function(i) { return function() { performGroup((Engine.HotkeyIsPressed("selection.add") ? "add" : "select"), i); }; })(i); | 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.ondoublepress = (function(i) { return function() { performGroup("snap", i); }; })(i); | ||||
button.onpressright = (function(i) { return function() { performGroup("breakUp", 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) | // Chose icon of the most common template (or the most costly if it's not unique) | ||||
if (g_Groups.groups[i].getTotalCount() > 0) | if (g_Groups.groups[i].getTotalCount() > 0) | ||||
{ | { | ||||
let icon = GetTemplateData(g_Groups.groups[i].getEntsGrouped().reduce((pre, cur) => { | let icon = GetTemplateData(GetEntityState(g_Groups.groups[i].getEntsGrouped().reduce((pre, cur) => { | ||||
if (pre.ents.length == cur.ents.length) | if (pre.ents.length == cur.ents.length) | ||||
return getCostSum(pre.template) > getCostSum(cur.template) ? pre : cur; | return getCostSum(pre.ents[0]) > getCostSum(cur.ents[0]) ? pre : cur; | ||||
return pre.ents.length > cur.ents.length ? pre : cur; | return pre.ents.length > cur.ents.length ? pre : cur; | ||||
}).template).icon; | }).ents[0]).template).icon; | ||||
Engine.GetGUIObjectByName("unitGroupIcon[" + i + "]").sprite = | Engine.GetGUIObjectByName("unitGroupIcon[" + i + "]").sprite = | ||||
icon ? ("stretched:session/portraits/" + icon) : "groupsIcon"; | icon ? ("stretched:session/portraits/" + icon) : "groupsIcon"; | ||||
} | } | ||||
setPanelObjectPosition(button, i, 1); | setPanelObjectPosition(button, i, 1); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 445 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator