Wall and gate selection usability improvements by Deiz/F00. Refs #619.
Fixes bug where selecting multiple wall types could convert to mismatching gates. This was SVN commit r12163.
This commit is contained in:
parent
512e3a01b6
commit
574e079d64
@ -1643,11 +1643,23 @@ function transformWallToGate(template)
|
||||
var selection = g_Selection.toList();
|
||||
Engine.PostNetworkCommand({
|
||||
"type": "wall-to-gate",
|
||||
"entities": selection,
|
||||
"entities": selection.filter( function(e) { return getWallGateTemplate(e) == template } ),
|
||||
"template": template,
|
||||
});
|
||||
}
|
||||
|
||||
// Gets the gate form (if any) of a given long wall piece
|
||||
function getWallGateTemplate(entity)
|
||||
{
|
||||
// TODO: find the gate template name in a better way
|
||||
var entState = GetEntityState(entity);
|
||||
var index;
|
||||
|
||||
if (entState && !entState.foundation && hasClass(entState, "LongWall") && (index = entState.template.indexOf("long")) >= 0)
|
||||
return entState.template.substr(0, index) + "gate";
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Set the camera to follow the given unit
|
||||
function setCameraFollow(entity)
|
||||
{
|
||||
|
@ -863,7 +863,7 @@
|
||||
size="10 12 100% 100%"
|
||||
>
|
||||
<object size="0 0 100% 100%">
|
||||
<repeat count="2">
|
||||
<repeat count="8">
|
||||
<object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
|
||||
<object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
|
||||
<object name="unitGateSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
|
||||
|
@ -209,8 +209,8 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||
break;
|
||||
|
||||
case GATE:
|
||||
if(numberOfItems > 2)
|
||||
numberOfItems = 2;
|
||||
if(numberOfItems > 8)
|
||||
numberOfItems = 8;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -513,17 +513,18 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||
// If already a gate, show locking actions
|
||||
if (unitEntState.gate)
|
||||
{
|
||||
gateIcon = "lock_" + GATE_ACTIONS[i].toLowerCase() + "ed.png";
|
||||
gateIcon = "icons/lock_" + GATE_ACTIONS[i].toLowerCase() + "ed.png";
|
||||
selection.hidden = unitEntState.gate.locked != item.locked;
|
||||
}
|
||||
// otherwise show gate upgrade icon
|
||||
else
|
||||
{
|
||||
gateIcon = "gate_closed.png";
|
||||
template = GetTemplateData(item.template);
|
||||
gateIcon = template.icon ? "portraits/" + template.icon : "icons/gate_closed.png";
|
||||
selection.hidden = true;
|
||||
}
|
||||
|
||||
icon.sprite = "stretched:session/icons/" + gateIcon;
|
||||
icon.sprite = "stretched:session/" + gateIcon;
|
||||
}
|
||||
else if (template.icon)
|
||||
{
|
||||
@ -806,6 +807,9 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s
|
||||
removeDupes(buildableEnts);
|
||||
removeDupes(trainableEnts);
|
||||
|
||||
// Whether the GUI's right panel has been filled.
|
||||
var rightUsed = true;
|
||||
|
||||
// The first selected entity's type has priority.
|
||||
if (entState.buildEntities)
|
||||
setupUnitPanel(CONSTRUCTION, usedPanels, entState, buildableEnts, startBuildingPlacement);
|
||||
@ -814,7 +818,54 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s
|
||||
function (trainEntType) { addTrainingToQueue(selection, trainEntType); } );
|
||||
else if (entState.trader)
|
||||
setupUnitTradingPanel(usedPanels, entState, selection);
|
||||
else if (entState.gate)
|
||||
{
|
||||
var items = [];
|
||||
for (var i = 0; i < GATE_ACTIONS.length; ++i)
|
||||
items.push({
|
||||
"tooltip": GATE_ACTIONS[i] + " gate",
|
||||
"locked": i == 0
|
||||
});
|
||||
setupUnitPanel(GATE, usedPanels, entState, items,
|
||||
function (item) { lockGate(item.locked); } );
|
||||
}
|
||||
else if (!entState.foundation && (hasClass(entState, "LongWall")))
|
||||
{
|
||||
// Allow long wall pieces to be converted to gates
|
||||
var longWallTypes = {};
|
||||
var items = [];
|
||||
for (var i in selection)
|
||||
{
|
||||
if ((state = GetEntityState(selection[i])) && hasClass(state, "LongWall") &&
|
||||
!state.gate && !state.foundation && !longWallTypes[state.template])
|
||||
{
|
||||
var gateTemplate = getWallGateTemplate(state.id);
|
||||
if (gateTemplate)
|
||||
{
|
||||
var wallName = GetTemplateData(state.template).name.generic;
|
||||
var gateName = GetTemplateData(gateTemplate).name.generic;
|
||||
|
||||
items.push({
|
||||
"tooltip": "Convert " + wallName + " to " + gateName,
|
||||
"template": gateTemplate
|
||||
});
|
||||
}
|
||||
|
||||
// We only need one entity per type.
|
||||
longWallTypes[state.template] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (items.length)
|
||||
setupUnitPanel(GATE, usedPanels, entState, items,
|
||||
function (item) { transformWallToGate(item.template); } );
|
||||
else
|
||||
rightUsed = false;
|
||||
}
|
||||
else
|
||||
rightUsed = false;
|
||||
|
||||
if (!rightUsed)
|
||||
{
|
||||
// The right pane is empty. Fill the pane with a sane type.
|
||||
// Prefer buildables for units and trainables for structures.
|
||||
@ -838,37 +889,6 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s
|
||||
setupUnitPanel(QUEUE, usedPanels, entState, entState.production.queue,
|
||||
function (item) { removeFromProductionQueue(entState.id, item.id); } );
|
||||
|
||||
if(!entState.foundation && (entState.gate || hasClass(entState, "LongWall")))
|
||||
{
|
||||
if (entState.gate)
|
||||
{
|
||||
var items = [];
|
||||
for (var i = 0; i < GATE_ACTIONS.length; ++i)
|
||||
items.push({
|
||||
"tooltip": GATE_ACTIONS[i] + " gate",
|
||||
"locked": i == 0
|
||||
});
|
||||
setupUnitPanel(GATE, usedPanels, entState, items,
|
||||
function (item) { lockGate(item.locked); } );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Allow long wall pieces to be converted to gates
|
||||
// TODO: find the gate template name in a better way
|
||||
// TODO: selections of multiple different types of walls (breaks currently)
|
||||
var longPos = entState.template.indexOf("long");
|
||||
if (longPos != -1)
|
||||
{
|
||||
var action = {
|
||||
"tooltip": "Convert to gate",
|
||||
"template": entState.template.substr(0, longPos) + "gate"
|
||||
};
|
||||
setupUnitPanel(GATE, usedPanels, entState, [action],
|
||||
function (item) { transformWallToGate(action.template); } );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
supplementalDetailsPanel.hidden = false;
|
||||
commandsPanel.hidden = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user