From ee2ca909bcf293aa18bf6d08bf86fcf8890b4265 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 1 Apr 2020 20:54:32 +0200 Subject: [PATCH] Now the editor will not allow to create invalid loops in the keyframe graph. Fixed smaller issues. --- procedural_animation_editor_plugin.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/procedural_animation_editor_plugin.cpp b/procedural_animation_editor_plugin.cpp index cf19270..89462ae 100644 --- a/procedural_animation_editor_plugin.cpp +++ b/procedural_animation_editor_plugin.cpp @@ -109,6 +109,23 @@ void ProceduralAnimationEditor::on_delete_popup_confirmed() { } void ProceduralAnimationEditor::on_connection_request(const String &from, const int from_slot, const String &to, const int to_slot) { + List conns; + _graph_edit->get_connection_list(&conns); + + //Lets make sure that there are no loops in the keyframe graph. Easiest way to check in this case, + //is to just make sure that nothing is connected to the current node. + //Note, that loops can still be created, but those will not be conected to the start node, + //so those are not a problem. + for (List::Element *E = conns.front(); E; E = E->next()) { + GraphEdit::Connection c = E->get(); + + if (c.to == to) { + return; + } + } + + //no loops found + Node *f = _graph_edit->get_node_or_null(from); ProceduralAnimationEditorGraphNode *gn = Object::cast_to(f); @@ -159,8 +176,10 @@ void ProceduralAnimationEditor::add_frame_button_pressed() { int id = _animation->add_keyframe(); ProceduralAnimationEditorGraphNode *gn = memnew(ProceduralAnimationEditorGraphNode); - gn->set_id(id); _graph_edit->add_child(gn); + gn->set_name(String::num(id)); + gn->set_id(id); + gn->set_animation(_animation); } Ref ProceduralAnimationEditor::get_animation_target_animation() { @@ -438,7 +457,8 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() { _animation_keyframe_index = 0; _next_keyframe = -1; - _time = 0; + _time = 1; + _transition = 1.0; set_title("Animation Frame"); set_show_close_button(true); @@ -469,6 +489,7 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() { _time_spinbox->set_max(999999999); _time_spinbox->set_min(0); _time_spinbox->set_step(0.01); + _time_spinbox->set_value(1); _time_spinbox->set_h_size_flags(SIZE_EXPAND_FILL); _time_spinbox->connect("value_changed", this, "on_time_spinbox_value_changed"); add_child(_time_spinbox);