Ticket #773: groups-v18-04-2011.diff

File groups-v18-04-2011.diff, 8.8 KB (added by Badmadblacksad, 13 years ago)
  • binaries/data/mods/public/gui/session/selection.js

     
    7777    return this.groups[templateName];
    7878};
    7979
     80EntityGroups.prototype.getTotalCount = function()
     81{
     82    var totalCount = 0;
     83    for each (var group in this.groups)
     84    {
     85        totalCount += group;
     86    }
     87    return totalCount;
     88};
     89
    8090EntityGroups.prototype.getTemplateNames = function()
    8191{
    8292    var templateNames = [];
     
    323333};
    324334
    325335var g_Selection = new EntitySelection();
     336
     337//-------------------------------- -------------------------------- --------------------------------
     338// EntityGroupsContainer class for managing grouped entities
     339//-------------------------------- -------------------------------- --------------------------------
     340function EntityGroupsContainer()
     341{
     342    this.groups = {};
     343    for (var i = 0; i<10; ++i)
     344    {
     345        this.groups[i] = new EntityGroups();
     346    }
     347}
     348
     349EntityGroupsContainer.prototype.addEntities = function(groupName, ents)
     350{
     351    for each (var ent in ents)
     352    {
     353        for each (var group in this.groups)
     354        {
     355            if (ent in group.ents)
     356            {
     357                group.removeEnt(ent);
     358            }
     359        }
     360    }
     361    this.groups[groupName].add(ents);
     362}
     363
     364EntityGroupsContainer.prototype.update = function()
     365{
     366    for each (var group in this.groups)
     367    {
     368        for (var ent in group.ents)
     369        {
     370            var entState = GetEntityState(+ent);
     371
     372            // Remove deleted units
     373            if (!entState)
     374            {
     375                group.removeEnt(ent);
     376            }
     377        }
     378    }
     379}
     380
     381var g_Groups = new EntityGroupsContainer();
  • binaries/data/mods/public/gui/session/session.xml

     
    387387    </object> <!-- END OF TOP PANEL -->
    388388
    389389    <!-- ================================  ================================ -->
     390    <!-- START of GROUPS PANEL -->
     391    <!-- ================================  ================================ -->
     392    <object
     393            name="unitGroupPanel"
     394            size="0% 50%-216 0%+36 50%+144"
     395            type="image"
     396            hidden="false"
     397            ghost="false"
     398        >
     399            <object size="0 0 100% 100%">
     400                <repeat count="10">
     401                    <object name="unitGroupButton[n]" hidden="false" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" z="100">
     402                        <object name="unitGroupIcon[n]" type="image" sprite="groupsIcon" ghost="true" size="3 3 33 33"/>
     403                        <object name="unitGroupLabel[n]" ghost="true" size="0 0 100% 100%" type="text" style="largeCenteredOutlinedText"/>
     404                    </object>
     405                </repeat>
     406            </object>
     407        </object>
     408
     409    <!-- ================================  ================================ -->
    390410    <!-- Idle Worker Button -->
    391411    <!-- ================================  ================================ -->
    392412    <object type="image"
  • binaries/data/mods/public/gui/session/input.js

     
    4747// Store the previously clicked entity - ensure a double/triple click happens on the same entity
    4848var prevClickedEntity = 0;
    4949
     50//same for keyboard
     51const doublePressTime = 500;
     52var doublePressTimer = 0;
     53var prevhotkey = 0;
     54
    5055function updateCursor()
    5156{
    5257    if (!mouseIsOverObject)
     
    646651                return doAction(action, ev);
    647652            }
    648653            break;
     654        case "hotkeydown":
     655                if (ev.hotkey.indexOf("selection.group.") == 0)
     656                {
     657                    var now = new Date();
     658                    if ((now.getTime() - doublePressTimer < doublePressTime) && (ev.hotkey == prevhotkey))
     659                    {
     660                        if (ev.hotkey.indexOf("selection.group.select") == 0)
     661                        {
     662                            var sptr = ev.hotkey.split(".");
     663                            performGroup("snap", sptr[3]);
     664                        }
     665                    }
     666                    else
     667                    {
     668                        var sptr = ev.hotkey.split(".");
     669                        performGroup(sptr[2], sptr[3]);
     670
     671                        doublePressTimer = now.getTime();
     672                        prevhotkey = ev.hotkey;
     673                    }
     674                }
     675                break;
    649676        }
    650677        break;
    651678    case INPUT_PRESELECTEDACTION:
     
    10701097    }
    10711098}
    10721099
     1100// Performs the specified group
     1101function performGroup(action, groupId)
     1102{
     1103    switch (action)
     1104    {
     1105    case "snap":
     1106    case "select":
     1107            var toSelect = [];
     1108            g_Groups.update();
     1109            for (var ent in g_Groups.groups[groupId].ents)
     1110            {
     1111                toSelect.push(+ent);
     1112            }
     1113            g_Selection.reset();
     1114            if (toSelect.length)
     1115            {
     1116                g_Selection.addList(toSelect);
     1117            }
     1118            if (action == "snap")
     1119            {
     1120                Engine.CameraFollow(toSelect[0]);
     1121            }
     1122            break;
     1123    case "add":
     1124            var selection = g_Selection.toList();
     1125            g_Groups.addEntities(groupId,selection);
     1126            updateGroups();
     1127            break;
     1128    case "save":
     1129            var selection = g_Selection.toList();
     1130            g_Groups.groups[groupId].reset();
     1131            g_Groups.addEntities(groupId,selection);
     1132            updateGroups();
     1133            break;
     1134    }
     1135}
     1136
    10731137// Set the camera to follow the given unit
    10741138function setCameraFollow(entity)
    10751139{
  • binaries/data/mods/public/gui/session/session.js

     
    223223    handleNotifications();
    224224
    225225    updateMinimap(simState);
     226    updateGroups();
    226227    updateDebug(simState);
    227228    updatePlayerDisplay(simState);
    228229    updateSelectionDetails();
     
    245246    }
    246247}
    247248
     249function updateGroups()
     250{
     251    var guiName = "Group";
     252    for (i = 0; i < 10; i++)
     253    {
     254        var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
     255        var label = getGUIObjectByName("unit"+guiName+"Label["+i+"]").caption = i;
     256        g_Groups.update();
     257        if (g_Groups.groups[i].getTotalCount() == 0)
     258            button.hidden = true;
     259        else
     260            button.hidden = false;
     261        button.tooltip = "Click to select grouped units";
     262        var callback = function (i) { performGroup("select",i); };
     263        button.onpress = (function(e) { return function() { callback(e) } })(i);
     264    }
     265    var numButtons = i;
     266    var rowLength = 1;
     267    var numRows = Math.ceil(numButtons / rowLength);
     268    var buttonSideLength = getGUIObjectByName("unit"+guiName+"Button[0]").size.bottom;
     269    var buttonSpacer = buttonSideLength+1;
     270    for (var i = 0; i < numRows; i++)
     271        layoutButtonRow(i, guiName, buttonSideLength, buttonSpacer, rowLength*i, rowLength*(i+1) );
     272}
     273
    248274function updateDebug(simState)
    249275{
    250276    var debug = getGUIObjectByName("debug");
  • binaries/data/config/default.cfg

     
    131131hotkey.console.paste = "Ctrl+V"             ; Paste clipboard to console
    132132
    133133; > ENTITY SELECTION
    134 hotkey.selection.add = Shift                ; Add units to selection
    135 hotkey.selection.remove = Ctrl              ; Remove units from selection
    136 hotkey.selection.group.0 = 0
    137 hotkey.selection.group.1 = 1
    138 hotkey.selection.group.2 = 2
    139 hotkey.selection.group.3 = 3
    140 hotkey.selection.group.4 = 4
    141 hotkey.selection.group.5 = 5
    142 hotkey.selection.group.6 = 6
    143 hotkey.selection.group.7 = 7
    144 hotkey.selection.group.8 = 8
    145 hotkey.selection.group.9 = 9
    146 hotkey.selection.group.add = Shift          ; +group: Add units to group
    147 hotkey.selection.group.save = Ctrl          ; +group: Save units to group
    148 hotkey.selection.group.snap = Alt           ; +group: Check up on group
     134hotkey.selection.add = Shift                ; Add units to selection
     135hotkey.selection.remove = Ctrl              ; Remove units from selection
     136hotkey.selection.group.select.0 = 0
     137hotkey.selection.group.save.0 = "Ctrl+0"
     138hotkey.selection.group.add.0 = "Shift+0"
     139hotkey.selection.group.select.1 = 1
     140hotkey.selection.group.save.1 = "Ctrl+1"
     141hotkey.selection.group.add.1 = "Shift+1"
     142hotkey.selection.group.select.2 = 2
     143hotkey.selection.group.save.2 = "Ctrl+2"
     144hotkey.selection.group.add.2 = "Shift+2"
     145hotkey.selection.group.select.3 = 3
     146hotkey.selection.group.save.3 = "Ctrl+3"
     147hotkey.selection.group.add.3 = "Shift+3"
     148hotkey.selection.group.select.4 = 4
     149hotkey.selection.group.save.4 = "Ctrl+4"
     150hotkey.selection.group.add.4 = "Shift+4"
     151hotkey.selection.group.select.5 = 5
     152hotkey.selection.group.save.5 = "Ctrl+5"
     153hotkey.selection.group.add.5 = "Shift+5"
     154hotkey.selection.group.select.6 = 6
     155hotkey.selection.group.save.6 = "Ctrl+6"
     156hotkey.selection.group.add.6 = "Shift+6"
     157hotkey.selection.group.select.7 = 7
     158hotkey.selection.group.save.7 = "Ctrl+7"
     159hotkey.selection.group.add.7 = "Shift+7"
     160hotkey.selection.group.select.8 = 8
     161hotkey.selection.group.save.8 = "Ctrl+8"
     162hotkey.selection.group.add.8 = "Shift+8"
     163hotkey.selection.group.select.9 = 9
     164hotkey.selection.group.save.9 = "Ctrl+9"
     165hotkey.selection.group.add.9 = "Shift+9"
    149166hotkey.selection.snap = Home                ; Centre view on selection
    150167hotkey.selection.idle = Period
    151168