Ticket #1492: hotkeys5.patch

File hotkeys5.patch, 3.5 KB (added by picobyte, 12 years ago)

This allows two actions: to follow units when unload all hotkey is pressed and to ungarrison n units. hotkey J = 1, K = 2, etc.

  • binaries/data/mods/public/gui/session/input.js

    commit fc698a3c4a64e556b20cfdf904b001987282aaeb
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Wed Jun 13 01:59:38 2012 +0200
    
        This allows two actions: to follow units when unload all hotkey is pressed
        and to ungarrison n units. hotkey J = 1, K = 2, etc.
        
        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 43cc741..eb0f140 100644
    a b const INPUT_BATCHTRAINING = 6;  
    3636const INPUT_PRESELECTEDACTION = 7;
    3737const INPUT_BUILDING_WALL_CLICK = 8;
    3838const INPUT_BUILDING_WALL_PATHING = 9;
     39const INPUT_FOLLOW_UNGARRISON = 10;
     40const INPUT_REPEATED_UNGARRISON = 11;
    3941
    4042var inputState = INPUT_NORMAL;
    4143var placementSupport = new PlacementSupport();
    function handleInputBeforeGui(ev, hoveredObject)  
    668670        mouseY = ev.y;
    669671        break;
    670672    }
    671 
     673    if (inputState == INPUT_FOLLOW_UNGARRISON)
     674    {
     675        gents = _optionsOfpreSelected;
     676        Engine.CameraFollow(0);
     677        Engine.CameraFollow(gents[0]);
     678        g_Selection.addList(gents);
     679        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();
     689    }
    672690    // Remember whether the mouse is over a GUI object or not
    673691    mouseIsOverObject = (hoveredObject != null);
    674692
    function performGroup(action, nr)  
    17251743            if (!lst) // shouldn't happen
    17261744                break;
    17271745
    1728             if (preSelectedAction & (ACTION_UNGARRISON | ACTION_GARRISON))
     1746            if (preSelectedAction & ACTION_GARRISON)
    17291747            {
    1730                 if (preSelectedAction & ACTION_GARRISON)
    1731                     ++nr;
    1732                 if (nr > lst.length)
     1748                if (++nr > lst.length)
    17331749                    nr = lst.length;
    1734             } else if (preSelectedAction != (ACTION_BUILD|ACTION_TRAIN)) {
     1750            } else if (preSelectedAction != ACTION_UNGARRISON) {
    17351751                if (nr >= lst.length)
    17361752                    break;
    17371753                lst = lst[nr];
    function performGroup(action, nr)  
    17631779                break;
    17641780            case ACTION_UNGARRISON:
    17651781                if (lst.length > 1 || nr == 0) {
     1782                    if (nr >= lst.length)
     1783                        nr = lst.length - 1;
    17661784                    if (lst.length != 1)   // TODO: uload all from all
    17671785                        lst = lst[nr]; // selected buildings
    17681786                    else
    17691787                        lst = lst[0];
    17701788                    var state = GetEntityState(lst);
    17711789                    var gents = state.garrisonHolder.entities;
     1790                    _optionsOfpreSelected = gents;
    17721791                    unloadAll(lst);
    1773                     // FIXME: follow when ungarrisoning all
    1774                     // sadly these gents cannot be viewed after ungarissoning:
    1775                     if (gents)
    1776                     {
    1777                         //Engine.CameraFollow(0);
    1778                         g_Selection.reset();
    1779                         g_Selection.addList(gents);
    1780                         Engine.CameraFollow(gents);
    1781                     }
     1792                    g_Selection.reset();
     1793                    inputState = INPUT_FOLLOW_UNGARRISON;
     1794                    break;
    17821795                } else {
    17831796                    lst = lst[0];
    17841797                    var state = GetEntityState(lst);
    17851798                    var gents = state.garrisonHolder.entities;
    1786                     // FIXME unload nr times, requires some update.
    1787                     unload(lst, gents);
     1799                    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;
    17881804                }
    17891805                break;
    17901806            case ACTION_FORMATION: