1
0
forked from 0ad/0ad

Added Delete Hotkey

Misc minor changes

This was SVN commit r7835.
This commit is contained in:
WhiteTreePaladin 2010-08-01 16:25:24 +00:00
parent e20f93ffdc
commit 67e3a95d74
6 changed files with 64 additions and 77 deletions

View File

@ -4,7 +4,7 @@ const SDL_BUTTON_RIGHT = 3;
const SDLK_RSHIFT = 303;
const SDLK_LSHIFT = 304;
const MAX_SELECTION_SIZE = 32;
const MAX_SELECTION_SIZE = 32; // Limits selection size and ensures that there will not be too many selection items in the GUI
// TODO: these constants should be defined somewhere else instead, in
// case any other code wants to use them too
@ -623,15 +623,18 @@ function changePrimarySelectionGroup(index)
g_Selection.makePrimarySelection(index, false);
}
// Performs the specified command
// Performs the specified command (delete, town bell, repair, etc.)
function performCommand(entity, commandName)
{
switch (commandName)
if (entity)
{
case "delete":
Engine.PostNetworkCommand({"type": "delete-entity", "entity": entity});
break;
default:
break;
switch (commandName)
{
case "delete":
Engine.PostNetworkCommand({"type": "delete-entity", "entity": entity});
break;
default:
break;
}
}
}
}

View File

@ -52,7 +52,6 @@ EntitySelection.prototype.makePrimarySelection = function(primaryIndex, modifier
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[i]);
if (!entState)
return;
if (entState.template == primaryEntState.template)
ents.push(selection[i]);
}
@ -61,7 +60,6 @@ EntitySelection.prototype.makePrimarySelection = function(primaryIndex, modifier
{
ents.push(selection[primaryIndex]);
}
this.reset();
this.addList(ents);
}
@ -78,29 +76,22 @@ EntitySelection.prototype.getTemplateNames = function()
if (entState)
templateNames.push(entState.template);
}
return templateNames;
}
// Update the selection to take care of changes (like units that have been killed)
EntitySelection.prototype.updateSelection = function()
EntitySelection.prototype.update = function()
{
var numberRemoved = 0;
var i = 0;
for each (var ent in this.selected)
{
var entState = Engine.GuiInterfaceCall("GetEntityState", ent);
if (!entState)
{
delete this.selected[ent];
numberRemoved++;
}
i++;
}
if (numberRemoved > 0)
this.dirty = true;
};

View File

@ -37,14 +37,15 @@ function displayGeneralInfo(playerState, entState, template)
var iconTooltip = "";
// Rank Icon
var rankId = getRankCellId(entState.template);
getGUIObjectByName("sdRankIcon").cell_id = rankId;
// var rankId = getRankCellId(entState.template);
// getGUIObjectByName("sdRankIcon").cell_id = rankId;
var rankText = getRankTitle(rankId);
rankText = (rankText? " (" + rankText + ")" : "");
// Rank Title
// var rankText = getRankTitle(getRankCellId(entState.template));
// rankText = (rankText? rankText : "");
// Specific Name
var name = template.name.specific + rankText;
var name = template.name.specific + getRankTitle(getRankCellId(entState.template));
getGUIObjectByName("sdSpecific").caption = name;
iconTooltip += "[font=\"serif-bold-16\"]" + name + "[/font]";
@ -126,7 +127,7 @@ function updateSelectionDetails(simState)
var detailsPanel = getGUIObjectByName("selectionDetails");
var commandsPanel = getGUIObjectByName("unitCommands");
g_Selection.updateSelection();
g_Selection.update();
var selection = g_Selection.toList();
if (selection.length == 0)

View File

