Ticket #619: gate-multiselect.patch

File gate-multiselect.patch, 5.5 KB (added by Deiz, 12 years ago)
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    209209            break;
    210210
    211211        case GATE:
    212             if(numberOfItems > 2)
    213                 numberOfItems = 2;
     212            if(numberOfItems > 8)
     213                numberOfItems = 8;
    214214            break;
    215215
    216216        default:
     
    513513            // If already a gate, show locking actions
    514514            if (unitEntState.gate)
    515515            {
    516                 gateIcon = "lock_" + GATE_ACTIONS[i].toLowerCase() + "ed.png";
     516                gateIcon = "icons/lock_" + GATE_ACTIONS[i].toLowerCase() + "ed.png";
    517517                selection.hidden = unitEntState.gate.locked != item.locked;
    518518            }
    519519            // otherwise show gate upgrade icon
    520520            else
    521521            {
    522                 gateIcon = "gate_closed.png";
     522                template = GetTemplateData(item.template);
     523                gateIcon = template.icon ?  "portraits/" + template.icon : "icons/gate_closed.png";
    523524                selection.hidden = true;
    524525            }
    525526
    526             icon.sprite = "stretched:session/icons/" + gateIcon;
     527            icon.sprite = "stretched:session/" + gateIcon;
    527528        }
    528529        else if (template.icon)
    529530        {
     
    806807        removeDupes(buildableEnts);
    807808        removeDupes(trainableEnts);
    808809
     810        // Whether the GUI's right panel has been filled.
     811        var rightUsed = true;
     812
    809813        // The first selected entity's type has priority.
    810814        if (entState.buildEntities)
    811815            setupUnitPanel(CONSTRUCTION, usedPanels, entState, buildableEnts, startBuildingPlacement);
     
    814818                function (trainEntType) { addTrainingToQueue(selection, trainEntType); } );
    815819        else if (entState.trader)
    816820            setupUnitTradingPanel(usedPanels, entState, selection);
     821        else if (entState.gate)
     822        {
     823            var items = [];
     824            for (var i = 0; i < GATE_ACTIONS.length; ++i)
     825                items.push({
     826                    "tooltip": GATE_ACTIONS[i] + " gate",
     827                    "locked": i == 0
     828                });
     829            setupUnitPanel(GATE, usedPanels, entState, items,
     830                function (item) { lockGate(item.locked); } );
     831        }
     832        else if (!entState.foundation && (hasClass(entState, "LongWall")))
     833        {
     834            // Allow long wall pieces to be converted to gates
     835            var longWallTypes = {};
     836            var items = [];
     837            for (var i in selection)
     838            {
     839                if ((state = GetEntityState(selection[i])) && hasClass(state, "LongWall") &&
     840                    !state.gate && !state.foundation && !longWallTypes[state.template])
     841                {
     842                    var gateTemplate = getWallGateTemplate(state.id);
     843                    if (gateTemplate)
     844                    {
     845                        var wallName = GetTemplateData(state.template).name.generic;
     846                        var gateName = GetTemplateData(gateTemplate).name.generic;
     847
     848                        items.push({
     849                            "tooltip": "Convert " + wallName + " to " + gateName,
     850                            "template": gateTemplate
     851                        });
     852                    }
     853
     854                    // We only need one entity per type.
     855                    longWallTypes[state.template] = true;
     856                }
     857            }
     858
     859            if (items.length)
     860                setupUnitPanel(GATE, usedPanels, entState, items,
     861                    function (item) { transformWallToGate(item.template); } );
     862            else
     863                rightUsed = false;
     864        }
    817865        else
     866            rightUsed = false;
     867
     868        if (!rightUsed)
    818869        {
    819870            // The right pane is empty. Fill the pane with a sane type.
    820871            // Prefer buildables for units and trainables for structures.
     
    838889            setupUnitPanel(QUEUE, usedPanels, entState, entState.production.queue,
    839890                function (item) { removeFromProductionQueue(entState.id, item.id); } );
    840891       
    841         if(!entState.foundation && (entState.gate || hasClass(entState, "LongWall")))
    842         {
    843             if (entState.gate)
    844             {
    845                 var items = [];
    846                 for (var i = 0; i < GATE_ACTIONS.length; ++i)
    847                     items.push({
    848                         "tooltip": GATE_ACTIONS[i] + " gate",
    849                         "locked": i == 0
    850                     });
    851                 setupUnitPanel(GATE, usedPanels, entState, items,
    852                     function (item) { lockGate(item.locked); } );
    853             }
    854             else
    855             {
    856                 // Allow long wall pieces to be converted to gates
    857                 // TODO: find the gate template name in a better way
    858                 // TODO: selections of multiple different types of walls (breaks currently)
    859                 var longPos = entState.template.indexOf("long");
    860                 if (longPos != -1)
    861                 {
    862                     var action = {
    863                         "tooltip": "Convert to gate",
    864                         "template": entState.template.substr(0, longPos) + "gate"
    865                     };
    866                     setupUnitPanel(GATE, usedPanels, entState, [action],
    867                         function (item) { transformWallToGate(action.template); } );
    868                 }
    869             }
    870         }
    871        
    872892        supplementalDetailsPanel.hidden = false;
    873893        commandsPanel.hidden = false;
    874894    }
  • binaries/data/mods/public/gui/session/input.js

     
    16431643    var selection = g_Selection.toList();
    16441644    Engine.PostNetworkCommand({
    16451645        "type": "wall-to-gate",
    1646         "entities": selection,
     1646        "entities": selection.filter( function(e) { return getWallGateTemplate(e) == template } ),
    16471647        "template": template,
    16481648    });
    16491649}
    16501650
     1651// Gets the gate form (if any) of a given entity.
     1652function getWallGateTemplate(entity)
     1653{
     1654    // TODO: find the gate template name in a better way
     1655    var entState = GetEntityState(entity);
     1656    var index;
     1657
     1658    if (entState && !entState.foundation && hasClass(entState, "LongWall") && (index = entState.template.indexOf("long")) >= 0)
     1659        return entState.template.substr(0, index) + "gate";
     1660    return undefined;
     1661}
     1662
    16511663// Set the camera to follow the given unit
    16521664function setCameraFollow(entity)
    16531665{