Ticket #1492: hotkeys4.patch

File hotkeys4.patch, 4.7 KB (added by picobyte, 12 years ago)

Allows hotkeys shift ./,/U/I/O/P to slect all idle villagers/warriors or building types (with my previous patch)

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

    commit 0e369958e9c17997d7e77c3e2aae28c5971ff7a0
    Author: Roel Kluin <roel.kluin@gmail.com>
    Date:   Tue Jun 12 01:24:00 2012 +0200
    
        Find all visible idle workers,warriors,buildings with Shift ./,/U/etc
        
        revert behavior and leave view to garrisonholder as the ungarrisoned
        cannot be followed.
        
        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 24f32a5..43cc741 100644
    a b function performGroup(action, nr)  
    17671767                        lst = lst[nr]; // selected buildings
    17681768                    else
    17691769                        lst = lst[0];
    1770                     // FIXME: follow when ungarrisoning all
    17711770                    var state = GetEntityState(lst);
    17721771                    var gents = state.garrisonHolder.entities;
    17731772                    unloadAll(lst);
    1774                     Engine.CameraFollow(0);
    1775                     g_Selection.reset();
    1776                     g_Selection.addList(gents);
    1777                     Engine.CameraFollow(gents[0]);
     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                    }
    17781782                } else {
    17791783                    lst = lst[0];
    17801784                    var state = GetEntityState(lst);
    function resetEntitySearch()  
    18471851    currEntClass = 0;
    18481852}
    18491853
     1854function findAllVisibleEntities(classes, mode)
     1855{
     1856    var player = Engine.GetPlayerID();
     1857    var plEnts = Engine.PickFriendlyEntitiesOnScreen(player);
     1858    // Or we could do somthing alike the below, but this is resolution dependent
     1859    //var plEnts = Engine.PickFriendlyEntitiesInRect(250, 250, 1400, 750, player);
     1860    if (!plEnts.length)
     1861        return;
     1862    var visibleEnts = [];
     1863    for each (cls in classes)
     1864    {
     1865        var data = {
     1866            entClass: cls,
     1867            searchMode: mode,
     1868            playerEnts: plEnts,
     1869        };
     1870        var entities = Engine.GuiInterfaceCall("SubsetMatchedEnts", data);
     1871        if (entities.length)
     1872            visibleEnts = visibleEnts.concat(entities);
     1873    }
     1874
     1875    if (visibleEnts.length) {
     1876        if (!getActionForSelection(player, visibleEnts).length)
     1877            resetPreselectedAction();
     1878        g_Selection.reset();
     1879        g_Selection.addList(visibleEnts);
     1880        Engine.CameraFollow(visibleEnts[0]);
     1881    }
     1882}
     1883
    18501884function findEntity(classes, mode)
    18511885{
     1886    var queued = Engine.HotkeyIsPressed("session.queue");
     1887    if (queued) {
     1888        findAllVisibleEntities(classes, mode)
     1889        return;
     1890    }
    18521891    var player = Engine.GetPlayerID();
    18531892    // Cycle through idling classes before giving up
    18541893    for (var i = 0; i <= classes.length; ++i)
  • binaries/data/mods/public/simulation/components/GuiInterface.js

    diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js
    index a2c29ba..6fd71d9 100644
    a b GuiInterface.prototype.PlaySound = function(player, data)  
    14261426    PlaySound(data.name, data.entity);
    14271427};
    14281428
     1429GuiInterface.prototype.MatchEnt = function(ent, data)
     1430{
     1431    var ret;
     1432    var cmpId = Engine.QueryInterface(ent, IID_Identity);
     1433    if (cmpId && cmpId.HasClass(data.entClass)) {
     1434        if (data.searchMode == 0) {
     1435            ret = ent;
     1436        }  else if (data.searchMode == 1) { // Search idle villager/soldier
     1437            var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
     1438            if (cmpUnitAI && cmpUnitAI.IsIdle() && !cmpUnitAI.IsGarrisoned())
     1439                ret = ent;
     1440        }
     1441    }
     1442    return ret;
     1443}
     1444
     1445GuiInterface.prototype.SubsetMatchedEnts = function(player, data)
     1446{
     1447    var ret = [];
     1448    for each (var ent in data.playerEnts)
     1449    {
     1450        var match = this.MatchEnt(ent, data);
     1451        if (match)
     1452            ret.push(match);
     1453    }
     1454    return ret;
     1455}
     1456
    14291457GuiInterface.prototype.FindEntity = function(player, data)
    14301458{
    14311459    var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    GuiInterface.prototype.FindEntity = function(player, data)  
    14351463    // so that we cycle around in a predictable order
    14361464    for each (var ent in playerEntities)
    14371465    {
    1438         var cmpId = Engine.QueryInterface(ent, IID_Identity);
    1439         if (ent > data.prevEntity && cmpId && cmpId.HasClass(data.entClass)) {
    1440             if (data.searchMode == 0) {
    1441                 return ent;
    1442             }  else if (data.searchMode == 1) { // Search idle villager/soldier
    1443                 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
    1444                 if (cmpUnitAI && cmpUnitAI.IsIdle() && !cmpUnitAI.IsGarrisoned())
    1445                     return ent;
    1446             }
     1466        if (ent > data.prevEntity)
     1467        {
     1468            var match = this.MatchEnt(ent, data);
     1469            if (match)
     1470                return match;
    14471471        }
    14481472    }
    14491473
    var exposedFunctions = {  
    15701594    "SetWallPlacementPreview": 1,
    15711595    "GetFoundationSnapData": 1,
    15721596    "PlaySound": 1,
     1597    "SubsetMatchedEnts": 1,
    15731598    "FindEntity": 1,
    15741599    "GetTradingDetails": 1,
    15751600    "CanAttack": 1,