diff --git a/scripts/system/assets/images/lock.svg b/scripts/system/assets/images/lock.svg
new file mode 100644
index 0000000000..1480359f43
--- /dev/null
+++ b/scripts/system/assets/images/lock.svg
@@ -0,0 +1,70 @@
+
+
+
+
diff --git a/scripts/system/assets/images/unlock.svg b/scripts/system/assets/images/unlock.svg
new file mode 100644
index 0000000000..a7664c1f59
--- /dev/null
+++ b/scripts/system/assets/images/unlock.svg
@@ -0,0 +1,70 @@
+
+
+
+
diff --git a/scripts/system/attachedEntitiesManager.js b/scripts/system/attachedEntitiesManager.js
index 9ddb040297..124b2f76ec 100644
--- a/scripts/system/attachedEntitiesManager.js
+++ b/scripts/system/attachedEntitiesManager.js
@@ -22,7 +22,7 @@ var MINIMUM_DROP_DISTANCE_FROM_JOINT = 0.8;
var ATTACHED_ENTITY_SEARCH_DISTANCE = 10.0;
var ATTACHED_ENTITIES_SETTINGS_KEY = "ATTACHED_ENTITIES";
var DRESSING_ROOM_DISTANCE = 2.0;
-var SHOW_TOOL_BAR = false;
+var SHOW_TOOL_BAR = true;
// tool bar
@@ -30,34 +30,20 @@ if (SHOW_TOOL_BAR) {
var BUTTON_SIZE = 32;
var PADDING = 3;
Script.include(["libraries/toolBars.js"]);
- var toolBar = new ToolBar(0, 0, ToolBar.VERTICAL, "highfidelity.attachedEntities.toolbar", function(screenSize) {
- return {
- x: (BUTTON_SIZE + PADDING),
- y: (screenSize.y / 2 - BUTTON_SIZE * 2 + PADDING)
- };
- });
- var saveButton = toolBar.addOverlay("image", {
+
+ var toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL, "highfidelity.attachedEntities.toolbar");
+ var lockButton = toolBar.addTool({
width: BUTTON_SIZE,
height: BUTTON_SIZE,
- imageURL: ".../save.png",
+ imageURL: Script.resolvePath("assets/images/lock.svg"),
color: {
red: 255,
green: 255,
blue: 255
},
- alpha: 1
- });
- var loadButton = toolBar.addOverlay("image", {
- width: BUTTON_SIZE,
- height: BUTTON_SIZE,
- imageURL: ".../load.png",
- color: {
- red: 255,
- green: 255,
- blue: 255
- },
- alpha: 1
- });
+ alpha: 1,
+ visible: true
+ }, false);
}
@@ -67,10 +53,8 @@ function mousePressEvent(event) {
y: event.y
});
- if (clickedOverlay == saveButton) {
- manager.saveAttachedEntities();
- } else if (clickedOverlay == loadButton) {
- manager.loadAttachedEntities();
+ if (lockButton === toolBar.clicked(clickedOverlay)) {
+ manager.toggleLocked();
}
}
@@ -92,6 +76,8 @@ Script.scriptEnding.connect(scriptEnding);
function AttachedEntitiesManager() {
+ var clothingLocked = true;
+
this.subscribeToMessages = function() {
Messages.subscribe('Hifi-Object-Manipulation');
Messages.messageReceived.connect(this.handleWearableMessages);
@@ -128,19 +114,6 @@ function AttachedEntitiesManager() {
}
}
- this.avatarIsInDressingRoom = function() {
- // return true if MyAvatar is near the dressing room
- var possibleDressingRoom = Entities.findEntities(MyAvatar.position, DRESSING_ROOM_DISTANCE);
- for (i = 0; i < possibleDressingRoom.length; i++) {
- var entityID = possibleDressingRoom[i];
- var props = Entities.getEntityProperties(entityID);
- if (props.name == 'Hifi-Dressing-Room-Base') {
- return true;
- }
- }
- return false;
- }
-
this.handleEntityRelease = function(grabbedEntity, releasedFromJoint) {
// if this is still equipped, just rewrite the position information.
var grabData = getEntityCustomData('grabKey', grabbedEntity, {});
@@ -179,21 +152,23 @@ function AttachedEntitiesManager() {
}
if (bestJointIndex != -1) {
- var wearProps = {
- parentID: MyAvatar.sessionUUID,
- parentJointIndex: bestJointIndex
- };
+ var wearProps = Entities.getEntityProperties(grabbedEntity);
+ wearProps.parentID = MyAvatar.sessionUUID;
+ wearProps.parentJointIndex = bestJointIndex;
if (bestJointOffset && bestJointOffset.constructor === Array) {
- if (this.avatarIsInDressingRoom() || bestJointOffset.length < 2) {
+ if (!clothingLocked || bestJointOffset.length < 2) {
this.updateRelativeOffsets(grabbedEntity);
} else {
- // don't snap the entity to the preferred position if the avatar is in the dressing room.
+ // don't snap the entity to the preferred position if unlocked
wearProps.localPosition = bestJointOffset[0];
wearProps.localRotation = bestJointOffset[1];
}
}
- Entities.editEntity(grabbedEntity, wearProps);
+
+ // Entities.editEntity(grabbedEntity, wearProps);
+ Entities.deleteEntity(grabbedEntity);
+ Entities.addEntity(wearProps, true);
} else if (props.parentID != NULL_UUID) {
// drop the entity and set it to have no parent (not on the avatar), unless it's being equipped in a hand.
if (props.parentID === MyAvatar.sessionUUID &&
@@ -201,7 +176,11 @@ function AttachedEntitiesManager() {
props.parentJointIndex == MyAvatar.getJointIndex("LeftHand"))) {
// this is equipped on a hand -- don't clear the parent.
} else {
- Entities.editEntity(grabbedEntity, { parentID: NULL_UUID });
+ var wearProps = Entities.getEntityProperties(grabbedEntity);
+ wearProps.parentID = NULL_UUID;
+ wearProps.parentJointIndex = -1;
+ Entities.deleteEntity(grabbedEntity);
+ Entities.addEntity(wearProps, false);
}
}
}
@@ -221,6 +200,17 @@ function AttachedEntitiesManager() {
return false;
}
+ this.toggleLocked = function() {
+ print("toggleLocked");
+ if (clothingLocked) {
+ clothingLocked = false;
+ toolBar.setImageURL(Script.resolvePath("assets/images/unlock.svg"), lockButton);
+ } else {
+ clothingLocked = true;
+ toolBar.setImageURL(Script.resolvePath("assets/images/lock.svg"), lockButton);
+ }
+ }
+
this.saveAttachedEntities = function() {
print("--- saving attached entities ---");
saveData = [];
diff --git a/scripts/system/libraries/toolBars.js b/scripts/system/libraries/toolBars.js
index d97575d349..9efe533457 100644
--- a/scripts/system/libraries/toolBars.js
+++ b/scripts/system/libraries/toolBars.js
@@ -56,6 +56,10 @@ Overlay2D = function(properties, overlay) { // overlay is an optional variable
properties.alpha = alpha;
Overlays.editOverlay(overlay, { alpha: alpha });
}
+ this.setImageURL = function(imageURL) {
+ properties.imageURL = imageURL;
+ Overlays.editOverlay(overlay, { imageURL: imageURL });
+ }
this.show = function(doShow) {
properties.visible = doShow;
Overlays.editOverlay(overlay, { visible: doShow });
@@ -254,7 +258,7 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
}
this.save();
}
-
+
this.setAlpha = function(alpha, tool) {
if(typeof(tool) === 'undefined') {
for(var tool in this.tools) {
@@ -268,7 +272,11 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
this.tools[tool].setAlpha(alpha);
}
}
-
+
+ this.setImageURL = function(imageURL, tool) {
+ this.tools[tool].setImageURL(imageURL);
+ }
+
this.setBack = function(color, alpha) {
if (color == null) {
Overlays.editOverlay(this.back, { visible: false });
@@ -478,4 +486,4 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
}
ToolBar.SPACING = 6;
ToolBar.VERTICAL = 0;
-ToolBar.HORIZONTAL = 1;
\ No newline at end of file
+ToolBar.HORIZONTAL = 1;