@ -219,17 +219,15 @@ function getRankCellId(templateName)
else if (endsWith == "_a")
return 1;
}
return -1;
}
function getRankTitle(cellId)
{
if (cellId == 0)
return "Elite";
return " (Elite)";
else if (cellId == 1)
return "Advanced";
return " (Advanced)";
return "";
}
@ -253,7 +251,7 @@ function getEntityName(template)
return "[font=\"serif-bold-16\"]" + (template.name.specific || template.name.generic || "???") + "[/font]";
}
function getEntityNameWithGeneric(template)
function getEntityNameWithGenericType(template)
{
var name;

View File

@ -50,6 +50,11 @@
]]></action>
</object>
<!-- Delete button Hotkey (For some reason it won't work when the console is visible -->
<object hotkey="killUnit">
<action on="Press">performCommand(g_Selection.toList()[0], "delete")</action>
</object>
<!-- ================================ ================================ -->
<!-- Developer / Debug items -->
<!-- ================================ ================================ -->
@ -311,26 +316,26 @@
</object>
<!-- Big unit icon -->
<object size= "6 30 86 110" name="sdIcon" type="image" tooltip_style="snToolTip">
<object size= "8 30 88 110" name="sdIcon" type="image" tooltip_style="snToolTip">
<object type="image" name="sdIconOutline" style="sdIconOutline" ghost="true"/>
<object type="image" name="sdIconImage" ghost="true"/>
<object size="100%-24 -6 100%+6 24" name="sdRankIcon" type="image" cell_id="0" sprite="snIconSheetRank" ghost="true"/>
<object size="100%-24 -6 100%+6 24" name="sdRankIcon" type="image" cell_id="-1" sprite="snIconSheetRank" ghost="true"/>
</object>
<!-- Health bar -->
<object size="6 112 86 118" type="image" name="sdHealth" tooltip="Hitpoints" tooltip_style="snToolTip">
<object size="8 112 88 118" type="image" name="sdHealth" tooltip="Hitpoints" tooltip_style="snToolTip">
<object type="image" sprite="sdHealthBackground" ghost="true"/>
<object type="image" sprite="sdHealthForeground" ghost="true" name="sdHealthBar"/>
</object>
<!-- Stamina bar -->
<object size="6 120 86 126" type="image" name="sdStamina" tooltip="Stamina" tooltip_style="snToolTip">
<object size="8 120 88 126" type="image" name="sdStamina" tooltip="Stamina" tooltip_style="snToolTip">
<object type="image" sprite="sdStaminaBackground" ghost="true"/>
<object type="image" sprite="sdStaminaForeground" ghost="true" name="sdStaminaBar"/>
</object>
<!-- Specific Name -->
<object size="0 0 100% 26" name="sdSpecific" type="text" style="leftAlignedText" font="serif-bold-18" tooltip_style="snToolTip"/>
<object size="2 0 100% 26" name="sdSpecific" type="text" style="leftAlignedText" font="serif-bold-18" tooltip_style="snToolTip"/>
<!-- Stats -->
<object size="86 30 100% 100%" name="sdStatsArea" type="image">
@ -338,13 +343,13 @@
<object size="0 0 100% 24" name="sdPlayer" type="text" style="centeredText" font="serif-stroke-14" tooltip_style="snToolTip"/>
<!-- Attack stats -->
<object size="4 32 100% 100%" type="image" name="sdAttack" tooltip="Attack strengths" tooltip_style="snToolTip">
<object size="12 32 100% 100%" type="image" name="sdAttack" tooltip="Attack strengths" tooltip_style="snToolTip">
<object size="-4 -8 36 36" type="image" name="sdAttackImage" ghost="true" sprite="snIconSheetStance" cell_id="1"/>
<object size="30 0 100% 100%" type="text" name="sdAttackStats" style="statsText"/>
</object>
<!-- Armour stats -->
<object size="100 32 100% 100%" type="image" name="sdArmour" tooltip="Armour strengths" tooltip_style="snToolTip">
<object size="108 32 100% 100%" type="image" name="sdArmour" tooltip="Armour strengths" tooltip_style="snToolTip">
<object size="-4 -4 36 36" type="image" name="sdArmourImage" ghost="true" sprite="snIconSheetStance" cell_id="3"/>
<object size="30 0 100% 100%" type="text" name="sdArmourStats" style="statsText"/>
</object>
@ -433,13 +438,13 @@
<object name="unitQueuePanel"
style="sessionPanelStyle"
size="72 -46 100% 100%-180"
size="80 -46 100% 100%-180"
type="image"
>
<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%">
<object size="44 3 100% 100%">
<repeat count="24">
<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"/>

View File

@ -40,55 +40,34 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
{
usedPanels[guiName] = 1;
var selection = g_Selection.toList();
// Set length of loop
var numberOfItems = items.length;
if (numberOfItems > 24)
{
if (guiName == "Selection")
{
if (numberOfItems > 32)
numberOfItems = 32;
}
else
numberOfItems = 24;
}
if ((numberOfItems > 24) && (guiName != "Selection"))
numberOfItems = 24;
var i;
for (i = 0; i < numberOfItems; i++)
{
var item = items[i];
// Get templates
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 = "";
switch (guiName)
{
case SELECTION:
tooltip = getEntityName(template);
var template = Engine.GuiInterfaceCall("GetTemplateData", item);
if (!template)
continue; // ignore attempts to use invalid templates (an error should have been reported already)
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[i]);
if (!entState)
return;
continue;
// Rank Title
var rankText = getRankTitle(getRankCellId(entState.template));
rankText = (rankText? " [font=\"serif-bold-16\"](" + rankText + ")[/font]" : "" );
tooltip += rankText;
var tooltip = getEntityName(template);
tooltip += "[font=\"serif-bold-16\"]" + getRankTitle(getRankCellId(entState.template)) + "[/font]";
// Hitpoints
if (entState.maxHitpoints != undefined)
{
var unitHealthBar = getGUIObjectByName("unitSelectionHealthForeground[" + i + "]");
var unitHealthBar = getGUIObjectByName("unitSelectionHealthForeground["+i+"]");
var healthSize = unitHealthBar.size;
healthSize.rright = 100*Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints));
unitHealthBar.size = healthSize;
@ -97,8 +76,11 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
break;
case QUEUE:
tooltip = getEntityNameWithGeneric(template);
var template = Engine.GuiInterfaceCall("GetTemplateData", item.template);
if (!template)
continue; // ignore attempts to use invalid templates (an error should have been reported already)
var tooltip = getEntityName(template);
var progress = Math.round(item.progress*100) + "%";
tooltip += " - " + progress;
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (item.count > 1 ? item.count : "");
@ -106,9 +88,12 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
break;
case TRAINING:
tooltip = getEntityNameWithGeneric(template) + "\n" + getEntityCost(template);
var template = Engine.GuiInterfaceCall("GetTemplateData", item);
if (!template)
continue; // ignore attempts to use invalid templates (an error should have been reported already)
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType);
var tooltip = getEntityNameWithGenericType(template) + "\n" + getEntityCost(template);
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, item);
if (batchSize)
{
tooltip += "\n[font=\"serif-13\"]Training [font=\"serif-bold-13\"]" + batchSize + "[font=\"serif-13\"] units; " +
@ -117,11 +102,15 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
break;
case CONSTRUCTION:
tooltip = getEntityNameWithGeneric(template) + "\n" + getEntityCost(template);
var template = Engine.GuiInterfaceCall("GetTemplateData", item);
if (!template)
continue; // ignore attempts to use invalid templates (an error should have been reported already)
var tooltip = getEntityNameWithGenericType(template) + "\n" + getEntityCost(template);
break;
case COMMAND:
tooltip = item;
tooltip = toTitleCase(item);
break;
default:
@ -138,7 +127,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
var parameter = ((guiName == "Selection")? i : item);
button.onpress = (function(e) { return function() { callback(e) } })(parameter); // (need nested functions to get the closure right)
// Get icon sheet
// Get icon image
if (guiName == "Command")
{
icon.cell_id = i;