1
0
forked from 0ad/0ad

Added working delete button

This was SVN commit r7832.
This commit is contained in:
WhiteTreePaladin 2010-08-01 05:09:30 +00:00
parent dd2fcad2a2
commit aa2d305b6e
6 changed files with 97 additions and 40 deletions

View File

@ -913,7 +913,7 @@
/> />
</sprite> </sprite>
<sprite name="snIconSheetCommandDisabled"> <sprite name="snIconSheetCommandDisabled">
<effect grayscale=""/>
<image texture="session/icons/sheets/command.dds" <image texture="session/icons/sheets/command.dds"
cell_size="64 64" cell_size="64 64"
size="0 0 100% 100%" size="0 0 100% 100%"

View File

@ -622,3 +622,16 @@ function changePrimarySelectionGroup(index)
else else
g_Selection.makePrimarySelection(index, false); g_Selection.makePrimarySelection(index, false);
} }
// Performs the specified command
function performCommand(entity, commandName)
{
switch (commandName)
{
case "delete":
Engine.PostNetworkCommand({"type": "delete-entity", "entity": entity});
break;
default:
break;
}
}

View File

@ -231,7 +231,7 @@
<object <object
name="mapAndResourcePanel" name="mapAndResourcePanel"
style="sessionPanelStyle" style="sessionPanelStyle"
size="0 100%-158 272 100%" size="0 100%-175 272 100%"
type="image" type="image"
z="30" z="30"
> >
@ -291,13 +291,13 @@
<object name="selectionDetails" <object name="selectionDetails"
type="image" type="image"
style="sessionPanelStyle" style="sessionPanelStyle"
size="277 100%-158 583 100%" size="282 100%-170 585 100%"
hidden="true" hidden="true"
z="20" z="20"
> >
<!-- Unit Selection Area --> <!-- Unit Selection Area -->
<object name="unitSelectionPanel" <object name="unitSelectionPanel"
size="6 6 274 56" size="4 6 274 56"
> >
<object size="0 0 100% 47"> <object size="0 0 100% 47">
<repeat count="32"> <repeat count="32">
@ -364,12 +364,12 @@
<object name="unitCommands" <object name="unitCommands"
type="image" type="image"
style="sessionPanelStyle" style="sessionPanelStyle"
size="588 100%-158 1024 100%" size="595 100%-175 1024 100%"
hidden="true" hidden="true"
z="50" z="50"
> >
<object name="unitConstructionPanel" <object name="unitConstructionPanel"
size="0 6 100% 100%" size="0 3 100% 100%"
> >
<object size="-2 -2 54 54" type="image" sprite="snIconSheetTab" tooltip_style="snToolTip" <object size="-2 -2 54 54" type="image" sprite="snIconSheetTab" tooltip_style="snToolTip"
cell_id="0" tooltip="Construction"/> cell_id="0" tooltip="Construction"/>
@ -417,7 +417,7 @@
</object> </object>
<object name="unitTrainingPanel" <object name="unitTrainingPanel"
size="0 6 100% 100%" size="0 3 100% 100%"
> >
<object size="-2 -2 54 54" type="image" sprite="snIconSheetTab" tooltip_style="snToolTip" <object size="-2 -2 54 54" type="image" sprite="snIconSheetTab" tooltip_style="snToolTip"
cell_id="2" tooltip="Training"/> cell_id="2" tooltip="Training"/>
@ -433,22 +433,37 @@
<object name="unitQueuePanel" <object name="unitQueuePanel"
style="sessionPanelStyle" style="sessionPanelStyle"
size="0 -56 100% 100%-164" size="72 -46 100% 100%-180"
type="image" type="image"
> >
<object size="-2 -2 54 54" type="image" sprite="snIconSheetTab" tooltip_style="snToolTip" <object size="-2 -2 44 44" type="image" sprite="snIconSheetTab" tooltip_style="snToolTip"
cell_id="3" tooltip="Production queue"/> cell_id="3" tooltip="Production queue"/>
<object size="54 3 100% 100%"> <object size="54 3 100% 100%">
<repeat count="24"> <repeat count="24">
<object name="unitQueueButton[n]" hidden="true" style="iconButton" type="button" size="0 0 45 45"> <object name="unitQueueButton[n]" hidden="true" style="iconButton" type="button" size="0 0 36 36">
<object name="unitQueueIcon[n]" ghost="true" type="image" size="3 3 42 42"/> <object name="unitQueueIcon[n]" ghost="true" type="image" size="3 3 34 34"/>
<object name="unitQueueCount[n]" ghost="true" style="iconButtonCount" type="text"/> <object name="unitQueueCount[n]" ghost="true" style="iconButtonCount" type="text"/>
<object name="unitQueueProgress[n]" ghost="true" style="iconButtonProgress" type="text"/> <object name="unitQueueProgress[n]" ghost="true" style="iconButtonProgress" type="text"/>
</object> </object>
</repeat> </repeat>
</object> </object>
</object> </object>
<object name="unitCommandPanel"
style="sessionPanelStyle"
size="0 100%-28 100% 100%"
type="image"
>
<object size="3 0 100% 100%">
<repeat count="24">
<object name="unitCommandButton[n]" hidden="true" style="iconButton" type="button" size="0 0 27 27">
<object name="unitCommandIcon[n]" ghost="true" type="image" size="3 3 24 24" style="commandIcon"/>
</object>
</repeat>
</object>
</object>
</object> </object>
</object> </object>

