From 884fa2f125289bff5aa7b141b7dbdda1d2fdec6f Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Wed, 12 May 2021 00:11:52 -0400 Subject: [PATCH 1/5] Add Location and Rotation Copy-Paste Add Location and Rotation Copy-Paste --- scripts/system/create/edit.js | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/scripts/system/create/edit.js b/scripts/system/create/edit.js index ed9763875de..c29eb329033 100644 --- a/scripts/system/create/edit.js +++ b/scripts/system/create/edit.js @@ -113,6 +113,9 @@ var hmdMultiSelectMode = false; var expectingRotateAsClickedSurface = false; var keepSelectedOnNextClick = false; +var copiedPosition; +var copiedRotation; + var cameraManager = new CameraManager(); var grid = new Grid(); @@ -2613,6 +2616,46 @@ var PropertiesTool = function (opts) { Entities.reloadServerScripts(selectionManager.selections[i]); } } + } else if (data.action === "copyPosition") { + selectionManager.saveProperties(); + properties = selectionManager.savedProperties[selectionManager.selections[0]]; + copiedPosition = properties.position; + Window.copyToClipboard(JSON.stringify(copiedPosition)); + print("COPIED: " + JSON.stringify(copiedPosition)); + } else if (data.action === "copyRotation") { + selectionManager.saveProperties(); + properties = selectionManager.savedProperties[selectionManager.selections[0]]; + copiedRotation = properties.rotation; + Window.copyToClipboard(JSON.stringify(copiedRotation)); + print("COPIED: " + JSON.stringify(copiedRotation)); + } else if (data.action === "pastePosition") { + if (copiedPosition !== undefined) { + selectionManager.saveProperties(); + for (i = 0; i < selectionManager.selections.length; i++) { + Entities.editEntity(selectionManager.selections[i], { + position: copiedPosition + }); + } + pushCommandForSelections(); + selectionManager._update(false, this); + print("PASTE POSITION"); + } else { + audioFeedback.rejection(); + } + } else if (data.action === "pasteRotation") { + if (copiedRotation !== undefined) { + selectionManager.saveProperties(); + for (i = 0; i < selectionManager.selections.length; i++) { + Entities.editEntity(selectionManager.selections[i], { + rotation: copiedRotation + }); + } + pushCommandForSelections(); + selectionManager._update(false, this); + print("PASTE ROTATION"); + } else { + audioFeedback.rejection(); + } } } else if (data.type === "propertiesPageReady") { updateSelections(true); From c1ee8801e0f32629b6c38890381b1bf0c6b865ac Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Wed, 12 May 2021 00:12:27 -0400 Subject: [PATCH 2/5] Add Location and Rotation Copy-Paste Add Location and Rotation Copy-Paste --- .../html/js/entityProperties.js | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/scripts/system/create/entityProperties/html/js/entityProperties.js b/scripts/system/create/entityProperties/html/js/entityProperties.js index 06ffbc2f99c..11f73833fd0 100644 --- a/scripts/system/create/entityProperties/html/js/entityProperties.js +++ b/scripts/system/create/entityProperties/html/js/entityProperties.js @@ -1353,6 +1353,12 @@ const GROUPS = [ propertyID: "localPosition", spaceMode: PROPERTY_SPACE_MODE.LOCAL, }, + { + type: "buttons", + buttons: [ { id: "copyPosition", label: "Copy Position", className: "black", onClick: copyPositionProperty }, + { id: "pastePosition", label: "Paste Position", className: "black", onClick: pastePositionProperty } ], + propertyID: "copyPastePosition" + }, { label: "Rotation", type: "vec3", @@ -1375,6 +1381,12 @@ const GROUPS = [ propertyID: "localRotation", spaceMode: PROPERTY_SPACE_MODE.LOCAL, }, + { + type: "buttons", + buttons: [ { id: "copyRotation", label: "Copy Rotation", className: "black", onClick: copyRotationProperty }, + { id: "pasteRotation", label: "Paste Rotation", className: "black", onClick: pasteRotationProperty } ], + propertyID: "copyPasteRotation" + }, { label: "Dimensions", type: "vec3", @@ -1852,6 +1864,24 @@ function setPropertyVisibility(property, visible) { property.elContainer.style.display = visible ? null : "none"; } +function setCopyPastePositionAndRotationAvailability (selectionLength, islocked) { + if (selectionLength === 1) { + $('#property-copyPastePosition-button-copyPosition').attr('disabled', false); + $('#property-copyPasteRotation-button-copyRotation').attr('disabled', false); + } else { + $('#property-copyPastePosition-button-copyPosition').attr('disabled', true); + $('#property-copyPasteRotation-button-copyRotation').attr('disabled', true); + } + + if (selectionLength > 0 && !islocked) { + $('#property-copyPastePosition-button-pastePosition').attr('disabled', false); + $('#property-copyPasteRotation-button-pasteRotation').attr('disabled', false); + } else { + $('#property-copyPastePosition-button-pastePosition').attr('disabled', true); + $('#property-copyPasteRotation-button-pasteRotation').attr('disabled', true); + } +} + function resetProperties() { for (let propertyID in properties) { let property = properties[propertyID]; @@ -3217,6 +3247,33 @@ function copySkyboxURLToAmbientURL() { updateProperty("ambientLight.ambientURL", skyboxURL, false); } +function copyPositionProperty() { + EventBridge.emitWebEvent(JSON.stringify({ + type: "action", + action: "copyPosition" + })); +} + +function pastePositionProperty() { + EventBridge.emitWebEvent(JSON.stringify({ + type: "action", + action: "pastePosition" + })); +} + +function copyRotationProperty() { + EventBridge.emitWebEvent(JSON.stringify({ + type: "action", + action: "copyRotation" + })); +} + +function pasteRotationProperty() { + EventBridge.emitWebEvent(JSON.stringify({ + type: "action", + action: "pasteRotation" + })); +} /** * USER DATA FUNCTIONS @@ -3952,7 +4009,7 @@ function handleEntitySelectionUpdate(selections, isPropertiesToolUpdate) { selectedEntityIDs = new Set(selections.map(selection => selection.id)); const multipleSelections = currentSelections.length > 1; const hasSelectedEntityChanged = !areSetsEqual(selectedEntityIDs, previouslySelectedEntityIDs); - + requestZoneList(); if (selections.length === 0) { @@ -3976,6 +4033,8 @@ function handleEntitySelectionUpdate(selections, isPropertiesToolUpdate) { showSaveMaterialDataButton(); showNewJSONMaterialEditorButton(); + setCopyPastePositionAndRotationAvailability (selections.length, true); + disableProperties(); } else { if (!isPropertiesToolUpdate && !hasSelectedEntityChanged && document.hasFocus()) { @@ -4006,10 +4065,12 @@ function handleEntitySelectionUpdate(selections, isPropertiesToolUpdate) { if (lockedMultiValue.isMultiDiffValue || lockedMultiValue.value) { disableProperties(); getPropertyInputElement('locked').removeAttribute('disabled'); + setCopyPastePositionAndRotationAvailability (selections.length, true); } else { enableProperties(); disableSaveUserDataButton(); disableSaveMaterialDataButton(); + setCopyPastePositionAndRotationAvailability (selections.length, false); } const certificateIDMultiValue = getMultiplePropertyValue('certificateID'); From 8827f9e8dea25b397e49492aea7ab5bbad229e6c Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Wed, 12 May 2021 22:10:09 -0400 Subject: [PATCH 3/5] Add a secondary button class for on field actions Add a secondary button class for on field actions To use when actions are to be added to a specific field. Like for Copy/Paste Location and Rotation. These smaller buttons make easier to figure that those actions are tied to a specific field or group of field. --- scripts/system/html/css/edit-style.css | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/system/html/css/edit-style.css b/scripts/system/html/css/edit-style.css index 9b3e862210c..9f7f3290405 100644 --- a/scripts/system/html/css/edit-style.css +++ b/scripts/system/html/css/edit-style.css @@ -463,6 +463,22 @@ input[type=button].white, button.hifi-edit-button.white { background-color: #afafaf; background: linear-gradient(#fff 20%, #afafaf 100%); } +input[type=button].secondary, button.hifi-edit-button.secondary { + font-family: Raleway-Bold; + font-size: 10px; + text-transform: uppercase; + vertical-align: top; + height: 18px; + min-width: 60px; + padding: 0 14px; + margin-right: 6px; + border-radius: 4px; + border: none; + color: #fff; + background-color: #000; + background: linear-gradient(#343434 20%, #000 100%); + cursor: pointer; +} input[type=button]:enabled:hover, button.hifi-edit-button:enabled:hover { background: linear-gradient(#000, #000); From cf66d1aca3430a8cd194e11d5ac843b225de9b6e Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Wed, 12 May 2021 22:11:15 -0400 Subject: [PATCH 4/5] Copy Paste Location and Rotation new button style Copy Paste Location and Rotation new button style --- .../create/entityProperties/html/js/entityProperties.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/system/create/entityProperties/html/js/entityProperties.js b/scripts/system/create/entityProperties/html/js/entityProperties.js index 11f73833fd0..5c6806653d4 100644 --- a/scripts/system/create/entityProperties/html/js/entityProperties.js +++ b/scripts/system/create/entityProperties/html/js/entityProperties.js @@ -1355,8 +1355,8 @@ const GROUPS = [ }, { type: "buttons", - buttons: [ { id: "copyPosition", label: "Copy Position", className: "black", onClick: copyPositionProperty }, - { id: "pastePosition", label: "Paste Position", className: "black", onClick: pastePositionProperty } ], + buttons: [ { id: "copyPosition", label: "Copy Position", className: "secondary", onClick: copyPositionProperty }, + { id: "pastePosition", label: "Paste Position", className: "secondary", onClick: pastePositionProperty } ], propertyID: "copyPastePosition" }, { @@ -1383,8 +1383,8 @@ const GROUPS = [ }, { type: "buttons", - buttons: [ { id: "copyRotation", label: "Copy Rotation", className: "black", onClick: copyRotationProperty }, - { id: "pasteRotation", label: "Paste Rotation", className: "black", onClick: pasteRotationProperty } ], + buttons: [ { id: "copyRotation", label: "Copy Rotation", className: "secondary", onClick: copyRotationProperty }, + { id: "pasteRotation", label: "Paste Rotation", className: "secondary", onClick: pasteRotationProperty } ], propertyID: "copyPasteRotation" }, { From a4483e63676f8caa64f546f8cdce53ac173fc9b2 Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Thu, 13 May 2021 21:45:49 -0400 Subject: [PATCH 5/5] Safeguard code for Copy/Paste Position/Rotation Safeguard code for Copy/Paste Position/Rotation The 4 actions has now validations to avoid to only have those validation on the UI. Making sure there is a single selection to execute these actions: Copy Position Copy Rotation Making sure there is a selection that doesn't contain locked entity and that we have a copied value in order to execute these actions: Paste Location Paste Rotation --- scripts/system/create/edit.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/system/create/edit.js b/scripts/system/create/edit.js index c29eb329033..614bd5fd597 100644 --- a/scripts/system/create/edit.js +++ b/scripts/system/create/edit.js @@ -2617,19 +2617,21 @@ var PropertiesTool = function (opts) { } } } else if (data.action === "copyPosition") { - selectionManager.saveProperties(); - properties = selectionManager.savedProperties[selectionManager.selections[0]]; - copiedPosition = properties.position; - Window.copyToClipboard(JSON.stringify(copiedPosition)); - print("COPIED: " + JSON.stringify(copiedPosition)); + if (selectionManager.selections.length === 1) { + selectionManager.saveProperties(); + properties = selectionManager.savedProperties[selectionManager.selections[0]]; + copiedPosition = properties.position; + Window.copyToClipboard(JSON.stringify(copiedPosition)); + } } else if (data.action === "copyRotation") { - selectionManager.saveProperties(); - properties = selectionManager.savedProperties[selectionManager.selections[0]]; - copiedRotation = properties.rotation; - Window.copyToClipboard(JSON.stringify(copiedRotation)); - print("COPIED: " + JSON.stringify(copiedRotation)); + if (selectionManager.selections.length === 1) { + selectionManager.saveProperties(); + properties = selectionManager.savedProperties[selectionManager.selections[0]]; + copiedRotation = properties.rotation; + Window.copyToClipboard(JSON.stringify(copiedRotation)); + } } else if (data.action === "pastePosition") { - if (copiedPosition !== undefined) { + if (copiedPosition !== undefined && selectionManager.selections.length > 0 && SelectionManager.hasUnlockedSelection()) { selectionManager.saveProperties(); for (i = 0; i < selectionManager.selections.length; i++) { Entities.editEntity(selectionManager.selections[i], { @@ -2638,12 +2640,11 @@ var PropertiesTool = function (opts) { } pushCommandForSelections(); selectionManager._update(false, this); - print("PASTE POSITION"); } else { audioFeedback.rejection(); } } else if (data.action === "pasteRotation") { - if (copiedRotation !== undefined) { + if (copiedRotation !== undefined && selectionManager.selections.length > 0 && SelectionManager.hasUnlockedSelection()) { selectionManager.saveProperties(); for (i = 0; i < selectionManager.selections.length; i++) { Entities.editEntity(selectionManager.selections[i], { @@ -2651,8 +2652,7 @@ var PropertiesTool = function (opts) { }); } pushCommandForSelections(); - selectionManager._update(false, this); - print("PASTE ROTATION"); + selectionManager._update(false, this); } else { audioFeedback.rejection(); }