From d2464d89e3ea6d33b4492b16d94d957577b49eda Mon Sep 17 00:00:00 2001 From: stojce Date: Thu, 30 Jan 2014 22:23:31 +0100 Subject: [PATCH] #19493 - @ function can jump to locations as well as avatars --- interface/src/Application.cpp | 2 +- interface/src/Menu.cpp | 89 ++++++++++++++++++++++++++--------- interface/src/Menu.h | 5 +- 3 files changed, 71 insertions(+), 25 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2efcd5b121..f420b2be45 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1093,7 +1093,7 @@ void Application::keyPressEvent(QKeyEvent* event) { _swatch.handleEvent(event->key(), Menu::getInstance()->isOptionChecked(MenuOption::VoxelGetColorMode)); break; case Qt::Key_At: - Menu::getInstance()->goToUser(); + Menu::getInstance()->goTo(); break; default: event->ignore(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 8fd268938e..67eaa8782c 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -116,10 +116,10 @@ Menu::Menu() : this, SLOT(goToLocation())); addActionToQMenuAndActionHash(fileMenu, - MenuOption::GoToUser, + MenuOption::GoTo, Qt::Key_At, this, - SLOT(goToUser())); + SLOT(goTo())); addDisabledActionAndSeparator(fileMenu, "Settings"); @@ -910,6 +910,60 @@ void Menu::goToDomain() { sendFakeEnterEvent(); } +void Menu::goTo() { + + QInputDialog gotoDialog(Application::getInstance()->getWindow()); + gotoDialog.setWindowTitle("Go to"); + gotoDialog.setLabelText("Destination:"); + QString destination = Application::getInstance()->getProfile()->getUsername(); + gotoDialog.setTextValue(destination); + gotoDialog.setWindowFlags(Qt::Sheet); + gotoDialog.resize(gotoDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, gotoDialog.size().height()); + + int dialogReturn = gotoDialog.exec(); + if (dialogReturn == QDialog::Accepted && !gotoDialog.textValue().isEmpty()) { + + destination = gotoDialog.textValue(); + + QStringList coordinateItems = destination.split(QRegExp("_|,"), QString::SkipEmptyParts); + + const int NUMBER_OF_COORDINATE_ITEMS = 3; + const int X_ITEM = 0; + const int Y_ITEM = 1; + const int Z_ITEM = 2; + if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) { + + double x = replaceLastOccurrence('-', '.', coordinateItems[X_ITEM].trimmed()).toDouble(); + double y = replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM].trimmed()).toDouble(); + double z = replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM].trimmed()).toDouble(); + + glm::vec3 newAvatarPos(x, y, z); + + MyAvatar* myAvatar = Application::getInstance()->getAvatar(); + glm::vec3 avatarPos = myAvatar->getPosition(); + if (newAvatarPos != avatarPos) { + // send a node kill request, indicating to other clients that they should play the "disappeared" effect + MyAvatar::sendKillAvatar(); + + qDebug("Going To Location: %f, %f, %f...", x, y, z); + myAvatar->setPosition(newAvatarPos); + } + + } else { + // there's a username entered by the user, make a request to the data-server + DataServerClient::getValuesForKeysAndUserString( + QStringList() + << DataServerKey::Domain + << DataServerKey::Position + << DataServerKey::Orientation, + destination, Application::getInstance()->getProfile()); + + } + } + + sendFakeEnterEvent(); +} + void Menu::goToLocation() { MyAvatar* myAvatar = Application::getInstance()->getAvatar(); glm::vec3 avatarPos = myAvatar->getPosition(); @@ -954,26 +1008,6 @@ void Menu::goToLocation() { sendFakeEnterEvent(); } -void Menu::goToUser() { - QInputDialog userDialog(Application::getInstance()->getWindow()); - userDialog.setWindowTitle("Go to User"); - userDialog.setLabelText("Destination user:"); - QString username = Application::getInstance()->getProfile()->getUsername(); - userDialog.setTextValue(username); - userDialog.setWindowFlags(Qt::Sheet); - userDialog.resize(userDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, userDialog.size().height()); - - int dialogReturn = userDialog.exec(); - if (dialogReturn == QDialog::Accepted && !userDialog.textValue().isEmpty()) { - // there's a username entered by the user, make a request to the data-server - DataServerClient::getValuesForKeysAndUserString( - QStringList() << DataServerKey::Domain << DataServerKey::Position << DataServerKey::Orientation, - userDialog.textValue(), Application::getInstance()->getProfile()); - } - - sendFakeEnterEvent(); -} - void Menu::pasteToVoxel() { QInputDialog pasteToOctalCodeDialog(Application::getInstance()->getWindow()); pasteToOctalCodeDialog.setWindowTitle("Paste to Voxel"); @@ -1137,3 +1171,14 @@ void Menu::updateFrustumRenderModeAction() { } } +QString Menu::replaceLastOccurrence(QChar search, QChar replace, QString string) { + int lastIndex; + lastIndex = string.lastIndexOf(search); + if (lastIndex > 0) { + lastIndex = string.lastIndexOf(search); + string.replace(lastIndex, 1, replace); + } + + return string; +} + diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 03149ce07c..5e49ca6fd1 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -92,7 +92,7 @@ public slots: void saveSettings(QSettings* settings = NULL); void importSettings(); void exportSettings(); - void goToUser(); + void goTo(); void pasteToVoxel(); private slots: @@ -152,6 +152,7 @@ private: QAction* _useVoxelShader; int _maxVoxelPacketsPerSecond; QMenu* _activeScriptsMenu; + QString replaceLastOccurrence(QChar search, QChar replace, QString string); }; namespace MenuOption { @@ -209,7 +210,7 @@ namespace MenuOption { const QString GlowMode = "Cycle Glow Mode"; const QString GoToDomain = "Go To Domain..."; const QString GoToLocation = "Go To Location..."; - const QString GoToUser = "Go To User..."; + const QString GoTo = "Go To..."; const QString ImportVoxels = "Import Voxels"; const QString ImportVoxelsClipboard = "Import Voxels to Clipboard"; const QString IncreaseAvatarSize = "Increase Avatar Size";