From eed6e2e8f657e57a934c3604224121ddb3bb3e5f Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Sep 2014 22:11:21 +0200 Subject: [PATCH 1/4] - Edit -> Model List menu option - Combo items can be JS objects now, write a toString() function for each JS object to describe them --- examples/editModels.js | 272 ++++++++++-------- .../scripting/WindowScriptingInterface.cpp | 28 +- 2 files changed, 172 insertions(+), 128 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index c47c497a78..b734864b84 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -2745,7 +2745,7 @@ function setupModelMenus() { } Menu.addMenuItem({ menuName: "Edit", menuItemName: "Paste Models", shortcutKey: "CTRL+META+V", afterItem: "Edit Properties..." }); - + Menu.addMenuItem({ menuName: "Edit", menuItemName: "Model List", afterItem: "Models" }); Menu.addMenuItem({ menuName: "File", menuItemName: "Models", isSeparator: true, beforeItem: "Settings" }); Menu.addMenuItem({ menuName: "File", menuItemName: "Export Models", shortcutKey: "CTRL+META+E", afterItem: "Models" }); Menu.addMenuItem({ menuName: "File", menuItemName: "Import Models", shortcutKey: "CTRL+META+I", afterItem: "Export Models" }); @@ -2796,6 +2796,128 @@ var dimensionY; var dimensionZ; var rescalePercentage; +function showPropertiesForm() { + propertiesForEditedEntity = Entities.getEntityProperties(editModelID); + var properties = propertiesForEditedEntity; + + var array = new Array(); + var index = 0; + var decimals = 3; + if (properties.type == "Model") { + array.push({ label: "Model URL:", value: properties.modelURL }); + index++; + array.push({ label: "Animation URL:", value: properties.animationURL }); + index++; + array.push({ label: "Animation is playing:", value: properties.animationIsPlaying }); + index++; + array.push({ label: "Animation FPS:", value: properties.animationFPS }); + index++; + array.push({ label: "Animation Frame:", value: properties.animationFrameIndex }); + index++; + } + array.push({ label: "Position:", type: "header" }); + index++; + array.push({ label: "X:", value: properties.position.x.toFixed(decimals) }); + index++; + array.push({ label: "Y:", value: properties.position.y.toFixed(decimals) }); + index++; + array.push({ label: "Z:", value: properties.position.z.toFixed(decimals) }); + index++; + + array.push({ label: "Registration X:", value: properties.registrationPoint.x.toFixed(decimals) }); + index++; + array.push({ label: "Registration Y:", value: properties.registrationPoint.y.toFixed(decimals) }); + index++; + array.push({ label: "Registration Z:", value: properties.registrationPoint.z.toFixed(decimals) }); + index++; + + array.push({ label: "Rotation:", type: "header" }); + index++; + var angles = Quat.safeEulerAngles(properties.rotation); + array.push({ label: "Pitch:", value: angles.x.toFixed(decimals) }); + index++; + array.push({ label: "Yaw:", value: angles.y.toFixed(decimals) }); + index++; + array.push({ label: "Roll:", value: angles.z.toFixed(decimals) }); + index++; + + array.push({ label: "Dimensions:", type: "header" }); + index++; + array.push({ label: "Width:", value: properties.dimensions.x.toFixed(decimals) }); + dimensionX = index; + index++; + array.push({ label: "Height:", value: properties.dimensions.y.toFixed(decimals) }); + dimensionY = index; + index++; + array.push({ label: "Depth:", value: properties.dimensions.z.toFixed(decimals) }); + dimensionZ = index; + index++; + array.push({ label: "", type: "inlineButton", buttonLabel: "Reset to Natural Dimensions", name: "resetDimensions" }); + index++; + array.push({ label: "Rescale Percentage:", value: 100 }); + rescalePercentage = index; + index++; + array.push({ label: "", type: "inlineButton", buttonLabel: "Rescale", name: "rescaleDimensions" }); + index++; + + array.push({ label: "Velocity:", type: "header" }); + index++; + array.push({ label: "Linear X:", value: properties.velocity.x.toFixed(decimals) }); + index++; + array.push({ label: "Linear Y:", value: properties.velocity.y.toFixed(decimals) }); + index++; + array.push({ label: "Linear Z:", value: properties.velocity.z.toFixed(decimals) }); + index++; + array.push({ label: "Linear Damping:", value: properties.damping.toFixed(decimals) }); + index++; + array.push({ label: "Angular Pitch:", value: properties.angularVelocity.x.toFixed(decimals) }); + index++; + array.push({ label: "Angular Yaw:", value: properties.angularVelocity.y.toFixed(decimals) }); + index++; + array.push({ label: "Angular Roll:", value: properties.angularVelocity.z.toFixed(decimals) }); + index++; + array.push({ label: "Angular Damping:", value: properties.angularDamping.toFixed(decimals) }); + index++; + + array.push({ label: "Gravity X:", value: properties.gravity.x.toFixed(decimals) }); + index++; + array.push({ label: "Gravity Y:", value: properties.gravity.y.toFixed(decimals) }); + index++; + array.push({ label: "Gravity Z:", value: properties.gravity.z.toFixed(decimals) }); + index++; + + array.push({ label: "Collisions:", type: "header" }); + index++; + array.push({ label: "Mass:", value: properties.mass.toFixed(decimals) }); + index++; + array.push({ label: "Ignore for Collisions:", value: properties.ignoreForCollisions }); + index++; + array.push({ label: "Collisions Will Move:", value: properties.collisionsWillMove }); + index++; + + array.push({ label: "Lifetime:", value: properties.lifetime.toFixed(decimals) }); + index++; + + array.push({ label: "Visible:", value: properties.visible }); + index++; + + if (properties.type == "Box" || properties.type == "Sphere") { + array.push({ label: "Color:", type: "header" }); + index++; + array.push({ label: "Red:", value: properties.color.red }); + index++; + array.push({ label: "Green:", value: properties.color.green }); + index++; + array.push({ label: "Blue:", value: properties.color.blue }); + index++; + } + array.push({ button: "Cancel" }); + index++; + + editEntityFormArray = array; + Window.nonBlockingForm("Edit Properties", array); +} + function handeMenuEvent(menuItem) { print("menuItemEvent() in JS... menuItem=" + menuItem); if (menuItem == "Delete") { @@ -2823,6 +2945,33 @@ function handeMenuEvent(menuItem) { } else { print(" Delete Entity.... not holding..."); } + } else if (menuItem == "Model List") { + var models = new Array(); + models = Entities.findEntities(MyAvatar.position, Number.MAX_VALUE); + for (var i = 0; i < models.length; i++) { + models[i].properties = Entities.getEntityProperties(models[i]); + models[i].toString = function() { + var modelname = decodeURIComponent( + this.properties.modelURL.indexOf("/") != -1 ? + this.properties.modelURL.substring(this.properties.modelURL.lastIndexOf("/") + 1) : + this.properties.modelURL); + return "[" + this.properties.type + "] " + modelname; + }; + } + var form = [{label: "Model: ", options: models}]; + form.push({label: "Action: ", options: ["Properties", "Delete", "Teleport"]}); + form.push({ button: "Cancel" }); + if (Window.form("Model List", form)) { + var selectedModel = form[0].value; + if (form[1].value == "Properties") { + editModelID = selectedModel; + showPropertiesForm(); + } else if (form[1].value == "Delete") { + Entities.deleteEntity(selectedModel); + } else if (form[1].value == "Teleport") { + MyAvatar.position = selectedModel.properties.position; + } + } } else if (menuItem == "Edit Properties...") { editModelID = -1; if (leftController.grabbing) { @@ -2839,126 +2988,7 @@ function handeMenuEvent(menuItem) { } if (editModelID != -1) { print(" Edit Properties.... about to edit properties..."); - - propertiesForEditedEntity = Entities.getEntityProperties(editModelID); - var properties = propertiesForEditedEntity; - - var array = new Array(); - var index = 0; - var decimals = 3; - if (properties.type == "Model") { - array.push({ label: "Model URL:", value: properties.modelURL }); - index++; - array.push({ label: "Animation URL:", value: properties.animationURL }); - index++; - array.push({ label: "Animation is playing:", value: properties.animationIsPlaying }); - index++; - array.push({ label: "Animation FPS:", value: properties.animationFPS }); - index++; - array.push({ label: "Animation Frame:", value: properties.animationFrameIndex }); - index++; - } - array.push({ label: "Position:", type: "header" }); - index++; - array.push({ label: "X:", value: properties.position.x.toFixed(decimals) }); - index++; - array.push({ label: "Y:", value: properties.position.y.toFixed(decimals) }); - index++; - array.push({ label: "Z:", value: properties.position.z.toFixed(decimals) }); - index++; - - array.push({ label: "Registration X:", value: properties.registrationPoint.x.toFixed(decimals) }); - index++; - array.push({ label: "Registration Y:", value: properties.registrationPoint.y.toFixed(decimals) }); - index++; - array.push({ label: "Registration Z:", value: properties.registrationPoint.z.toFixed(decimals) }); - index++; - - array.push({ label: "Rotation:", type: "header" }); - index++; - var angles = Quat.safeEulerAngles(properties.rotation); - array.push({ label: "Pitch:", value: angles.x.toFixed(decimals) }); - index++; - array.push({ label: "Yaw:", value: angles.y.toFixed(decimals) }); - index++; - array.push({ label: "Roll:", value: angles.z.toFixed(decimals) }); - index++; - - array.push({ label: "Dimensions:", type: "header" }); - index++; - array.push({ label: "Width:", value: properties.dimensions.x.toFixed(decimals) }); - dimensionX = index; - index++; - array.push({ label: "Height:", value: properties.dimensions.y.toFixed(decimals) }); - dimensionY = index; - index++; - array.push({ label: "Depth:", value: properties.dimensions.z.toFixed(decimals) }); - dimensionZ = index; - index++; - array.push({ label: "", type: "inlineButton", buttonLabel: "Reset to Natural Dimensions", name: "resetDimensions" }); - index++; - array.push({ label: "Rescale Percentage:", value: 100 }); - rescalePercentage = index; - index++; - array.push({ label: "", type: "inlineButton", buttonLabel: "Rescale", name: "rescaleDimensions" }); - index++; - - array.push({ label: "Velocity:", type: "header" }); - index++; - array.push({ label: "Linear X:", value: properties.velocity.x.toFixed(decimals) }); - index++; - array.push({ label: "Linear Y:", value: properties.velocity.y.toFixed(decimals) }); - index++; - array.push({ label: "Linear Z:", value: properties.velocity.z.toFixed(decimals) }); - index++; - array.push({ label: "Linear Damping:", value: properties.damping.toFixed(decimals) }); - index++; - array.push({ label: "Angular Pitch:", value: properties.angularVelocity.x.toFixed(decimals) }); - index++; - array.push({ label: "Angular Yaw:", value: properties.angularVelocity.y.toFixed(decimals) }); - index++; - array.push({ label: "Angular Roll:", value: properties.angularVelocity.z.toFixed(decimals) }); - index++; - array.push({ label: "Angular Damping:", value: properties.angularDamping.toFixed(decimals) }); - index++; - - array.push({ label: "Gravity X:", value: properties.gravity.x.toFixed(decimals) }); - index++; - array.push({ label: "Gravity Y:", value: properties.gravity.y.toFixed(decimals) }); - index++; - array.push({ label: "Gravity Z:", value: properties.gravity.z.toFixed(decimals) }); - index++; - - array.push({ label: "Collisions:", type: "header" }); - index++; - array.push({ label: "Mass:", value: properties.mass.toFixed(decimals) }); - index++; - array.push({ label: "Ignore for Collisions:", value: properties.ignoreForCollisions }); - index++; - array.push({ label: "Collisions Will Move:", value: properties.collisionsWillMove }); - index++; - - array.push({ label: "Lifetime:", value: properties.lifetime.toFixed(decimals) }); - index++; - - array.push({ label: "Visible:", value: properties.visible }); - index++; - - if (properties.type == "Box" || properties.type == "Sphere") { - array.push({ label: "Color:", type: "header" }); - index++; - array.push({ label: "Red:", value: properties.color.red }); - index++; - array.push({ label: "Green:", value: properties.color.green }); - index++; - array.push({ label: "Blue:", value: properties.color.blue }); - index++; - } - array.push({ button: "Cancel" }); - index++; - - editEntityFormArray = array; - Window.nonBlockingForm("Edit Properties", array); + showPropertiesForm(editModelID); } } else if (menuItem == "Paste Models") { modelImporter.paste(); diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 913655195d..4f0020ee61 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -265,7 +265,11 @@ QScriptValue WindowScriptingInterface::doPeekNonBlockingFormResult(QScriptValue _form.setProperty(i, item); } else if (item.property("options").isArray()) { c += 1; - item.setProperty("value", _combos.at(c)->currentText()); + item.setProperty("value", + _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? + item.property("options").property(_combos.at(c)->currentIndex()) : + array.engine()->undefinedValue() + ); _form.setProperty(i, item); } else { e += 1; @@ -318,7 +322,11 @@ QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue a _form.setProperty(i, item); } else if (item.property("options").isArray()) { c += 1; - item.setProperty("value", _combos.at(c)->currentText()); + item.setProperty("value", + _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? + item.property("options").property(_combos.at(c)->currentIndex()) : + array.engine()->undefinedValue() + ); _form.setProperty(i, item); } else { e += 1; @@ -349,6 +357,7 @@ QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue a _form = QScriptValue(); _edits.clear(); _directories.clear(); + _combos.clear(); array = _form; return (_formResult == QDialog::Accepted); @@ -391,8 +400,12 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal form.setProperty(i, item); } else if (item.property("options").isArray()) { c += 1; - item.setProperty("value", _combos.at(c)->currentText()); - _form.setProperty(i, item); + item.setProperty("value", + _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? + item.property("options").property(_combos.at(c)->currentIndex()) : + form.engine()->undefinedValue() + ); + form.setProperty(i, item); } else { e += 1; bool ok = true; @@ -418,6 +431,7 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal } delete editDialog; + _combos.clear(); _edits.clear(); _directories.clear(); return (result == QDialog::Accepted); @@ -498,9 +512,9 @@ QDialog* WindowScriptingInterface::createForm(const QString& title, QScriptValue } else if (item.property("options").isArray()) { QComboBox* combo = new QComboBox(); combo->setMinimumWidth(200); - QStringList options = item.property("options").toVariant().toStringList(); - for (QStringList::const_iterator it = options.begin(); it != options.end(); it += 1) { - combo->addItem(*it); + qint32 options_count = item.property("options").property("length").toInt32();// .toJsonArray(); + for (qint32 i = 0; i < options_count; i++) { + combo->addItem(item.property("options").property(i).toString()); } _combos.push_back(combo); formLayout->addRow(new QLabel(item.property("label").toString()), combo); From 9ba2a9736c3155aa67c3306170bd58052d7d3e0d Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Sep 2014 22:23:40 +0200 Subject: [PATCH 2/4] style --- examples/editModels.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/editModels.js b/examples/editModels.js index b734864b84..5c426c9fb3 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -2964,7 +2964,7 @@ function handeMenuEvent(menuItem) { if (Window.form("Model List", form)) { var selectedModel = form[0].value; if (form[1].value == "Properties") { - editModelID = selectedModel; + editModelID = selectedModel; showPropertiesForm(); } else if (form[1].value == "Delete") { Entities.deleteEntity(selectedModel); From 7f34079d8fde6fe850d3cea401d8688d521f5d2b Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Sep 2014 22:31:41 +0200 Subject: [PATCH 3/4] cleared comment --- interface/src/scripting/WindowScriptingInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 4f0020ee61..2c0226e3bc 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -512,7 +512,7 @@ QDialog* WindowScriptingInterface::createForm(const QString& title, QScriptValue } else if (item.property("options").isArray()) { QComboBox* combo = new QComboBox(); combo->setMinimumWidth(200); - qint32 options_count = item.property("options").property("length").toInt32();// .toJsonArray(); + qint32 options_count = item.property("options").property("length").toInt32(); for (qint32 i = 0; i < options_count; i++) { combo->addItem(item.property("options").property(i).toString()); } From fd21d100f6a9dd90566e53e1fa9cd22afba630c6 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Sep 2014 22:37:29 +0200 Subject: [PATCH 4/4] line indention fixes --- .../scripting/WindowScriptingInterface.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 2c0226e3bc..ed6f0cf600 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -266,10 +266,10 @@ QScriptValue WindowScriptingInterface::doPeekNonBlockingFormResult(QScriptValue } else if (item.property("options").isArray()) { c += 1; item.setProperty("value", - _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? - item.property("options").property(_combos.at(c)->currentIndex()) : - array.engine()->undefinedValue() - ); + _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? + item.property("options").property(_combos.at(c)->currentIndex()) : + array.engine()->undefinedValue() + ); _form.setProperty(i, item); } else { e += 1; @@ -323,10 +323,10 @@ QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue a } else if (item.property("options").isArray()) { c += 1; item.setProperty("value", - _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? - item.property("options").property(_combos.at(c)->currentIndex()) : - array.engine()->undefinedValue() - ); + _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? + item.property("options").property(_combos.at(c)->currentIndex()) : + array.engine()->undefinedValue() + ); _form.setProperty(i, item); } else { e += 1; @@ -401,10 +401,10 @@ QScriptValue WindowScriptingInterface::showForm(const QString& title, QScriptVal } else if (item.property("options").isArray()) { c += 1; item.setProperty("value", - _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? - item.property("options").property(_combos.at(c)->currentIndex()) : - form.engine()->undefinedValue() - ); + _combos.at(c)->currentIndex() < item.property("options").property("length").toInt32() ? + item.property("options").property(_combos.at(c)->currentIndex()) : + form.engine()->undefinedValue() + ); form.setProperty(i, item); } else { e += 1;