mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 01:43:27 +02:00
Add JavaScript event bridge for Web 3D overlay
This commit is contained in:
parent
a8a04cfbba
commit
a5bdd9066f
6 changed files with 48 additions and 2 deletions
|
@ -292,6 +292,14 @@ QString Overlays::getOverlayType(unsigned int overlayId) const {
|
|||
return "";
|
||||
}
|
||||
|
||||
QObject* Overlays::getOverlayObject(unsigned int id) {
|
||||
Overlay::Pointer thisOverlay = getOverlay(id);
|
||||
if (thisOverlay) {
|
||||
return qobject_cast<QObject*>(&(*thisOverlay));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unsigned int Overlays::getParentPanel(unsigned int childId) const {
|
||||
Overlay::Pointer overlay = getOverlay(childId);
|
||||
auto attachable = std::dynamic_pointer_cast<PanelAttachable>(overlay);
|
||||
|
|
|
@ -155,6 +155,15 @@ public slots:
|
|||
*/
|
||||
QString getOverlayType(unsigned int overlayId) const;
|
||||
|
||||
/**jsdoc
|
||||
* Get the overlay Script object.
|
||||
*
|
||||
* @function Overlays.getOverlayObject
|
||||
* @param {Overlays.OverlayID} overlayID The ID of the overlay to get the script object of.
|
||||
* @return {Object} The script object for the overlay if found.
|
||||
*/
|
||||
QObject* getOverlayObject(unsigned int id);
|
||||
|
||||
/**jsdoc
|
||||
* Get the ID of the overlay at a particular point on the HUD/screen.
|
||||
*
|
||||
|
|
|
@ -68,6 +68,9 @@ Web3DOverlay::~Web3DOverlay() {
|
|||
QObject::disconnect(_hoverLeaveConnection);
|
||||
_hoverLeaveConnection = QMetaObject::Connection();
|
||||
|
||||
QObject::disconnect(_webEventReceivedConnection);
|
||||
_webEventReceivedConnection = QMetaObject::Connection();
|
||||
|
||||
// The lifetime of the QML surface MUST be managed by the main thread
|
||||
// Additionally, we MUST use local variables copied by value, rather than
|
||||
// member variables, since they would implicitly refer to a this that
|
||||
|
@ -147,6 +150,8 @@ void Web3DOverlay::render(RenderArgs* args) {
|
|||
QCoreApplication::postEvent(_webSurface->getWindow(), touchEvent);
|
||||
}
|
||||
});
|
||||
|
||||
_webEventReceivedConnection = connect(_webSurface.data(), &OffscreenQmlSurface::webEventReceived, this, &Web3DOverlay::webEventReceived);
|
||||
}
|
||||
|
||||
vec2 halfSize = getSize() / 2.0f;
|
||||
|
|
|
@ -51,6 +51,9 @@ public:
|
|||
|
||||
virtual Web3DOverlay* createClone() const override;
|
||||
|
||||
signals:
|
||||
void webEventReceived(const QVariant& message);
|
||||
|
||||
private:
|
||||
QSharedPointer<OffscreenQmlSurface> _webSurface;
|
||||
QMetaObject::Connection _connection;
|
||||
|
@ -68,6 +71,8 @@ private:
|
|||
QMetaObject::Connection _mouseReleaseConnection;
|
||||
QMetaObject::Connection _mouseMoveConnection;
|
||||
QMetaObject::Connection _hoverLeaveConnection;
|
||||
|
||||
QMetaObject::Connection _webEventReceivedConnection;
|
||||
};
|
||||
|
||||
#endif // hifi_Web3DOverlay_h
|
||||
|
|
|
@ -85,10 +85,18 @@ WebTablet = function (url, width, dpi, clientOnly) {
|
|||
this.state = "idle";
|
||||
};
|
||||
|
||||
WebTablet.prototype.setURL = function (url) {
|
||||
Overlays.editOverlay(this.webOverlayID, { url: url });
|
||||
};
|
||||
|
||||
WebTablet.prototype.setScriptURL = function (scriptURL) {
|
||||
Overlays.editOverlay(this.webOverlayID, { scriptURL: scriptURL });
|
||||
};
|
||||
|
||||
WebTablet.prototype.getOverlayObject = function () {
|
||||
return Overlays.getOverlayObject(this.webOverlayID);
|
||||
};
|
||||
|
||||
WebTablet.prototype.destroy = function () {
|
||||
Overlays.deleteOverlay(this.webOverlayID);
|
||||
Entities.deleteEntity(this.tabletEntityID);
|
||||
|
|
|
@ -28,7 +28,6 @@ var marketplaceWindow = new OverlayWebWindow({
|
|||
visible: false
|
||||
});
|
||||
marketplaceWindow.setScriptURL(MARKETPLACES_DIRECTORY_SCRIPT_URL);
|
||||
|
||||
marketplaceWindow.webEventReceived.connect(function (data) {
|
||||
if (data === "INJECT_CLARA") {
|
||||
marketplaceWindow.setScriptURL(MARKETPLACES_CLARA_SCRIPT_URL);
|
||||
|
@ -65,10 +64,22 @@ function showMarketplace(marketplaceID) {
|
|||
marketplaceWebTablet = new WebTablet(MARKETPLACES_URL, null, null, true);
|
||||
Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
|
||||
marketplaceWebTablet.setScriptURL(MARKETPLACES_DIRECTORY_SCRIPT_URL);
|
||||
marketplaceWebTablet.getOverlayObject().webEventReceived.connect(function (data) {
|
||||
if (data === "INJECT_CLARA") {
|
||||
marketplaceWebTablet.setScriptURL(MARKETPLACES_CLARA_SCRIPT_URL);
|
||||
}
|
||||
if (data === "INJECT_HIFI") {
|
||||
marketplaceWebTablet.setScriptURL(MARKETPLACES_HFIF_SCRIPT_URL);
|
||||
}
|
||||
if (data === "RELOAD_DIRECTORY") {
|
||||
marketplaceWebTablet.setScriptURL(MARKETPLACES_DIRECTORY_SCRIPT_URL);
|
||||
marketplaceWebTablet.setURL(""); // Force reload of URL.
|
||||
marketplaceWebTablet.setURL(MARKETPLACES_URL);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var url = MARKETPLACES_URL;
|
||||
if (marketplaceID) {
|
||||
// $$$$$$$ TODO
|
||||
url = url + "/items/" + marketplaceID;
|
||||
}
|
||||
marketplaceWindow.setURL(url);
|
||||
|
|
Loading…
Reference in a new issue