diff --git a/examples/airGuitar.js b/examples/airGuitar.js index b7c4b72948..78c16be7bc 100644 --- a/examples/airGuitar.js +++ b/examples/airGuitar.js @@ -35,16 +35,26 @@ var chords = new Array(); chords[1] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+A.raw"); chords[2] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+B.raw"); chords[3] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+E.raw"); +chords[4] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+G.raw"); + // Electric guitar -chords[4] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+A+short.raw"); -chords[5] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+B+short.raw"); -chords[6] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+E+short.raw"); +chords[5] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+A+short.raw"); +chords[6] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+B+short.raw"); +chords[7] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+E+short.raw"); +chords[8] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+G+short.raw"); -var guitarSelector = 3; +// Steel Guitar +chords[9] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+A.raw"); +chords[10] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+B.raw"); +chords[11] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+E.raw"); +chords[12] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+G.raw"); -var whichChord = chords[guitarSelector + 1]; +var NUM_CHORDS = 4; +var NUM_GUITARS = 3; +var guitarSelector = NUM_CHORDS; +var whichChord = 1; -var leftHanded = false; +var leftHanded = true; if (leftHanded) { var strumHand = 0; var chordHand = 1; @@ -59,20 +69,23 @@ var lastPosition = { x: 0.0, var soundPlaying = false; var selectorPressed = false; +var position; MyAvatar.attach(guitarModel, "Hips", {x: -0.0, y: -0.0, z: 0.0}, Quat.fromPitchYawRollDegrees(0, 0, 0), 1.0); function checkHands(deltaTime) { for (var palm = 0; palm < 2; palm++) { var palmVelocity = Controller.getSpatialControlVelocity(palm * 2 + 1); - var speed = length(palmVelocity) / 4.0; + var volume = length(palmVelocity) / 5.0; var position = Controller.getSpatialControlPosition(palm * 2 + 1); var myPelvis = MyAvatar.position; var trigger = Controller.getTriggerValue(strumHand); var chord = Controller.getTriggerValue(chordHand); + if (volume > 1.0) volume = 1.0; if ((chord > 0.1) && Audio.isInjectorPlaying(soundPlaying)) { // If chord finger trigger pulled, stop current chord + print("stopped sound"); Audio.stopInjector(soundPlaying); } @@ -81,11 +94,10 @@ function checkHands(deltaTime) { // Change guitars if button FWD (5) pressed if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 5)) { if (!selectorPressed) { - if (guitarSelector == 0) { - guitarSelector = 3; - } else { + guitarSelector += NUM_CHORDS; + if (guitarSelector >= NUM_CHORDS * NUM_GUITARS) { guitarSelector = 0; - } + } selectorPressed = true; } } else { @@ -93,38 +105,65 @@ function checkHands(deltaTime) { } if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 1)) { - whichChord = chords[guitarSelector + 1]; + whichChord = 1; } else if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 2)) { - whichChord = chords[guitarSelector + 2]; + whichChord = 2; } else if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 3)) { - whichChord = chords[guitarSelector + 3]; + whichChord = 3; + } else if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 4)) { + whichChord = 4; } if (palm == strumHand) { - var STRUM_HEIGHT_ABOVE_PELVIS = 0.00; + var STRUM_HEIGHT_ABOVE_PELVIS = 0.10; var strumTriggerHeight = myPelvis.y + STRUM_HEIGHT_ABOVE_PELVIS; //printVector(position); if ( ( ((position.y < strumTriggerHeight) && (lastPosition.y >= strumTriggerHeight)) || ((position.y > strumTriggerHeight) && (lastPosition.y <= strumTriggerHeight)) ) && (trigger > 0.1) ){ // If hand passes downward or upward through 'strings', and finger trigger pulled, play - var options = new AudioInjectionOptions(); - options.position = position; - if (speed > 1.0) { speed = 1.0; } - options.volume = speed; - if (Audio.isInjectorPlaying(soundPlaying)) { - Audio.stopInjector(soundPlaying); - } - soundPlaying = Audio.playSound(whichChord, options); + playChord(position, volume); } lastPosition = Controller.getSpatialControlPosition(palm * 2 + 1); } } } +function playChord(position, volume) { + var options = new AudioInjectionOptions(); + options.position = position; + options.volume = volume; + if (Audio.isInjectorPlaying(soundPlaying)) { + print("stopped sound"); + Audio.stopInjector(soundPlaying); + } + print("Played sound: " + whichChord + " at volume " + options.volume); + soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], options); +} + +function keyPressEvent(event) { + // check for keypresses and use those to trigger sounds if not hydra + keyVolume = 0.4; + if (event.text == "1") { + whichChord = 1; + playChord(MyAvatar.position, keyVolume); + } else if (event.text == "2") { + whichChord = 2; + playChord(MyAvatar.position, keyVolume); + } else if (event.text == "3") { + whichChord = 3; + playChord(MyAvatar.position, keyVolume); + } else if (event.text == "4") { + whichChord = 4; + playChord(MyAvatar.position, keyVolume); + } +} + function scriptEnding() { MyAvatar.detachOne(guitarModel); } // Connect a call back that happens every frame Script.update.connect(checkHands); Script.scriptEnding.connect(scriptEnding); +Controller.keyPressEvent.connect(keyPressEvent); + diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 61666ccdeb..0b59fc3aa2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -152,6 +152,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)), _cameraPushback(0.0f), _scaleMirror(1.0f), + _rotateMirror(0.0f), + _raiseMirror(0.0f), _mouseX(0), _mouseY(0), _lastMouseMove(usecTimestampNow()), @@ -3374,71 +3376,6 @@ void Application::saveScripts() { _settings->endArray(); } -void Application::stopAllScripts() { - // stops all current running scripts - for (int i = 0; i < _scriptEnginesHash.size(); ++i) { - _scriptEnginesHash.values().at(i)->stop(); - qDebug() << "stopping script..." << getRunningScripts().at(i); - } - _scriptEnginesHash.clear(); - _runningScriptsWidget->setRunningScripts(getRunningScripts()); - bumpSettings(); -} - -void Application::stopScript(const QString &scriptName) { - if (_scriptEnginesHash.contains(scriptName)) { - _scriptEnginesHash.value(scriptName)->stop(); - qDebug() << "stopping script..." << scriptName; - _scriptEnginesHash.remove(scriptName); - _runningScriptsWidget->setRunningScripts(getRunningScripts()); - bumpSettings(); - } -} - -void Application::reloadAllScripts() { - // remember all the current scripts so we can reload them - QStringList reloadList = getRunningScripts(); - // reloads all current running scripts - stopAllScripts(); - - foreach (QString scriptName, reloadList){ - qDebug() << "reloading script..." << scriptName; - loadScript(scriptName); - } -} - -void Application::manageRunningScriptsWidgetVisibility(bool shown) { - if (_runningScriptsWidgetWasVisible && shown) { - _runningScriptsWidget->show(); - } else if (_runningScriptsWidgetWasVisible && !shown) { - _runningScriptsWidget->hide(); - } -} - -void Application::toggleRunningScriptsWidget() { - if (_runningScriptsWidgetWasVisible) { - _runningScriptsWidget->hide(); - _runningScriptsWidgetWasVisible = false; - } else { - _runningScriptsWidget->setBoundary(QRect(_window->geometry().topLeft(), - _window->size())); - _runningScriptsWidget->show(); - _runningScriptsWidgetWasVisible = true; - } -} - -void Application::uploadHead() { - uploadModel(HEAD_MODEL); -} - -void Application::uploadSkeleton() { - uploadModel(SKELETON_MODEL); -} - -void Application::uploadAttachment() { - uploadModel(ATTACHMENT_MODEL); -} - ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScriptFromEditor) { if(loadScriptFromEditor && _scriptEnginesHash.contains(scriptName) && !_scriptEnginesHash[scriptName]->isFinished()){ return _scriptEnginesHash[scriptName]; @@ -3518,6 +3455,67 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript return scriptEngine; } +void Application::stopAllScripts(bool restart) { + // stops all current running scripts + for (QHash::const_iterator it = _scriptEnginesHash.constBegin(); + it != _scriptEnginesHash.constEnd(); it++) { + if (restart) { + connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&))); + } + it.value()->stop(); + qDebug() << "stopping script..." << it.key(); + } + _scriptEnginesHash.clear(); + _runningScriptsWidget->setRunningScripts(getRunningScripts()); + bumpSettings(); +} + +void Application::stopScript(const QString &scriptName) { + if (_scriptEnginesHash.contains(scriptName)) { + _scriptEnginesHash.value(scriptName)->stop(); + qDebug() << "stopping script..." << scriptName; + _scriptEnginesHash.remove(scriptName); + _runningScriptsWidget->setRunningScripts(getRunningScripts()); + bumpSettings(); + } +} + +void Application::reloadAllScripts() { + stopAllScripts(true); +} + +void Application::manageRunningScriptsWidgetVisibility(bool shown) { + if (_runningScriptsWidgetWasVisible && shown) { + _runningScriptsWidget->show(); + } else if (_runningScriptsWidgetWasVisible && !shown) { + _runningScriptsWidget->hide(); + } +} + +void Application::toggleRunningScriptsWidget() { + if (_runningScriptsWidgetWasVisible) { + _runningScriptsWidget->hide(); + _runningScriptsWidgetWasVisible = false; + } else { + _runningScriptsWidget->setBoundary(QRect(_window->geometry().topLeft(), + _window->size())); + _runningScriptsWidget->show(); + _runningScriptsWidgetWasVisible = true; + } +} + +void Application::uploadHead() { + uploadModel(HEAD_MODEL); +} + +void Application::uploadSkeleton() { + uploadModel(SKELETON_MODEL); +} + +void Application::uploadAttachment() { + uploadModel(ATTACHMENT_MODEL); +} + QString Application::getPreviousScriptLocation() { QString suggestedName; if (_previousScriptLocation.isEmpty()) { @@ -3657,7 +3655,17 @@ void Application::takeSnapshot() { player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); player->play(); - Snapshot::saveSnapshot(_glWidget, _myAvatar); + QString fileName = Snapshot::saveSnapshot(_glWidget, _myAvatar); + + AccountManager& accountManager = AccountManager::getInstance(); + if (!accountManager.isLoggedIn()) { + return; + } + + if (!_snapshotShareDialog) { + _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget); + } + _snapshotShareDialog->show(); } void Application::urlGoTo(int argc, const char * constArgv[]) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 91a7ebd29b..67cf7dad44 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -74,6 +74,7 @@ #include "ui/ModelsBrowser.h" #include "ui/OctreeStatsDialog.h" #include "ui/RearMirrorTools.h" +#include "ui/SnapshotShareDialog.h" #include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" #include "ui/UpdateDialog.h" @@ -126,7 +127,6 @@ public: ~Application(); void restoreSizeAndPosition(); - ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false); void loadScripts(); QString getPreviousScriptLocation(); void setPreviousScriptLocation(const QString& previousScriptLocation); @@ -291,7 +291,8 @@ public slots: void loadScriptURLDialog(); void toggleLogDialog(); void initAvatarAndViewFrustum(); - void stopAllScripts(); + ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false); + void stopAllScripts(bool restart = false); void stopScript(const QString& scriptName); void reloadAllScripts(); void toggleRunningScriptsWidget(); @@ -517,6 +518,7 @@ private: std::vector _voxelFades; ControllerScriptingInterface _controllerScriptingInterface; QPointer _logDialog; + QPointer _snapshotShareDialog; QString _previousScriptLocation; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 27e07d747e..e1d0c6a574 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -970,9 +970,7 @@ void Menu::goToUser(const QString& user) { /// Open a url, shortcutting any "hifi" scheme URLs to the local application. void Menu::openUrl(const QUrl& url) { if (url.scheme() == "hifi") { - QString path = url.toString(QUrl::RemoveScheme); - path = path.remove(QRegExp("^:?/*")); - goTo(path); + goToURL(url.toString()); } else { QDesktopServices::openUrl(url); } diff --git a/interface/src/XmppClient.cpp b/interface/src/XmppClient.cpp index 666906681c..2d421b1afa 100644 --- a/interface/src/XmppClient.cpp +++ b/interface/src/XmppClient.cpp @@ -16,7 +16,7 @@ #include "XmppClient.h" const QString DEFAULT_XMPP_SERVER = "chat.highfidelity.io"; -const QString DEFAULT_CHAT_ROOM = "public@public-chat.highfidelity.io"; +const QString DEFAULT_CHAT_ROOM = "test@public-chat.highfidelity.io"; XmppClient::XmppClient() : _xmppClient(), diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 00b7b8c682..2bd0bbbc6d 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -353,7 +353,7 @@ void Avatar::renderBody(RenderMode renderMode, float glowLevel) { return; } _skeletonModel.render(1.0f, modelRenderMode); - renderAttachments(modelRenderMode); + renderAttachments(renderMode); getHand()->render(false, modelRenderMode); } getHead()->render(1.0f, modelRenderMode); @@ -370,6 +370,9 @@ void Avatar::simulateAttachments(float deltaTime) { int jointIndex = getJointIndex(attachment.jointName); glm::vec3 jointPosition; glm::quat jointRotation; + if (!isMyAvatar()) { + model->setLODDistance(getLODDistance()); + } if (_skeletonModel.getJointPosition(jointIndex, jointPosition) && _skeletonModel.getJointRotation(jointIndex, jointRotation)) { model->setTranslation(jointPosition + jointRotation * attachment.translation * _scale); @@ -380,9 +383,11 @@ void Avatar::simulateAttachments(float deltaTime) { } } -void Avatar::renderAttachments(Model::RenderMode renderMode) { +void Avatar::renderAttachments(RenderMode renderMode) { + Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? + Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; foreach (Model* model, _attachmentModels) { - model->render(1.0f, renderMode); + model->render(1.0f, modelRenderMode); } } @@ -401,7 +406,7 @@ void Avatar::renderBillboard() { } _billboardTexture.reset(new Texture()); glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID()); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 1, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, image.constBits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index edd53e4b8f..289a0500d0 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -192,7 +192,7 @@ protected: virtual bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const; void simulateAttachments(float deltaTime); - void renderAttachments(Model::RenderMode renderMode); + virtual void renderAttachments(RenderMode renderMode); virtual void updateJointMappings(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 6ce362071b..52eff6e2ce 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -669,7 +669,7 @@ void MyAvatar::renderBody(RenderMode renderMode, float glowLevel) { Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; _skeletonModel.render(1.0f, modelRenderMode); - renderAttachments(modelRenderMode); + renderAttachments(renderMode); // Render head so long as the camera isn't inside it if (shouldRenderHead(Application::getInstance()->getCamera()->getPosition(), renderMode)) { @@ -1489,6 +1489,23 @@ void MyAvatar::updateMotionBehaviorsFromMenu() { } } +void MyAvatar::renderAttachments(RenderMode renderMode) { + if (!Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON || renderMode == MIRROR_RENDER_MODE) { + Avatar::renderAttachments(renderMode); + return; + } + const FBXGeometry& geometry = _skeletonModel.getGeometry()->getFBXGeometry(); + QString headJointName = (geometry.headJointIndex == -1) ? QString() : geometry.joints.at(geometry.headJointIndex).name; + Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? + Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; + for (int i = 0; i < _attachmentData.size(); i++) { + const QString& jointName = _attachmentData.at(i).jointName; + if (jointName != headJointName && jointName != "Head") { + _attachmentModels.at(i)->render(1.0f, modelRenderMode); + } + } +} + void MyAvatar::setCollisionGroups(quint32 collisionGroups) { Avatar::setCollisionGroups(collisionGroups & VALID_COLLISION_GROUPS); Menu* menu = Menu::getInstance(); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 96249aec33..2e47d9c973 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -121,6 +121,9 @@ public slots: signals: void transformChanged(); +protected: + virtual void renderAttachments(RenderMode renderMode); + private: bool _mousePressed; float _bodyPitchDelta; // degrees diff --git a/interface/src/renderer/TextureCache.cpp b/interface/src/renderer/TextureCache.cpp index f31e4f9060..0588ca70d2 100644 --- a/interface/src/renderer/TextureCache.cpp +++ b/interface/src/renderer/TextureCache.cpp @@ -366,10 +366,10 @@ void NetworkTexture::setImage(const QImage& image, bool translucent) { imageLoaded(image); glBindTexture(GL_TEXTURE_2D, getID()); if (image.hasAlphaChannel()) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 1, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, image.constBits()); } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 1, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.constBits()); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -404,10 +404,10 @@ QSharedPointer DilatableNetworkTexture::getDilatedTexture(float dilatio glBindTexture(GL_TEXTURE_2D, texture->getID()); if (dilatedImage.hasAlphaChannel()) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dilatedImage.width(), dilatedImage.height(), 1, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dilatedImage.width(), dilatedImage.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, dilatedImage.constBits()); } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, dilatedImage.width(), dilatedImage.height(), 1, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, dilatedImage.width(), dilatedImage.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, dilatedImage.constBits()); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 72445fa69a..fce900f352 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -30,7 +30,7 @@ const int NUM_MESSAGES_TO_TIME_STAMP = 20; -const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)"); +const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?)|(?:hifi))://\\S+)"); const QRegularExpression regexHifiLinks("([#@]\\S+)"); const QString mentionSoundsPath("/sounds/mention/"); const QString mentionRegex("@(\\b%1\\b)"); diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index 243acdfb10..d530be57d2 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -64,7 +64,7 @@ SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) { return data; } -void Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { +QString Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { QImage shot = widget->grabFrameBuffer(); glm::vec3 location = avatar->getPosition(); @@ -99,6 +99,8 @@ void Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { fileName.append(QString(FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT), formattedLocation))); shot.save(fileName, 0, 100); + + return fileName; } diff --git a/interface/src/ui/Snapshot.h b/interface/src/ui/Snapshot.h index 0fa9017b0a..2872b3fdcb 100644 --- a/interface/src/ui/Snapshot.h +++ b/interface/src/ui/Snapshot.h @@ -41,7 +41,7 @@ private: class Snapshot { public: - static void saveSnapshot(QGLWidget* widget, Avatar* avatar); + static QString saveSnapshot(QGLWidget* widget, Avatar* avatar); static SnapshotMetaData* parseSnapshotData(QString snapshotPath); }; diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp new file mode 100644 index 0000000000..b5694b3e48 --- /dev/null +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -0,0 +1,198 @@ +// +// SnapshotShareDialog.cpp +// interface/src/ui +// +// Created by Stojce Slavkovski on 2/16/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "SnapshotShareDialog.h" +#include "AccountManager.h" + +#include +#include +#include +#include +#include +#include + + +const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; +const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; +const int SUCCESS_LABEL_HEIGHT = 140; + +const QString FORUM_URL = "https://alphas.highfidelity.io"; +const QString FORUM_UPLOADS_URL = FORUM_URL + "/uploads"; +const QString FORUM_POST_URL = FORUM_URL + "/posts"; +const QString FORUM_REPLY_TO_TOPIC = "244"; +const QString FORUM_POST_TEMPLATE = "

