From 63f958878d5fe292f9c383a100c2374e4822e1ad Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Thu, 24 Feb 2011 02:12:47 +0000 Subject: [PATCH] Fix GUI errors and glitches when placing buildings and not moving the mouse. This was SVN commit r8977. --- .../data/mods/public/gui/session/input.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index d37fd86046..fe1a0f5e64 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -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; }