2012-07-19 06:45:01 +02:00
|
|
|
// Limits selection size
|
|
|
|
const MAX_SELECTION_SIZE = 200;
|
2010-10-13 21:48:13 +02:00
|
|
|
|
2012-07-19 06:45:01 +02:00
|
|
|
// Alpha value of hovered/mouseover/highlighted selection overlays
|
|
|
|
// (should probably be greater than always visible alpha value,
|
|
|
|
// see CCmpSelectable)
|
|
|
|
const HIGHLIGHTED_ALPHA = 0.75;
|
|
|
|
|
|
|
|
function _setHighlight(ents, alpha, selected)
|
2010-03-11 21:01:16 +01:00
|
|
|
{
|
2010-05-01 18:20:58 +02:00
|
|
|
if (ents.length)
|
2012-07-19 06:45:01 +02:00
|
|
|
Engine.GuiInterfaceCall("SetSelectionHighlight", { "entities":ents, "alpha":alpha, "selected":selected });
|
2010-03-11 21:01:16 +01:00
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2010-10-02 14:41:29 +02:00
|
|
|
function _setStatusBars(ents, enabled)
|
|
|
|
{
|
|
|
|
if (ents.length)
|
|
|
|
Engine.GuiInterfaceCall("SetStatusBars", { "entities":ents, "enabled":enabled });
|
|
|
|
}
|
|
|
|
|
2010-04-30 01:36:05 +02:00
|
|
|
function _setMotionOverlay(ents, enabled)
|
|
|
|
{
|
2010-05-01 18:20:58 +02:00
|
|
|
if (ents.length)
|
|
|
|
Engine.GuiInterfaceCall("SetMotionDebugOverlay", { "entities":ents, "enabled":enabled });
|
2010-04-30 01:36:05 +02:00
|
|
|
}
|
|
|
|
|
2010-08-10 03:25:24 +02:00
|
|
|
function _playSound(ent)
|
|
|
|
{
|
|
|
|
Engine.GuiInterfaceCall("PlaySound", { "name":"select", "entity":ent });
|
|
|
|
}
|
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* EntityGroups class for managing grouped entities
|
|
|
|
*/
|
2010-10-13 21:48:13 +02:00
|
|
|
function EntityGroups()
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-10-13 21:48:13 +02:00
|
|
|
this.groups = {};
|
|
|
|
this.ents = {};
|
2010-09-25 17:22:41 +02:00
|
|
|
}
|
|
|
|
|
2010-10-13 21:48:13 +02:00
|
|
|
EntityGroups.prototype.reset = function()
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-10-13 21:48:13 +02:00
|
|
|
this.groups = {};
|
|
|
|
this.ents = {};
|
2010-10-11 19:24:06 +02:00
|
|
|
};
|
|
|
|
|
2010-10-13 21:48:13 +02:00
|
|
|
EntityGroups.prototype.add = function(ents)
|
2010-10-11 19:24:06 +02:00
|
|
|
{
|
2010-10-13 21:48:13 +02:00
|
|
|
for each (var ent in ents)
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-10-13 21:48:13 +02:00
|
|
|
if (!this.ents[ent])
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-10-13 21:48:13 +02:00
|
|
|
var entState = GetEntityState(ent);
|
2012-08-07 02:41:57 +02:00
|
|
|
|
|
|
|
// When this function is called during group rebuild, deleted
|
|
|
|
// entities will not yet have been removed, so entities might
|
|
|
|
// still be present in the group despite not existing.
|
|
|
|
if (!entState)
|
|
|
|
continue;
|
|
|
|
|
2010-10-11 19:24:06 +02:00
|
|
|
var templateName = entState.template;
|
2013-04-18 20:18:24 +02:00
|
|
|
var key = GetTemplateData(templateName).selectionGroupName || templateName;
|
|
|
|
|
|
|
|
// Prefix garrisoned unit's selection name with the player they belong to
|
|
|
|
var index = templateName.indexOf("&");
|
|
|
|
if (index != -1 && key.indexOf("&") == -1)
|
|
|
|
key = templateName.slice(0, index+1) + key;
|
2013-04-14 02:34:14 +02:00
|
|
|
|
2010-11-13 06:35:40 +01:00
|
|
|
if (this.groups[key])
|
|
|
|
this.groups[key] += 1;
|
|
|
|
else
|
|
|
|
this.groups[key] = 1;
|
|
|
|
|
|
|
|
this.ents[ent] = key;
|
2010-09-25 17:22:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-13 21:48:13 +02:00
|
|
|
EntityGroups.prototype.removeEnt = function(ent)
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-11-13 06:35:40 +01:00
|
|
|
var templateName = this.ents[ent];
|
2010-10-13 21:48:13 +02:00
|
|
|
|
|
|
|
// Remove the entity
|
|
|
|
delete this.ents[ent];
|
2010-11-13 06:35:40 +01:00
|
|
|
this.groups[templateName]--;
|
2010-10-13 21:48:13 +02:00
|
|
|
|
|
|
|
// Remove the entire group
|
2010-11-13 06:35:40 +01:00
|
|
|
if (this.groups[templateName] == 0)
|
|
|
|
delete this.groups[templateName];
|
2010-09-25 17:22:41 +02:00
|
|
|
};
|
|
|
|
|
2012-07-26 00:20:57 +02:00
|
|
|
EntityGroups.prototype.rebuildGroup = function(renamed)
|
|
|
|
{
|
|
|
|
var oldGroup = this.ents;
|
|
|
|
this.reset();
|
|
|
|
|
|
|
|
var toAdd = [];
|
|
|
|
for (var ent in oldGroup)
|
2013-02-24 01:25:13 +01:00
|
|
|
toAdd.push(renamed[ent] ? renamed[ent] : +ent);
|
2012-07-26 00:20:57 +02:00
|
|
|
|
|
|
|
this.add(toAdd);
|
|
|
|
}
|
|
|
|
|
2010-11-13 06:35:40 +01:00
|
|
|
EntityGroups.prototype.getCount = function(templateName)
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-11-13 06:35:40 +01:00
|
|
|
return this.groups[templateName];
|
2010-09-25 17:22:41 +02:00
|
|
|
};
|
|
|
|
|
2011-04-26 20:19:16 +02:00
|
|
|
EntityGroups.prototype.getTotalCount = function()
|
|
|
|
{
|
|
|
|
var totalCount = 0;
|
|
|
|
for each (var group in this.groups)
|
|
|
|
{
|
|
|
|
totalCount += group;
|
|
|
|
}
|
|
|
|
return totalCount;
|
|
|
|
};
|
|
|
|
|
2010-10-13 21:48:13 +02:00
|
|
|
EntityGroups.prototype.getTemplateNames = function()
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-10-13 21:48:13 +02:00
|
|
|
var templateNames = [];
|
2010-11-13 06:35:40 +01:00
|
|
|
for (var templateName in this.groups)
|
|
|
|
templateNames.push(templateName);
|
2010-12-08 21:12:24 +01:00
|
|
|
//Preserve order even when shuffling units around
|
|
|
|
//Can be optimized by moving the sorting elsewhere
|
|
|
|
templateNames.sort();
|
2010-10-13 21:48:13 +02:00
|
|
|
return templateNames;
|
2010-09-25 17:22:41 +02:00
|
|
|
};
|
|
|
|
|
2010-11-13 06:35:40 +01:00
|
|
|
EntityGroups.prototype.getEntsByName = function(templateName)
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
2010-10-13 21:48:13 +02:00
|
|
|
var ents = [];
|
2010-11-13 06:35:40 +01:00
|
|
|
for (var ent in this.ents)
|
|
|
|
{
|
2012-05-07 06:18:54 +02:00
|
|
|
if (this.ents[ent] == templateName)
|
2013-02-24 01:25:13 +01:00
|
|
|
ents.push(+ent);
|
2010-11-13 06:35:40 +01:00
|
|
|
}
|
|
|
|
|
2010-10-13 21:48:13 +02:00
|
|
|
return ents;
|
2010-09-25 17:22:41 +02:00
|
|
|
};
|
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* Gets all ents in every group except ones of the specified group
|
|
|
|
*/
|
2010-11-13 06:35:40 +01:00
|
|
|
EntityGroups.prototype.getEntsByNameInverse = function(templateName)
|
2010-09-25 17:22:41 +02:00
|
|
|
{
|
|
|
|
var ents = [];
|
2010-11-13 06:35:40 +01:00
|
|
|
for (var ent in this.ents)
|
|
|
|
{
|
2012-05-07 06:18:54 +02:00
|
|
|
if (this.ents[ent] != templateName)
|
2013-02-24 01:25:13 +01:00
|
|
|
ents.push(+ent);
|
2010-11-13 06:35:40 +01:00
|
|
|
}
|
|
|
|
|
2010-09-25 17:22:41 +02:00
|
|
|
return ents;
|
|
|
|
};
|
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* EntitySelection class for managing the entity selection list and the primary selection
|
|
|
|
*/
|
2010-03-11 21:01:16 +01:00
|
|
|
function EntitySelection()
|
2010-01-25 23:31:43 +01:00
|
|
|
{
|
2010-05-01 18:20:58 +02:00
|
|
|
// Private properties:
|
2010-06-26 20:10:03 +02:00
|
|
|
//--------------------------------
|
2010-05-09 15:56:06 +02:00
|
|
|
this.selected = {}; // { id:id, id:id, ... } for each selected entity ID 'id'
|
2010-06-26 20:10:03 +02:00
|
|
|
|
|
|
|
// { id:id, ... } for mouseover-highlighted entity IDs in these, the key is a string and the value is an int;
|
|
|
|
// we want to use the int form wherever possible since it's more efficient to send to the simulation code)
|
|
|
|
this.highlighted = {};
|
|
|
|
|
2010-04-30 01:36:05 +02:00
|
|
|
this.motionDebugOverlay = false;
|
2010-05-01 18:20:58 +02:00
|
|
|
|
|
|
|
// Public properties:
|
2010-06-26 20:10:03 +02:00
|
|
|
//--------------------------------
|
2010-05-01 18:20:58 +02:00
|
|
|
this.dirty = false; // set whenever the selection has changed
|
2010-10-13 21:48:13 +02:00
|
|
|
this.groups = new EntityGroups();
|
2010-01-25 23:31:43 +01:00
|
|
|
}
|
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* Deselect everything but entities of the chosen type if the modifier is true otherwise deselect just the chosen entity
|
|
|
|
*/
|
2010-11-13 06:35:40 +01:00
|
|
|
EntitySelection.prototype.makePrimarySelection = function(templateName, modifierKey)
|
2010-07-19 23:23:12 +02:00
|
|
|
{
|
2010-07-31 00:19:43 +02:00
|
|
|
var selection = this.toList();
|
2012-06-10 04:39:16 +02:00
|
|
|
|
2010-11-13 06:35:40 +01:00
|
|
|
var template = GetTemplateData(templateName);
|
|
|
|
var key = template.selectionGroupName || templateName;
|
2010-09-25 17:22:41 +02:00
|
|
|
|
|
|
|
var ents = [];
|
|
|
|
if (modifierKey)
|
2010-11-13 06:35:40 +01:00
|
|
|
ents = this.groups.getEntsByNameInverse(key);
|
2010-06-26 20:10:03 +02:00
|
|
|
else
|
2010-11-13 06:35:40 +01:00
|
|
|
ents = this.groups.getEntsByName(key);
|
2010-09-25 17:22:41 +02:00
|
|
|
|
2010-07-31 00:19:43 +02:00
|
|
|
this.reset();
|
|
|
|
this.addList(ents);
|
|
|
|
}
|
2010-06-26 20:10:03 +02:00
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* Get a list of the template names
|
|
|
|
*/
|
2010-07-31 00:19:43 +02:00
|
|
|
EntitySelection.prototype.getTemplateNames = function()
|
2010-06-26 20:10:03 +02:00
|
|
|
{
|
2010-07-31 00:19:43 +02:00
|
|
|
var templateNames = [];
|
|
|
|
var ents = this.toList();
|
|
|
|
|
|
|
|
for each (var ent in ents)
|
|
|
|
{
|
2010-08-28 23:12:52 +02:00
|
|
|
var entState = GetEntityState(ent);
|
2010-07-31 00:19:43 +02:00
|
|
|
if (entState)
|
|
|
|
templateNames.push(entState.template);
|
|
|
|
}
|
|
|
|
return templateNames;
|
|
|
|
}
|
2010-06-26 20:10:03 +02:00
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* Update the selection to take care of changes (like units that have been killed)
|
|
|
|
*/
|
2010-08-01 18:25:24 +02:00
|
|
|
EntitySelection.prototype.update = function()
|
2010-07-04 03:03:14 +02:00
|
|
|
{
|
2011-05-02 17:03:01 +02:00
|
|
|
this.checkRenamedEntities();
|
2010-07-31 00:19:43 +02:00
|
|
|
for each (var ent in this.selected)
|
2010-07-04 03:03:14 +02:00
|
|
|
{
|
2010-08-28 23:12:52 +02:00
|
|
|
var entState = GetEntityState(ent);
|
2010-10-13 21:48:13 +02:00
|
|
|
|
2010-10-05 02:08:05 +02:00
|
|
|
// Remove deleted units
|
2010-07-04 03:03:14 +02:00
|
|
|
if (!entState)
|
|
|
|
{
|
2013-04-14 02:34:14 +02:00
|
|
|
delete this.selected[ent];
|
2010-10-13 21:48:13 +02:00
|
|
|
this.groups.removeEnt(ent);
|
|
|
|
this.dirty = true;
|
2010-10-05 02:08:05 +02:00
|
|
|
continue;
|
|
|
|
}
|
2010-10-13 21:48:13 +02:00
|
|
|
|
2010-10-05 02:08:05 +02:00
|
|
|
// Remove non-visible units (e.g. moved back into fog-of-war)
|
|
|
|
if (entState.visibility == "hidden")
|
|
|
|
{
|
|
|
|
// Disable any highlighting of the disappeared unit
|
2012-07-19 06:45:01 +02:00
|
|
|
_setHighlight([ent], 0, false);
|
2010-10-05 02:08:05 +02:00
|
|
|
_setStatusBars([ent], false);
|
|
|
|
_setMotionOverlay([ent], false);
|
|
|
|
|
|
|
|
delete this.selected[ent];
|
2012-08-14 16:02:52 +02:00
|
|
|
this.groups.removeEnt(ent);
|
2010-10-13 21:48:13 +02:00
|
|
|
this.dirty = true;
|
2010-10-05 02:08:05 +02:00
|
|
|
continue;
|
2010-07-04 03:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-02 17:03:01 +02:00
|
|
|
/**
|
2011-08-31 00:29:03 +02:00
|
|
|
* Update selection if some selected entities were renamed
|
2011-05-02 17:03:01 +02:00
|
|
|
* (in case of unit promotion or finishing building structure)
|
|
|
|
*/
|
|
|
|
EntitySelection.prototype.checkRenamedEntities = function()
|
|
|
|
{
|
2011-08-31 00:29:03 +02:00
|
|
|
var renamedEntities = Engine.GuiInterfaceCall("GetRenamedEntities");
|
2011-05-02 17:03:01 +02:00
|
|
|
if (renamedEntities.length > 0)
|
|
|
|
{
|
2012-07-26 00:20:57 +02:00
|
|
|
var renamedLookup = {};
|
|
|
|
for each (var renamedEntity in renamedEntities)
|
|
|
|
renamedLookup[renamedEntity.entity] = renamedEntity.newentity;
|
|
|
|
|
|
|
|
// Reconstruct the selection if at least one entity has been renamed.
|
2011-05-02 17:03:01 +02:00
|
|
|
for each (var renamedEntity in renamedEntities)
|
|
|
|
{
|
|
|
|
if (this.selected[renamedEntity.entity])
|
|
|
|
{
|
2012-07-26 00:20:57 +02:00
|
|
|
this.rebuildSelection(renamedLookup);
|
|
|
|
break;
|
2011-05-02 17:03:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* Add entities to selection. Play selection sound unless quiet is true
|
|
|
|
*/
|
|
|
|
EntitySelection.prototype.addList = function(ents, quiet)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2012-04-21 22:50:07 +02:00
|
|
|
var selection = this.toList();
|
|
|
|
var playerID = Engine.GetPlayerID();
|
|
|
|
|
|
|
|
// If someone else's player is the sole selected unit, don't allow adding to the selection
|
|
|
|
if (!g_DevSettings.controlAll && selection.length == 1)
|
|
|
|
{
|
|
|
|
var firstEntState = GetEntityState(selection[0]);
|
|
|
|
if (firstEntState && firstEntState.player != playerID)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow selecting things not belong to this player (enemy, ally, gaia)
|
|
|
|
var allowUnownedSelect = g_DevSettings.controlAll || (ents.length == 1 && selection.length == 0);
|
|
|
|
|
2010-10-13 21:48:13 +02:00
|
|
|
var i = 1;
|
2010-03-11 21:01:16 +01:00
|
|
|
var added = [];
|
2010-10-13 21:48:13 +02:00
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
for each (var ent in ents)
|
|
|
|
{
|
2011-07-02 02:06:39 +02:00
|
|
|
// Only add entities we own to our selection
|
|
|
|
var entState = GetEntityState(ent);
|
2012-04-21 22:50:07 +02:00
|
|
|
if (!this.selected[ent] && (selection.length + i) <= MAX_SELECTION_SIZE && (allowUnownedSelect || (entState && entState.player == playerID)))
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2010-03-11 21:01:16 +01:00
|
|
|
added.push(ent);
|
2010-05-09 15:56:06 +02:00
|
|
|
this.selected[ent] = ent;
|
2010-10-13 21:48:13 +02:00
|
|
|
i++;
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
}
|
2010-10-13 21:48:13 +02:00
|
|
|
|
2012-07-19 06:45:01 +02:00
|
|
|
_setHighlight(added, 1, true);
|
2010-10-02 14:41:29 +02:00
|
|
|
_setStatusBars(added, true);
|
2010-04-30 01:36:05 +02:00
|
|
|
_setMotionOverlay(added, this.motionDebugOverlay);
|
2010-08-10 03:25:24 +02:00
|
|
|
if (added.length)
|
2012-08-30 04:02:59 +02:00
|
|
|
{
|
|
|
|
// Play the sound if the entity is controllable by us or Gaia-owned.
|
|
|
|
var owner = GetEntityState(added[0]).player;
|
2012-12-10 22:35:52 +01:00
|
|
|
if (!quiet && (owner == playerID || owner == 0 || g_DevSettings.controlAll))
|
2012-08-30 04:02:59 +02:00
|
|
|
_playSound(added[0]);
|
|
|
|
}
|
2010-10-13 21:48:13 +02:00
|
|
|
|
2010-10-11 19:24:06 +02:00
|
|
|
this.groups.add(this.toList()); // Create Selection Groups
|
2010-05-01 18:20:58 +02:00
|
|
|
this.dirty = true;
|
2010-03-11 21:01:16 +01:00
|
|
|
};
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2010-11-07 21:42:52 +01:00
|
|
|
EntitySelection.prototype.removeList = function(ents)
|
|
|
|
{
|
|
|
|
var removed = [];
|
|
|
|
|
|
|
|
for each (var ent in ents)
|
|
|
|
{
|
|
|
|
if (this.selected[ent])
|
|
|
|
{
|
|
|
|
this.groups.removeEnt(ent);
|
|
|
|
removed.push(ent);
|
|
|
|
delete this.selected[ent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 06:45:01 +02:00
|
|
|
_setHighlight(removed, 0, false);
|
2010-11-07 21:42:52 +01:00
|
|
|
_setStatusBars(removed, false);
|
|
|
|
_setMotionOverlay(removed, false);
|
|
|
|
|
|
|
|
this.dirty = true;
|
|
|
|
};
|
|
|
|
|
2010-03-11 21:01:16 +01:00
|
|
|
EntitySelection.prototype.reset = function()
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2012-07-19 06:45:01 +02:00
|
|
|
_setHighlight(this.toList(), 0, false);
|
2010-10-02 14:41:29 +02:00
|
|
|
_setStatusBars(this.toList(), false);
|
2010-04-30 01:36:05 +02:00
|
|
|
_setMotionOverlay(this.toList(), false);
|
2010-03-11 21:01:16 +01:00
|
|
|
this.selected = {};
|
2010-10-11 19:24:06 +02:00
|
|
|
this.groups.reset();
|
2010-05-01 18:20:58 +02:00
|
|
|
this.dirty = true;
|
2010-03-11 21:01:16 +01:00
|
|
|
};
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2012-07-26 00:20:57 +02:00
|
|
|
EntitySelection.prototype.rebuildSelection = function(renamed)
|
|
|
|
{
|
|
|
|
var oldSelection = this.selected;
|
2013-11-03 18:41:59 +01:00
|
|
|
this.reset();
|
2012-07-26 00:20:57 +02:00
|
|
|
|
|
|
|
var toAdd = [];
|
|
|
|
for each (var ent in oldSelection)
|
|
|
|
toAdd.push(renamed[ent] ? renamed[ent] : ent);
|
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
this.addList(toAdd, true); // don't play selection sounds
|
2012-07-26 00:20:57 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
EntitySelection.prototype.toList = function(){
|
2010-01-09 20:20:14 +01:00
|
|
|
var ents = [];
|
2010-05-09 15:56:06 +02:00
|
|
|
for each (var ent in this.selected)
|
|
|
|
ents.push(ent);
|
2010-01-09 20:20:14 +01:00
|
|
|
return ents;
|
2010-03-11 21:01:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
EntitySelection.prototype.setHighlightList = function(ents)
|
|
|
|
{
|
2010-10-02 14:41:29 +02:00
|
|
|
var highlighted = {};
|
|
|
|
for each (var ent in ents)
|
|
|
|
highlighted[ent] = ent;
|
|
|
|
|
2010-03-11 21:01:16 +01:00
|
|
|
var removed = [];
|
|
|
|
var added = [];
|
|
|
|
|
2010-10-02 14:41:29 +02:00
|
|
|
// Remove highlighting for the old units that are no longer highlighted
|
|
|
|
// (excluding ones that are actively selected too)
|
2010-05-09 15:56:06 +02:00
|
|
|
for each (var ent in this.highlighted)
|
2010-10-02 14:41:29 +02:00
|
|
|
if (!highlighted[ent] && !this.selected[ent])
|
|
|
|
removed.push(+ent);
|
2010-03-11 21:01:16 +01:00
|
|
|
|
2010-10-02 14:41:29 +02:00
|
|
|
// Add new highlighting for units that aren't already highlighted
|
2010-03-11 21:01:16 +01:00
|
|
|
for each (var ent in ents)
|
2010-10-02 14:41:29 +02:00
|
|
|
if (!this.highlighted[ent] && !this.selected[ent])
|
|
|
|
added.push(+ent);
|
2010-03-11 21:01:16 +01:00
|
|
|
|
2012-07-19 06:45:01 +02:00
|
|
|
_setHighlight(removed, 0, false);
|
2010-10-02 14:41:29 +02:00
|
|
|
_setStatusBars(removed, false);
|
2010-03-11 21:01:16 +01:00
|
|
|
|
2012-07-19 06:45:01 +02:00
|
|
|
_setHighlight(added, HIGHLIGHTED_ALPHA, true);
|
2010-10-02 14:41:29 +02:00
|
|
|
_setStatusBars(added, true);
|
2010-03-11 21:01:16 +01:00
|
|
|
|
2010-10-02 14:41:29 +02:00
|
|
|
// Store the new highlight list
|
|
|
|
this.highlighted = highlighted;
|
2010-03-11 21:01:16 +01:00
|
|
|
};
|
|
|
|
|
2010-04-30 01:36:05 +02:00
|
|
|
EntitySelection.prototype.SetMotionDebugOverlay = function(enabled)
|
|
|
|
{
|
|
|
|
this.motionDebugOverlay = enabled;
|
|
|
|
_setMotionOverlay(this.toList(), enabled);
|
|
|
|
};
|
2010-03-11 21:01:16 +01:00
|
|
|
|
|
|
|
var g_Selection = new EntitySelection();
|
2011-04-26 20:19:16 +02:00
|
|
|
|
2012-12-10 22:35:52 +01:00
|
|
|
/**
|
|
|
|
* EntityGroupsContainer class for managing grouped entities
|
|
|
|
*/
|
2011-04-26 20:19:16 +02:00
|
|
|
function EntityGroupsContainer()
|
|
|
|
{
|
2012-05-07 06:18:54 +02:00
|
|
|
this.groups = [];
|
2011-04-26 20:19:16 +02:00
|
|
|
for (var i = 0; i < 10; ++i)
|
|
|
|
{
|
|
|
|
this.groups[i] = new EntityGroups();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityGroupsContainer.prototype.addEntities = function(groupName, ents)
|
|
|
|
{
|
|
|
|
for each (var ent in ents)
|
|
|
|
{
|
|
|
|
for each (var group in this.groups)
|
|
|
|
{
|
|
|
|
if (ent in group.ents)
|
|
|
|
{
|
|
|
|
group.removeEnt(ent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.groups[groupName].add(ents);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityGroupsContainer.prototype.update = function()
|
|
|
|
{
|
2011-08-31 00:29:03 +02:00
|
|
|
this.checkRenamedEntities();
|
2011-04-26 20:19:16 +02:00
|
|
|
for each (var group in this.groups)
|
|
|
|
{
|
|
|
|
for (var ent in group.ents)
|
|
|
|
{
|
|
|
|
var entState = GetEntityState(+ent);
|
|
|
|
|
|
|
|
// Remove deleted units
|
|
|
|
if (!entState)
|
|
|
|
{
|
|
|
|
group.removeEnt(ent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-31 00:29:03 +02:00
|
|
|
/**
|
|
|
|
* Update control group if some entities in the group were renamed
|
|
|
|
* (in case of unit promotion or finishing building structure)
|
|
|
|
*/
|
|
|
|
EntityGroupsContainer.prototype.checkRenamedEntities = function()
|
|
|
|
{
|
|
|
|
var renamedEntities = Engine.GuiInterfaceCall("GetRenamedEntities");
|
|
|
|
if (renamedEntities.length > 0)
|
|
|
|
{
|
2012-07-26 00:20:57 +02:00
|
|
|
var renamedLookup = {};
|
|
|
|
for each (var renamedEntity in renamedEntities)
|
|
|
|
renamedLookup[renamedEntity.entity] = renamedEntity.newentity;
|
|
|
|
|
2011-08-31 00:29:03 +02:00
|
|
|
for each (var group in this.groups)
|
|
|
|
{
|
|
|
|
for each (var renamedEntity in renamedEntities)
|
|
|
|
{
|
2012-07-26 00:20:57 +02:00
|
|
|
// Reconstruct the group if at least one entity has been renamed.
|
2011-08-31 00:29:03 +02:00
|
|
|
if (renamedEntity.entity in group.ents)
|
|
|
|
{
|
2012-07-26 00:20:57 +02:00
|
|
|
group.rebuildGroup(renamedLookup);
|
|
|
|
break;
|
2011-08-31 00:29:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-26 20:19:16 +02:00
|
|
|
var g_Groups = new EntityGroupsContainer();
|