From 1e608b13b2b869aeedb7d7cc2efe84faa44f1495 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 11 Jan 2018 14:45:43 -0800 Subject: [PATCH] Show username when admin (this probably isn't the way to get username --- .../qml/hifi/commerce/wallet/Wallet.qml | 1 + .../wallet/sendMoney/ConnectionItem.qml | 2 +- .../commerce/wallet/sendMoney/SendMoney.qml | 162 ++++++++++++++---- libraries/avatars/src/AvatarData.h | 3 +- libraries/avatars/src/ScriptAvatarData.cpp | 1 + libraries/avatars/src/ScriptAvatarData.h | 3 +- scripts/system/commerce/wallet.js | 35 +++- scripts/system/pal.js | 4 +- 8 files changed, 169 insertions(+), 42 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml index 5340f0e202..6b350f9f93 100644 --- a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml +++ b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml @@ -736,6 +736,7 @@ Rectangle { sendMoney.updateConnections(message.connections); break; case 'selectRecipient': + case 'updateSelectedRecipientUsername': sendMoney.fromScript(message); break; default: diff --git a/interface/resources/qml/hifi/commerce/wallet/sendMoney/ConnectionItem.qml b/interface/resources/qml/hifi/commerce/wallet/sendMoney/ConnectionItem.qml index 80c87e307b..84d6b304f6 100644 --- a/interface/resources/qml/hifi/commerce/wallet/sendMoney/ConnectionItem.qml +++ b/interface/resources/qml/hifi/commerce/wallet/sendMoney/ConnectionItem.qml @@ -114,7 +114,7 @@ Item { width: 110; text: "CHOOSE"; onClicked: { - var msg = { method: 'chooseConnection', userName: root.userName }; + var msg = { method: 'chooseConnection', userName: root.userName, profilePicUrl: root.profilePicUrl }; sendToSendMoney(msg); } } diff --git a/interface/resources/qml/hifi/commerce/wallet/sendMoney/SendMoney.qml b/interface/resources/qml/hifi/commerce/wallet/sendMoney/SendMoney.qml index 9e21cb7289..0d948bbe4b 100644 --- a/interface/resources/qml/hifi/commerce/wallet/sendMoney/SendMoney.qml +++ b/interface/resources/qml/hifi/commerce/wallet/sendMoney/SendMoney.qml @@ -14,6 +14,7 @@ import Hifi 1.0 as Hifi import QtQuick 2.6 import QtQuick.Controls 2.2 +import QtGraphicalEffects 1.0 import "../../../../styles-uit" import "../../../../controls-uit" as HifiControlsUit import "../../../../controls" as HifiControls @@ -440,6 +441,7 @@ Item { sendMoneyStep.selectedRecipientNodeID = ''; sendMoneyStep.selectedRecipientDisplayName = msg.userName; sendMoneyStep.selectedRecipientUserName = 'connection'; + sendMoneyStep.selectedRecipientProfilePic = msg.profilePicUrl; root.nextActiveView = "sendMoneyStep"; } @@ -561,8 +563,8 @@ Item { } RalewaySemiBold { - id: avatarNodeID; - text: chooseRecipientNearby.selectedRecipient; + id: avatarDisplayName; + text: '"' + AvatarList.getAvatar(chooseRecipientNearby.selectedRecipient).sessionDisplayName + '"'; // Anchors anchors.top: sendToText.bottom; anchors.topMargin: 60; @@ -572,7 +574,43 @@ Item { anchors.rightMargin: 30; height: paintedHeight; // Text size - size: 18; + size: 22; + // Style + horizontalAlignment: Text.AlignHCenter; + color: hifi.colors.baseGray; + } + + RalewaySemiBold { + id: avatarNodeID; + text: chooseRecipientNearby.selectedRecipient; + // Anchors + anchors.top: avatarDisplayName.bottom; + anchors.topMargin: 6; + anchors.left: parent.left; + anchors.leftMargin: 30; + anchors.right: parent.right; + anchors.rightMargin: 30; + height: paintedHeight; + // Text size + size: 14; + // Style + horizontalAlignment: Text.AlignHCenter; + color: hifi.colors.lightGrayText; + } + + RalewaySemiBold { + id: avatarUserName; + text: sendMoneyStep.selectedRecipientUserName; + // Anchors + anchors.top: avatarNodeID.bottom; + anchors.topMargin: 12; + anchors.left: parent.left; + anchors.leftMargin: 30; + anchors.right: parent.right; + anchors.rightMargin: 30; + height: paintedHeight; + // Text size + size: 22; // Style horizontalAlignment: Text.AlignHCenter; color: hifi.colors.baseGray; @@ -632,8 +670,6 @@ Item { onClicked: { sendMoneyStep.referrer = "nearby"; sendMoneyStep.selectedRecipientNodeID = chooseRecipientNearby.selectedRecipient; - sendMoneyStep.selectedRecipientDisplayName = '"ZRF Changeme"'; - sendMoneyStep.selectedRecipientUserName = 'unknown username'; chooseRecipientNearby.selectedRecipient = ""; root.nextActiveView = "sendMoneyStep"; @@ -652,6 +688,7 @@ Item { property string selectedRecipientNodeID; property string selectedRecipientDisplayName; property string selectedRecipientUserName; + property string selectedRecipientProfilePic; visible: root.currentActiveView === "sendMoneyStep"; anchors.fill: parent; @@ -703,37 +740,94 @@ Item { verticalAlignment: Text.AlignVCenter; } - RalewaySemiBold { - id: recipientDisplayName; - text: sendMoneyStep.selectedRecipientDisplayName; - // Anchors + Item { + id: recipientIsNearby; + visible: sendMoneyStep.referrer === "nearby"; anchors.top: parent.top; anchors.left: sendToText_sendMoneyStep.right; anchors.right: changeButton.left; anchors.rightMargin: 12; - height: parent.height/2; - // Text size - size: 18; - // Style - color: hifi.colors.baseGray; - verticalAlignment: Text.AlignBottom; + height: parent.height; + + RalewaySemiBold { + id: recipientDisplayName; + text: sendMoneyStep.selectedRecipientDisplayName; + // Anchors + anchors.top: parent.top; + anchors.left: parent.left; + anchors.right: parent.right; + anchors.rightMargin: 12; + height: parent.height/2; + // Text size + size: 18; + // Style + color: hifi.colors.baseGray; + verticalAlignment: Text.AlignBottom; + } + + RalewaySemiBold { + text: sendMoneyStep.selectedRecipientUserName; + // Anchors + anchors.bottom: parent.bottom; + anchors.left: recipientDisplayName.anchors.left; + anchors.leftMargin: recipientDisplayName.anchors.leftMargin; + anchors.right: recipientDisplayName.anchors.right; + anchors.rightMargin: recipientDisplayName.anchors.rightMargin; + height: parent.height/2; + // Text size + size: 16; + // Style + color: hifi.colors.baseGray; + verticalAlignment: Text.AlignTop; + } } - RalewaySemiBold { - id: recipientUsername; - text: sendMoneyStep.selectedRecipientUserName; - // Anchors - anchors.bottom: parent.bottom; - anchors.left: recipientDisplayName.anchors.left; - anchors.leftMargin: recipientDisplayName.anchors.leftMargin; - anchors.right: recipientDisplayName.anchors.right; - anchors.rightMargin: recipientDisplayName.anchors.rightMargin; - height: parent.height/2; - // Text size - size: 16; - // Style - color: hifi.colors.baseGray; - verticalAlignment: Text.AlignTop; + Item { + id: recipientIsConnection; + visible: sendMoneyStep.referrer === "connections"; + anchors.top: parent.top; + anchors.left: sendToText_sendMoneyStep.right; + anchors.right: changeButton.left; + anchors.rightMargin: 12; + height: parent.height; + + Image { + id: userImage; + source: sendMoneyStep.selectedRecipientProfilePic !== "" ? ((0 === sendMoneyStep.selectedRecipientProfilePic.indexOf("http")) ? + sendMoneyStep.selectedRecipientProfilePic : (Account.metaverseServerURL + sendMoneyStep.selectedRecipientProfilePic)) : ""; + mipmap: true; + // Anchors + anchors.left: parent.left; + anchors.verticalCenter: parent.verticalCenter; + height: parent.height - 4; + layer.enabled: true; + layer.effect: OpacityMask { + maskSource: Item { + width: userImage.width; + height: userImage.height; + Rectangle { + anchors.centerIn: parent; + width: userImage.width; // This works because userImage is square + height: width; + radius: width; + } + } + } + } + + RalewaySemiBold { + text: sendMoneyStep.selectedRecipientUserName; + // Anchors + anchors.left: userImage.right; + anchors.leftMargin: 8; + anchors.verticalCenter: parent.verticalCenter; + height: parent.height - 4; + // Text size + size: 16; + // Style + color: hifi.colors.baseGray; + verticalAlignment: Text.AlignVCenter; + } } // "CHANGE" button @@ -1472,6 +1566,7 @@ Item { sendMoneyStep.selectedRecipientNodeID = ""; sendMoneyStep.selectedRecipientDisplayName = ""; sendMoneyStep.selectedRecipientUserName = ""; + sendMoneyStep.selectedRecipientProfilePic = ""; amountTextField.text = ""; optionalMessage.text = ""; } @@ -1494,10 +1589,17 @@ Item { case 'selectRecipient': if (message.isSelected) { chooseRecipientNearby.selectedRecipient = message.id[0]; + sendMoneyStep.selectedRecipientDisplayName = message.displayName; + sendMoneyStep.selectedRecipientUserName = message.userName; } else { chooseRecipientNearby.selectedRecipient = ""; + sendMoneyStep.selectedRecipientDisplayName = ''; + sendMoneyStep.selectedRecipientUserName = ''; } break; + case 'updateSelectedRecipientUsername': + sendMoneyStep.selectedRecipientUserName = message.userName; + break; default: console.log('SendMoney: Unrecognized message from wallet.js:', JSON.stringify(message)); } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index d7dd2837cb..00cc760658 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -358,7 +358,7 @@ class AvatarData : public QObject, public SpatiallyNestable { Q_PROPERTY(QString displayName READ getDisplayName WRITE setDisplayName NOTIFY displayNameChanged) // sessionDisplayName is sanitized, defaulted version displayName that is defined by the AvatarMixer rather than by Interface clients. // The result is unique among all avatars present at the time. - Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName WRITE setSessionDisplayName) + Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName WRITE setSessionDisplayName NOTIFY sessionDisplayNameChanged) Q_PROPERTY(bool lookAtSnappingEnabled MEMBER _lookAtSnappingEnabled NOTIFY lookAtSnappingChanged) Q_PROPERTY(QString skeletonModelURL READ getSkeletonModelURLFromScript WRITE setSkeletonModelURLFromScript) Q_PROPERTY(QVector attachmentData READ getAttachmentData WRITE setAttachmentData) @@ -685,6 +685,7 @@ public: signals: void displayNameChanged(); + void sessionDisplayNameChanged(); void lookAtSnappingChanged(bool enabled); void sessionUUIDChanged(); diff --git a/libraries/avatars/src/ScriptAvatarData.cpp b/libraries/avatars/src/ScriptAvatarData.cpp index 64cd534c8b..1fd001e536 100644 --- a/libraries/avatars/src/ScriptAvatarData.cpp +++ b/libraries/avatars/src/ScriptAvatarData.cpp @@ -15,6 +15,7 @@ ScriptAvatarData::ScriptAvatarData(AvatarSharedPointer avatarData) : _avatarData(avatarData) { QObject::connect(avatarData.get(), &AvatarData::displayNameChanged, this, &ScriptAvatarData::displayNameChanged); + QObject::connect(avatarData.get(), &AvatarData::sessionDisplayNameChanged, this, &ScriptAvatarData::sessionDisplayNameChanged); QObject::connect(avatarData.get(), &AvatarData::lookAtSnappingChanged, this, &ScriptAvatarData::lookAtSnappingChanged); } diff --git a/libraries/avatars/src/ScriptAvatarData.h b/libraries/avatars/src/ScriptAvatarData.h index 46dfb5325f..68074b838d 100644 --- a/libraries/avatars/src/ScriptAvatarData.h +++ b/libraries/avatars/src/ScriptAvatarData.h @@ -44,7 +44,7 @@ class ScriptAvatarData : public QObject { // Q_PROPERTY(QUuid sessionUUID READ getSessionUUID) Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged) - Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName) + Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName NOTIFY sessionDisplayNameChanged) Q_PROPERTY(bool isReplicated READ getIsReplicated) Q_PROPERTY(bool lookAtSnappingEnabled READ getLookAtSnappingEnabled NOTIFY lookAtSnappingChanged) @@ -131,6 +131,7 @@ public: signals: void displayNameChanged(); + void sessionDisplayNameChanged(); void lookAtSnappingChanged(bool enabled); public slots: diff --git a/scripts/system/commerce/wallet.js b/scripts/system/commerce/wallet.js index e8156ae5fc..0826325a57 100644 --- a/scripts/system/commerce/wallet.js +++ b/scripts/system/commerce/wallet.js @@ -390,13 +390,32 @@ // // Clicks. // + function usernameFromIDReply(id, username, machineFingerprint, isAdmin) { + if (selectedIds[0] === id) { + var message = { + method: 'updateSelectedRecipientUsername', + userName: username === "" ? "unknown username" : username + }; + sendToQml(message); + } + } function handleClick(pickRay) { ExtendedOverlay.applyPickRay(pickRay, function (overlay) { var nextSelectedStatus = !overlay.selected; - var message = { method: 'selectRecipient', id: [overlay.key], isSelected: nextSelectedStatus }; + var avatarId = overlay.key; + selectedIds = nextSelectedStatus ? [avatarId] : []; + if (nextSelectedStatus) { + Users.requestUsernameFromID(avatarId); + } + var message = { + method: 'selectRecipient', + id: [avatarId], + isSelected: nextSelectedStatus, + displayName: '"' + AvatarList.getAvatar(avatarId).sessionDisplayName + '"', + userName: '' + }; sendToQml(message); - - selectedIds = nextSelectedStatus ? [overlay.key] : []; + ExtendedOverlay.some(function (overlay) { var id = overlay.key; var selected = ExtendedOverlay.isSelected(id); @@ -625,6 +644,11 @@ if (onWalletScreen) { isWired = true; + Users.usernameFromIDReply.connect(usernameFromIDReply); + Controller.mousePressEvent.connect(handleMouseEvent); + Controller.mouseMoveEvent.connect(handleMouseMoveEvent); + triggerMapping.enable(); + triggerPressMapping.enable(); } else { off(); } @@ -648,15 +672,12 @@ }); button.clicked.connect(onButtonClicked); tablet.screenChanged.connect(onTabletScreenChanged); - Controller.mousePressEvent.connect(handleMouseEvent); - Controller.mouseMoveEvent.connect(handleMouseMoveEvent); - triggerMapping.enable(); - triggerPressMapping.enable(); } } var isWired = false; function off() { if (isWired) { // It is not ok to disconnect these twice, hence guard. + Users.usernameFromIDReply.disconnect(usernameFromIDReply); Script.update.disconnect(updateOverlays); Controller.mousePressEvent.disconnect(handleMouseEvent); Controller.mouseMoveEvent.disconnect(handleMouseMoveEvent); diff --git a/scripts/system/pal.js b/scripts/system/pal.js index ed7059f9f3..1b93bdde32 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -685,7 +685,6 @@ function startup() { }); button.clicked.connect(onTabletButtonClicked); tablet.screenChanged.connect(onTabletScreenChanged); - Users.usernameFromIDReply.connect(usernameFromIDReply); Window.domainChanged.connect(clearLocalQMLDataAndClosePAL); Window.domainConnectionRefused.connect(clearLocalQMLDataAndClosePAL); Messages.subscribe(CHANNEL); @@ -708,6 +707,7 @@ function off() { Controller.mousePressEvent.disconnect(handleMouseEvent); Controller.mouseMoveEvent.disconnect(handleMouseMoveEvent); tablet.tabletShownChanged.disconnect(tabletVisibilityChanged); + Users.usernameFromIDReply.disconnect(usernameFromIDReply); isWired = false; ContextOverlay.enabled = true } @@ -744,6 +744,7 @@ function onTabletButtonClicked() { Script.update.connect(updateOverlays); Controller.mousePressEvent.connect(handleMouseEvent); Controller.mouseMoveEvent.connect(handleMouseMoveEvent); + Users.usernameFromIDReply.connect(usernameFromIDReply); triggerMapping.enable(); triggerPressMapping.enable(); audioTimer = createAudioInterval(conserveResources ? AUDIO_LEVEL_CONSERVED_UPDATE_INTERVAL_MS : AUDIO_LEVEL_UPDATE_INTERVAL_MS); @@ -890,7 +891,6 @@ function shutdown() { button.clicked.disconnect(onTabletButtonClicked); tablet.removeButton(button); tablet.screenChanged.disconnect(onTabletScreenChanged); - Users.usernameFromIDReply.disconnect(usernameFromIDReply); Window.domainChanged.disconnect(clearLocalQMLDataAndClosePAL); Window.domainConnectionRefused.disconnect(clearLocalQMLDataAndClosePAL); Messages.subscribe(CHANNEL);