1
0
forked from 0ad/0ad

Fix GUI errors and glitches when placing buildings and not moving the mouse.

This was SVN commit r8977.
This commit is contained in:
Ykkrosh 2011-02-24 02:12:47 +00:00
parent e16681f0e5
commit 63f958878d

View File

@ -29,8 +29,8 @@ var INPUT_PRESELECTEDACTION = 7;
var inputState = INPUT_NORMAL;
var defaultPlacementAngle = Math.PI*3/4;
var placementAngle;
var placementPosition;
var placementAngle = undefined;
var placementPosition = undefined;
var placementEntity = undefined;
var mouseX = 0;
@ -73,7 +73,7 @@ function updateBuildingPlacementPreview()
// The preview should be recomputed every turn, so that it responds
// to obstructions/fog/etc moving underneath it
if (placementEntity)
if (placementEntity && placementPosition)
{
Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {
"template": placementEntity,
@ -84,6 +84,14 @@ function updateBuildingPlacementPreview()
}
}
function resetPlacementEntity()
{
Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""});
placementEntity = undefined;
placementPosition = undefined;
placementAngle = undefined;
}
function findGatherType(gatherer, supply)
{
if (!gatherer || !supply)
@ -318,9 +326,6 @@ function tryPlaceBuilding(queued)
return false;
}
// Remove the preview
Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""});
// Start the construction
Engine.PostNetworkCommand({
"type": "construct",
@ -335,7 +340,7 @@ function tryPlaceBuilding(queued)
});
Engine.GuiInterfaceCall("PlaySound", { "name": "order_repair", "entity": selection[0] });
placementEntity = undefined;
resetPlacementEntity();
return true;
}
@ -511,8 +516,7 @@ function handleInputBeforeGui(ev, hoveredObject)
if (ev.button == SDL_BUTTON_RIGHT)
{
// Cancel building
Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""});
placementEntity = undefined;
resetPlacementEntity();
inputState = INPUT_NORMAL;
return true;
}
@ -572,8 +576,7 @@ function handleInputBeforeGui(ev, hoveredObject)
if (ev.button == SDL_BUTTON_RIGHT)
{
// Cancel building
Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""});
placementEntity = undefined;
resetPlacementEntity();
inputState = INPUT_NORMAL;
return true;
}
@ -779,8 +782,7 @@ function handleInputAfterGui(ev)
else if (ev.button == SDL_BUTTON_RIGHT)
{
// Cancel building
Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {"template": ""});
placementEntity = undefined;
resetPlacementEntity();
inputState = INPUT_NORMAL;
return true;
}