Ticket #3745: backtowork.2.patch

File backtowork.2.patch, 3.4 KB (added by svott, 8 years ago)
  • binaries/data/mods/public/gui/session/selection_panels.js

     
    192192    {
    193193        return 6;
    194194    },
    195     "getItems": function(unitEntState)
     195    "getItems": function(unitEntState, selection)
    196196    {
    197         var commands = [];
    198         for (var c in g_EntityCommands)
     197        let commands = [];
     198
     199        for (let c in g_EntityCommands)
    199200        {
    200201            var info = g_EntityCommands[c].getInfo(unitEntState);
    201202            if (!info)
    202203                continue;
     204
    203205            info.name = c;
    204206            commands.push(info);
    205207        }
     208
     209        // if the given unit state has no back-to-work entry, we need to check the other units as well
     210        // otherwise the command back-to-work is not shown
     211        if (!commands["back-to-work"]) {
     212            for (let id of selection) {
     213                let uEntState = GetExtendedEntityState(id);
     214               
     215                let info = g_EntityCommands["back-to-work"].getInfo(uEntState);
     216                if (!info)
     217                    continue;
     218                   
     219                info.name = "back-to-work";
     220                commands.push(info);
     221                break;
     222            }
     223        }
     224
    206225        return commands;
    207226    },
    208227    "setTooltip": function(data)
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    2828 * (i.e. panels with rows of icons) for the currently selected unit.
    2929 *
    3030 * @param guiName Short identifier string of this panel. See g_SelectionPanels.
    31  * @param unitEntState Entity state of the (first) selected unit.
     31 * @param unitEntState Entity state of the selected unit with the lowest id.
    3232 * @param payerState Player state
     33 * @param selectedEntries All selected units
    3334 */
    34 function setupUnitPanel(guiName, unitEntState, playerState)
     35function setupUnitPanel(guiName, unitEntState, playerState, selection)
    3536{
    3637    if (!g_SelectionPanels[guiName])
    3738    {
     
    3839        error("unknown guiName used '" + guiName + "'");
    3940        return;
    4041    }
    41     var selection = g_Selection.toList();
    42 
    4342    var items = g_SelectionPanels[guiName].getItems(unitEntState, selection);
    4443
    4544    if (!items || !items.length)
     
    146145 * Delegates to setupUnitPanel to set up individual subpanels,
    147146 * appropriately activated depending on the selected unit's state.
    148147 *
    149  * @param entState Entity state of the (first) selected unit.
     148 * @param entState Entity state of the selected unit with the lowest id
    150149 * @param supplementalDetailsPanel Reference to the
    151150 *        "supplementalSelectionDetails" GUI Object
    152151 * @param commandsPanel Reference to the "commandsPanel" GUI Object
     
    175174            )
    176175                continue;
    177176
    178             setupUnitPanel(guiName, entState, simState.players[entState.player]);
     177            setupUnitPanel(guiName, entState, simState.players[entState.player], selection);
    179178        }
    180179
    181180        supplementalDetailsPanel.hidden = false;
     
    185184    {
    186185        // TODO if there's a second panel needed for a different player
    187186        // we should consider adding the players list to g_SelectionPanels
    188         setupUnitPanel("Garrison", entState, playerState);
    189         setupUnitPanel("AllyCommand", entState, playerState);
     187        setupUnitPanel("Garrison", entState, playerState, selection);
     188        setupUnitPanel("AllyCommand", entState, playerState, selection);
    190189
    191190        supplementalDetailsPanel.hidden = !g_SelectionPanels.Garrison.used;
    192191