mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 20:34:07 +02:00
Merge pull request #3675 from birarda/lobby
add groundwork to jump to a location from lobby
This commit is contained in:
commit
12b6318eb3
5 changed files with 85 additions and 88 deletions
|
@ -1118,18 +1118,22 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
_myAvatar->resetSize();
|
||||
break;
|
||||
case Qt::Key_Space: {
|
||||
// this starts an HFActionEvent
|
||||
HFActionEvent startActionEvent(HFActionEvent::startType(), getViewportCenter());
|
||||
sendEvent(this, &startActionEvent);
|
||||
if (!event->isAutoRepeat()) {
|
||||
// this starts an HFActionEvent
|
||||
HFActionEvent startActionEvent(HFActionEvent::startType(), getViewportCenter());
|
||||
sendEvent(this, &startActionEvent);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case Qt::Key_Escape: {
|
||||
OculusManager::abandonCalibration();
|
||||
|
||||
// this starts the HFCancelEvent
|
||||
HFBackEvent startBackEvent(HFBackEvent::startType());
|
||||
sendEvent(this, &startBackEvent);
|
||||
if (!event->isAutoRepeat()) {
|
||||
// this starts the HFCancelEvent
|
||||
HFBackEvent startBackEvent(HFBackEvent::startType());
|
||||
sendEvent(this, &startBackEvent);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1205,16 +1209,20 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
|
|||
_myAvatar->clearDriveKeys();
|
||||
break;
|
||||
case Qt::Key_Space: {
|
||||
// this ends the HFActionEvent
|
||||
HFActionEvent endActionEvent(HFActionEvent::endType(), getViewportCenter());
|
||||
sendEvent(this, &endActionEvent);
|
||||
if (!event->isAutoRepeat()) {
|
||||
// this ends the HFActionEvent
|
||||
HFActionEvent endActionEvent(HFActionEvent::endType(), getViewportCenter());
|
||||
sendEvent(this, &endActionEvent);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case Qt::Key_Escape: {
|
||||
// this ends the HFCancelEvent
|
||||
HFBackEvent endBackEvent(HFBackEvent::endType());
|
||||
sendEvent(this, &endBackEvent);
|
||||
if (!event->isAutoRepeat()) {
|
||||
// this ends the HFCancelEvent
|
||||
HFBackEvent endBackEvent(HFBackEvent::endType());
|
||||
sendEvent(this, &endBackEvent);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "NodeList.h"
|
||||
#include <AddressManager.h>
|
||||
|
||||
#include "LocationScriptingInterface.h"
|
||||
|
||||
|
@ -20,36 +18,23 @@ LocationScriptingInterface* LocationScriptingInterface::getInstance() {
|
|||
return &sharedInstance;
|
||||
}
|
||||
|
||||
bool LocationScriptingInterface::isConnected() {
|
||||
return NodeList::getInstance()->getDomainHandler().isConnected();
|
||||
}
|
||||
|
||||
QString LocationScriptingInterface::getHref() {
|
||||
return getProtocol() + "//" + getHostname() + getPathname();
|
||||
}
|
||||
|
||||
QString LocationScriptingInterface::getPathname() {
|
||||
return AddressManager::getInstance().currentPath();
|
||||
}
|
||||
|
||||
QString LocationScriptingInterface::getHostname() {
|
||||
return NodeList::getInstance()->getDomainHandler().getHostname();
|
||||
}
|
||||
|
||||
QString LocationScriptingInterface::getDomainID() const {
|
||||
const QUuid& domainID = NodeList::getInstance()->getDomainHandler().getUUID();
|
||||
return domainID.isNull() ? "" : uuidStringWithoutCurlyBraces(domainID);
|
||||
}
|
||||
|
||||
void LocationScriptingInterface::assign(const QString& url) {
|
||||
QMetaObject::invokeMethod(&AddressManager::getInstance(), "handleLookupString", Q_ARG(const QString&, url));
|
||||
}
|
||||
|
||||
QScriptValue LocationScriptingInterface::locationGetter(QScriptContext* context, QScriptEngine* engine) {
|
||||
return engine->newQObject(getInstance());
|
||||
return engine->newQObject(&AddressManager::getInstance());
|
||||
}
|
||||
|
||||
QScriptValue LocationScriptingInterface::locationSetter(QScriptContext* context, QScriptEngine* engine) {
|
||||
LocationScriptingInterface::getInstance()->assign(context->argument(0).toString());
|
||||
const QVariant& argumentVariant = context->argument(0).toVariant();
|
||||
|
||||
|
||||
if (argumentVariant.canConvert(QMetaType::QVariantMap)) {
|
||||
// this argument is a variant map, so we'll assume it's an address map
|
||||
QMetaObject::invokeMethod(&AddressManager::getInstance(), "goToAddressFromObject",
|
||||
Q_ARG(const QVariantMap&, argumentVariant.toMap()));
|
||||
} else {
|
||||
// just try and convert the argument to a string, should be a hifi:// address
|
||||
QMetaObject::invokeMethod(&AddressManager::getInstance(), "handleLookupString",
|
||||
Q_ARG(const QString&, argumentVariant.toString()));
|
||||
}
|
||||
|
||||
return QScriptValue::UndefinedValue;
|
||||
}
|
||||
|
|
|
@ -12,41 +12,17 @@
|
|||
#ifndef hifi_LocationScriptingInterface_h
|
||||
#define hifi_LocationScriptingInterface_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QScriptContext>
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValue>
|
||||
#include <QString>
|
||||
|
||||
#include <AddressManager.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include <qscriptengine.h>
|
||||
|
||||
class LocationScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isConnected READ isConnected)
|
||||
Q_PROPERTY(QString href READ getHref)
|
||||
Q_PROPERTY(QString protocol READ getProtocol)
|
||||
Q_PROPERTY(QString hostname READ getHostname)
|
||||
Q_PROPERTY(QString pathname READ getPathname)
|
||||
Q_PROPERTY(QString domainID READ getDomainID)
|
||||
LocationScriptingInterface() { };
|
||||
public:
|
||||
static LocationScriptingInterface* getInstance();
|
||||
|
||||
bool isConnected();
|
||||
QString getHref();
|
||||
QString getProtocol() { return HIFI_URL_SCHEME; };
|
||||
QString getPathname();
|
||||
QString getHostname();
|
||||
QString getDomainID() const;
|
||||
|
||||
static QScriptValue locationGetter(QScriptContext* context, QScriptEngine* engine);
|
||||
static QScriptValue locationSetter(QScriptContext* context, QScriptEngine* engine);
|
||||
|
||||
public slots:
|
||||
void assign(const QString& url);
|
||||
|
||||
private:
|
||||
LocationScriptingInterface() {};
|
||||
};
|
||||
|
||||
#endif // hifi_LocationScriptingInterface_h
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include <GLMHelpers.h>
|
||||
|
||||
#include "NodeList.h"
|
||||
|
||||
#include "AddressManager.h"
|
||||
|
||||
AddressManager& AddressManager::getInstance() {
|
||||
|
@ -31,7 +33,11 @@ AddressManager::AddressManager() :
|
|||
|
||||
}
|
||||
|
||||
const QUrl AddressManager::currentAddress() {
|
||||
bool AddressManager::isConnected() {
|
||||
return NodeList::getInstance()->getDomainHandler().isConnected();
|
||||
}
|
||||
|
||||
const QUrl AddressManager::currentAddress() const {
|
||||
QUrl hifiURL;
|
||||
|
||||
hifiURL.setScheme(HIFI_URL_SCHEME);
|
||||
|
@ -139,14 +145,20 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
|
|||
QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
||||
QJsonObject dataObject = responseObject["data"].toObject();
|
||||
|
||||
goToAddressFromObject(dataObject.toVariantMap());
|
||||
|
||||
emit lookupResultsFinished();
|
||||
}
|
||||
|
||||
void AddressManager::goToAddressFromObject(const QVariantMap& addressMap) {
|
||||
const QString ADDRESS_API_DOMAIN_KEY = "domain";
|
||||
const QString ADDRESS_API_ONLINE_KEY = "online";
|
||||
|
||||
if (!dataObject.contains(ADDRESS_API_ONLINE_KEY)
|
||||
|| dataObject[ADDRESS_API_ONLINE_KEY].toBool()) {
|
||||
if (!addressMap.contains(ADDRESS_API_ONLINE_KEY)
|
||||
|| addressMap[ADDRESS_API_ONLINE_KEY].toBool()) {
|
||||
|
||||
if (dataObject.contains(ADDRESS_API_DOMAIN_KEY)) {
|
||||
QJsonObject domainObject = dataObject[ADDRESS_API_DOMAIN_KEY].toObject();
|
||||
if (addressMap.contains(ADDRESS_API_DOMAIN_KEY)) {
|
||||
QVariantMap domainObject = addressMap[ADDRESS_API_DOMAIN_KEY].toMap();
|
||||
|
||||
const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
|
||||
const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address";
|
||||
|
@ -178,10 +190,12 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
|
|||
if (domainObject.contains(LOCATION_PATH_KEY)) {
|
||||
returnedPath = domainObject[LOCATION_PATH_KEY].toString();
|
||||
} else if (domainObject.contains(LOCATION_KEY)) {
|
||||
returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
|
||||
returnedPath = domainObject[LOCATION_KEY].toMap()[LOCATION_PATH_KEY].toString();
|
||||
} else if (addressMap.contains(LOCATION_PATH_KEY)) {
|
||||
returnedPath = addressMap[LOCATION_PATH_KEY].toString();
|
||||
}
|
||||
|
||||
bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
|
||||
|
||||
bool shouldFaceViewpoint = addressMap.contains(ADDRESS_API_ONLINE_KEY);
|
||||
|
||||
if (!returnedPath.isEmpty()) {
|
||||
// try to parse this returned path as a viewpoint, that's the only thing it could be for now
|
||||
|
@ -192,13 +206,12 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
|
|||
|
||||
} else {
|
||||
qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
|
||||
qDebug() << responseObject;
|
||||
qDebug() << addressMap;
|
||||
}
|
||||
} else {
|
||||
// we've been told that this result exists but is offline, emit our signal so the application can handle
|
||||
emit lookupResultIsOffline();
|
||||
}
|
||||
emit lookupResultsFinished();
|
||||
}
|
||||
|
||||
void AddressManager::handleAPIError(QNetworkReply& errorReply) {
|
||||
|
@ -232,10 +245,8 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
|||
if (hostnameRegex.indexIn(lookupString) != -1) {
|
||||
QString domainHostname = hostnameRegex.cap(0);
|
||||
|
||||
emit possibleDomainChangeRequiredToHostname(domainHostname);
|
||||
emit lookupResultsFinished();
|
||||
|
||||
_currentDomain = domainHostname;
|
||||
setDomainHostnameAndName(domainHostname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -245,10 +256,9 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
|||
if (ipAddressRegex.indexIn(lookupString) != -1) {
|
||||
QString domainIPString = ipAddressRegex.cap(0);
|
||||
|
||||
emit possibleDomainChangeRequiredToHostname(domainIPString);
|
||||
emit lookupResultsFinished();
|
||||
setDomainHostnameAndName(domainIPString);
|
||||
|
||||
_currentDomain = domainIPString;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -322,6 +332,12 @@ bool AddressManager::handleUsername(const QString& lookupString) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void AddressManager::setDomainHostnameAndName(const QString& hostname, const QString& domainName) {
|
||||
_currentDomain = domainName.isEmpty() ? hostname : domainName;
|
||||
emit possibleDomainChangeRequiredToHostname(hostname);
|
||||
}
|
||||
|
||||
void AddressManager::goToUser(const QString& username) {
|
||||
QString formattedUsername = QUrl::toPercentEncoding(username);
|
||||
// this is a username - pull the captured name and lookup that user's location
|
||||
|
|
|
@ -26,10 +26,18 @@ typedef glm::quat (*OrientationGetter)();
|
|||
|
||||
class AddressManager : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isConnected READ isConnected)
|
||||
Q_PROPERTY(QUrl href READ currentAddress)
|
||||
Q_PROPERTY(QString protocol READ getProtocol)
|
||||
Q_PROPERTY(QString hostname READ getCurrentDomain)
|
||||
Q_PROPERTY(QString pathname READ currentPath)
|
||||
public:
|
||||
static AddressManager& getInstance();
|
||||
|
||||
const QUrl currentAddress();
|
||||
bool isConnected();
|
||||
const QString& getProtocol() { return HIFI_URL_SCHEME; };
|
||||
|
||||
const QUrl currentAddress() const;
|
||||
const QString currentPath(bool withOrientation = true) const;
|
||||
|
||||
const QString& getCurrentDomain() const { return _currentDomain; }
|
||||
|
@ -41,10 +49,9 @@ public:
|
|||
|
||||
public slots:
|
||||
void handleLookupString(const QString& lookupString);
|
||||
|
||||
void handleAPIResponse(QNetworkReply& requestReply);
|
||||
void handleAPIError(QNetworkReply& errorReply);
|
||||
void goToUser(const QString& username);
|
||||
void goToAddressFromObject(const QVariantMap& addressMap);
|
||||
|
||||
signals:
|
||||
void lookupResultsFinished();
|
||||
void lookupResultIsOffline();
|
||||
|
@ -54,9 +61,14 @@ signals:
|
|||
void locationChangeRequired(const glm::vec3& newPosition,
|
||||
bool hasOrientationChange, const glm::quat& newOrientation,
|
||||
bool shouldFaceLocation);
|
||||
private slots:
|
||||
void handleAPIResponse(QNetworkReply& requestReply);
|
||||
void handleAPIError(QNetworkReply& errorReply);
|
||||
private:
|
||||
AddressManager();
|
||||
|
||||
void setDomainHostnameAndName(const QString& hostname, const QString& domainName = QString());
|
||||
|
||||
const JSONCallbackParameters& apiCallbackParameters();
|
||||
|
||||
bool handleUrl(const QUrl& lookupUrl);
|
||||
|
|
Loading…
Reference in a new issue