From c4eac1660c378ff5574e1079bfb0f40e5c6d0f46 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 3 Aug 2017 11:46:05 +1200 Subject: [PATCH] Fix app toggling and hand swapping issues --- scripts/vr-edit/modules/toolMenu.js | 39 ++++++++++++++++++---- scripts/vr-edit/vr-edit.js | 51 +++++++++++++---------------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/scripts/vr-edit/modules/toolMenu.js b/scripts/vr-edit/modules/toolMenu.js index 887e7b40da..266abf1596 100644 --- a/scripts/vr-edit/modules/toolMenu.js +++ b/scripts/vr-edit/modules/toolMenu.js @@ -44,7 +44,7 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) { alpha: 1.0, parentID: AVATAR_SELF_ID, ignoreRayIntersection: true, - visible: true + visible: false }, MENU_PANEL_PROPERTIES = { @@ -177,12 +177,12 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) { intersectionOverlays, intersectionCallbacks, intersectionProperties, - highlightedItem = NONE, - highlightedSource = null, - isHighlightingButton = false, - pressedItem = NONE, - pressedSource = null, - isButtonPressed = false, + highlightedItem, + highlightedSource, + isHighlightingButton, + pressedItem, + pressedSource, + isButtonPressed, isDisplaying = false, @@ -238,6 +238,9 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) { } } + function clearTool() { + openOptions(); + } function update(intersectionOverlayID) { var intersectedItem, @@ -372,6 +375,17 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) { properties.parentID = menuOriginOverlay; highlightOverlay = Overlays.addOverlay("cube", properties); + // Initial values. + intersectionOverlays = null; + intersectionCallbacks = null; + intersectionProperties = null; + highlightedItem = NONE; + highlightedSource = null; + isHighlightingButton = false; + pressedItem = NONE; + pressedSource = null; + isButtonPressed = false; + isDisplaying = true; } @@ -385,11 +399,21 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) { } Overlays.deleteOverlay(highlightOverlay); + for (i = 0, length = optionsOverlays.length; i < length; i += 1) { + Overlays.deleteOverlay(optionsOverlays[i]); + } + optionsOverlays = []; + optionsCallbacks = []; + for (i = 0, length = menuOverlays.length; i < length; i += 1) { Overlays.deleteOverlay(menuOverlays[i]); } + menuOverlays = []; + menuCallbacks = []; + Overlays.deleteOverlay(menuPanelOverlay); Overlays.deleteOverlay(menuOriginOverlay); + isDisplaying = false; } @@ -400,6 +424,7 @@ ToolMenu = function (side, leftInputs, rightInputs, commandCallback) { return { setHand: setHand, entityIDs: getEntityIDs, + clearTool: clearTool, update: update, display: display, clear: clear, diff --git a/scripts/vr-edit/vr-edit.js b/scripts/vr-edit/vr-edit.js index 9cde84503c..c810d7f712 100644 --- a/scripts/vr-edit/vr-edit.js +++ b/scripts/vr-edit/vr-edit.js @@ -212,6 +212,7 @@ function clearToolIcon() { toolIcon.clear(); + toolMenu.clearTool(); } function setUIEntities() { @@ -1240,6 +1241,23 @@ } } + function startApp() { + ui.display(); + update(); + } + + function stopApp() { + Script.clearTimeout(updateTimer); + updateTimer = null; + inputs[LEFT_HAND].clear(); + inputs[RIGHT_HAND].clear(); + ui.clear(); + grouping.clear(); + editors[LEFT_HAND].clear(); + editors[RIGHT_HAND].clear(); + toolSelected = TOOL_NONE; + } + function onAppButtonClicked() { // Application tablet/toolbar button clicked. isAppActive = !isAppActive; @@ -1247,16 +1265,9 @@ button.editProperties({ isActive: isAppActive }); if (isAppActive) { - ui.display(); - update(); + startApp(); } else { - Script.clearTimeout(updateTimer); - updateTimer = null; - inputs[LEFT_HAND].clear(); - inputs[RIGHT_HAND].clear(); - ui.clear(); - editors[LEFT_HAND].clear(); - editors[RIGHT_HAND].clear(); + stopApp(); } } @@ -1265,33 +1276,15 @@ if (isAppActive) { // Stop operations. - Script.clearTimeout(updateTimer); - updateTimer = null; - inputs[LEFT_HAND].clear(); - inputs[RIGHT_HAND].clear(); - ui.clear(); - editors[LEFT_HAND].clear(); - editors[RIGHT_HAND].clear(); + stopApp(); } // Swap UI hands. ui.setHand(otherHand(dominantHand)); - switch (toolSelected) { - case TOOL_SCALE: - ui.setToolIcon(ui.SCALE_TOOL); - break; - case TOOL_CLONE: - ui.setToolIcon(ui.CLONE_TOOL); - break; - case TOOL_GROUP: - ui.setToolIcon(ui.GROUP_TOOL); - break; - } if (isAppActive) { // Resume operations. - ui.display(); - update(); + startApp(); } }