node: removed dumb undoable param

This commit is contained in:
itsmattkc
2023-02-19 11:36:46 -08:00
parent 9745b536f6
commit b8ee27e1cb
7 changed files with 71 additions and 84 deletions
+46 -59
View File
@@ -778,87 +778,74 @@ bool Node::InputIsArray(const QString &id) const
return GetInputFlags(id) & kInputFlagArray;
}
void Node::InputArrayInsert(const QString &id, int index, bool undoable)
void Node::InputArrayInsert(const QString &id, int index)
{
if (undoable) {
Core::instance()->undo_stack()->push(new ArrayInsertCommand(this, id, index));
} else {
// Add new input
ArrayResizeInternal(id, InputArraySize(id) + 1);
// Add new input
ArrayResizeInternal(id, InputArraySize(id) + 1);
// Move connections down
InputConnections copied_edges = input_connections();
for (auto it=copied_edges.crbegin(); it!=copied_edges.crend(); it++) {
if (it->first.input() == id && it->first.element() >= index) {
// Disconnect this and reconnect it one element down
NodeInput new_edge = it->first;
new_edge.set_element(new_edge.element() + 1);
// Move connections down
InputConnections copied_edges = input_connections();
for (auto it=copied_edges.crbegin(); it!=copied_edges.crend(); it++) {
if (it->first.input() == id && it->first.element() >= index) {
// Disconnect this and reconnect it one element down
NodeInput new_edge = it->first;
new_edge.set_element(new_edge.element() + 1);
DisconnectEdge(it->second, it->first);
ConnectEdge(it->second, new_edge);
}
DisconnectEdge(it->second, it->first);
ConnectEdge(it->second, new_edge);
}
// Shift values and keyframes up one element
for (int i=InputArraySize(id)-1; i>index; i--) {
CopyValuesOfElement(this, this, id, i-1, i);
}
// Reset value of element we just "inserted"
ClearElement(id, index);
}
// Shift values and keyframes up one element
for (int i=InputArraySize(id)-1; i>index; i--) {
CopyValuesOfElement(this, this, id, i-1, i);
}
// Reset value of element we just "inserted"
ClearElement(id, index);
}
void Node::InputArrayResize(const QString &id, int size, bool undoable)
void Node::InputArrayResize(const QString &id, int size)
{
if (InputArraySize(id) == size) {
return;
}
ArrayResizeCommand* c = new ArrayResizeCommand(this, id, size);
if (undoable) {
Core::instance()->undo_stack()->push(c);
} else {
c->redo_now();
delete c;
}
c->redo_now();
delete c;
}
void Node::InputArrayRemove(const QString &id, int index, bool undoable)
void Node::InputArrayRemove(const QString &id, int index)
{
if (undoable) {
Core::instance()->undo_stack()->push(new ArrayRemoveCommand(this, id, index));
} else {
// Remove input
ArrayResizeInternal(id, InputArraySize(id) - 1);
// Remove input
ArrayResizeInternal(id, InputArraySize(id) - 1);
// Move connections up
InputConnections copied_edges = input_connections();
for (auto it=copied_edges.cbegin(); it!=copied_edges.cend(); it++) {
if (it->first.input() == id && it->first.element() >= index) {
// Disconnect this and reconnect it one element up if it's not the element being removed
DisconnectEdge(it->second, it->first);
// Move connections up
InputConnections copied_edges = input_connections();
for (auto it=copied_edges.cbegin(); it!=copied_edges.cend(); it++) {
if (it->first.input() == id && it->first.element() >= index) {
// Disconnect this and reconnect it one element up if it's not the element being removed
DisconnectEdge(it->second, it->first);
if (it->first.element() > index) {
NodeInput new_edge = it->first;
new_edge.set_element(new_edge.element() - 1);
if (it->first.element() > index) {
NodeInput new_edge = it->first;
new_edge.set_element(new_edge.element() - 1);
ConnectEdge(it->second, new_edge);
}
ConnectEdge(it->second, new_edge);
}
}
// Shift values and keyframes down one element
int arr_sz = InputArraySize(id);
for (int i=index; i<arr_sz; i++) {
// Copying ArraySize()+1 is actually legal because immediates are never deleted
CopyValuesOfElement(this, this, id, i+1, i);
}
// Reset value of last element
ClearElement(id, arr_sz);
}
// Shift values and keyframes down one element
int arr_sz = InputArraySize(id);
for (int i=index; i<arr_sz; i++) {
// Copying ArraySize()+1 is actually legal because immediates are never deleted
CopyValuesOfElement(this, this, id, i+1, i);
}
// Reset value of last element
ClearElement(id, arr_sz);
}
int Node::InputArraySize(const QString &id) const
+13 -13
View File
@@ -614,23 +614,23 @@ public:
bool InputIsArray(const QString& id) const;
void InputArrayInsert(const QString& id, int index, bool undoable = false);
void InputArrayResize(const QString& id, int size, bool undoable = false);
void InputArrayRemove(const QString& id, int index, bool undoable = false);
void InputArrayInsert(const QString& id, int index);
void InputArrayResize(const QString& id, int size);
void InputArrayRemove(const QString& id, int index);
void InputArrayAppend(const QString& id, bool undoable = false)
void InputArrayAppend(const QString& id)
{
InputArrayResize(id, InputArraySize(id) + 1, undoable);
InputArrayResize(id, InputArraySize(id) + 1);
}
void InputArrayPrepend(const QString& id, bool undoable = false)
void InputArrayPrepend(const QString& id)
{
InputArrayInsert(id, 0, undoable);
InputArrayInsert(id, 0);
}
void InputArrayRemoveLast(const QString& id, bool undoable = false)
void InputArrayRemoveLast(const QString& id)
{
InputArrayResize(id, InputArraySize(id) - 1, undoable);
InputArrayResize(id, InputArraySize(id) - 1);
}
int InputArraySize(const QString& id) const;
@@ -980,12 +980,12 @@ public:
protected:
virtual void redo() override
{
node_->InputArrayInsert(input_, index_, false);
node_->InputArrayInsert(input_, index_);
}
virtual void undo() override
{
node_->InputArrayRemove(input_, index_, false);
node_->InputArrayRemove(input_, index_);
}
private:
@@ -1072,12 +1072,12 @@ public:
keyframes_ = node_->GetKeyframeTracks(input_, index_);
node_->GetImmediate(input_, index_)->delete_all_keyframes(&memory_manager_);
node_->InputArrayRemove(input_, index_, false);
node_->InputArrayRemove(input_, index_);
}
virtual void undo() override
{
node_->InputArrayInsert(input_, index_, false);
node_->InputArrayInsert(input_, index_);
// Restore keyframes
foreach (const NodeKeyframeTrack& track, keyframes_) {
+4 -4
View File
@@ -167,14 +167,14 @@ int TrackList::ArraySize() const
return parent()->InputArraySize(track_input());
}
void TrackList::ArrayAppend(bool undoable)
void TrackList::ArrayAppend()
{
parent()->InputArrayAppend(track_input(), undoable);
parent()->InputArrayAppend(track_input());
}
void TrackList::ArrayRemoveLast(bool undoable)
void TrackList::ArrayRemoveLast()
{
parent()->InputArrayRemoveLast(track_input(), undoable);
parent()->InputArrayRemoveLast(track_input());
}
void TrackList::UpdateTotalLength()
+2 -2
View File
@@ -67,8 +67,8 @@ public:
int ArraySize() const;
void ArrayAppend(bool undoable = false);
void ArrayRemoveLast(bool undoable = false);
void ArrayAppend();
void ArrayRemoveLast();
int GetArrayIndexFromCacheIndex(int index) const
{
+1 -1
View File
@@ -140,7 +140,7 @@ Project *FolderAddChild::GetRelevantProject() const
void FolderAddChild::redo()
{
int array_index = folder_->InputArraySize(Folder::kChildInput);
folder_->InputArrayAppend(Folder::kChildInput, false);
folder_->InputArrayAppend(Folder::kChildInput);
Node::ConnectEdge(child_, NodeInput(folder_, Folder::kChildInput, array_index));
}
@@ -444,7 +444,7 @@ void NodeParamViewItemBody::ArrayAppendClicked()
for (auto it=array_ui_.cbegin(); it!=array_ui_.cend(); it++) {
if (it.value().append_btn == sender()) {
NodeInput real_input = NodeGroup::ResolveInput(NodeInput(it.key().node, it.key().input));
real_input.node()->InputArrayAppend(real_input.input(), true);
Core::instance()->undo_stack()->push(new Node::ArrayInsertCommand(real_input.node(), real_input.input(), real_input.GetArraySize()+1));
break;
}
}
@@ -456,7 +456,7 @@ void NodeParamViewItemBody::ArrayInsertClicked()
if (it.value().array_insert_btn == sender()) {
// Found our input and element
NodeInput ic = NodeGroup::ResolveInput(it.key());
ic.node()->InputArrayInsert(ic.input(), ic.element(), true);
Core::instance()->undo_stack()->push(new Node::ArrayInsertCommand(ic.node(), ic.input(), ic.element()));
break;
}
}
@@ -468,7 +468,7 @@ void NodeParamViewItemBody::ArrayRemoveClicked()
if (it.value().array_remove_btn == sender()) {
// Found our input and element
NodeInput ic = NodeGroup::ResolveInput(it.key());
ic.node()->InputArrayRemove(ic.input(), ic.element(), true);
Core::instance()->undo_stack()->push(new Node::ArrayRemoveCommand(ic.node(), ic.input(), ic.element()));
break;
}
}
@@ -193,12 +193,12 @@ Project *NodeParamArrayAppendCommand::GetRelevantProject() const
void NodeParamArrayAppendCommand::redo()
{
node_->InputArrayAppend(input_, false);
node_->InputArrayAppend(input_);
}
void NodeParamArrayAppendCommand::undo()
{
node_->InputArrayRemoveLast(input_, false);
node_->InputArrayRemoveLast(input_);
}
void NodeSetValueHintCommand::redo()