diff --git a/binaries/data/mods/public/gui/session_new/input.js b/binaries/data/mods/public/gui/session_new/input.js index 5a6732d95c..84dc1e585a 100644 --- a/binaries/data/mods/public/gui/session_new/input.js +++ b/binaries/data/mods/public/gui/session_new/input.js @@ -249,25 +249,8 @@ function handleInputBeforeGui(ev) g_Selection.reset(); g_Selection.addList(ents); - // Make selection groups - var j = 0; - for (var i = 0; i < ents.length; i++) - { - var template = Engine.GuiInterfaceCall("GetEntityState", ents[i]).template; - - if (!g_Selection.groups.groupTypeCount[template]) - { - g_Selection.groups.groupTypeCount[template] = 1; - g_Selection.groups.firstOfType[template] = i; - g_Selection.groups.groupTemplates.push(template); - g_Selection.groups.groupNumbers[template] = j; - j++; - } - else if (g_Selection.groups.groupTypeCount[template]) - { - g_Selection.groups.groupTypeCount[template] += 1; - } - } + // Create the selection groups + g_Selection.createSelectionGroups(ents); // turn on unit highlight for first unit in selection getGUIObjectByName("unitSelectionHighlight[0]").hidden = false; diff --git a/binaries/data/mods/public/gui/session_new/selection.js b/binaries/data/mods/public/gui/session_new/selection.js index 7fa785185e..f84e8eebb2 100644 --- a/binaries/data/mods/public/gui/session_new/selection.js +++ b/binaries/data/mods/public/gui/session_new/selection.js @@ -22,8 +22,8 @@ function EntityGroups() this.primary = 0; this.groupNumbers = {}; this.firstOfType = {}; // array for holding index to first appearance of a specific unit type in g_Selection - this.groupTypeCount = {}; // format { name:count, name:count, ... } - maps units to the currently selected quantity of that type - this.groupTemplates = []; + this.typeCount = {}; // format { name:count, name:count, ... } - maps units to the currently selected quantity of that type + this.templates = []; } EntityGroups.prototype.reset = function() @@ -32,8 +32,8 @@ EntityGroups.prototype.reset = function() this.primary = 0; this.groupNumbers = {}; this.firstOfType = {}; - this.groupTypeCount = {}; - this.groupTemplates = []; + this.typeCount = {}; + this.templates = []; }; //-------------------------------- -------------------------------- -------------------------------- @@ -76,6 +76,60 @@ EntitySelection.prototype.resetPrimary = function() this.primary = 0; // the primary selection must be reset whenever the selection changes }; +// Make the selection groups for the selection display buttons +EntitySelection.prototype.createSelectionGroups = function(ents) +{ + // Erase old selection first + this.groups.reset(); + + // Make selection groups + var j = 0; + for (var i = 0; i < ents.length; i++) + { + var template = Engine.GuiInterfaceCall("GetEntityState", ents[i]).template; + + if (!this.groups.typeCount[template]) + { + this.groups.typeCount[template] = 1; + this.groups.firstOfType[template] = i; + this.groups.templates.push(template); + this.groups.groupNumbers[template] = j; + j++; + } + else if (this.groups.typeCount[template]) + { + this.groups.typeCount[template] += 1; + } + } +}; + +// Update the selection to take care of changes (like units that have been killed) +EntitySelection.prototype.updateSelection = function() +{ + var numberRemoved = 0; + var i = 0; + + for each (var unit in this.selected) + { + var entState = Engine.GuiInterfaceCall("GetEntityState", unit); + + if (!entState) + { + delete this.selected[unit]; + numberRemoved++; + } + + i++; + } + + if (numberRemoved > 0) + { + this.dirty = true; + this.createSelectionGroups(g_Selection.toList()); + getGUIObjectByName("unitSelectionHighlight[0]").hidden = false; + } +}; + EntitySelection.prototype.toggle = function(ent) { if (this.selected[ent]) diff --git a/binaries/data/mods/public/gui/session_new/selection_details.js b/binaries/data/mods/public/gui/session_new/selection_details.js index 55caa56acf..4aa4d994af 100644 --- a/binaries/data/mods/public/gui/session_new/selection_details.js +++ b/binaries/data/mods/public/gui/session_new/selection_details.js @@ -153,11 +153,7 @@ function updateSelectionDetails(simState) also need to handle multi-unit selections) */ var entState = Engine.GuiInterfaceCall("GetEntityState", selection[g_Selection.getPrimary()]); if (!entState) - { - detailsPanel.hidden = true; - commandsPanel.hidden = true; return; - } var playerState = simState.players[entState.player]; if (!playerState) diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js index f85e5fcb2b..37b48e16af 100644 --- a/binaries/data/mods/public/gui/session_new/session.js +++ b/binaries/data/mods/public/gui/session_new/session.js @@ -111,6 +111,7 @@ function onSimulationUpdate() updateDebug(simState); updatePlayerDisplay(simState); + updateSelection(); updateSelectionDetails(simState); } @@ -158,6 +159,11 @@ function updatePlayerDisplay(simState) getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; } +function updateSelection() +{ + g_Selection.updateSelection(); +} + //-------------------------------- -------------------------------- -------------------------------- // Utility functions //-------------------------------- -------------------------------- -------------------------------- diff --git a/binaries/data/mods/public/gui/session_new/unit_commands.js b/binaries/data/mods/public/gui/session_new/unit_commands.js index 4ad5a5fc23..d92b27e7ff 100644 --- a/binaries/data/mods/public/gui/session_new/unit_commands.js +++ b/binaries/data/mods/public/gui/session_new/unit_commands.js @@ -59,9 +59,9 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c if (guiName == "Selection") { getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = - (g_Selection.groups.groupTypeCount[item] > 1 ? g_Selection.groups.groupTypeCount[item] : ""); + (g_Selection.groups.typeCount[item] > 1 ? g_Selection.groups.typeCount[item] : ""); - tooltip += (g_Selection.groups.groupTypeCount[item] > 1 ? " (" + g_Selection.groups.groupTypeCount[item] + ")" : "") + tooltip += (g_Selection.groups.typeCount[item] > 1 ? " (" + g_Selection.groups.typeCount[item] + ")" : "") } else if (guiName == "Queue") { @@ -173,7 +173,7 @@ function updateUnitCommands(playerState, entState, commandsPanel, selection) function (item) { removeFromTrainingQueue(entState.id, item.id); } ); if (selection.length > 1) - setupUnitPanel("Selection", usedPanels, playerState, entState, g_Selection.groups.groupTemplates, + setupUnitPanel("Selection", usedPanels, playerState, entState, g_Selection.groups.templates, function (entType) { changePrimarySelectionGroup(entType); } ); // Stamina