mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 17:35:45 +02:00
Register OverlayPanel binding map as a meta type.
This commit is contained in:
parent
f870f19837
commit
fa24df765d
5 changed files with 82 additions and 47 deletions
|
@ -3750,6 +3750,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
|
qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
|
||||||
qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue,
|
qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue,
|
||||||
RayToOverlayIntersectionResultFromScriptValue);
|
RayToOverlayIntersectionResultFromScriptValue);
|
||||||
|
qScriptRegisterMetaType(scriptEngine, propertyBindingToScriptValue, propertyBindingFromScriptValue);
|
||||||
|
|
||||||
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data());
|
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data());
|
||||||
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
|
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
|
||||||
|
|
|
@ -21,6 +21,38 @@
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Base3DOverlay.h"
|
#include "Base3DOverlay.h"
|
||||||
|
|
||||||
|
PropertyBinding::PropertyBinding(QString avatar, QUuid entity) :
|
||||||
|
avatar(avatar),
|
||||||
|
entity(entity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue propertyBindingToScriptValue(QScriptEngine* engine, const PropertyBinding& value) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
|
||||||
|
if (value.avatar == "MyAvatar") {
|
||||||
|
obj.setProperty("avatar", "MyAvatar");
|
||||||
|
} else if (!value.entity.isNull()) {
|
||||||
|
obj.setProperty("entity", engine->newVariant(value.entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void propertyBindingFromScriptValue(const QScriptValue& object, PropertyBinding& value) {
|
||||||
|
value.avatar = "";
|
||||||
|
value.entity = {};
|
||||||
|
QScriptValue avatar = object.property("avatar");
|
||||||
|
QScriptValue entity = object.property("entity");
|
||||||
|
|
||||||
|
if (avatar.isValid() && !avatar.isNull()) {
|
||||||
|
value.avatar = avatar.toVariant().toString();
|
||||||
|
} else if (entity.isValid() && !entity.isNull()) {
|
||||||
|
value.entity = entity.toVariant().toUuid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void OverlayPanel::addChild(unsigned int childId) {
|
void OverlayPanel::addChild(unsigned int childId) {
|
||||||
if (!_children.contains(childId)) {
|
if (!_children.contains(childId)) {
|
||||||
_children.append(childId);
|
_children.append(childId);
|
||||||
|
@ -38,29 +70,35 @@ QScriptValue OverlayPanel::getProperty(const QString &property) {
|
||||||
return vec3toScriptValue(_scriptEngine, getPosition());
|
return vec3toScriptValue(_scriptEngine, getPosition());
|
||||||
}
|
}
|
||||||
if (property == "positionBinding") {
|
if (property == "positionBinding") {
|
||||||
QScriptValue obj = _scriptEngine->newObject();
|
return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_positionBindMyAvatar ?
|
||||||
|
"MyAvatar" : "",
|
||||||
if (_positionBindMyAvatar) {
|
_positionBindEntity));
|
||||||
obj.setProperty("avatar", "MyAvatar");
|
// QScriptValue obj = _scriptEngine->newObject();
|
||||||
} else if (!_positionBindEntity.isNull()) {
|
//
|
||||||
obj.setProperty("entity", _scriptEngine->newVariant(_positionBindEntity));
|
// if (_positionBindMyAvatar) {
|
||||||
}
|
// obj.setProperty("avatar", "MyAvatar");
|
||||||
|
// } else if (!_positionBindEntity.isNull()) {
|
||||||
return obj;
|
// obj.setProperty("entity", _scriptEngine->newVariant(_positionBindEntity));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return obj;
|
||||||
}
|
}
|
||||||
if (property == "rotation") {
|
if (property == "rotation") {
|
||||||
return quatToScriptValue(_scriptEngine, getRotation());
|
return quatToScriptValue(_scriptEngine, getRotation());
|
||||||
}
|
}
|
||||||
if (property == "rotationBinding") {
|
if (property == "rotationBinding") {
|
||||||
QScriptValue obj = _scriptEngine->newObject();
|
return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_rotationBindMyAvatar ?
|
||||||
|
"MyAvatar" : "",
|
||||||
if (_rotationBindMyAvatar) {
|
_rotationBindEntity));
|
||||||
obj.setProperty("avatar", "MyAvatar");
|
// QScriptValue obj = _scriptEngine->newObject();
|
||||||
} else if (!_rotationBindEntity.isNull()) {
|
//
|
||||||
obj.setProperty("entity", _scriptEngine->newVariant(_rotationBindEntity));
|
// if (_rotationBindMyAvatar) {
|
||||||
}
|
// obj.setProperty("avatar", "MyAvatar");
|
||||||
|
// } else if (!_rotationBindEntity.isNull()) {
|
||||||
return obj;
|
// obj.setProperty("entity", _scriptEngine->newVariant(_rotationBindEntity));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return obj;
|
||||||
}
|
}
|
||||||
if (property == "visible") {
|
if (property == "visible") {
|
||||||
return getVisible();
|
return getVisible();
|
||||||
|
@ -80,17 +118,11 @@ void OverlayPanel::setProperties(const QScriptValue &properties) {
|
||||||
PanelAttachable::setProperties(properties);
|
PanelAttachable::setProperties(properties);
|
||||||
|
|
||||||
QScriptValue position = properties.property("position");
|
QScriptValue position = properties.property("position");
|
||||||
if (position.isValid()) {
|
if (position.isValid() &&
|
||||||
QScriptValue x = position.property("x");
|
position.property("x").isValid() &&
|
||||||
QScriptValue y = position.property("y");
|
position.property("y").isValid() &&
|
||||||
QScriptValue z = position.property("z");
|
position.property("z").isValid()) {
|
||||||
if (x.isValid() && y.isValid() && z.isValid()) {
|
vec3FromScriptValue(position, _position);
|
||||||
glm::vec3 newPosition;
|
|
||||||
newPosition.x = x.toVariant().toFloat();
|
|
||||||
newPosition.y = y.toVariant().toFloat();
|
|
||||||
newPosition.z = z.toVariant().toFloat();
|
|
||||||
setPosition(newPosition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue positionBinding = properties.property("positionBinding");
|
QScriptValue positionBinding = properties.property("positionBinding");
|
||||||
|
@ -109,20 +141,12 @@ void OverlayPanel::setProperties(const QScriptValue &properties) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue rotation = properties.property("rotation");
|
QScriptValue rotation = properties.property("rotation");
|
||||||
if (rotation.isValid()) {
|
if (rotation.isValid() &&
|
||||||
QScriptValue x = rotation.property("x");
|
rotation.property("x").isValid() &&
|
||||||
QScriptValue y = rotation.property("y");
|
rotation.property("y").isValid() &&
|
||||||
QScriptValue z = rotation.property("z");
|
rotation.property("z").isValid() &&
|
||||||
QScriptValue w = rotation.property("w");
|
rotation.property("w").isValid()) {
|
||||||
|
quatFromScriptValue(rotation, _rotation);
|
||||||
if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) {
|
|
||||||
glm::quat newRotation;
|
|
||||||
newRotation.x = x.toVariant().toFloat();
|
|
||||||
newRotation.y = y.toVariant().toFloat();
|
|
||||||
newRotation.z = z.toVariant().toFloat();
|
|
||||||
newRotation.w = w.toVariant().toFloat();
|
|
||||||
setRotation(newRotation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue rotationBinding = properties.property("rotationBinding");
|
QScriptValue rotationBinding = properties.property("rotationBinding");
|
||||||
|
|
|
@ -21,6 +21,19 @@
|
||||||
|
|
||||||
#include "PanelAttachable.h"
|
#include "PanelAttachable.h"
|
||||||
|
|
||||||
|
class PropertyBinding {
|
||||||
|
public:
|
||||||
|
PropertyBinding() {}
|
||||||
|
PropertyBinding(QString avatar, QUuid entity);
|
||||||
|
QString avatar;
|
||||||
|
QUuid entity;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(PropertyBinding);
|
||||||
|
QScriptValue propertyBindingToScriptValue(QScriptEngine* engine, const PropertyBinding& value);
|
||||||
|
void propertyBindingFromScriptValue(const QScriptValue& object, PropertyBinding& value);
|
||||||
|
|
||||||
|
|
||||||
class OverlayPanel : public QObject, public PanelAttachable {
|
class OverlayPanel : public QObject, public PanelAttachable {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,6 @@ bool PanelAttachable::getParentVisible() const {
|
||||||
|
|
||||||
void PanelAttachable::applyTransformTo(Transform& transform) {
|
void PanelAttachable::applyTransformTo(Transform& transform) {
|
||||||
if (getParentPanel()) {
|
if (getParentPanel()) {
|
||||||
// transform.setTranslation(getParentPanel()->getComputedPosition());
|
|
||||||
// transform.setRotation(getParentPanel()->getComputedRotation());
|
|
||||||
// transform.postTranslate(getParentPanel()->getOffsetPosition());
|
|
||||||
// transform.postRotate(getParentPanel()->getOffsetRotation());
|
|
||||||
getParentPanel()->applyTransformTo(transform);
|
getParentPanel()->applyTransformTo(transform);
|
||||||
transform.postTranslate(getOffsetPosition());
|
transform.postTranslate(getOffsetPosition());
|
||||||
transform.postRotate(getOffsetRotation());
|
transform.postRotate(getOffsetRotation());
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <Transform.h>
|
#include <Transform.h>
|
||||||
#include <QScriptValue>
|
#include <QScriptValue>
|
||||||
#include <QScriptEngine>
|
#include <QScriptEngine>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
class OverlayPanel;
|
class OverlayPanel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue