Ticket #1552: gate-convert-lock.patch

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

     
    421421        button.tooltip = tooltip;
    422422
    423423        // Button Function (need nested functions to get the closure right)
    424         button.onpress = (function(e){ return function() { callback(e) } })(item);
     424        if (item.func)
     425            button.onpress = (function(e){ return function() { e.func(e) } })(item);
     426        else
     427            button.onpress = (function(e){ return function() { callback(e) } })(item);
    425428
    426429        if (guiName == RESEARCH)
    427430        {
     
    511514        {
    512515            var gateIcon;
    513516            // If already a gate, show locking actions
    514             if (unitEntState.gate)
     517            if (item.gate)
    515518            {
    516                 gateIcon = "icons/lock_" + GATE_ACTIONS[i].toLowerCase() + "ed.png";
    517                 selection.hidden = unitEntState.gate.locked != item.locked;
     519                gateIcon = "icons/lock_" + GATE_ACTIONS[ Number(!item.locked) ].toLowerCase() + "ed.png";
     520                selection.hidden = item.gate.locked === undefined ? false : item.gate.locked != item.locked;
    518521            }
    519522            // otherwise show gate upgrade icon
    520523            else
     
    818821                function (trainEntType) { addTrainingToQueue(selection, trainEntType); } );
    819822        else if (entState.trader)
    820823            setupUnitTradingPanel(usedPanels, entState, selection);
    821         else if (entState.gate)
     824        else if (!entState.foundation && entState.gate || hasClass(entState, "LongWall"))
    822825        {
    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         {
    834826            // Allow long wall pieces to be converted to gates
    835827            var longWallTypes = {};
    836             var items = [];
     828            var walls = [];
     829            var gates = [];
    837830            for (var i in selection)
    838831            {
    839                 if ((state = GetEntityState(selection[i])) && hasClass(state, "LongWall") &&
    840                     !state.gate && !state.foundation && !longWallTypes[state.template])
     832                state = GetEntityState(selection[i]);
     833                if (hasClass(state, "LongWall") && !state.gate && !longWallTypes[state.template])
    841834                {
    842835                    var gateTemplate = getWallGateTemplate(state.id);
    843836                    if (gateTemplate)
     
    845838                        var wallName = GetTemplateData(state.template).name.generic;
    846839                        var gateName = GetTemplateData(gateTemplate).name.generic;
    847840
    848                         items.push({
     841                        walls.push({
    849842                            "tooltip": "Convert " + wallName + " to " + gateName,
    850                             "template": gateTemplate
     843                            "template": gateTemplate,
     844                            "func": function (item) { transformWallToGate(item.template); }
    851845                        });
    852846                    }
    853847
    854848                    // We only need one entity per type.
    855849                    longWallTypes[state.template] = true;
    856850                }
     851                else if (state.gate && !gates.length)
     852                    for (var j = 0; j < GATE_ACTIONS.length; ++j)
     853                        gates.push({
     854                            "gate": state.gate,
     855                            "tooltip": GATE_ACTIONS[j] + " gate",
     856                            "locked": j == 0,
     857                            "func": function (item) { lockGate(item.locked); }
     858                        });
     859                // Show both 'locked' and 'unlocked' as active if the selected gates have both lock states.
     860                else if (state.gate && state.gate.locked != gates[0].gate.locked)
     861                    for (var j = 0; j < gates.length; ++j)
     862                        delete gates[j].gate.locked;
    857863            }
    858864
     865            // Place gate control icons first if the main selection is a gate.
     866            var items = entState.gate ? gates.concat(walls) : walls.concat(gates);
    859867            if (items.length)
    860                 setupUnitPanel(GATE, usedPanels, entState, items,
    861                     function (item) { transformWallToGate(item.template); } );
     868                setupUnitPanel(GATE, usedPanels, entState, items);
    862869            else
    863870                rightUsed = false;
    864871        }