summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2020-09-27 14:05:19 +0300
committerYuri Roubinsky <chaosus89@gmail.com>2020-09-27 14:05:19 +0300
commit11043b1a8f3a059f3744d96fee5757f4fc527b57 (patch)
tree4b25065114cbd76a60ad39f7c860d3b75a277d0e /editor
parent545da8242723b9856119f5a8f27892a2cddeb2ac (diff)
Fix undo for moving multiple visual shader nodes
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp25
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h9
2 files changed, 29 insertions, 5 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 7a70f4c5b6..c14d07789f 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -1735,12 +1735,26 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
VisualShader::Type type = get_current_shader_type();
+ drag_buffer.push_back({ type, p_node, p_from, p_to });
+ if (!drag_dirty) {
+ call_deferred("_nodes_dragged");
+ }
+ drag_dirty = true;
+}
+
+void VisualShaderEditor::_nodes_dragged() {
+ drag_dirty = false;
+
+ undo_redo->create_action(TTR("Node(s) Moved"));
+
+ for (List<DragOp>::Element *E = drag_buffer.front(); E; E = E->next()) {
+ undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E->get().type, E->get().node, E->get().to);
+ undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E->get().type, E->get().node, E->get().from);
+ undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E->get().type, E->get().node, E->get().to);
+ undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E->get().type, E->get().node, E->get().from);
+ }
- undo_redo->create_action(TTR("Node Moved"));
- undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", type, p_node, p_to);
- undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", type, p_node, p_from);
- undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", type, p_node, p_to);
- undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", type, p_node, p_from);
+ drag_buffer.clear();
undo_redo->commit_action();
}
@@ -2650,6 +2664,7 @@ void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_clear_buffer", &VisualShaderEditor::_clear_buffer);
ClassDB::bind_method("_update_uniforms", &VisualShaderEditor::_update_uniforms);
ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
+ ClassDB::bind_method("_nodes_dragged", &VisualShaderEditor::_nodes_dragged);
ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw);
ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw);
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index 531a117156..49d7721ecd 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -261,7 +261,16 @@ class VisualShaderEditor : public VBoxContainer {
static VisualShaderEditor *singleton;
+ struct DragOp {
+ VisualShader::Type type;
+ int node;
+ Vector2 from;
+ Vector2 to;
+ };
+ List<DragOp> drag_buffer;
+ bool drag_dirty = false;
void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node);
+ void _nodes_dragged();
bool updating;
void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);