1
0
forked from 0ad/0ad

Shade and show an insufficient resources tooltip for unaffordable walls. Fixes #1641.

This was SVN commit r12569.
This commit is contained in:
Deiz 2012-08-31 19:20:16 +00:00
parent 2ed11f6a84
commit 0340cc2baa
2 changed files with 20 additions and 17 deletions

View File

@ -853,12 +853,10 @@ function handleInputBeforeGui(ev, hoveredObject)
if (result && result.cost)
{
placementSupport.wallDragTooltip = "";
for (var resource in result.cost)
{
if (result.cost[resource] > 0)
placementSupport.wallDragTooltip += getCostComponentDisplayName(resource) + ": " + result.cost[resource] + "\n";
}
placementSupport.wallDragTooltip = getEntityCostTooltip(result);
var neededResources = Engine.GuiInterfaceCall("GetNeededResources", result.cost);
if (neededResources)
placementSupport.wallDragTooltip += getNeededResourcesTooltip(neededResources);
}
break;

View File

@ -1272,18 +1272,9 @@ GuiInterface.prototype.SetWallPlacementPreview = function(player, cmd)
if (validPlacement && entInfo.controlGroups && entInfo.controlGroups.length > 1)
validPlacement = cmpObstruction.CheckDuplicateFoundation();
}
allPiecesValid = allPiecesValid && validPlacement;
var cmpVisual = Engine.QueryInterface(ent, IID_Visual);
if (cmpVisual)
{
if (!allPiecesValid)
cmpVisual.SetShadingColour(1.4, 0.4, 0.4, 1);
else
cmpVisual.SetShadingColour(1, 1, 1, 1);
}
// The requirement below that all pieces so far have to have valid positions, rather than only this single one,
// ensures that no more foundations will be placed after a first invalidly-positioned piece. (It is possible
// for pieces past some invalidly-positioned ones to still have valid positions, e.g. if you drag a wall
@ -1316,7 +1307,21 @@ GuiInterface.prototype.SetWallPlacementPreview = function(player, cmd)
result.cost.population += tplData.cost.population;
result.cost.populationBonus += tplData.cost.populationBonus;
}
var canAfford = true;
var cmpPlayer = QueryPlayerIDInterface(player, IID_Player);
if (cmpPlayer && cmpPlayer.GetNeededResources(result.cost))
var canAfford = false;
var cmpVisual = Engine.QueryInterface(ent, IID_Visual);
if (cmpVisual)
{
if (!allPiecesValid || !canAfford)
cmpVisual.SetShadingColour(1.4, 0.4, 0.4, 1);
else
cmpVisual.SetShadingColour(1, 1, 1, 1);
}
entPool.numUsed++;
}