1
0
forked from 0ad/0ad

Fixed the GUI selection issue where killed units were not being removed from the selection or the selection display

This was SVN commit r7683.
This commit is contained in:
WhiteTreePaladin 2010-07-04 01:03:14 +00:00
parent 56b836f58d
commit 3af3cbe99a
5 changed files with 69 additions and 30 deletions

View File

@ -249,25 +249,8 @@ function handleInputBeforeGui(ev)
g_Selection.reset();
g_Selection.addList(ents);
// Make selection groups
var j = 0;
for (var i = 0; i < ents.length; i++)
{
var template = Engine.GuiInterfaceCall("GetEntityState", ents[i]).template;
if (!g_Selection.groups.groupTypeCount[template])
{
g_Selection.groups.groupTypeCount[template] = 1;
g_Selection.groups.firstOfType[template] = i;
g_Selection.groups.groupTemplates.push(template);
g_Selection.groups.groupNumbers[template] = j;
j++;
}
else if (g_Selection.groups.groupTypeCount[template])
{
g_Selection.groups.groupTypeCount[template] += 1;
}
}
// Create the selection groups
g_Selection.createSelectionGroups(ents);
// turn on unit highlight for first unit in selection
getGUIObjectByName("unitSelectionHighlight[0]").hidden = false;

View File

@ -22,8 +22,8 @@ function EntityGroups()
this.primary = 0;
this.groupNumbers = {};
this.firstOfType = {}; // array for holding index to first appearance of a specific unit type in g_Selection
this.groupTypeCount = {}; // format { name:count, name:count, ... } - maps units to the currently selected quantity of that type
this.groupTemplates = [];
this.typeCount = {}; // format { name:count, name:count, ... } - maps units to the currently selected quantity of that type
this.templates = [];
}
EntityGroups.prototype.reset = function()
@ -32,8 +32,8 @@ EntityGroups.prototype.reset = function()
this.primary = 0;
this.groupNumbers = {};
this.firstOfType = {};
this.groupTypeCount = {};
this.groupTemplates = [];
this.typeCount = {};
this.templates = [];
};
//-------------------------------- -------------------------------- --------------------------------
@ -76,6 +76,60 @@ EntitySelection.prototype.resetPrimary = function()
this.primary = 0; // the primary selection must be reset whenever the selection changes
};
// Make the selection groups for the selection display buttons
EntitySelection.prototype.createSelectionGroups = function(ents)
{
// Erase old selection first
this.groups.reset();
// Make selection groups
var j = 0;
for (var i = 0; i < ents.length; i++)
{
var template = Engine.GuiInterfaceCall("GetEntityState", ents[i]).template;
if (!this.groups.typeCount[template])
{
this.groups.typeCount[template] = 1;
this.groups.firstOfType[template] = i;
this.groups.templates.push(template);
this.groups.groupNumbers[template] = j;
j++;
}
else if (this.groups.typeCount[template])
{
this.groups.typeCount[template] += 1;
}
}
};
// Update the selection to take care of changes (like units that have been killed)
EntitySelection.prototype.updateSelection = function()
{
var numberRemoved = 0;
var i = 0;
for each (var unit in this.selected)
{
var entState = Engine.GuiInterfaceCall("GetEntityState", unit);
if (!entState)
{
delete this.selected[unit];
numberRemoved++;
}
i++;
}
if (numberRemoved > 0)
{
this.dirty = true;
this.createSelectionGroups(g_Selection.toList());
getGUIObjectByName("unitSelectionHighlight[0]").hidden = false;
}
};
EntitySelection.prototype.toggle = function(ent)
{
if (this.selected[ent])

View File

@ -153,11 +153,7 @@ function updateSelectionDetails(simState)
also need to handle multi-unit selections) */
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[g_Selection.getPrimary()]);
if (!entState)
{
detailsPanel.hidden = true;
commandsPanel.hidden = true;
return;
}
var playerState = simState.players[entState.player];
if (!playerState)

View File

@ -111,6 +111,7 @@ function onSimulationUpdate()
updateDebug(simState);
updatePlayerDisplay(simState);
updateSelection();
updateSelectionDetails(simState);
}
@ -158,6 +159,11 @@ function updatePlayerDisplay(simState)
getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit;
}
function updateSelection()
{
g_Selection.updateSelection();
}
//-------------------------------- -------------------------------- --------------------------------
// Utility functions
//-------------------------------- -------------------------------- --------------------------------

View File

@ -59,9 +59,9 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
if (guiName == "Selection")
{
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption =
(g_Selection.groups.groupTypeCount[item] > 1 ? g_Selection.groups.groupTypeCount[item] : "");
(g_Selection.groups.typeCount[item] > 1 ? g_Selection.groups.typeCount[item] : "");
tooltip += (g_Selection.groups.groupTypeCount[item] > 1 ? " (" + g_Selection.groups.groupTypeCount[item] + ")" : "")
tooltip += (g_Selection.groups.typeCount[item] > 1 ? " (" + g_Selection.groups.typeCount[item] + ")" : "")
}
else if (guiName == "Queue")
{
@ -173,7 +173,7 @@ function updateUnitCommands(playerState, entState, commandsPanel, selection)
function (item) { removeFromTrainingQueue(entState.id, item.id); } );
if (selection.length > 1)
setupUnitPanel("Selection", usedPanels, playerState, entState, g_Selection.groups.groupTemplates,
setupUnitPanel("Selection", usedPanels, playerState, entState, g_Selection.groups.templates,
function (entType) { changePrimarySelectionGroup(entType); } );
// Stamina