From 76657a670c5d19ca3255b9e69c39c80df95567a1 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Mon, 27 Mar 2017 11:28:57 -0700 Subject: [PATCH] added notifications (faked user name for now), along with switch to avatar entities --- .../src/scripting/WindowScriptingInterface.cpp | 10 +++++++++- interface/src/scripting/WindowScriptingInterface.h | 4 ++++ scripts/system/makeUserConnection.js | 9 ++++++--- scripts/system/notifications.js | 14 +++++++++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 9c1aedf7a0..39c2f2e402 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -235,6 +235,14 @@ void WindowScriptingInterface::shareSnapshot(const QString& path, const QUrl& hr qApp->shareSnapshot(path, href); } +void WindowScriptingInterface::makeConnection(bool success, const QString& userNameOrError) { + if (success) { + emit connectionAdded(userNameOrError); + } else { + emit connectionError(userNameOrError); + } +} + bool WindowScriptingInterface::isPhysicsEnabled() { return qApp->isPhysicsEnabled(); } @@ -255,7 +263,7 @@ int WindowScriptingInterface::openMessageBox(QString title, QString text, int bu } int WindowScriptingInterface::createMessageBox(QString title, QString text, int buttons, int defaultButton) { - auto messageBox = DependencyManager::get()->createMessageBox(OffscreenUi::ICON_INFORMATION, title, text, + auto messageBox = DependencyManager::get()->createMessageBox(OffscreenUi::ICON_INFORMATION, title, text, static_cast>(buttons), static_cast(defaultButton)); connect(messageBox, SIGNAL(selected(int)), this, SLOT(onMessageBoxSelected(int))); diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 60d24d50df..b7bed7d85f 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -56,6 +56,7 @@ public slots: void showAssetServer(const QString& upload = ""); void copyToClipboard(const QString& text); void takeSnapshot(bool notify = true, bool includeAnimated = false, float aspectRatio = 0.0f); + void makeConnection(bool success, const QString& userNameOrError); void shareSnapshot(const QString& path, const QUrl& href = QUrl("")); bool isPhysicsEnabled(); @@ -74,6 +75,9 @@ signals: void snapshotShared(const QString& error); void processingGif(); + void connectionAdded(const QString& connectionName); + void connectionError(const QString& errorString); + void messageBoxClosed(int id, int button); // triggered when window size or position changes diff --git a/scripts/system/makeUserConnection.js b/scripts/system/makeUserConnection.js index 0b73beaca5..bb3d99ddee 100644 --- a/scripts/system/makeUserConnection.js +++ b/scripts/system/makeUserConnection.js @@ -271,7 +271,8 @@ function updateVisualization() { particleProps = PARTICLE_EFFECT_PROPS; particleProps.isEmitting = 0; particleProps.position = calcParticlePos(myHandPosition, otherHand, otherOrientation); - particleEffect = Entities.addEntity(particleProps); + particleProps.parentID = MyAvatar.sessionUUID; + particleEffect = Entities.addEntity(particleProps, true); } else { particleProps.position = calcParticlePos(myHandPosition, otherHand, otherOrientation); particleProps.isEmitting = 1; @@ -279,10 +280,11 @@ function updateVisualization() { } if (!makingConnectionParticleEffect) { var props = MAKING_CONNECTION_PARTICLE_PROPS; + props.parentID = MyAvatar.sessionUUID; makingConnectionEmitRate = 2000; props.emitRate = makingConnectionEmitRate; props.position = myHandPosition; - makingConnectionParticleEffect = Entities.addEntity(props); + makingConnectionParticleEffect = Entities.addEntity(props, true); } else { makingConnectionEmitRate *= 0.5; Entities.editEntity(makingConnectionParticleEffect, {emitRate: makingConnectionEmitRate, position: myHandPosition, isEmitting: 1}); @@ -485,7 +487,6 @@ function makeConnection(id) { // probably, in which we do this. Controller.triggerHapticPulse(HAPTIC_DATA.background.strength, MAKING_CONNECTION_TIMEOUT, handToHaptic(currentHand)); - // now that we made connection, reset everything makingFriendsTimeout = Script.setTimeout(function () { if (!successfulHandshakeInjector) { successfulHandshakeInjector = Audio.playSound(successfulHandshakeSound, {position: getHandPosition(MyAvatar, currentHand), volume: 0.5, localOnly: true}); @@ -494,6 +495,8 @@ function makeConnection(id) { } Controller.triggerHapticPulse(HAPTIC_DATA.success.strength, HAPTIC_DATA.success.duration, handToHaptic(currentHand)); // don't change state (so animation continues while gripped) + // but do send a notification, by calling the slot that emits the signal for it + Window.makeConnection(true, "otherGuy"); // this is successful, unsucessful would be false, errorString }, MAKING_CONNECTION_TIMEOUT); } diff --git a/scripts/system/notifications.js b/scripts/system/notifications.js index b2ebb1fd46..59384114e0 100644 --- a/scripts/system/notifications.js +++ b/scripts/system/notifications.js @@ -94,11 +94,13 @@ var NotificationType = { LOD_WARNING: 2, CONNECTION_REFUSED: 3, EDIT_ERROR: 4, + CONNECTION: 5, properties: [ { text: "Snapshot" }, { text: "Level of Detail" }, { text: "Connection Refused" }, - { text: "Edit error" } + { text: "Edit error" }, + { text: "Connection" } ], getTypeFromMenuItem: function(menuItemName) { if (menuItemName.substr(menuItemName.length - NOTIFICATION_MENU_ITEM_POST.length) !== NOTIFICATION_MENU_ITEM_POST) { @@ -539,6 +541,14 @@ function processingGif() { createNotification("Processing GIF snapshot...", NotificationType.SNAPSHOT); } +function connectionAdded(connectionName) { + createNotification(wordWrap("Successfully connected to " + connectionName), NotificationType.CONNECTION); +} + +function connectionError(error) { + createNotification(wordWrap("Error trying to make connection: " + error), NotificationType.CONNECTION); +} + // handles mouse clicks on buttons function mousePressEvent(event) { var pickRay, @@ -639,6 +649,8 @@ Menu.menuItemEvent.connect(menuItemEvent); Window.domainConnectionRefused.connect(onDomainConnectionRefused); Window.snapshotTaken.connect(onSnapshotTaken); Window.processingGif.connect(processingGif); +Window.connectionAdded.connect(connectionAdded); +Window.connectionError.connect(connectionError); Window.notifyEditError = onEditError; Window.notify = onNotify;