From 4fa72eab6d09c99f2f5a95c19523bbea3e14c852 Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Sat, 5 May 2018 13:25:00 +0300 Subject: [PATCH] show real wearables from avatar in combobox --- .../resources/qml/controls-uit/ComboBox.qml | 1 + interface/resources/qml/hifi/AvatarApp.qml | 29 ++++++++++++----- .../qml/hifi/avatarapp/AdjustWearables.qml | 32 +++++++++++++++---- scripts/system/avatarapp.js | 12 +++++-- 4 files changed, 58 insertions(+), 16 deletions(-) diff --git a/interface/resources/qml/controls-uit/ComboBox.qml b/interface/resources/qml/controls-uit/ComboBox.qml index be8c9f6740..9ec5ed19ba 100644 --- a/interface/resources/qml/controls-uit/ComboBox.qml +++ b/interface/resources/qml/controls-uit/ComboBox.qml @@ -46,6 +46,7 @@ FocusScope { hoverEnabled: true visible: true height: hifi.fontSizes.textFieldInput + 13 // Match height of TextField control. + textRole: "text" function previousItem() { root.currentHighLightedIndex = (root.currentHighLightedIndex + comboBox.count - 1) % comboBox.count; } function nextItem() { root.currentHighLightedIndex = (root.currentHighLightedIndex + comboBox.count + 1) % comboBox.count; } diff --git a/interface/resources/qml/hifi/AvatarApp.qml b/interface/resources/qml/hifi/AvatarApp.qml index d54c58643b..a650a3cd9f 100644 --- a/interface/resources/qml/hifi/AvatarApp.qml +++ b/interface/resources/qml/hifi/AvatarApp.qml @@ -19,10 +19,17 @@ Rectangle { sendToScript(message); } + ListModel { // the only purpose of this model is to convert JS object to ListElement + id: currentAvatarModel + } + + property var jointNames; + function fromScript(message) { console.debug('AvatarApp.qml: fromScript: ', JSON.stringify(message, null, '\t')) if(message.method === 'initialize') { + jointNames = message.reply.jointNames; emitSendToScript({'method' : getAvatarsMethod}); } else if(message.method === getAvatarsMethod) { var getAvatarsReply = message.reply; @@ -32,7 +39,7 @@ Rectangle { var avatarEntry = { 'name' : avatarName, 'url' : Qt.resolvedUrl(allAvatars.urls[i++ % allAvatars.urls.length]), - 'wearables' : '', + 'wearables' : getAvatarsReply.bookmarks[avatarName].avatarEntites ? getAvatarsReply.bookmarks[avatarName].avatarEntites : [], 'entry' : getAvatarsReply.bookmarks[avatarName], 'getMoreAvatars' : false }; @@ -76,14 +83,18 @@ Rectangle { console.debug('selectedAvatarIndex = -1, avatar is not favorite') if(selectedAvatarIndex === -1) { - var currentAvatarEntry = { + + var currentAvatarEntry = { 'name' : '', 'url' : Qt.resolvedUrl(allAvatars.urls[i++ % allAvatars.urls.length]), - 'wearables' : '', + 'wearables' : currentAvatar.avatarEntites ? currentAvatar.avatarEntites : [], 'entry' : currentAvatar, 'getMoreAvatars' : false }; + currentAvatarModel.append(currentAvatarEntry); + currentAvatarEntry = allAvatars.get(allAvatars.count - 1); + selectedAvatar = currentAvatarEntry; view.setPage(0); @@ -111,7 +122,7 @@ Rectangle { property string avatarName: selectedAvatar ? selectedAvatar.name : '' property string avatarUrl: selectedAvatar ? selectedAvatar.url : null - property int avatarWearablesCount: selectedAvatar && selectedAvatar.wearables !== '' ? selectedAvatar.wearables.split('|').length : 0 + property int avatarWearablesCount: selectedAvatar ? selectedAvatar.wearables.count : 0 property bool isAvatarInFavorites: selectedAvatar ? allAvatars.findAvatar(selectedAvatar.name) !== undefined : false property bool isInManageState: false @@ -174,6 +185,7 @@ Rectangle { anchors.right: parent.right anchors.top: header.bottom anchors.bottom: parent.bottom + jointNames: root.jointNames z: 3 } @@ -364,7 +376,8 @@ Rectangle { MouseArea { anchors.fill: parent onClicked: { - adjustWearables.open(); + console.debug('adjustWearables.open'); + adjustWearables.open(selectedAvatar); } } } @@ -395,7 +408,7 @@ Rectangle { var avatar = { 'url': Qt.resolvedUrl('../../images/samples/hifi-mp-e76946cc-c272-4adf-9bb6-02cde0a4b57d-2.png'), 'name': 'Lexi' + (++debug_newAvatarIndex), - 'wearables': '' + 'wearables': [] }; allAvatars.append(avatar) @@ -629,7 +642,7 @@ Rectangle { imageUrl: url border.color: container.highlighted ? style.colors.blueHighlight : 'transparent' border.width: container.highlighted ? 2 : 0 - wearablesCount: (!getMoreAvatars && wearables && wearables !== '') ? wearables.split('|').length : 0 + wearablesCount: !getMoreAvatars ? wearables.count : 0 onWearablesCountChanged: { console.debug('delegate: AvatarThumbnail.wearablesCount: ', wearablesCount) } @@ -882,7 +895,7 @@ Rectangle { var avatar = { 'url': Qt.resolvedUrl(url), 'name': 'Lexi' + (++newAvatarIndex), - 'wearables': 'hat|sunglasses|bracelet' + 'wearables': [] }; allAvatars.append(avatar) diff --git a/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml b/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml index 9a2fc3bc72..abcd1e3353 100644 --- a/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml +++ b/interface/resources/qml/hifi/avatarapp/AdjustWearables.qml @@ -22,9 +22,30 @@ Rectangle { property var onButton2Clicked; property var onButton1Clicked; + property var jointNames; + + function open(avatar) { + console.debug('AdjustWearables.qml: open'); - function open() { visible = true; + wearablesCombobox.model.clear(); + + console.debug('AdjustWearables.qml: avatar.wearables.count: ', avatar.wearables.count); + for(var i = 0; i < avatar.wearables.count; ++i) { + var wearable = avatar.wearables.get(i).properties; + console.debug('wearable: ', JSON.stringify(wearable, null, '\t')) + + for(var j = (wearable.modelURL.length - 1); j >= 0; --j) { + if(wearable.modelURL[j] === '/') { + wearable.text = wearable.modelURL.substring(j + 1) + ' [%jointIndex%]'.replace('%jointIndex%', jointNames[wearable.parentJointIndex]); + console.debug('wearable.text = ', wearable.text); + break; + } + } + wearablesCombobox.model.append(wearable); + } + + wearablesCombobox.currentIndex = 0; } function close() { @@ -51,14 +72,13 @@ Rectangle { width: parent.width - 30 * 2 HifiControlsUit.ComboBox { + id: wearablesCombobox anchors.left: parent.left anchors.right: parent.right + comboBox.textRole: "text" - model: [ - 'Fedora.fbx [HeadTop_End]', - 'Fedora1.fbx [HeadTop_End]', - 'Fedora2.fbx [HeadTop_End]' - ] + model: ListModel { + } } Column { diff --git a/scripts/system/avatarapp.js b/scripts/system/avatarapp.js index 78e152f22a..ef7c3c1b20 100644 --- a/scripts/system/avatarapp.js +++ b/scripts/system/avatarapp.js @@ -21,7 +21,7 @@ Script.include("/~/system/libraries/controllers.js"); // constants from AvatarBookmarks.h var ENTRY_AVATAR_URL = "avatarUrl"; var ENTRY_AVATAR_ATTACHMENTS = "attachments"; -var ENTRY_AVATAR_ENTITIES = "avatarEntities"; +var ENTRY_AVATAR_ENTITIES = "avatarEntites"; var ENTRY_AVATAR_SCALE = "avatarScale"; var ENTRY_VERSION = "version"; @@ -134,7 +134,15 @@ function onTabletScreenChanged(type, url) { button.editProperties({isActive: onAvatarAppScreen}); if (onAvatarAppScreen) { - sendToQml({'method' : 'initialize'}) + + var message = { + 'method' : 'initialize', + 'reply' : { + 'jointNames' : MyAvatar.getJointNames() + } + }; + + sendToQml(message) } console.debug('onAvatarAppScreen: ', onAvatarAppScreen);