diff --git a/binaries/data/mods/public/gui/session/selection_panels.js b/binaries/data/mods/public/gui/session/selection_panels.js index b836dafefe..d58e487f7e 100644 --- a/binaries/data/mods/public/gui/session/selection_panels.js +++ b/binaries/data/mods/public/gui/session/selection_panels.js @@ -192,17 +192,38 @@ g_SelectionPanels.Command = { { return 6; }, - "getItems": function(unitEntState) + "getItems": function(unitEntState, selection) { - var commands = []; - for (var c in g_EntityCommands) + let commands = []; + + for (let c in g_EntityCommands) { var info = g_EntityCommands[c].getInfo(unitEntState); if (!info) continue; + info.name = c; commands.push(info); } + + // if the given unit state has no back-to-work entry, we need to check the other units as well + // otherwise the command back-to-work is not shown + if (!commands["back-to-work"]) + { + for (let id of selection) + { + let uEntState = GetExtendedEntityState(id); + + let info = g_EntityCommands["back-to-work"].getInfo(uEntState); + if (!info) + continue; + + info.name = "back-to-work"; + commands.push(info); + break; + } + } + return commands; }, "setTooltip": function(data) diff --git a/binaries/data/mods/public/gui/session/unit_commands.js b/binaries/data/mods/public/gui/session/unit_commands.js index 397464ddef..a1a5f01306 100644 --- a/binaries/data/mods/public/gui/session/unit_commands.js +++ b/binaries/data/mods/public/gui/session/unit_commands.js @@ -28,18 +28,17 @@ function setPanelObjectPosition(object, index, rowLength, vMargin = 1, hMargin = * (i.e. panels with rows of icons) for the currently selected unit. * * @param guiName Short identifier string of this panel. See g_SelectionPanels. - * @param unitEntState Entity state of the (first) selected unit. + * @param unitEntState Entity state of the selected unit with the lowest id. * @param payerState Player state + * @param selectedEntries All selected units */ -function setupUnitPanel(guiName, unitEntState, playerState) +function setupUnitPanel(guiName, unitEntState, playerState, selection) { if (!g_SelectionPanels[guiName]) { error("unknown guiName used '" + guiName + "'"); return; } - var selection = g_Selection.toList(); - var items = g_SelectionPanels[guiName].getItems(unitEntState, selection); if (!items || !items.length) @@ -146,7 +145,7 @@ function setupUnitPanel(guiName, unitEntState, playerState) * Delegates to setupUnitPanel to set up individual subpanels, * appropriately activated depending on the selected unit's state. * - * @param entState Entity state of the (first) selected unit. + * @param entState Entity state of the selected unit with the lowest id. * @param supplementalDetailsPanel Reference to the * "supplementalSelectionDetails" GUI Object * @param commandsPanel Reference to the "commandsPanel" GUI Object @@ -174,7 +173,7 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s ) continue; - setupUnitPanel(guiName, entState, playerStates[entState.player]); + setupUnitPanel(guiName, entState, playerStates[entState.player], selection); } supplementalDetailsPanel.hidden = false; @@ -184,8 +183,8 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s { // TODO if there's a second panel needed for a different player // we should consider adding the players list to g_SelectionPanels - setupUnitPanel("Garrison", entState, playerState); - setupUnitPanel("AllyCommand", entState, playerState); + setupUnitPanel("Garrison", entState, playerState, selection); + setupUnitPanel("AllyCommand", entState, playerState, selection); supplementalDetailsPanel.hidden = !g_SelectionPanels.Garrison.used;