mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 07:19:05 +02:00
Improve cross-thread support for panel children.
This commit is contained in:
parent
021dff63b4
commit
6165e7e6ca
5 changed files with 37 additions and 35 deletions
|
@ -186,6 +186,10 @@ function onScriptEnd() {
|
||||||
mainPanel.destroy();
|
mainPanel.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print(JSON.stringify(mainPanel.children));
|
||||||
|
print(JSON.stringify(bluePanel.children));
|
||||||
|
print(bluePanel._id);
|
||||||
|
|
||||||
Controller.mousePressEvent.connect(onMouseDown);
|
Controller.mousePressEvent.connect(onMouseDown);
|
||||||
Controller.mouseReleaseEvent.connect(onMouseUp);
|
Controller.mouseReleaseEvent.connect(onMouseUp);
|
||||||
Script.scriptEnding.connect(onScriptEnd);
|
Script.scriptEnding.connect(onScriptEnd);
|
||||||
|
|
|
@ -60,10 +60,6 @@
|
||||||
}
|
}
|
||||||
var overlay = new overlayTypes[type]();
|
var overlay = new overlayTypes[type]();
|
||||||
overlay._id = id;
|
overlay._id = id;
|
||||||
var attachedPanel = findPanel(Overlays.getAttachedPanel(id))
|
|
||||||
if (attachedPanel) {
|
|
||||||
attachedPanel.addChild(overlay);
|
|
||||||
}
|
|
||||||
overlays[id] = overlay;
|
overlays[id] = overlay;
|
||||||
return overlay;
|
return overlay;
|
||||||
}
|
}
|
||||||
|
@ -101,10 +97,6 @@
|
||||||
}
|
}
|
||||||
var panel = new FloatingUIPanel();
|
var panel = new FloatingUIPanel();
|
||||||
panel._id = id;
|
panel._id = id;
|
||||||
var attachedPanel = findPanel(Overlays.getAttachedPanel(id))
|
|
||||||
if (attachedPanel) {
|
|
||||||
attachedPanel.addChild(panel);
|
|
||||||
}
|
|
||||||
overlays[id] = overlay;
|
overlays[id] = overlay;
|
||||||
return overlay;
|
return overlay;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +125,11 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findOverlayOrPanel(id, knownObjectsOnly, searchList) {
|
||||||
|
return findOverlay(id, knownObjectsOnly, searchList) ||
|
||||||
|
findPanel(id, knownObjectsOnly, searchList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Perform global scoped operations on overlays, such as finding by ray intersection.
|
// Perform global scoped operations on overlays, such as finding by ray intersection.
|
||||||
|
@ -154,10 +151,10 @@
|
||||||
return OverlayManager.findOnRay(pickRay, knownOverlaysOnly, searchList);
|
return OverlayManager.findOnRay(pickRay, knownOverlaysOnly, searchList);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
makeSearchList: function(overlayArray) {
|
makeSearchList: function(array) {
|
||||||
var searchList = {};
|
var searchList = {};
|
||||||
overlayArray.forEach(function(overlay){
|
array.forEach(function(object) {
|
||||||
searchList[overlay._id] = overlay;
|
searchList[object._id] = object;
|
||||||
});
|
});
|
||||||
return searchList;
|
return searchList;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +277,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
that.prototype.isPanelAttachable = function() {
|
that.prototype.isPanelAttachable = function() {
|
||||||
return true;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
return generateOverlayClass(that, ABSTRACT, [
|
return generateOverlayClass(that, ABSTRACT, [
|
||||||
|
@ -380,17 +377,11 @@
|
||||||
FloatingUIPanel = (function() {
|
FloatingUIPanel = (function() {
|
||||||
var that = function(params) {
|
var that = function(params) {
|
||||||
this._id = Overlays.addPanel(params);
|
this._id = Overlays.addPanel(params);
|
||||||
this._children = [];
|
|
||||||
this._visible = Boolean(params.visible);
|
|
||||||
panels[this._id] = this;
|
panels[this._id] = this;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.prototype.constructor = that;
|
that.prototype.constructor = that;
|
||||||
|
|
||||||
that.AddChildException = function(message) {
|
|
||||||
this.message = message;
|
|
||||||
};
|
|
||||||
|
|
||||||
[
|
[
|
||||||
"anchorPosition", "anchorPositionBinding", "offsetRotation", "offsetRotationBinding",
|
"anchorPosition", "anchorPositionBinding", "offsetRotation", "offsetRotationBinding",
|
||||||
"offsetPosition", "facingRotation", "visible"
|
"offsetPosition", "facingRotation", "visible"
|
||||||
|
@ -416,27 +407,23 @@
|
||||||
|
|
||||||
Object.defineProperty(that.prototype, "children", {
|
Object.defineProperty(that.prototype, "children", {
|
||||||
get: function() {
|
get: function() {
|
||||||
return this._children.slice();
|
var idArray = Overlays.getPanelProperty(this._id, "children");
|
||||||
|
var objArray = [];
|
||||||
|
for (var i = 0; i < idArray.length; i++) {
|
||||||
|
objArray[i] = findOverlayOrPanel(idArray[i]);
|
||||||
|
}
|
||||||
|
return objArray;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
that.prototype.addChild = function(child) {
|
that.prototype.addChild = function(child) {
|
||||||
if (child instanceof Overlay && child.isPanelAttachable() ||
|
|
||||||
child instanceof FloatingUIPanel) {
|
|
||||||
Overlays.setAttachedPanel(child._id, this._id);
|
Overlays.setAttachedPanel(child._id, this._id);
|
||||||
} else {
|
|
||||||
throw new that.AddChildException("Given child is not panel attachable.");
|
|
||||||
}
|
|
||||||
child.visible = this.visible;
|
|
||||||
this._children.push(child);
|
|
||||||
return child;
|
return child;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.prototype.removeChild = function(child) {
|
that.prototype.removeChild = function(child) {
|
||||||
var i = this._children.indexOf(child);
|
if (child.attachedPanel === this) {
|
||||||
if (i >= 0) {
|
|
||||||
Overlays.setAttachedPanel(child._id, 0);
|
Overlays.setAttachedPanel(child._id, 0);
|
||||||
this._children.splice(i, 1);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -445,7 +432,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
that.prototype.setChildrenVisible = function() {
|
that.prototype.setChildrenVisible = function() {
|
||||||
this._children.forEach(function(child) {
|
this.children.forEach(function(child) {
|
||||||
child.visible = true;
|
child.visible = true;
|
||||||
if (child.setChildrenVisible !== undefined) {
|
if (child.setChildrenVisible !== undefined) {
|
||||||
child.setChildrenVisible();
|
child.setChildrenVisible();
|
||||||
|
|
|
@ -116,6 +116,13 @@ QScriptValue FloatingUIPanel::getProperty(const QString &property) {
|
||||||
if (property == "visible") {
|
if (property == "visible") {
|
||||||
return getVisible();
|
return getVisible();
|
||||||
}
|
}
|
||||||
|
if (property == "children") {
|
||||||
|
QScriptValue array = _scriptEngine->newArray(_children.length());
|
||||||
|
for (int i = 0; i < _children.length(); i++) {
|
||||||
|
array.setProperty(i, _children[i]);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
return QScriptValue();
|
return QScriptValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ private:
|
||||||
|
|
||||||
Pointer _attachedPanel = nullptr;
|
Pointer _attachedPanel = nullptr;
|
||||||
QList<unsigned int> _children;
|
QList<unsigned int> _children;
|
||||||
bool _visible = false;
|
bool _visible = true;
|
||||||
|
|
||||||
QScriptEngine* _scriptEngine;
|
QScriptEngine* _scriptEngine;
|
||||||
};
|
};
|
||||||
|
|
|
@ -202,7 +202,12 @@ unsigned int Overlays::cloneOverlay(unsigned int id) {
|
||||||
Overlay::Pointer thisOverlay = getOverlay(id);
|
Overlay::Pointer thisOverlay = getOverlay(id);
|
||||||
|
|
||||||
if (thisOverlay) {
|
if (thisOverlay) {
|
||||||
return addOverlay(Overlay::Pointer(thisOverlay->createClone()));
|
unsigned int cloneId = addOverlay(Overlay::Pointer(thisOverlay->createClone()));
|
||||||
|
auto attachable = std::dynamic_pointer_cast<PanelAttachable>(thisOverlay);
|
||||||
|
if (attachable && attachable->getAttachedPanel()) {
|
||||||
|
attachable->getAttachedPanel()->addChild(cloneId);
|
||||||
|
}
|
||||||
|
return cloneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; // Not found
|
return 0; // Not found
|
||||||
|
@ -284,8 +289,7 @@ unsigned int Overlays::getAttachedPanel(unsigned int childId) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overlays::setAttachedPanel(unsigned int childId, unsigned int panelId) {
|
void Overlays::setAttachedPanel(unsigned int childId, unsigned int panelId) {
|
||||||
Overlay::Pointer overlay = getOverlay(childId);
|
auto attachable = std::dynamic_pointer_cast<PanelAttachable>(getOverlay(childId));
|
||||||
auto attachable = std::dynamic_pointer_cast<PanelAttachable>(overlay);
|
|
||||||
if (attachable) {
|
if (attachable) {
|
||||||
if (_panels.contains(panelId)) {
|
if (_panels.contains(panelId)) {
|
||||||
auto panel = getPanel(panelId);
|
auto panel = getPanel(panelId);
|
||||||
|
|
Loading…
Reference in a new issue