Ticket #1492: hotkeys6.patch

File hotkeys6.patch, 40.0 KB (added by picobyte, 12 years ago)

Default available actions dependent on selection, non-default actions remapped

  • binaries/data/config/default.cfg

    commit 8667be2fa976064e67569141734d319c8401d385
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Thu Jun 14 00:54:35 2012 +0200
    
        This implements the V, B, N and M hotkeys for
        Stance, Formation, garrison, ungarrison respectively
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg
    index 5015b15..9e7c9aa 100644
    a b hotkey.selection.group.action.10 = "Ctrl+K"  
    203203hotkey.selection.group.action.11 = "Ctrl+L"
    204204hotkey.selection.group.action.12 = "Ctrl+Semicolon"
    205205hotkey.selection.group.action.13 = "Ctrl+SingleQuote"
    206 hotkey.selection.group.action.reset = ForwardSlash
     206hotkey.selection.group.reset.0 = ForwardSlash
     207hotkey.selection.group.stance.0 = V
     208hotkey.selection.group.formation.0 = B
     209hotkey.selection.group.garrison.0 = N
     210hotkey.selection.group.ungarrison.0 = M
    207211
    208212; > SESSION CONTROLS
    209213hotkey.session.kill = Delete                ; Destroy selected units
  • binaries/data/mods/public/gui/session/input.js

    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index adb7bb5..743bdf8 100644
    a b const INPUT_BATCHTRAINING = 6;  
    3535const INPUT_PRESELECTEDACTION = 7;
    3636const INPUT_BUILDING_WALL_CLICK = 8;
    3737const INPUT_BUILDING_WALL_PATHING = 9;
     38const INPUT_ACTION_STATE = 10;
    3839
    3940var inputState = INPUT_NORMAL;
    4041var placementSupport = new PlacementSupport();
    function handleInputAfterGui(ev)  
    10281029    switch (inputState)
    10291030    {
    10301031    case INPUT_NORMAL:
     1032    case INPUT_ACTION_STATE:
    10311033        switch (ev.type)
    10321034        {
    10331035        case "mousemotion":
    function performCommand(entity, commandName)  
    15381540                    openDeleteDialog(selection);
    15391541                break;
    15401542            case "garrison":
    1541                 inputState = INPUT_PRESELECTEDACTION;
     1543                inputState = INPUT_SELECTING;
    15421544                preSelectedAction = ACTION_GARRISON;
    15431545                break;
    15441546            case "repair":
    1545                 inputState = INPUT_PRESELECTEDACTION;
     1547                inputState = INPUT_SELECTING;
    15461548                preSelectedAction = ACTION_BUILD;
    15471549                break;
    15481550            case "unload-all":
    function handleHotkey(ev)  
    15931595    {
    15941596        var sptr = ev.hotkey.split(".");
    15951597        var now = new Date();
    1596         if (inputState = INPUT_NORMAL && (ev.hotkey == prevHotkey) &&
     1598        if ((inputState == INPUT_NORMAL) && (ev.hotkey == prevHotkey) &&
    15971599                ev.hotkey.indexOf("selection.group.select.") == 0 &&
    15981600                (now.getTime() - doublePressTimer < doublePressTime)) {
    15991601            performGroup("snap", sptr[3]);
    function handleHotkey(ev)  
    16081610}
    16091611
    16101612// Performs the specified group
    1611 function performGroup(action, nr)
     1613function performGroup(action, x)
    16121614{
    1613     if (nr == "reset")
    1614     {
    1615         resetPreselectedAction();
    1616         return;
    1617     }
    16181615    switch (action)
    16191616    {
    16201617    case "snap":
    function performGroup(action, nr)  
    16221619    case "add":
    16231620        var toSelect = [];
    16241621        g_Groups.update();
    1625         for (var ent in g_Groups.groups[nr].ents)
     1622        for (var ent in g_Groups.groups[x].ents)
    16261623            toSelect.push(+ent);
    16271624
    16281625        if (action != "add")
    function performGroup(action, nr)  
    16321629
    16331630        if (action == "snap" && toSelect.length)
    16341631            Engine.CameraFollow(toSelect[0]);
    1635         break;
     1632        return;
    16361633    case "save":
    16371634        var selection = g_Selection.toList();
    1638         g_Groups.groups[nr].reset();
    1639         g_Groups.addEntities(nr, selection);
     1635        g_Groups.groups[x].reset();
     1636        g_Groups.addEntities(x, selection);
    16401637        updateGroups();
    1641         break;
     1638        return;
    16421639    case "action":
    16431640        var selection = g_Selection.toList();
    16441641        var player = Engine.GetPlayerID();
     1642        if (inputState != INPUT_ACTION_STATE)
     1643            preSelectedAction = getDefaultActionForSelection(player, selection);
     1644        break;
     1645    case "reset":
     1646        resetPreselectedAction();
     1647        return;
     1648    case "garrison":
     1649        preSelectedAction = ACTION_GARRISON;
     1650        inputState = INPUT_PRESELECTEDACTION;
     1651        return;
     1652    case "ungarrison":
     1653        preSelectedAction = ACTION_UNGARRISON;
     1654        inputState = INPUT_ACTION_STATE;
     1655        return;
     1656    case "stance":
     1657        preSelectedAction = ACTION_STANCE;
     1658        inputState = INPUT_ACTION_STATE;
     1659        return;
     1660    case "formation":
     1661        preSelectedAction = ACTION_FORMATION;
     1662        inputState = INPUT_ACTION_STATE;
     1663        return;
     1664    }
     1665    if (inputState == INPUT_ACTION_STATE)
     1666        inputState = INPUT_NORMAL;
     1667    if (preSelectedAction == ACTION_NONE)
     1668        return;
    16451669
    1646         preSelectedAction = getDefaultActionForSelection(player, selection);
    1647         if (preSelectedAction == ACTION_NONE)
    1648             break;
     1670    var lst = selectAction(player, selection);
     1671    if (!lst) // shouldn't happen
     1672        return;
    16491673
    1650         var lst = selectAction(player, selection);
    1651         if (!lst) // shouldn't happen
    1652             break;
     1674    if (preSelectedAction & ACTION_GARRISON)
     1675    {
     1676        if (++x > lst.length)
     1677            x = lst.length;
     1678    } else if (preSelectedAction != ACTION_UNGARRISON) {
     1679        if (x >= lst.length)
     1680            return;
     1681        lst = lst[x];
     1682    }
    16531683
    1654         if (preSelectedAction & ACTION_GARRISON)
    1655         {
    1656             if (++nr > lst.length)
    1657                 nr = lst.length;
    1658         } else if (preSelectedAction != ACTION_UNGARRISON) {
    1659             if (nr >= lst.length)
    1660                 break;
    1661             lst = lst[nr];
     1684    switch (preSelectedAction)
     1685    {
     1686    case ACTION_BUILD:
     1687        var tmpl = GetTemplateData(lst);
     1688        if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
     1689            // N.B. sets inputState = INPUT_BUILDING_PLACEMENT:
     1690            startBuildingPlacement(lst);
     1691            placementSupport.position = Engine.GetTerrainAtScreenPoint(mouseX, mouseY);
     1692            initBuildingPlacementView();
    16621693        }
    1663 
    1664         switch (preSelectedAction)
    1665         {
    1666         case ACTION_BUILD:
    1667             var tmpl = GetTemplateData(lst);
    1668             if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
    1669                 // N.B. sets inputState = INPUT_BUILDING_PLACEMENT:
    1670                 startBuildingPlacement(lst);
    1671                 placementSupport.position = Engine.GetTerrainAtScreenPoint(mouseX, mouseY);
    1672                 initBuildingPlacementView();
    1673             }
    1674             break;
    1675         case ACTION_TRAIN:
    1676             var tmpl = GetTemplateData(lst);
    1677             if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
    1678                 var ents = g_Selection.toList();
    1679                 addTrainingToQueue(ents, lst);
    1680             }
    1681             break;
    1682         case ACTION_GARRISON: // we garison nr+1 count
    1683             g_Selection.reset();
    1684             lst.splice(nr, lst.length - nr)
    1685             g_Selection.addList(lst);
    1686             inputState = INPUT_PRESELECTEDACTION;
    1687             break;
    1688         case ACTION_UNGARRISON:
    1689             if (lst.length > 1 || nr == 0) {
    1690                 if (nr >= lst.length)
    1691                     nr = lst.length - 1;
    1692                 if (lst.length != 1 && nr == 0) {
    1693                     // unload all from all buildings
    1694                     for each (var gh in lst)
    1695                         unloadAll(gh);
    1696                 } else {
    1697                     if (lst.length != 1)
    1698                         nr--;
    1699                     unloadAll(lst[nr]);
    1700                 }
    1701                 g_Selection.reset();
    1702                 break;
     1694        break;
     1695    case ACTION_TRAIN:
     1696        var tmpl = GetTemplateData(lst);
     1697        if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
     1698            var ents = g_Selection.toList();
     1699            addTrainingToQueue(ents, lst);
     1700        }
     1701        break;
     1702    case ACTION_GARRISON: // we garison x+1 count
     1703        g_Selection.reset();
     1704        lst.splice(x, lst.length - x)
     1705        g_Selection.addList(lst);
     1706        inputState = INPUT_PRESELECTEDACTION;
     1707        break;
     1708    case ACTION_UNGARRISON:
     1709        if (lst.length > 1 || x == 0) {
     1710            if (x >= lst.length)
     1711                x = lst.length - 1;
     1712            if (lst.length != 1 && x == 0) {
     1713                // unload all from all buildings
     1714                for each (var gh in lst)
     1715                    unloadAll(gh);
    17031716            } else {
    1704                 lst = lst[0];
    1705                 var state = GetEntityState(lst);
    1706                 var gents = state.garrisonHolder.entities;
    1707                 if (nr > gents.length)
    1708                     nr = gents.length;
    1709                 while (nr--)
    1710                     Engine.PostNetworkCommand({"type": "unload", "entities": [gents[nr]], "garrisonHolder": lst});
    1711                 // we could assign a key to follow them here
    1712                 break;
     1717                if (lst.length != 1)
     1718                    x--;
     1719                unloadAll(lst[x]);
    17131720            }
    1714             break;
    1715         case ACTION_FORMATION:
    1716             ents = g_Selection.toList();
    1717             var formationOk = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", {
    1718                 "ents": g_Selection.toList(),
    1719                 "formationName": lst
    1720             });
    1721             if (formationOk)
    1722                 performFormation(ents, lst);
    1723             break
    1724         case ACTION_STANCE:
    1725             ents = g_Selection.toList();
    1726             performStance(ents, lst);
    1727             break;
    1728         case ACTION_BARTER: //TODO
    1729             break;
    1730         case ACTION_TRADER: //TODO
    1731             break;
     1721            g_Selection.reset();
     1722        } else {
     1723            lst = lst[0];
     1724            var state = GetEntityState(lst);
     1725            var gents = state.garrisonHolder.entities;
     1726            if (x > gents.length)
     1727                x = gents.length;
     1728            while (x--)
     1729                Engine.PostNetworkCommand({"type": "unload", "entities": [gents[x]], "garrisonHolder": lst});
     1730            // we could assign a key to follow them here
    17321731        }
    17331732        break;
     1733    case ACTION_FORMATION:
     1734        ents = g_Selection.toList();
     1735        var formationOk = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", {
     1736            "ents": g_Selection.toList(),
     1737            "formationName": lst
     1738        });
     1739        if (formationOk)
     1740            performFormation(ents, lst);
     1741        break
     1742    case ACTION_STANCE:
     1743        ents = g_Selection.toList();
     1744        performStance(ents, lst);
     1745        break;
     1746    case ACTION_BARTER: //TODO
     1747        break;
     1748    case ACTION_TRADER: //TODO
     1749        break;
    17341750    }
    17351751}
    17361752
    17371753// This returns a list of actions. Caller still has to check Technology availability
    17381754function selectAction(player, selection)
    17391755{
    1740     var ret = [];
    17411756    if (preSelectedAction == ACTION_FORMATION)
    1742     {
    17431757        return Engine.GuiInterfaceCall("GetAvailableFormations");
    1744     } else if (preSelectedAction == ACTION_STANCE)
    1745     {
     1758    else if (preSelectedAction == ACTION_STANCE)
    17461759        return ["violent", "aggressive", "passive", "defensive", "standground"];
    1747     }
     1760
     1761    var ret = [];
    17481762    for each (var ent in selection)
    17491763    {
    17501764        var state = GetEntityState(ent);
  • binaries/data/mods/public/gui/session/input.js

    commit 286f76f2aa3bf8259fe4de6edb279e89d6215484
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 23:41:05 2012 +0200
    
        don't mix up function argument and global
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index 37508f3..adb7bb5 100644
    a b function handleInputAfterGui(ev)  
    10661066        switch (ev.type)
    10671067        {
    10681068        case "mousebuttondown":
    1069             if (ev.button == SDL_BUTTON_LEFT && preSelectedAction)
     1069            if (ev.button == SDL_BUTTON_LEFT && preSelectedAction != ACTION_NONE)
    10701070            {
    10711071                var action = determineAction(ev.x, ev.y);
    10721072                resetPreselectedAction();
    function performGroup(action, nr)  
    16471647        if (preSelectedAction == ACTION_NONE)
    16481648            break;
    16491649
    1650         var lst = selectAction(player, selection, action);
     1650        var lst = selectAction(player, selection);
    16511651        if (!lst) // shouldn't happen
    16521652            break;
    16531653
    function performGroup(action, nr)  
    17341734    }
    17351735}
    17361736
    1737 function selectAction(player, selection, action)
     1737// This returns a list of actions. Caller still has to check Technology availability
     1738function selectAction(player, selection)
    17381739{
    17391740    var ret = [];
    1740     if (action == ACTION_FORMATION)
     1741    if (preSelectedAction == ACTION_FORMATION)
    17411742    {
    17421743        return Engine.GuiInterfaceCall("GetAvailableFormations");
    1743     } else if (action == ACTION_STANCE)
     1744    } else if (preSelectedAction == ACTION_STANCE)
    17441745    {
    17451746        return ["violent", "aggressive", "passive", "defensive", "standground"];
    17461747    }
    function selectAction(player, selection, action)  
    17861787    return ret;
    17871788}
    17881789
    1789 // This returns a list of actions. Caller still has to check Technology availability
    17901790function getDefaultActionForSelection(player, selection)
    17911791{
    17921792    var action;
    function findEntity(classes, mode)  
    19111911        var newEntity = Engine.GuiInterfaceCall("FindEntity", data);
    19121912        if (newEntity && newEntity != lastEntity)
    19131913        {
    1914             if (!selectAction(player, [newEntity], preSelectedAction).length)
     1914            if (!selectAction(player, [newEntity]).length)
    19151915                resetPreselectedAction();
    19161916            else if (preSelectedAction == ACTION_BUILD)
    19171917                updateBuildingPlacementPreview();
  • binaries/data/mods/public/gui/session/input.js

    commit 92ad5f0b42b98f9d7beae0c884af378a99bc60e9
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 23:31:36 2012 +0200
    
        reorder a bit (no functional change)
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index 7e12d39..37508f3 100644
    a b function handleInputAfterGui(ev)  
    10571057            break;
    10581058
    10591059        case "hotkeydown":
    1060             if (ev.hotkey && ev.hotkey.indexOf("selection.group.") == 0)
    1061             {
    1062                 var sptr = ev.hotkey.split(".");
    1063                 var now = new Date();
    1064                 if ((now.getTime() - doublePressTimer < doublePressTime) && (ev.hotkey == prevHotkey) && ev.hotkey.indexOf("selection.group.select.") == 0) {
    1065                     performGroup("snap", sptr[3]);
    1066                 }
    1067                 else
    1068                 {
    1069                     performGroup(sptr[2], sptr[3]);
    1070 
    1071                     doublePressTimer = now.getTime();
    1072                     prevHotkey = ev.hotkey;
    1073                 }
    1074             }
     1060            handleHotkey(ev);
    10751061            break;
    10761062        }
    10771063        break;
    function handleInputAfterGui(ev)  
    10941080                break;
    10951081            }
    10961082        case "hotkeydown":
    1097             if (ev.hotkey && ev.hotkey.indexOf("selection.group.action.") == 0)
    1098             {
    1099                 var sptr = ev.hotkey.split(".");
    1100                 performGroup(sptr[2], sptr[3]);
    1101             }
     1083            handleHotkey(ev);
    11021084            break;
    11031085        default:
    11041086            // Slight hack: If selection is empty, reset the input state
    function handleInputAfterGui(ev)  
    12681250                updateBuildingPlacementPreview();
    12691251                break;
    12701252            default:
    1271                 if (ev.hotkey.indexOf("selection.group.action.") == 0)
    1272                 {   // can switch buildings
    1273                     var sptr = ev.hotkey.split(".");
    1274                     performGroup(sptr[2], sptr[3]);
    1275                 }
     1253                handleHotkey(ev); // to switch buildings
    12761254            }
    12771255            break;
    12781256
    function performFormation(entity, formationName)  
    16091587    }
    16101588}
    16111589
    1612 function selectAction(player, selection, action)
     1590function handleHotkey(ev)
    16131591{
    1614     var ret = [];
    1615     if (action == ACTION_FORMATION)
    1616     {
    1617         return Engine.GuiInterfaceCall("GetAvailableFormations");
    1618     } else if (action == ACTION_STANCE)
    1619     {
    1620         return ["violent", "aggressive", "passive", "defensive", "standground"];
    1621     }
    1622     for each (var ent in selection)
     1592    if (ev.hotkey && ev.hotkey.indexOf("selection.group.") == 0)
    16231593    {
    1624         var state = GetEntityState(ent);
    1625         if (!state || (state.player != player && !g_DevSettings.controlAll))
    1626             continue;
    1627 
    1628         switch (preSelectedAction)
     1594        var sptr = ev.hotkey.split(".");
     1595        var now = new Date();
     1596        if (inputState = INPUT_NORMAL && (ev.hotkey == prevHotkey) &&
     1597                ev.hotkey.indexOf("selection.group.select.") == 0 &&
     1598                (now.getTime() - doublePressTimer < doublePressTime)) {
     1599            performGroup("snap", sptr[3]);
     1600        }
     1601        else
    16291602        {
    1630         case ACTION_GARRISON:
    1631             if (state.buildEntities || (hasClass(state, "Unit") && !hasClass(state, "Animal") && !state.garrisonHolder)) {
    1632                 inputState = INPUT_PRESELECTEDACTION;
    1633                 ret.push(ent);
    1634             }
    1635             break;
    1636         case ACTION_BUILD:
    1637             if (state.buildEntities && state.buildEntities.length) {
    1638                 if (inputState != INPUT_BUILDING_PLACEMENT)
    1639                     inputState = INPUT_PRESELECTEDACTION;
    1640                 return state.buildEntities;
    1641             }
    1642             break;
    1643         case ACTION_TRAIN:
    1644             if (state.production && state.production.entities.length)
    1645                 return state.production.entities;
    1646             break;
    1647         case ACTION_UNGARRISON:
    1648             if (state.garrisonHolder && state.garrisonHolder.entities && state.garrisonHolder.entities.length)
    1649                 ret.push(ent);
    1650             break;
    1651         case ACTION_BARTER:
    1652             if (state.barterMarket)
    1653                 ret.push(ent);
    1654             break;
    1655         case ACTION_TRADER:
    1656             if (state.trader)
    1657                 ret.push([ent, state]);
    1658             break;
     1603            performGroup(sptr[2], sptr[3]);
     1604            doublePressTimer = now.getTime();
     1605            prevHotkey = ev.hotkey;
    16591606        }
    16601607    }
    1661     return ret;
    1662 }
    1663 
    1664 // This returns a list of actions. Caller still has to check Technology availability
    1665 function getDefaultActionForSelection(player, selection)
    1666 {
    1667     var action;
    1668     var count = 0;
    1669     for each (var ent in selection)
    1670     {
    1671         var state = GetEntityState(ent);
    1672         if (!state || (state.player != player && !g_DevSettings.controlAll))
    1673             continue;
    1674 
    1675         if (state.buildEntities && state.buildEntities.length)
    1676             return ACTION_BUILD; // by default
    1677 
    1678         if (state.production && state.production.entities.length)
    1679             action |= ACTION_TRAIN;
    1680         else if (!hasClass(state, "Unit") || hasClass(state, "Animal") ||
    1681                 !state.garrisonHolder) {
    1682             if (++count > 1) //only works with at least two units
    1683                 action |= ACTION_FORMATION;
    1684         } else if (state.barterMarket)
    1685             action |= ACTION_BARTER;
    1686         else if (state.trader)
    1687             action |= ACTION_TRADER;
    1688     }
    1689     if (action & ACTION_TRAIN)
    1690         return ACTION_TRAIN;
    1691     else if (action & ACTION_FORMATION)
    1692         return ACTION_FORMATION;
    1693     else if (action & ACTION_BARTER) {
    1694         setupUnitBarterPanel(state);
    1695         return ACTION_BARTER;
    1696     } else if (action & ACTION_TRADER) {
    1697         setupUnitTradingPanel(state, selection);
    1698         return ACTION_TRADER;
    1699     }
    1700     return 0; //shouldn't happen
    17011608}
    17021609
    17031610// Performs the specified group
    function performGroup(action, nr)  
    18271734    }
    18281735}
    18291736
     1737function selectAction(player, selection, action)
     1738{
     1739    var ret = [];
     1740    if (action == ACTION_FORMATION)
     1741    {
     1742        return Engine.GuiInterfaceCall("GetAvailableFormations");
     1743    } else if (action == ACTION_STANCE)
     1744    {
     1745        return ["violent", "aggressive", "passive", "defensive", "standground"];
     1746    }
     1747    for each (var ent in selection)
     1748    {
     1749        var state = GetEntityState(ent);
     1750        if (!state || (state.player != player && !g_DevSettings.controlAll))
     1751            continue;
     1752
     1753        switch (preSelectedAction)
     1754        {
     1755        case ACTION_GARRISON:
     1756            if (state.buildEntities || (hasClass(state, "Unit") && !hasClass(state, "Animal") && !state.garrisonHolder)) {
     1757                inputState = INPUT_PRESELECTEDACTION;
     1758                ret.push(ent);
     1759            }
     1760            break;
     1761        case ACTION_BUILD:
     1762            if (state.buildEntities && state.buildEntities.length) {
     1763                if (inputState != INPUT_BUILDING_PLACEMENT)
     1764                    inputState = INPUT_PRESELECTEDACTION;
     1765                return state.buildEntities;
     1766            }
     1767            break;
     1768        case ACTION_TRAIN:
     1769            if (state.production && state.production.entities.length)
     1770                return state.production.entities;
     1771            break;
     1772        case ACTION_UNGARRISON:
     1773            if (state.garrisonHolder && state.garrisonHolder.entities && state.garrisonHolder.entities.length)
     1774                ret.push(ent);
     1775            break;
     1776        case ACTION_BARTER:
     1777            if (state.barterMarket)
     1778                ret.push(ent);
     1779            break;
     1780        case ACTION_TRADER:
     1781            if (state.trader)
     1782                ret.push([ent, state]);
     1783            break;
     1784        }
     1785    }
     1786    return ret;
     1787}
     1788
     1789// This returns a list of actions. Caller still has to check Technology availability
     1790function getDefaultActionForSelection(player, selection)
     1791{
     1792    var action;
     1793    var count = 0;
     1794    for each (var ent in selection)
     1795    {
     1796        var state = GetEntityState(ent);
     1797        if (!state || (state.player != player && !g_DevSettings.controlAll))
     1798            continue;
     1799
     1800        if (state.buildEntities && state.buildEntities.length)
     1801            return ACTION_BUILD; // by default
     1802
     1803        if (state.production && state.production.entities.length)
     1804            action |= ACTION_TRAIN;
     1805        else if (!hasClass(state, "Unit") || hasClass(state, "Animal") ||
     1806                !state.garrisonHolder) {
     1807            if (++count > 1) //only works with at least two units
     1808                action |= ACTION_FORMATION;
     1809        } else if (state.barterMarket)
     1810            action |= ACTION_BARTER;
     1811        else if (state.trader)
     1812            action |= ACTION_TRADER;
     1813    }
     1814    if (action & ACTION_TRAIN)
     1815        return ACTION_TRAIN;
     1816    else if (action & ACTION_FORMATION)
     1817        return ACTION_FORMATION;
     1818    else if (action & ACTION_BARTER) {
     1819        setupUnitBarterPanel(state);
     1820        return ACTION_BARTER;
     1821    } else if (action & ACTION_TRADER) {
     1822        setupUnitTradingPanel(state, selection);
     1823        return ACTION_TRADER;
     1824    }
     1825    return 0; //shouldn't happen
     1826}
     1827
    18301828// Performs the specified stance
    18311829function performStance(entity, stanceName)
    18321830{
  • binaries/data/mods/public/gui/session/input.js

    commit a459d5e2b2413a021e01bb7dd9ef4f16468778b3
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 23:25:14 2012 +0200
    
        Generalize All unloaded following
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index 8897d01..7e12d39 100644
    a b function handleInputBeforeGui(ev, hoveredObject)  
    666666        mouseY = ev.y;
    667667        break;
    668668    }
    669     if (followQueue.lenght)
     669    if (followQueue.length)
    670670    {
    671671        var gents = followQueue;
    672672        var state = GetEntityState(gents[0]);
    673         // FIXME this stalls until the selection actually occurs
    674673        if (state.visibility == "hidden")
    675674            return true;
    676675        Engine.CameraFollow(0);
    677676        Engine.CameraFollow(gents[0]);
    678677        g_Selection.addList(gents);
    679678        resetPreselectedAction();
    680         followQueue = [];
     679        followQueue = []; // for next time.
    681680    }
    682681    // Remember whether the mouse is over a GUI object or not
    683682    mouseIsOverObject = (hoveredObject != null);
    function performGroup(action, nr)  
    17841783                if (nr >= lst.length)
    17851784                    nr = lst.length - 1;
    17861785                if (lst.length != 1 && nr == 0) {
    1787                     followQueue = [];
    17881786                    // unload all from all buildings
    1789                     for each (var gh in lst) {
    1790                         var s = GetEntityState(gh);
    1791                         var gs = s.garrisonHolder.entities;
    1792                         followQueue = followQueue.concat(gs);
     1787                    for each (var gh in lst)
    17931788                        unloadAll(gh);
    1794                     }
    17951789                } else {
    17961790                    if (lst.length != 1)
    17971791                        nr--;
    1798                     lst = lst[nr];
    1799 
    1800                     var state = GetEntityState(lst);
    1801                     var gents = state.garrisonHolder.entities;
    1802                     followQueue = gents;
    1803                     unloadAll(lst);
     1792                    unloadAll(lst[nr]);
    18041793                }
    18051794                g_Selection.reset();
    18061795                break;
    function unload(garrisonHolder, entities)  
    19531942
    19541943function unloadAll(garrisonHolder)
    19551944{
     1945    var state = GetEntityState(garrisonHolder);
     1946    var gents = state.garrisonHolder.entities;
     1947    followQueue = followQueue.concat(gents);
    19561948    Engine.PostNetworkCommand({"type": "unload-all", "garrisonHolder": garrisonHolder});
    19571949}
  • binaries/data/mods/public/gui/session/input.js

    commit b89368e8dede26f9b2a412c1c62bde5aceefed9a
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 22:45:44 2012 +0200
    
        This patch makes a default choice active. e.g. for a worker the default
        action is to build, for a building to train. keys G to singlequote are
        implemented as choices. Setting non-default options aren't available
        anymore but a next patch will implement hotkeys for that.
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index eb6d59a..8897d01 100644
    a b const ACTION_BARTER = 64;  
    2323const ACTION_TRADER =128;
    2424var preSelectedAction = ACTION_NONE;
    2525
    26 // N.B. reset this after selecting different units or buildings
    27 var _optionsOfpreSelected = [];
     26var followQueue = [];
    2827
    2928const INPUT_NORMAL = 0;
    3029const INPUT_SELECTING = 1;
    const INPUT_BATCHTRAINING = 6;  
    3635const INPUT_PRESELECTEDACTION = 7;
    3736const INPUT_BUILDING_WALL_CLICK = 8;
    3837const INPUT_BUILDING_WALL_PATHING = 9;
    39 const INPUT_FOLLOW_UNGARRISON = 10;
    4038
    4139var inputState = INPUT_NORMAL;
    4240var placementSupport = new PlacementSupport();
    function resetPreselectedAction()  
    188186{
    189187    preSelectedAction = ACTION_NONE;
    190188    inputState = INPUT_NORMAL;
    191     _optionsOfpreSelected = [];
    192189    placementSupport.Reset(); // or a hotkey may leave a building snapshot
    193190    updateCursorAndTooltip();
    194191
    function handleInputBeforeGui(ev, hoveredObject)  
    669666        mouseY = ev.y;
    670667        break;
    671668    }
    672     if (inputState == INPUT_FOLLOW_UNGARRISON)
     669    if (followQueue.lenght)
    673670    {
    674         var gents = _optionsOfpreSelected;
     671        var gents = followQueue;
    675672        var state = GetEntityState(gents[0]);
    676673        // FIXME this stalls until the selection actually occurs
    677674        if (state.visibility == "hidden")
    function handleInputBeforeGui(ev, hoveredObject)  
    680677        Engine.CameraFollow(gents[0]);
    681678        g_Selection.addList(gents);
    682679        resetPreselectedAction();
     680        followQueue = [];
    683681    }
    684682    // Remember whether the mouse is over a GUI object or not
    685683    mouseIsOverObject = (hoveredObject != null);
    function handleInputAfterGui(ev)  
    10441042            return false;
    10451043
    10461044        case "mousebuttondown":
    1047             _optionsOfpreSelected = [];
    10481045            if (ev.button == SDL_BUTTON_LEFT)
    10491046            {
    10501047                dragStart = [ ev.x, ev.y ];
    function handleInputAfterGui(ev)  
    12451242                    placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
    12461243                    dragStart = [ ev.x, ev.y ];
    12471244                    inputState = INPUT_BUILDING_CLICK;
    1248                     _optionsOfpreSelected = [];
    12491245                }
    12501246                return true;
    12511247            }
    function performFormation(entity, formationName)  
    16141610    }
    16151611}
    16161612
    1617 // This returns a list of actions. Caller still has to check Technology availability
    1618 function getActionForSelection(player, selection)
     1613function selectAction(player, selection, action)
    16191614{
    16201615    var ret = [];
    1621 
     1616    if (action == ACTION_FORMATION)
     1617    {
     1618        return Engine.GuiInterfaceCall("GetAvailableFormations");
     1619    } else if (action == ACTION_STANCE)
     1620    {
     1621        return ["violent", "aggressive", "passive", "defensive", "standground"];
     1622    }
    16221623    for each (var ent in selection)
    16231624    {
    16241625        var state = GetEntityState(ent);
    function getActionForSelection(player, selection)  
    16481649            if (state.garrisonHolder && state.garrisonHolder.entities && state.garrisonHolder.entities.length)
    16491650                ret.push(ent);
    16501651            break;
    1651         case ACTION_FORMATION:
    1652         case ACTION_STANCE:
    1653             if (!hasClass(state, "Unit") || hasClass(state, "Animal") || state.garrisonHolder)
    1654                 break;
    1655 
    1656             if (preSelectedAction == ACTION_STANCE)
    1657                 return ["violent", "aggressive", "passive", "defensive", "standground"];
    1658             if (ret.length) // minimimum is 2 units for formation to be enabled
    1659                 return Engine.GuiInterfaceCall("GetAvailableFormations");
    1660             ret.push(1);
    1661             break;
    16621652        case ACTION_BARTER:
    16631653            if (state.barterMarket)
    16641654                ret.push(ent);
    function getActionForSelection(player, selection)  
    16671657            if (state.trader)
    16681658                ret.push([ent, state]);
    16691659            break;
    1670         default:
    1671             return ret; //shouldn't happen
    16721660        }
    16731661    }
    16741662    return ret;
    16751663}
    16761664
     1665// This returns a list of actions. Caller still has to check Technology availability
     1666function getDefaultActionForSelection(player, selection)
     1667{
     1668    var action;
     1669    var count = 0;
     1670    for each (var ent in selection)
     1671    {
     1672        var state = GetEntityState(ent);
     1673        if (!state || (state.player != player && !g_DevSettings.controlAll))
     1674            continue;
     1675
     1676        if (state.buildEntities && state.buildEntities.length)
     1677            return ACTION_BUILD; // by default
     1678
     1679        if (state.production && state.production.entities.length)
     1680            action |= ACTION_TRAIN;
     1681        else if (!hasClass(state, "Unit") || hasClass(state, "Animal") ||
     1682                !state.garrisonHolder) {
     1683            if (++count > 1) //only works with at least two units
     1684                action |= ACTION_FORMATION;
     1685        } else if (state.barterMarket)
     1686            action |= ACTION_BARTER;
     1687        else if (state.trader)
     1688            action |= ACTION_TRADER;
     1689    }
     1690    if (action & ACTION_TRAIN)
     1691        return ACTION_TRAIN;
     1692    else if (action & ACTION_FORMATION)
     1693        return ACTION_FORMATION;
     1694    else if (action & ACTION_BARTER) {
     1695        setupUnitBarterPanel(state);
     1696        return ACTION_BARTER;
     1697    } else if (action & ACTION_TRADER) {
     1698        setupUnitTradingPanel(state, selection);
     1699        return ACTION_TRADER;
     1700    }
     1701    return 0; //shouldn't happen
     1702}
     1703
    16771704// Performs the specified group
    16781705function performGroup(action, nr)
    16791706{
    function performGroup(action, nr)  
    17071734        updateGroups();
    17081735        break;
    17091736    case "action":
    1710         if (!_optionsOfpreSelected.length) {
    1711             // action hotkey (first pass): With current selection, check possible
    1712             // ACTION_XXX's and set preSelectedAction when applicable
    1713             preSelectedAction = (1 << nr);
    1714 
    1715             var selection = g_Selection.toList();
    1716             var player = Engine.GetPlayerID();
     1737        var selection = g_Selection.toList();
     1738        var player = Engine.GetPlayerID();
    17171739
    1718             var actions = getActionForSelection(player, selection);
    1719             if (!actions || !actions.length) {
    1720                 preSelectedAction = ACTION_NONE;
    1721                 break;
    1722             }
     1740        preSelectedAction = getDefaultActionForSelection(player, selection);
     1741        if (preSelectedAction == ACTION_NONE)
     1742            break;
    17231743
    1724             if (preSelectedAction == ACTION_BARTER)
    1725                 setupUnitBarterPanel(state);
    1726             else if (preSelectedAction == ACTION_TRADER)
    1727                 setupUnitTradingPanel(state, selection);
     1744        var lst = selectAction(player, selection, action);
     1745        if (!lst) // shouldn't happen
     1746            break;
    17281747
    1729             _optionsOfpreSelected = actions;
    1730         }
    1731         else
     1748        if (preSelectedAction & ACTION_GARRISON)
    17321749        {
    1733             // 2nd action hotkey. Do preselectedAction[nr]
    1734             // The result depends on the action.
    1735 
    1736             var lst = _optionsOfpreSelected;
    1737             if (!lst) // shouldn't happen
     1750            if (++nr > lst.length)
     1751                nr = lst.length;
     1752        } else if (preSelectedAction != ACTION_UNGARRISON) {
     1753            if (nr >= lst.length)
    17381754                break;
     1755            lst = lst[nr];
     1756        }
    17391757
    1740             if (preSelectedAction & ACTION_GARRISON)
    1741             {
    1742                 if (++nr > lst.length)
    1743                     nr = lst.length;
    1744             } else if (preSelectedAction != ACTION_UNGARRISON) {
    1745                 if (nr >= lst.length)
    1746                     break;
    1747                 lst = lst[nr];
     1758        switch (preSelectedAction)
     1759        {
     1760        case ACTION_BUILD:
     1761            var tmpl = GetTemplateData(lst);
     1762            if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
     1763                // N.B. sets inputState = INPUT_BUILDING_PLACEMENT:
     1764                startBuildingPlacement(lst);
     1765                placementSupport.position = Engine.GetTerrainAtScreenPoint(mouseX, mouseY);
     1766                initBuildingPlacementView();
    17481767            }
    1749 
    1750             switch (preSelectedAction)
    1751             {
    1752             case ACTION_BUILD:
    1753                 var tmpl = GetTemplateData(lst);
    1754                 if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
    1755                     // N.B. sets inputState = INPUT_BUILDING_PLACEMENT:
    1756                     startBuildingPlacement(lst);
    1757                     placementSupport.position = Engine.GetTerrainAtScreenPoint(mouseX, mouseY);
    1758                     initBuildingPlacementView();
    1759                 }
    1760                 break;
    1761             case ACTION_TRAIN:
    1762                 var tmpl = GetTemplateData(lst);
    1763                 if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
    1764                     var ents = g_Selection.toList();
    1765                     addTrainingToQueue(ents, lst);
    1766                 }
    1767                 break;
    1768             case ACTION_GARRISON: // we garison nr+1 count
    1769                 g_Selection.reset();
    1770                 lst.splice(nr, lst.length - nr)
    1771                 g_Selection.addList(lst);
    1772                 inputState = INPUT_PRESELECTEDACTION;
    1773                 break;
    1774             case ACTION_UNGARRISON:
    1775                 if (lst.length > 1 || nr == 0) {
    1776                     if (nr >= lst.length)
    1777                         nr = lst.length - 1;
    1778                     if (lst.length != 1 && nr == 0) {
    1779                         // unload all from all buildings
    1780                         _optionsOfpreSelected = [];
    1781                         for each (var gh in lst) {
    1782                             var s = GetEntityState(gh);
    1783                             var gs = s.garrisonHolder.entities;
    1784                             _optionsOfpreSelected = _optionsOfpreSelected.concat(gs);
    1785                             unloadAll(gh);
    1786                         }
    1787                     } else {
    1788                         if (lst.length != 1)
    1789                             nr--;
    1790                         lst = lst[nr];
    1791 
    1792                         var state = GetEntityState(lst);
    1793                         var gents = state.garrisonHolder.entities;
    1794                         _optionsOfpreSelected = gents;
    1795                         unloadAll(lst);
     1768            break;
     1769        case ACTION_TRAIN:
     1770            var tmpl = GetTemplateData(lst);
     1771            if (!tmpl.requiredTechnology || Engine.GuiInterfaceCall("IsTechnologyResearched", tmpl.requiredTechnology)) {
     1772                var ents = g_Selection.toList();
     1773                addTrainingToQueue(ents, lst);
     1774            }
     1775            break;
     1776        case ACTION_GARRISON: // we garison nr+1 count
     1777            g_Selection.reset();
     1778            lst.splice(nr, lst.length - nr)
     1779            g_Selection.addList(lst);
     1780            inputState = INPUT_PRESELECTEDACTION;
     1781            break;
     1782        case ACTION_UNGARRISON:
     1783            if (lst.length > 1 || nr == 0) {
     1784                if (nr >= lst.length)
     1785                    nr = lst.length - 1;
     1786                if (lst.length != 1 && nr == 0) {
     1787                    followQueue = [];
     1788                    // unload all from all buildings
     1789                    for each (var gh in lst) {
     1790                        var s = GetEntityState(gh);
     1791                        var gs = s.garrisonHolder.entities;
     1792                        followQueue = followQueue.concat(gs);
     1793                        unloadAll(gh);
    17961794                    }
    1797                     g_Selection.reset();
    1798                     inputState = INPUT_FOLLOW_UNGARRISON;
    1799                     break;
    18001795                } else {
    1801                     lst = lst[0];
     1796                    if (lst.length != 1)
     1797                        nr--;
     1798                    lst = lst[nr];
     1799
    18021800                    var state = GetEntityState(lst);
    18031801                    var gents = state.garrisonHolder.entities;
    1804                     if (nr > gents.length)
    1805                         nr = gents.length;
    1806                     while (nr--)
    1807                         Engine.PostNetworkCommand({"type": "unload", "entities": [gents[nr]], "garrisonHolder": lst});
    1808                     // we could assign a key to follow them here
    1809                     break;
     1802                    followQueue = gents;
     1803                    unloadAll(lst);
    18101804                }
     1805                g_Selection.reset();
    18111806                break;
    1812             case ACTION_FORMATION:
    1813                 ents = g_Selection.toList();
    1814                 var formationOk = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", {
    1815                     "ents": g_Selection.toList(),
    1816                     "formationName": lst
    1817                 });
    1818                 if (formationOk)
    1819                     performFormation(ents, lst);
    1820                 break
    1821             case ACTION_STANCE:
    1822                 ents = g_Selection.toList();
    1823                 performStance(ents, lst);
    1824                 break;
    1825             case ACTION_BARTER: //TODO
    1826                 break;
    1827             case ACTION_TRADER: //TODO
     1807            } else {
     1808                lst = lst[0];
     1809                var state = GetEntityState(lst);
     1810                var gents = state.garrisonHolder.entities;
     1811                if (nr > gents.length)
     1812                    nr = gents.length;
     1813                while (nr--)
     1814                    Engine.PostNetworkCommand({"type": "unload", "entities": [gents[nr]], "garrisonHolder": lst});
     1815                // we could assign a key to follow them here
    18281816                break;
    18291817            }
     1818            break;
     1819        case ACTION_FORMATION:
     1820            ents = g_Selection.toList();
     1821            var formationOk = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", {
     1822                "ents": g_Selection.toList(),
     1823                "formationName": lst
     1824            });
     1825            if (formationOk)
     1826                performFormation(ents, lst);
     1827            break
     1828        case ACTION_STANCE:
     1829            ents = g_Selection.toList();
     1830            performStance(ents, lst);
     1831            break;
     1832        case ACTION_BARTER: //TODO
     1833            break;
     1834        case ACTION_TRADER: //TODO
     1835            break;
    18301836        }
    18311837        break;
    18321838    }
    function findAllVisibleEntities(classes, mode)  
    18951901    }
    18961902
    18971903    if (visibleEnts.length) {
    1898         if (!getActionForSelection(player, visibleEnts).length)
     1904        if (!getDefaultActionForSelection(player, visibleEnts).length)
    18991905            resetPreselectedAction();
    19001906        g_Selection.reset();
    19011907        g_Selection.addList(visibleEnts);
    function findEntity(classes, mode)  
    19181924        var newEntity = Engine.GuiInterfaceCall("FindEntity", data);
    19191925        if (newEntity && newEntity != lastEntity)
    19201926        {
    1921             if (!getActionForSelection(player, [newEntity]).length)
     1927            if (!selectAction(player, [newEntity], preSelectedAction).length)
    19221928                resetPreselectedAction();
    19231929            else if (preSelectedAction == ACTION_BUILD)
    19241930                updateBuildingPlacementPreview();
  • binaries/data/config/default.cfg

    commit 273d868803cecf5e17938e49a2a0b6944327257e
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 20:35:27 2012 +0200
    
        as suggested by historic_bruno the backslash isn't always in line
        Also use Ctrl rather than shift for the 7+ keys (we may want to use shift
        for batchtrain later).
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg
    index 5201210..5015b15 100644
    a b hotkey.selection.group.select.9 = 9  
    189189hotkey.selection.group.save.9 = "Ctrl+9"
    190190hotkey.selection.group.add.9 = "Shift+9"
    191191
    192 hotkey.selection.group.action.0 = H
    193 hotkey.selection.group.action.1 = J
    194 hotkey.selection.group.action.2 = K
    195 hotkey.selection.group.action.3 = L
    196 hotkey.selection.group.action.4 = Semicolon
    197 hotkey.selection.group.action.5 = SingleQuote
    198 hotkey.selection.group.action.6 = BackSlash
    199 hotkey.selection.group.action.7 = "Shift+H"
    200 hotkey.selection.group.action.8 = "Shift+J"
    201 hotkey.selection.group.action.9 = "Shift+K"
    202 hotkey.selection.group.action.10 = "Shift+L"
    203 hotkey.selection.group.action.11 = Colon
    204 hotkey.selection.group.action.12 = DoubleQuote
     192hotkey.selection.group.action.0 = G
     193hotkey.selection.group.action.1 = H
     194hotkey.selection.group.action.2 = J
     195hotkey.selection.group.action.3 = K
     196hotkey.selection.group.action.4 = L
     197hotkey.selection.group.action.5 = Semicolon
     198hotkey.selection.group.action.6 = SingleQuote
     199hotkey.selection.group.action.7 = "Ctrl+G"
     200hotkey.selection.group.action.8 = "Ctrl+H"
     201hotkey.selection.group.action.9 = "Ctrl+J"
     202hotkey.selection.group.action.10 = "Ctrl+K"
     203hotkey.selection.group.action.11 = "Ctrl+L"
     204hotkey.selection.group.action.12 = "Ctrl+Semicolon"
     205hotkey.selection.group.action.13 = "Ctrl+SingleQuote"
    205206hotkey.selection.group.action.reset = ForwardSlash
    206207
    207208; > SESSION CONTROLS
  • binaries/data/mods/public/gui/session/input.js

    commit 97150316bb560554c7f1e5d3f45f90a71d574191
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 20:16:55 2012 +0200
    
        Unload all from all selected buildings
        ensure selection occurs
    
    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index bc48d73..eb6d59a 100644
    a b function handleInputBeforeGui(ev, hoveredObject)  
    671671    }
    672672    if (inputState == INPUT_FOLLOW_UNGARRISON)
    673673    {
    674         gents = _optionsOfpreSelected;
     674        var gents = _optionsOfpreSelected;
     675        var state = GetEntityState(gents[0]);
     676        // FIXME this stalls until the selection actually occurs
     677        if (state.visibility == "hidden")
     678            return true;
    675679        Engine.CameraFollow(0);
    676680        Engine.CameraFollow(gents[0]);
    677681        g_Selection.addList(gents);
    function performGroup(action, nr)  
    17711775                if (lst.length > 1 || nr == 0) {
    17721776                    if (nr >= lst.length)
    17731777                        nr = lst.length - 1;
    1774                     if (lst.length != 1)   // TODO: uload all from all
    1775                         lst = lst[nr]; // selected buildings
    1776                     else
    1777                         lst = lst[0];
    1778                     var state = GetEntityState(lst);
    1779                     var gents = state.garrisonHolder.entities;
    1780                     _optionsOfpreSelected = gents;
    1781                     unloadAll(lst);
     1778                    if (lst.length != 1 && nr == 0) {
     1779                        // unload all from all buildings
     1780                        _optionsOfpreSelected = [];
     1781                        for each (var gh in lst) {
     1782                            var s = GetEntityState(gh);
     1783                            var gs = s.garrisonHolder.entities;
     1784                            _optionsOfpreSelected = _optionsOfpreSelected.concat(gs);
     1785                            unloadAll(gh);
     1786                        }
     1787                    } else {
     1788                        if (lst.length != 1)
     1789                            nr--;
     1790                        lst = lst[nr];
     1791
     1792                        var state = GetEntityState(lst);
     1793                        var gents = state.garrisonHolder.entities;
     1794                        _optionsOfpreSelected = gents;
     1795                        unloadAll(lst);
     1796                    }
    17821797                    g_Selection.reset();
    17831798                    inputState = INPUT_FOLLOW_UNGARRISON;
    17841799                    break;
    function performGroup(action, nr)  
    17861801                    lst = lst[0];
    17871802                    var state = GetEntityState(lst);
    17881803                    var gents = state.garrisonHolder.entities;
    1789                     if (nr >= gents.length)
     1804                    if (nr > gents.length)
    17901805                        nr = gents.length;
    17911806                    while (nr--)
    17921807                        Engine.PostNetworkCommand({"type": "unload", "entities": [gents[nr]], "garrisonHolder": lst});
  • binaries/data/mods/public/gui/session/input.js

    commit a40750c24a7bf9faa84b7e45c4a465c1dafa96c9
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 19:37:50 2012 +0200
    
        actually the INPUT_REPEATED_UNGARRISON state is not needed
        
        Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    
    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index eb0f140..bc48d73 100644
    a b const INPUT_PRESELECTEDACTION = 7;  
    3737const INPUT_BUILDING_WALL_CLICK = 8;
    3838const INPUT_BUILDING_WALL_PATHING = 9;
    3939const INPUT_FOLLOW_UNGARRISON = 10;
    40 const INPUT_REPEATED_UNGARRISON = 11;
    4140
    4241var inputState = INPUT_NORMAL;
    4342var placementSupport = new PlacementSupport();
    function handleInputBeforeGui(ev, hoveredObject)  
    677676        Engine.CameraFollow(gents[0]);
    678677        g_Selection.addList(gents);
    679678        resetPreselectedAction();
    680     } else if (inputState == INPUT_REPEATED_UNGARRISON) {
    681         var garrisonHolder =  _optionsOfpreSelected[0];
    682         var state = GetEntityState(garrisonHolder);
    683         var gents = state.garrisonHolder.entities;
    684         var gent = gents[_optionsOfpreSelected[1]]
    685         Engine.PostNetworkCommand({"type": "unload", "entities": [gent], "garrisonHolder": garrisonHolder});
    686         if (_optionsOfpreSelected[1]-- > 0)
    687             return true;
    688         resetPreselectedAction();
    689679    }
    690680    // Remember whether the mouse is over a GUI object or not
    691681    mouseIsOverObject = (hoveredObject != null);
    function performGroup(action, nr)  
    17971787                    var state = GetEntityState(lst);
    17981788                    var gents = state.garrisonHolder.entities;
    17991789                    if (nr >= gents.length)
    1800                         nr = gents.length - 1;
    1801                     // unload nr times, requires some update.
    1802                     _optionsOfpreSelected = [lst, nr];
    1803                     inputState = INPUT_REPEATED_UNGARRISON;
     1790                        nr = gents.length;
     1791                    while (nr--)
     1792                        Engine.PostNetworkCommand({"type": "unload", "entities": [gents[nr]], "garrisonHolder": lst});
     1793                    // we could assign a key to follow them here
     1794                    break;
    18041795                }
    18051796                break;
    18061797            case ACTION_FORMATION: