show real wearables from avatar in combobox

This commit is contained in:
Alexander Ivash 2018-05-05 13:25:00 +03:00
parent 245ab7a309
commit 4fa72eab6d
4 changed files with 58 additions and 16 deletions

View file

@ -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; }

View file

@ -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)

View file

@ -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 {

View file

@ -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);