Ticket #1552: gate-convert-lock.patch
File gate-convert-lock.patch, 3.9 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/unit_commands.js
421 421 button.tooltip = tooltip; 422 422 423 423 // 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); 425 428 426 429 if (guiName == RESEARCH) 427 430 { … … 511 514 { 512 515 var gateIcon; 513 516 // If already a gate, show locking actions 514 if ( unitEntState.gate)517 if (item.gate) 515 518 { 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; 518 521 } 519 522 // otherwise show gate upgrade icon 520 523 else … … 818 821 function (trainEntType) { addTrainingToQueue(selection, trainEntType); } ); 819 822 else if (entState.trader) 820 823 setupUnitTradingPanel(usedPanels, entState, selection); 821 else if ( entState.gate)824 else if (!entState.foundation && entState.gate || hasClass(entState, "LongWall")) 822 825 { 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 == 0828 });829 setupUnitPanel(GATE, usedPanels, entState, items,830 function (item) { lockGate(item.locked); } );831 }832 else if (!entState.foundation && (hasClass(entState, "LongWall")))833 {834 826 // Allow long wall pieces to be converted to gates 835 827 var longWallTypes = {}; 836 var items = []; 828 var walls = []; 829 var gates = []; 837 830 for (var i in selection) 838 831 { 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]) 841 834 { 842 835 var gateTemplate = getWallGateTemplate(state.id); 843 836 if (gateTemplate) … … 845 838 var wallName = GetTemplateData(state.template).name.generic; 846 839 var gateName = GetTemplateData(gateTemplate).name.generic; 847 840 848 items.push({841 walls.push({ 849 842 "tooltip": "Convert " + wallName + " to " + gateName, 850 "template": gateTemplate 843 "template": gateTemplate, 844 "func": function (item) { transformWallToGate(item.template); } 851 845 }); 852 846 } 853 847 854 848 // We only need one entity per type. 855 849 longWallTypes[state.template] = true; 856 850 } 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; 857 863 } 858 864 865 // Place gate control icons first if the main selection is a gate. 866 var items = entState.gate ? gates.concat(walls) : walls.concat(gates); 859 867 if (items.length) 860 setupUnitPanel(GATE, usedPanels, entState, items, 861 function (item) { transformWallToGate(item.template); } ); 868 setupUnitPanel(GATE, usedPanels, entState, items); 862 869 else 863 870 rightUsed = false; 864 871 }