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

File groups-v08-04-2011.diff, 9.2 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["group-"+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            for (var gent in group.ents)
     356            {
     357                if (ent == gent)
     358                {
     359                    group.removeEnt(ent);
     360                }
     361            }
     362        }
     363    }
     364    this.groups[groupName].add(ents);
     365}
     366
     367EntityGroupsContainer.prototype.update = function()
     368{
     369    for each (var group in this.groups)
     370    {
     371        for (var ent in group.ents)
     372        {
     373            var entState = GetEntityState(parseInt(ent));
     374
     375            // Remove deleted units
     376            if (!entState)
     377            {
     378                group.removeEnt(ent);
     379            }
     380        }
     381    }
     382}
     383
     384var g_Groups = new EntityGroupsContainer();
  • binaries/data/mods/public/gui/session/session.xml

     
    7979            <action on="Press">performCommand(g_Selection.toList()[0], "delete");</action>
    8080        </object>
    8181
     82        <object hotkey="selection.group.0">
     83            <action on="Press">performGroup("group-0");</action>
     84        </object>
     85        <object hotkey="selection.group.1">
     86            <action on="Press">performGroup("group-1");</action>
     87        </object>
     88        <object hotkey="selection.group.2">
     89            <action on="Press">performGroup("group-2");</action>
     90        </object>
     91        <object hotkey="selection.group.3">
     92            <action on="Press">performGroup("group-3");</action>
     93        </object>
     94        <object hotkey="selection.group.4">
     95            <action on="Press">performGroup("group-4");</action>
     96        </object>
     97        <object hotkey="selection.group.5">
     98            <action on="Press">performGroup("group-5");</action>
     99        </object>
     100        <object hotkey="selection.group.6">
     101            <action on="Press">performGroup("group-6");</action>
     102        </object>
     103        <object hotkey="selection.group.7">
     104            <action on="Press">performGroup("group-7");</action>
     105        </object>
     106        <object hotkey="selection.group.8">
     107            <action on="Press">performGroup("group-8");</action>
     108        </object>
     109        <object hotkey="selection.group.9">
     110            <action on="Press">performGroup("group-9");</action>
     111        </object>
     112
    82113        <!-- camera.follow mode - follow the first unit in the selection -->
    83114        <object hotkey="camera.follow">
    84115            <action on="Press">setCameraFollow(g_Selection.toList()[0]);</action>
     
    387418    </object> <!-- END OF TOP PANEL -->
    388419
    389420    <!-- ================================  ================================ -->
     421    <!-- START of GROUPS PANEL -->
     422    <!-- ================================  ================================ -->
     423    <object
     424            name="unitGroupPanel"
     425            size="0% 50%-216 0%+36 50%+144"
     426            type="image"
     427            hidden="false"
     428            ghost="false"
     429        >
     430            <object size="0 0 100% 100%">
     431                <repeat count="10">
     432                    <object name="unitGroupButton[n]" hidden="false" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" z="100">
     433                        <object name="unitGroupIcon[n]" type="image" style="groupIcon" ghost="true" size="3 3 33 33"/>
     434                    </object>
     435                </repeat>
     436            </object>
     437        </object>
     438
     439    <!-- ================================  ================================ -->
    390440    <!-- Idle Worker Button -->
    391441    <!-- ================================  ================================ -->
    392442    <object type="image"
  • binaries/data/mods/public/gui/session/styles.xml

     
    123123        ghost="true"
    124124    />
    125125
     126    <style name="groupIcon"
     127        sprite="group"
     128        ghost="true"
     129    />
     130
    126131    <style name="commandIcon"
    127132        sprite="commands"
    128133        ghost="true"
  • binaries/data/mods/public/gui/session/utility_functions.js

     
    291291    return formations;
    292292}
    293293
     294function getGroupList()
     295{
     296    var groups = [];
     297
     298    groups.push("group-0");
     299    groups.push("group-1");
     300    groups.push("group-2");
     301    groups.push("group-3");
     302    groups.push("group-4");
     303    groups.push("group-5");
     304    groups.push("group-6");
     305    groups.push("group-7");
     306    groups.push("group-8");
     307    groups.push("group-9");
     308    return groups;
     309}
     310
    294311function getEntityCommandsList(entState)
    295312{
    296313    var commands = [];
  • binaries/data/mods/public/gui/session/sprites.xml

     
    1717        />
    1818    </sprite>
    1919
     20    <sprite name="group">
     21        <image
     22            texture="session/icons/sheets/groups.png"
     23            cell_size="64 64"
     24            size="0 0 100% 100%"
     25        />
     26    </sprite>
     27
    2028    <!-- ================================  ================================ -->
    2129    <!-- Unit Command Icons -->
    2230    <!-- ================================  ================================ -->
  • binaries/data/mods/public/gui/session/input.js

     
    10701070    }
    10711071}
    10721072
     1073// Performs the specified group
     1074function performGroup(groupName)
     1075{
     1076    console.write(groupName);
     1077
     1078    if (Engine.HotkeyIsPressed("selection.group.save"))
     1079    {
     1080        var selection = g_Selection.toList();
     1081        g_Groups.groups[groupName].reset();
     1082        g_Groups.addEntities(groupName,selection);
     1083    }
     1084    else if (Engine.HotkeyIsPressed("selection.group.add"))
     1085    {
     1086        var selection = g_Selection.toList();
     1087        g_Groups.addEntities(groupName,selection);
     1088    }
     1089    else
     1090    {
     1091        var toSelect = [];
     1092        g_Groups.update();
     1093        for (var ent in g_Groups.groups[groupName].ents)
     1094        {
     1095            toSelect.push(parseInt(ent));
     1096        }
     1097        g_Selection.reset();
     1098        if (toSelect.length)
     1099        {
     1100            g_Selection.addList(toSelect);
     1101            if (Engine.HotkeyIsPressed("selection.group.snap"))
     1102            {
     1103                //@todo snap
     1104            }
     1105        }
     1106    }
     1107}
     1108
    10731109// Set the camera to follow the given unit
    10741110function setCameraFollow(entity)
    10751111{
  • 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 groups = getGroupList();
     252    var numberOfItems = groups.length;
     253    var guiName = "Group";
     254    for (i = 0; i < numberOfItems; i++)
     255    {
     256        var item = groups[i];
     257        var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
     258        var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
     259        g_Groups.update();
     260        if (g_Groups.groups["group-"+i].getTotalCount() == 0)
     261            button.hidden = true;
     262        else
     263            button.hidden = false;
     264        button.tooltip = toTitleCase(item);
     265        var callback = function (item) { performGroup(item); };
     266        button.onpress = (function(e) { return function() { callback(e) } })(item);
     267        icon.cell_id = i;
     268        icon.enabled = false;
     269        if (!icon.enabled)
     270            icon.sprite = "group";
     271    }
     272    var numButtons = i;
     273    var rowLength = 1;
     274    var numRows = Math.ceil(numButtons / rowLength);
     275    var buttonSideLength = getGUIObjectByName("unit"+guiName+"Button[0]").size.bottom;
     276    var buttonSpacer = buttonSideLength+1;
     277    for (var i = 0; i < numRows; i++)
     278        layoutButtonRow(i, guiName, buttonSideLength, buttonSpacer, rowLength*i, rowLength*(i+1) );
     279}
     280
    248281function updateDebug(simState)
    249282{
    250283    var debug = getGUIObjectByName("debug");