From 90fb0d7be6a40ef3fe36f5c2f62cc56f62c68150 Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Fri, 10 Aug 2018 17:59:11 +0300 Subject: [PATCH] add possibility to add wearable from external url --- interface/resources/qml/hifi/AvatarApp.qml | 3 +++ .../qml/hifi/avatarapp/AdjustWearables.qml | 9 +++++++ .../qml/hifi/avatarapp/MessageBoxes.qml | 20 ++++++++++++++ scripts/system/avatarapp.js | 27 +++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/interface/resources/qml/hifi/AvatarApp.qml b/interface/resources/qml/hifi/AvatarApp.qml index bd3f8fd1cf..217525498d 100644 --- a/interface/resources/qml/hifi/AvatarApp.qml +++ b/interface/resources/qml/hifi/AvatarApp.qml @@ -285,6 +285,9 @@ Rectangle { onWearableSelected: { emitSendToScript({'method' : 'selectWearable', 'entityID' : id}); } + onAddWearable: { + emitSendToScript({'method' : 'addWearable', 'avatarName' : avatarName, 'url' : url}); + } z: 3 } diff --git a/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml b/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml index e99fdfd243..27ae590fc5 100644 --- a/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml +++ b/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml @@ -18,6 +18,7 @@ Rectangle { signal adjustWearablesOpened(var avatarName); signal adjustWearablesClosed(bool status, var avatarName); + signal addWearable(string avatarName, string url); property bool modified: false; Component.onCompleted: { @@ -40,6 +41,8 @@ Rectangle { function refresh(avatar) { wearablesCombobox.model.clear(); + wearablesCombobox.currentIndex = -1; + for(var i = 0; i < avatar.wearables.count; ++i) { var wearable = avatar.wearables.get(i).properties; for(var j = (wearable.modelURL.length - 1); j >= 0; --j) { @@ -167,6 +170,12 @@ Rectangle { linkColor: hifi.colors.blueHighlight anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right + onLinkActivated: { + popup.showSpecifyWearableUrl(function(url) { + console.debug('popup.showSpecifyWearableUrl: ', url); + addWearable(root.avatarName, url); + }); + } } } } diff --git a/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml b/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml index a381da7d0b..64c2d478c0 100644 --- a/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml +++ b/interface/resources/qml/hifi/avatarapp/MessageBoxes.qml @@ -33,6 +33,26 @@ MessageBox { popup.inputText.forceActiveFocus(); } + function showSpecifyWearableUrl(callback) { + popup.button2text = 'CONFIRM' + popup.button1text = 'CANCEL' + popup.titleText = 'Specify Wearable URL' + popup.bodyText = 'If you want to add a custom wearable, you can specify the URL of the wearable file here.' + + popup.inputText.visible = true; + popup.inputText.placeholderText = 'Enter Wearable URL'; + + popup.onButton2Clicked = function() { + if(callback) + callback(popup.inputText.text); + + popup.close(); + } + + popup.open(); + popup.inputText.forceActiveFocus(); + } + property url getWearablesUrl: '../../../images/avatarapp/AvatarIsland.jpg' function showGetWearables(callback, linkCallback) { diff --git a/scripts/system/avatarapp.js b/scripts/system/avatarapp.js index 4bc4d1a762..38b6d2447c 100644 --- a/scripts/system/avatarapp.js +++ b/scripts/system/avatarapp.js @@ -235,6 +235,33 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See Messages.messageReceived.disconnect(handleWearableMessages); Messages.unsubscribe('Hifi-Object-Manipulation'); break; + case 'addWearable': + + var joints = MyAvatar.getJointNames(); + var hipsIndex = -1; + + for(var i = 0; i < joints.length; ++i) { + if(joints[i] === 'Hips') { + hipsIndex = i; + break; + } + } + + var properties = { + name: "Custom wearable", + type: "Model", + modelURL: message.url, + parentID: MyAvatar.sessionUUID, + relayParentJoints: false, + parentJointIndex: hipsIndex + }; + + var entityID = Entities.addEntity(properties, true); + updateAvatarWearables(currentAvatar, message.avatarName); + executeLater(function() { + onSelectedEntity(entityID); + }); + break; case 'selectWearable': ensureWearableSelected(message.entityID); break;