%2

"; +const QString SHARE_DEFAULT_ERROR = "The server isn't responding. Please try again in a few minutes."; +const QString SUCCESS_LABEL_TEMPLATE = "Success!!! Go check out your image ...
%1"; + +Q_DECLARE_METATYPE(QNetworkAccessManager::Operation) + +SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : + QDialog(parent), + _fileName(fileName), + _networkAccessManager(NULL) +{ + + setAttribute(Qt::WA_DeleteOnClose); + + _ui.setupUi(this); + + QPixmap snaphsotPixmap(fileName); + float snapshotRatio = static_cast(snaphsotPixmap.size().width()) / snaphsotPixmap.size().height(); + + // narrow snapshot + if (snapshotRatio > 1) { + setFixedWidth(WIDE_SNAPSHOT_DIALOG_WIDTH); + _ui.snapshotWidget->setFixedWidth(WIDE_SNAPSHOT_DIALOG_WIDTH); + } + + float labelRatio = static_cast(_ui.snapshotWidget->size().width()) / _ui.snapshotWidget->size().height(); + + // set the same aspect ratio of label as of snapshot + if (snapshotRatio > labelRatio) { + int oldHeight = _ui.snapshotWidget->size().height(); + _ui.snapshotWidget->setFixedHeight((int) (_ui.snapshotWidget->size().width() / snapshotRatio)); + + // if height is less then original, resize the window as well + if (_ui.snapshotWidget->size().height() < NARROW_SNAPSHOT_DIALOG_SIZE) { + setFixedHeight(size().height() - (oldHeight - _ui.snapshotWidget->size().height())); + } + } else { + _ui.snapshotWidget->setFixedWidth((int) (_ui.snapshotWidget->size().height() * snapshotRatio)); + } + + _ui.snapshotWidget->setPixmap(snaphsotPixmap); + _ui.snapshotWidget->adjustSize(); +} + +void SnapshotShareDialog::accept() { + uploadSnapshot(); +} + +void SnapshotShareDialog::uploadSnapshot() { + + if (AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().isEmpty()) { + QMessageBox::warning(this, "", + "Your Discourse API key is missing, you cannot share snapshots. Please try to relog."); + return; + } + + if (!_networkAccessManager) { + _networkAccessManager = new QNetworkAccessManager(this); + } + + QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + + QHttpPart apiKeyPart; + apiKeyPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"api_key\"")); + apiKeyPart.setBody(AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().toLatin1()); + + QFile* file = new QFile(_fileName); + file->open(QIODevice::ReadOnly); + + QHttpPart imagePart; + imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); + imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, + QVariant("form-data; name=\"file\"; filename=\"" + file->fileName() +"\"")); + imagePart.setBodyDevice(file); + file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart + + multiPart->append(apiKeyPart); + multiPart->append(imagePart); + + QUrl url(FORUM_UPLOADS_URL); + QNetworkRequest request(url); + + QNetworkReply* reply = _networkAccessManager->post(request, multiPart); + + + connect(reply, &QNetworkReply::finished, this, &SnapshotShareDialog::uploadRequestFinished); + + QEventLoop loop; + connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); +} + +void SnapshotShareDialog::sendForumPost(QString snapshotPath) { + + if (!_networkAccessManager) { + _networkAccessManager = new QNetworkAccessManager(this); + } + + // post to Discourse forum + QNetworkRequest request; + QUrl forumUrl(FORUM_POST_URL); + + QUrlQuery query; + query.addQueryItem("api_key", AccountManager::getInstance().getAccountInfo().getDiscourseApiKey()); + query.addQueryItem("topic_id", FORUM_REPLY_TO_TOPIC); + query.addQueryItem("raw", FORUM_POST_TEMPLATE.arg(snapshotPath, _ui.textEdit->toPlainText())); + forumUrl.setQuery(query); + + QByteArray postData = forumUrl.toEncoded(QUrl::RemoveFragment); + request.setUrl(forumUrl); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + QNetworkReply* requestReply = _networkAccessManager->post(request, postData); + connect(requestReply, &QNetworkReply::finished, this, &SnapshotShareDialog::postRequestFinished); + + QEventLoop loop; + connect(requestReply, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); +} + +void SnapshotShareDialog::postRequestFinished() { + + QNetworkReply* requestReply = reinterpret_cast(sender()); + QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll()); + const QJsonObject& responseObject = jsonResponse.object(); + + if (responseObject.contains("id")) { + _ui.textEdit->setHtml(""); + const QString urlTemplate = "%1/t/%2/%3/%4"; + QString link = urlTemplate.arg(FORUM_URL, + responseObject["topic_slug"].toString(), + QString::number(responseObject["topic_id"].toDouble()), + QString::number(responseObject["post_number"].toDouble())); + + _ui.successLabel->setText(SUCCESS_LABEL_TEMPLATE.arg(link)); + _ui.successLabel->setFixedHeight(SUCCESS_LABEL_HEIGHT); + + // hide input widgets + _ui.shareButton->hide(); + _ui.textEdit->hide(); + _ui.labelNotes->hide(); + + } else { + QString errorMessage(SHARE_DEFAULT_ERROR); + if (responseObject.contains("errors")) { + QJsonArray errorArray = responseObject["errors"].toArray(); + if (!errorArray.first().toString().isEmpty()) { + errorMessage = errorArray.first().toString(); + } + } + QMessageBox::warning(this, "", errorMessage); + } +} + +void SnapshotShareDialog::uploadRequestFinished() { + + QNetworkReply* requestReply = reinterpret_cast(sender()); + QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll()); + const QJsonObject& responseObject = jsonResponse.object(); + + if (responseObject.contains("url")) { + sendForumPost(responseObject["url"].toString()); + } else { + QMessageBox::warning(this, "", SHARE_DEFAULT_ERROR); + } + + delete requestReply; +} diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h new file mode 100644 index 0000000000..a8795d578a --- /dev/null +++ b/interface/src/ui/SnapshotShareDialog.h @@ -0,0 +1,41 @@ +// +// SnapshotShareDialog.h +// interface/src/ui +// +// Created by Stojce Slavkovski on 2/16/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_snapshotShareDialog +#define hifi_snapshotShareDialog + +#include "ui_shareSnapshot.h" + +#include +#include +#include + +class SnapshotShareDialog : public QDialog { + Q_OBJECT + +public: + SnapshotShareDialog(QString fileName, QWidget* parent = 0); + +private: + QString _fileName; + QNetworkAccessManager* _networkAccessManager; + Ui_SnapshotShareDialog _ui; + + void uploadSnapshot(); + void sendForumPost(QString snapshotPath); + +private slots: + void uploadRequestFinished(); + void postRequestFinished(); + void accept(); +}; + +#endif // hifi_snapshotShareDialog diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 6abd0f2d5a..cb0106cd48 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -88,10 +88,6 @@ padding-top: 3px; Reload all - - - ../resources/images/reload.svg../resources/images/reload.svg - @@ -115,10 +111,6 @@ padding-top: 3px; Stop all - - - ../resources/images/stop.svg../resources/images/stop.svg - @@ -251,10 +243,6 @@ padding-top: 3px; Load script - - - ../resources/images/plus.svg../resources/images/plus.svg - widgetTitle currentlyRunningLabel diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui new file mode 100644 index 0000000000..df7fc4939f --- /dev/null +++ b/interface/ui/shareSnapshot.ui @@ -0,0 +1,377 @@ + + + SnapshotShareDialog + + + Qt::NonModal + + + + 0 + 0 + 502 + 616 + + + + + 0 + 0 + + + + + 500 + 616 + + + + + 502 + 616 + + + + Share with Alphas + + + background-color: rgb(255, 255, 255); + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + QLayout::SetMinAndMaxSize + + + + + + 0 + 0 + + + + + 500 + 500 + + + + + 30 + 2000 + + + + background-color: #ccc; + + + 0 + + + true + + + Qt::AlignCenter + + + 0 + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 9 + + + + + + + + true + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 0 + + + + + Arial + + + + color: #666 + + + + + + Qt::RichText + + + Qt::AlignCenter + + + true + + + Qt::TextBrowserInteraction + + + + + + + + 0 + 0 + + + + + 0 + 19 + + + + + Helvetica + 14 + 75 + true + + + + color: #666; +padding-left:20px; + + + QFrame::NoFrame + + + 0 + + + Notes about this image + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + 0 + + + 0 + + + + + + + 0 + + + QLayout::SetFixedSize + + + 0 + + + 0 + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 19 + 20 + + + + + + + + + 0 + 0 + + + + + 16777215 + 60 + + + + + Helvetica + 14 + + + + border: 1px solid #c5c5c5; + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Helvetica'; font-size:14pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 25 + 19 + + + + + + + + background-color: #333333; + border-width: 0; + border-radius: 9px; + border-radius: 9px; + font-family: Arial; + font-size: 18px; + font-weight: 100; + color: #FFFFFF; + width: 120px; + height: 50px; + + + Share + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 25 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 11 + + + + + + + + + + + + shareButton + clicked() + SnapshotShareDialog + accept() + + + 420 + 565 + + + 250 + 307 + + + + + diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index 87d3b694a7..a9522148a8 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -16,7 +16,8 @@ DataServerAccountInfo::DataServerAccountInfo() : _accessToken(), _username(), - _xmppPassword() + _xmppPassword(), + _discourseApiKey() { } @@ -29,12 +30,14 @@ DataServerAccountInfo::DataServerAccountInfo(const QJsonObject& jsonObject) : QJsonObject userJSONObject = jsonObject["user"].toObject(); setUsername(userJSONObject["username"].toString()); setXMPPPassword(userJSONObject["xmpp_password"].toString()); + setDiscourseApiKey(userJSONObject["discourse_api_key"].toString()); } DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherInfo) { _accessToken = otherInfo._accessToken; _username = otherInfo._username; _xmppPassword = otherInfo._xmppPassword; + _discourseApiKey = otherInfo._discourseApiKey; } DataServerAccountInfo& DataServerAccountInfo::operator=(const DataServerAccountInfo& otherInfo) { @@ -49,6 +52,7 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) { swap(_accessToken, otherInfo._accessToken); swap(_username, otherInfo._username); swap(_xmppPassword, otherInfo._xmppPassword); + swap(_discourseApiKey, otherInfo._discourseApiKey); } void DataServerAccountInfo::setUsername(const QString& username) { @@ -65,6 +69,12 @@ void DataServerAccountInfo::setXMPPPassword(const QString& xmppPassword) { } } +void DataServerAccountInfo::setDiscourseApiKey(const QString& discourseApiKey) { + if (_discourseApiKey != discourseApiKey) { + _discourseApiKey = discourseApiKey; + } +} + QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) { out << info._accessToken << info._username << info._xmppPassword; return out; diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h index 21380c0855..a7d1fa9cb0 100644 --- a/libraries/networking/src/DataServerAccountInfo.h +++ b/libraries/networking/src/DataServerAccountInfo.h @@ -31,7 +31,10 @@ public: const QString& getXMPPPassword() const { return _xmppPassword; } void setXMPPPassword(const QString& xmppPassword); - + + const QString& getDiscourseApiKey() const { return _discourseApiKey; } + void setDiscourseApiKey(const QString& discourseApiKey); + friend QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info); friend QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info); private: @@ -40,6 +43,7 @@ private: OAuthAccessToken _accessToken; QString _username; QString _xmppPassword; + QString _discourseApiKey; }; #endif // hifi_DataServerAccountInfo_h