View File

@ -54,8 +54,9 @@
tooltip_style="snToolTip" tooltip_style="snToolTip"
/> />
<style name="commandsIcon" <style name="commandIcon"
sprite="snIconSheetCommand" sprite="snIconSheetCommand"
sprite_disabled="snIconSheetCommandDisabled"
ghost="true" ghost="true"
/> />

View File

@ -3,16 +3,17 @@ const SELECTION = "Selection";
const QUEUE = "Queue"; const QUEUE = "Queue";
const TRAINING = "Training"; const TRAINING = "Training";
const CONSTRUCTION = "Construction"; const CONSTRUCTION = "Construction";
const COMMAND = "Command";
// Constants used by the Queue or Garrison panel // Constants used by the Queue or Garrison panel
const UNIT_PANEL_BASE = -56; // The offset above the main panel (will often be negative) const UNIT_PANEL_BASE = -47; // The offset above the main panel (will often be negative)
const UNIT_PANEL_HEIGHT = 47; // The height needed for a row of buttons const UNIT_PANEL_HEIGHT = 37; // The height needed for a row of buttons
// The number of currently visible buttons (used to optimise showing/hiding) // The number of currently visible buttons (used to optimise showing/hiding)
var g_unitPanelButtons = {"Selection": 0, "Queue": 0, "Training": 0, "Construction": 0}; var g_unitPanelButtons = {"Selection": 0, "Queue": 0, "Training": 0, "Construction": 0, "Command": 0};
// Unit panels are panels with row(s) of buttons // Unit panels are panels with row(s) of buttons
var g_unitPanels = ["Selection", "Queue", "Training", "Construction", "Research", "Stance", "Formation"]; var g_unitPanels = ["Selection", "Queue", "Training", "Construction", "Research", "Stance", "Formation", "Command"];
// Lay out button rows // Lay out button rows
function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, startIndex, endIndex) function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, startIndex, endIndex)
@ -43,7 +44,15 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
// Set length of loop // Set length of loop
var numberOfItems = items.length; var numberOfItems = items.length;
if (numberOfItems > 24) if (numberOfItems > 24)
numberOfItems = (((numberOfItems > 32) && (guiName == "Selection"))? 32 : 24); {
if (guiName == "Selection")
{
if (numberOfItems > 32)
numberOfItems = 32;
}
else
numberOfItems = 24;
}
var i; var i;
for (i = 0; i < numberOfItems; i++) for (i = 0; i < numberOfItems; i++)
@ -51,10 +60,13 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
var item = items[i]; var item = items[i];
// Get templates // Get templates
var entType = ((guiName == "Queue")? item.template : item); if (guiName != "Command")
var template = Engine.GuiInterfaceCall("GetTemplateData", entType); {
if (!template) var entType = ((guiName == "Queue")? item.template : item);
continue; // ignore attempts to use invalid templates (an error should have been reported already) var template = Engine.GuiInterfaceCall("GetTemplateData", entType);
if (!template)
continue; // ignore attempts to use invalid templates (an error should have been reported already)
}
// Tooltip // Tooltip
var tooltip = ""; var tooltip = "";
@ -108,6 +120,10 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
tooltip = getEntityNameWithGeneric(template) + "\n" + getEntityCost(template); tooltip = getEntityNameWithGeneric(template) + "\n" + getEntityCost(template);
break; break;
case COMMAND:
tooltip = item;
break;
default: default:
break; break;
} }
@ -123,20 +139,23 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
button.onpress = (function(e) { return function() { callback(e) } })(parameter); // (need nested functions to get the closure right) button.onpress = (function(e) { return function() { callback(e) } })(parameter); // (need nested functions to get the closure right)
// Get icon sheet // Get icon sheet
icon.sprite = template.icon_sheet; if (guiName == "Command")
{
if (typeof template.icon_cell == "undefined") icon.cell_id = i;
icon.cell_id = 0; }
else else
icon.cell_id = template.icon_cell; {
icon.sprite = template.icon_sheet;
icon.cell_id = ((typeof template.icon_cell == "undefined")? 0 : template.icon_cell);
}
} }
// Position the visible buttons (TODO: if there's lots, maybe they should be squeezed together to fit) // Position the visible buttons (TODO: if there's lots, maybe they should be squeezed together to fit)
var numButtons = i; var numButtons = i;
var rowLength = 8; var rowLength = ((guiName == "Command")? 15 : 8);
var numRows = Math.ceil(numButtons / rowLength); var numRows = Math.ceil(numButtons / rowLength);
var buttonSideLength = getGUIObjectByName("unit"+guiName+"Button[0]").size.bottom; var buttonSideLength = getGUIObjectByName("unit"+guiName+"Button[0]").size.bottom;
var buttonSpacer = ((guiName == "Selection")? buttonSideLength+1 : buttonSideLength+2); var buttonSpacer = buttonSideLength+1;
// Resize Queue panel if needed // Resize Queue panel if needed
if (guiName == "Queue") // or garrison if (guiName == "Queue") // or garrison
@ -194,6 +213,17 @@ function updateUnitCommands(entState, commandsPanel, selection)
setupUnitPanel("Selection", usedPanels, entState, g_Selection.getTemplateNames(), setupUnitPanel("Selection", usedPanels, entState, g_Selection.getTemplateNames(),
function (entType) { changePrimarySelectionGroup(entType); } ); function (entType) { changePrimarySelectionGroup(entType); } );
// HACK: This should be referenced in the entities template, rather that completely faked here
var commands = [];
for (var i = 0; i < 15; i++)
commands.push("test"+i);
commands[4] = "delete";
// Needs to have list provided by the entity
if (commands.length)
setupUnitPanel("Command", usedPanels, entState, commands,
function (item) { performCommand(entState.id, item); } );
commandsPanel.hidden = false; commandsPanel.hidden = false;
} }
else else
@ -208,18 +238,8 @@ function updateUnitCommands(entState, commandsPanel, selection)
{ {
var panel = getGUIObjectByName("unit" + panelName + "Panel"); var panel = getGUIObjectByName("unit" + panelName + "Panel");
if (usedPanels[panelName]) if (usedPanels[panelName])
{
// var size = panel.size;
// var h = size.bottom - size.top;
// size.bottom = offset;
// size.top = offset - h;
// panel.size = size;
panel.hidden = false; panel.hidden = false;
// offset -= (h + 6); // changed 12 point spacing to 6 point: offset -= (h + 12);
}
else else
{
panel.hidden = true; panel.hidden = true;
}
} }
} }

View File

@ -124,6 +124,14 @@ function ProcessCommand(player, cmd)
break; break;
case "delete-entity":
var cmpOwnership = Engine.QueryInterface(cmd.entity, IID_Ownership);
var entityOwner = cmpOwnership.GetOwner()
if (player == entityOwner)
Engine.DestroyEntity(cmd.entity);
break;
default: default:
error("Ignoring unrecognised command type '" + cmd.type + "'"); error("Ignoring unrecognised command type '" + cmd.type + "'");
} }