Added working delete button
This was SVN commit r7832.
This commit is contained in:
parent
dd2fcad2a2
commit
aa2d305b6e
@ -913,7 +913,7 @@
|
||||
/>
|
||||
</sprite>
|
||||
<sprite name="snIconSheetCommandDisabled">
|
||||
|
||||
<effect grayscale=""/>
|
||||
<image texture="session/icons/sheets/command.dds"
|
||||
cell_size="64 64"
|
||||
size="0 0 100% 100%"
|
||||
|
@ -622,3 +622,16 @@ function changePrimarySelectionGroup(index)
|
||||
else
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +231,7 @@
|
||||
<object
|
||||
name="mapAndResourcePanel"
|
||||
style="sessionPanelStyle"
|
||||
size="0 100%-158 272 100%"
|
||||
size="0 100%-175 272 100%"
|
||||
type="image"
|
||||
z="30"
|
||||
>
|
||||
@ -291,13 +291,13 @@
|
||||
<object name="selectionDetails"
|
||||
type="image"
|
||||
style="sessionPanelStyle"
|
||||
size="277 100%-158 583 100%"
|
||||
size="282 100%-170 585 100%"
|
||||
hidden="true"
|
||||
z="20"
|
||||
>
|
||||
<!-- Unit Selection Area -->
|
||||
<object name="unitSelectionPanel"
|
||||
size="6 6 274 56"
|
||||
size="4 6 274 56"
|
||||
>
|
||||
<object size="0 0 100% 47">
|
||||
<repeat count="32">
|
||||
@ -364,12 +364,12 @@
|
||||
<object name="unitCommands"
|
||||
type="image"
|
||||
style="sessionPanelStyle"
|
||||
size="588 100%-158 1024 100%"
|
||||
size="595 100%-175 1024 100%"
|
||||
hidden="true"
|
||||
z="50"
|
||||
>
|
||||
<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"
|
||||
cell_id="0" tooltip="Construction"/>
|
||||
@ -417,7 +417,7 @@
|
||||
</object>
|
||||
|
||||
<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"
|
||||
cell_id="2" tooltip="Training"/>
|
||||
@ -433,22 +433,37 @@
|
||||
|
||||
<object name="unitQueuePanel"
|
||||
style="sessionPanelStyle"
|
||||
size="0 -56 100% 100%-164"
|
||||
size="72 -46 100% 100%-180"
|
||||
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"/>
|
||||
|
||||
<object size="54 3 100% 100%">
|
||||
<repeat count="24">
|
||||
<object name="unitQueueButton[n]" hidden="true" style="iconButton" type="button" size="0 0 45 45">
|
||||
<object name="unitQueueIcon[n]" ghost="true" type="image" size="3 3 42 42"/>
|
||||
<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 34 34"/>
|
||||
<object name="unitQueueCount[n]" ghost="true" style="iconButtonCount" type="text"/>
|
||||
<object name="unitQueueProgress[n]" ghost="true" style="iconButtonProgress" type="text"/>
|
||||
</object>
|
||||
</repeat>
|
||||
</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>
|
||||
|
@ -54,11 +54,12 @@
|
||||
tooltip_style="snToolTip"
|
||||
/>
|
||||
|
||||
<style name="commandsIcon"
|
||||
sprite="snIconSheetCommand"
|
||||
<style name="commandIcon"
|
||||
sprite="snIconSheetCommand"
|
||||
sprite_disabled="snIconSheetCommandDisabled"
|
||||
ghost="true"
|
||||
/>
|
||||
|
||||
|
||||
<style name="sdIconOutline"
|
||||
sprite="sdIconOutline"
|
||||
/>
|
||||
|
@ -3,16 +3,17 @@ const SELECTION = "Selection";
|
||||
const QUEUE = "Queue";
|
||||
const TRAINING = "Training";
|
||||
const CONSTRUCTION = "Construction";
|
||||
const COMMAND = "Command";
|
||||
|
||||
// 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_HEIGHT = 47; // The height needed for a row of buttons
|
||||
const UNIT_PANEL_BASE = -47; // The offset above the main panel (will often be negative)
|
||||
const UNIT_PANEL_HEIGHT = 37; // The height needed for a row of buttons
|
||||
|
||||
// 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
|
||||
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
|
||||
function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, startIndex, endIndex)
|
||||
@ -43,7 +44,15 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||
// Set length of loop
|
||||
var numberOfItems = items.length;
|
||||
if (numberOfItems > 24)
|
||||
numberOfItems = (((numberOfItems > 32) && (guiName == "Selection"))? 32 : 24);
|
||||
{
|
||||
if (guiName == "Selection")
|
||||
{
|
||||
if (numberOfItems > 32)
|
||||
numberOfItems = 32;
|
||||
}
|
||||
else
|
||||
numberOfItems = 24;
|
||||
}
|
||||
|
||||
var i;
|
||||
for (i = 0; i < numberOfItems; i++)
|
||||
@ -51,10 +60,13 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||
var item = items[i];
|
||||
|
||||
// Get templates
|
||||
var entType = ((guiName == "Queue")? item.template : item);
|
||||
var template = Engine.GuiInterfaceCall("GetTemplateData", entType);
|
||||
if (!template)
|
||||
continue; // ignore attempts to use invalid templates (an error should have been reported already)
|
||||
if (guiName != "Command")
|
||||
{
|
||||
var entType = ((guiName == "Queue")? item.template : item);
|
||||
var template = Engine.GuiInterfaceCall("GetTemplateData", entType);
|
||||
if (!template)
|
||||
continue; // ignore attempts to use invalid templates (an error should have been reported already)
|
||||
}
|
||||
|
||||
// Tooltip
|
||||
var tooltip = "";
|
||||
@ -107,6 +119,10 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||
case CONSTRUCTION:
|
||||
tooltip = getEntityNameWithGeneric(template) + "\n" + getEntityCost(template);
|
||||
break;
|
||||
|
||||
case COMMAND:
|
||||
tooltip = item;
|
||||
break;
|
||||
|
||||
default:
|
||||
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)
|
||||
|
||||
// Get icon sheet
|
||||
icon.sprite = template.icon_sheet;
|
||||
|
||||
if (typeof template.icon_cell == "undefined")
|
||||
icon.cell_id = 0;
|
||||
if (guiName == "Command")
|
||||
{
|
||||
icon.cell_id = i;
|
||||
}
|
||||
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)
|
||||
var numButtons = i;
|
||||
var rowLength = 8;
|
||||
var rowLength = ((guiName == "Command")? 15 : 8);
|
||||
var numRows = Math.ceil(numButtons / rowLength);
|
||||
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
|
||||
if (guiName == "Queue") // or garrison
|
||||
@ -194,6 +213,17 @@ function updateUnitCommands(entState, commandsPanel, selection)
|
||||
setupUnitPanel("Selection", usedPanels, entState, g_Selection.getTemplateNames(),
|
||||
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;
|
||||
}
|
||||
else
|
||||
@ -208,18 +238,8 @@ function updateUnitCommands(entState, commandsPanel, selection)
|
||||
{
|
||||
var panel = getGUIObjectByName("unit" + panelName + "Panel");
|
||||
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;
|
||||
// offset -= (h + 6); // changed 12 point spacing to 6 point: offset -= (h + 12);
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.hidden = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +123,14 @@ function ProcessCommand(player, cmd)
|
||||
});
|
||||
|
||||
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:
|
||||
error("Ignoring unrecognised command type '" + cmd.type + "'");
|
||||
|
Loading…
Reference in New Issue
Block a user