mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 20:23:06 +02:00
Add UndoStackScriptingInterface and support when editing entities
This commit is contained in:
parent
0bda7699a6
commit
14555c4534
6 changed files with 156 additions and 6 deletions
|
@ -845,7 +845,7 @@ SelectionDisplay = (function () {
|
||||||
|
|
||||||
Overlays.editOverlay(grabberMoveUp, { visible: translateHandlesVisible, position: { x: boundsCenter.x, y: top + grabberMoveUpOffset, z: boundsCenter.z } });
|
Overlays.editOverlay(grabberMoveUp, { visible: translateHandlesVisible, position: { x: boundsCenter.x, y: top + grabberMoveUpOffset, z: boundsCenter.z } });
|
||||||
|
|
||||||
that.updateHandles(entityID);
|
that.updateHandles();
|
||||||
|
|
||||||
|
|
||||||
Overlays.editOverlay(baseOfEntityProjectionOverlay,
|
Overlays.editOverlay(baseOfEntityProjectionOverlay,
|
||||||
|
@ -926,18 +926,17 @@ SelectionDisplay = (function () {
|
||||||
entitySelected = false;
|
entitySelected = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.updateHandles = function(entityID) {
|
that.updateHandles = function() {
|
||||||
|
// print("Updating handles");
|
||||||
if (SelectionManager.selections.length == 0) {
|
if (SelectionManager.selections.length == 0) {
|
||||||
that.setOverlaysVisible(false);
|
that.setOverlaysVisible(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = Entities.getEntityProperties(entityID);
|
|
||||||
|
|
||||||
var rotation, dimensions, position;
|
var rotation, dimensions, position;
|
||||||
|
|
||||||
if (spaceMode == SPACE_LOCAL) {
|
if (spaceMode == SPACE_LOCAL) {
|
||||||
rotation = properties.rotation;
|
rotation = SelectionManager.localRotation;
|
||||||
dimensions = SelectionManager.localDimensions;
|
dimensions = SelectionManager.localDimensions;
|
||||||
position = SelectionManager.localPosition;
|
position = SelectionManager.localPosition;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1097,6 +1096,44 @@ SelectionDisplay = (function () {
|
||||||
entitySelected = false;
|
entitySelected = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function applyEntityProperties(data) {
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
var entityID = data[i].entityID;
|
||||||
|
var properties = data[i].properties;
|
||||||
|
Entities.editEntity(entityID, properties);
|
||||||
|
}
|
||||||
|
selectionManager._update();
|
||||||
|
};
|
||||||
|
|
||||||
|
// For currently selected entities, push a command to the UndoStack that uses the current entity properties for the
|
||||||
|
// redo command, and the saved properties for the undo command.
|
||||||
|
function pushCommandForSelections() {
|
||||||
|
var undoData = [];
|
||||||
|
var redoData = [];
|
||||||
|
for (var i = 0; i < SelectionManager.selections.length; i++) {
|
||||||
|
var entityID = SelectionManager.selections[i];
|
||||||
|
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
||||||
|
var currentProperties = Entities.getEntityProperties(entityID);
|
||||||
|
undoData.push({
|
||||||
|
entityID: entityID,
|
||||||
|
properties: {
|
||||||
|
position: initialProperties.position,
|
||||||
|
rotation: initialProperties.rotation,
|
||||||
|
dimensions: initialProperties.dimensions,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
redoData.push({
|
||||||
|
entityID: entityID,
|
||||||
|
properties: {
|
||||||
|
position: currentProperties.position,
|
||||||
|
rotation: currentProperties.rotation,
|
||||||
|
dimensions: currentProperties.dimensions,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
UndoStack.pushCommand(applyEntityProperties, undoData, applyEntityProperties, redoData);
|
||||||
|
}
|
||||||
|
|
||||||
var lastXZPick = null;
|
var lastXZPick = null;
|
||||||
var translateXZTool = {
|
var translateXZTool = {
|
||||||
mode: 'TRANSLATE_XZ',
|
mode: 'TRANSLATE_XZ',
|
||||||
|
@ -1116,6 +1153,8 @@ SelectionDisplay = (function () {
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
||||||
Entities.editEntity(entityID, initialProperties);
|
Entities.editEntity(entityID, initialProperties);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pushCommandForSelections();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onMove: function(event) {
|
onMove: function(event) {
|
||||||
|
@ -1174,6 +1213,8 @@ SelectionDisplay = (function () {
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
||||||
Entities.editEntity(entityID, initialProperties);
|
Entities.editEntity(entityID, initialProperties);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pushCommandForSelections();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onMove: function(event) {
|
onMove: function(event) {
|
||||||
|
@ -1336,6 +1377,8 @@ SelectionDisplay = (function () {
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
||||||
Entities.editEntity(entityID, initialProperties);
|
Entities.editEntity(entityID, initialProperties);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pushCommandForSelections();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1498,6 +1541,8 @@ SelectionDisplay = (function () {
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
||||||
Entities.editEntity(entityID, initialProperties);
|
Entities.editEntity(entityID, initialProperties);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pushCommandForSelections();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onMove: function(event) {
|
onMove: function(event) {
|
||||||
|
@ -1604,6 +1649,8 @@ SelectionDisplay = (function () {
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
||||||
Entities.editEntity(entityID, initialProperties);
|
Entities.editEntity(entityID, initialProperties);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pushCommandForSelections();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onMove: function(event) {
|
onMove: function(event) {
|
||||||
|
@ -1708,6 +1755,8 @@ SelectionDisplay = (function () {
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
var initialProperties = SelectionManager.savedProperties[entityID.id];
|
||||||
Entities.editEntity(entityID, initialProperties);
|
Entities.editEntity(entityID, initialProperties);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pushCommandForSelections();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onMove: function(event) {
|
onMove: function(event) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ var entityPropertyDialogBox = EntityPropertyDialogBox;
|
||||||
Script.include("libraries/entityCameraTool.js");
|
Script.include("libraries/entityCameraTool.js");
|
||||||
var entityCameraTool = new EntityCameraTool();
|
var entityCameraTool = new EntityCameraTool();
|
||||||
|
|
||||||
selectionManager.setEventListener(selectionDisplay.updateHandles());
|
selectionManager.setEventListener(selectionDisplay.updateHandles);
|
||||||
|
|
||||||
var windowDimensions = Controller.getViewportDimensions();
|
var windowDimensions = Controller.getViewportDimensions();
|
||||||
var toolIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/";
|
var toolIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/";
|
||||||
|
|
|
@ -172,6 +172,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
_nodeBoundsDisplay(this),
|
_nodeBoundsDisplay(this),
|
||||||
_previousScriptLocation(),
|
_previousScriptLocation(),
|
||||||
_applicationOverlay(),
|
_applicationOverlay(),
|
||||||
|
_undoStack(),
|
||||||
|
_undoStackScriptingInterface(&_undoStack),
|
||||||
_runningScriptsWidget(NULL),
|
_runningScriptsWidget(NULL),
|
||||||
_runningScriptsWidgetWasVisible(false),
|
_runningScriptsWidgetWasVisible(false),
|
||||||
_trayIcon(new QSystemTrayIcon(_window)),
|
_trayIcon(new QSystemTrayIcon(_window)),
|
||||||
|
@ -3810,6 +3812,8 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
|
||||||
scriptEngine->registerGlobalObject("Joysticks", &JoystickScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("Joysticks", &JoystickScriptingInterface::getInstance());
|
||||||
qScriptRegisterMetaType(scriptEngine, joystickToScriptValue, joystickFromScriptValue);
|
qScriptRegisterMetaType(scriptEngine, joystickToScriptValue, joystickFromScriptValue);
|
||||||
|
|
||||||
|
scriptEngine->registerGlobalObject("UndoStack", &_undoStackScriptingInterface);
|
||||||
|
|
||||||
#ifdef HAVE_RTMIDI
|
#ifdef HAVE_RTMIDI
|
||||||
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -91,6 +91,9 @@
|
||||||
#include "voxels/VoxelSystem.h"
|
#include "voxels/VoxelSystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "UndoStackScriptingInterface.h"
|
||||||
|
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class QActionGroup;
|
class QActionGroup;
|
||||||
class QGLWidget;
|
class QGLWidget;
|
||||||
|
@ -450,6 +453,7 @@ private:
|
||||||
int _numChangedSettings;
|
int _numChangedSettings;
|
||||||
|
|
||||||
QUndoStack _undoStack;
|
QUndoStack _undoStack;
|
||||||
|
UndoStackScriptingInterface _undoStackScriptingInterface;
|
||||||
|
|
||||||
glm::vec3 _gravity;
|
glm::vec3 _gravity;
|
||||||
|
|
||||||
|
|
46
libraries/script-engine/src/UndoStackScriptingInterface.cpp
Normal file
46
libraries/script-engine/src/UndoStackScriptingInterface.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
//
|
||||||
|
// UndoStackScriptingInterface.cpp
|
||||||
|
// libraries/script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Ryan Huffman on 10/22/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QScriptValueList>
|
||||||
|
#include <QScriptEngine>
|
||||||
|
|
||||||
|
#include "UndoStackScriptingInterface.h"
|
||||||
|
|
||||||
|
UndoStackScriptingInterface::UndoStackScriptingInterface(QUndoStack* undoStack) : _undoStack(undoStack) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoStackScriptingInterface::pushCommand(QScriptValue undoFunction, QScriptValue undoData,
|
||||||
|
QScriptValue redoFunction, QScriptValue redoData) {
|
||||||
|
ScriptUndoCommand* undoCommand = new ScriptUndoCommand(undoFunction, undoData, redoFunction, redoData);
|
||||||
|
qDebug() << "Pushing command";
|
||||||
|
_undoStack->push(undoCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptUndoCommand::ScriptUndoCommand(QScriptValue undoFunction, QScriptValue undoData,
|
||||||
|
QScriptValue redoFunction, QScriptValue redoData) :
|
||||||
|
_undoFunction(undoFunction),
|
||||||
|
_undoData(undoData),
|
||||||
|
_redoFunction(redoFunction),
|
||||||
|
_redoData(redoData) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptUndoCommand::undo() {
|
||||||
|
QScriptValueList args;
|
||||||
|
args << _undoData;
|
||||||
|
_undoFunction.call(QScriptValue(), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptUndoCommand::redo() {
|
||||||
|
QScriptValueList args;
|
||||||
|
args << _redoData;
|
||||||
|
_redoFunction.call(QScriptValue(), args);
|
||||||
|
}
|
47
libraries/script-engine/src/UndoStackScriptingInterface.h
Normal file
47
libraries/script-engine/src/UndoStackScriptingInterface.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// UndoStackScriptingInterface.h
|
||||||
|
// libraries/script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Ryan Huffman on 10/22/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_UndoStackScriptingInterface_h
|
||||||
|
#define hifi_UndoStackScriptingInterface_h
|
||||||
|
|
||||||
|
#include <QUndoCommand>
|
||||||
|
#include <QUndoStack>
|
||||||
|
#include <QScriptValue>
|
||||||
|
|
||||||
|
class UndoStackScriptingInterface : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
UndoStackScriptingInterface(QUndoStack* undoStack);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void pushCommand(QScriptValue undoFunction, QScriptValue undoData, QScriptValue redoFunction, QScriptValue redoData);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUndoStack* _undoStack;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ScriptUndoCommand : public QUndoCommand {
|
||||||
|
public:
|
||||||
|
ScriptUndoCommand(QScriptValue undoFunction, QScriptValue undoData, QScriptValue redoFunction, QScriptValue redoData);
|
||||||
|
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
virtual bool mergeWith(const QUndoCommand* command) { return false; }
|
||||||
|
virtual int id() const { return -1; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScriptValue _undoFunction;
|
||||||
|
QScriptValue _undoData;
|
||||||
|
QScriptValue _redoFunction;
|
||||||
|
QScriptValue _redoData;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_UndoStackScriptingInterface_h
|
Loading…
Reference in a new issue