mirror of
https://github.com/Relintai/procedural_animations.git
synced 2024-11-13 08:27:19 +01:00
Implement graph connections for the editor plugin.
This commit is contained in:
parent
2f4e3af4f5
commit
3962252196
@ -176,7 +176,7 @@ void ProceduralAnimation::set_animation_node_position(const int category_index,
|
||||
cat->animations[animation_index]->position = value;
|
||||
}
|
||||
|
||||
int ProceduralAnimation::get_start_frame_index(const int category_index, const int animation_index) const {
|
||||
int ProceduralAnimation::get_animation_start_frame_index(const int category_index, const int animation_index) const {
|
||||
ERR_FAIL_COND_V(!_categories.has(category_index), 0);
|
||||
|
||||
Category *cat = _categories[category_index];
|
||||
@ -185,7 +185,7 @@ int ProceduralAnimation::get_start_frame_index(const int category_index, const i
|
||||
|
||||
return cat->animations[animation_index]->start_frame_index;
|
||||
}
|
||||
void ProceduralAnimation::set_start_frame_index(const int category_index, const int animation_index, const int value) {
|
||||
void ProceduralAnimation::set_animation_start_frame_index(const int category_index, const int animation_index, const int value) {
|
||||
ERR_FAIL_COND(!_categories.has(category_index));
|
||||
|
||||
Category *cat = _categories[category_index];
|
||||
@ -591,7 +591,6 @@ void ProceduralAnimation::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/animation_keyframe_index", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/next_keyframe", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/next_animation", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/in_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR2, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
|
||||
}
|
||||
@ -628,8 +627,8 @@ void ProceduralAnimation::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_animation_node_position", "category_index", "animation_index"), &ProceduralAnimation::get_animation_node_position);
|
||||
ClassDB::bind_method(D_METHOD("set_animation_node_position", "category_index", "animation_index", "value"), &ProceduralAnimation::set_animation_node_position);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_start_frame_index", "category_index", "animation_index"), &ProceduralAnimation::get_start_frame_index);
|
||||
ClassDB::bind_method(D_METHOD("set_start_frame_index", "category_index", "animation_index", "value"), &ProceduralAnimation::set_start_frame_index);
|
||||
ClassDB::bind_method(D_METHOD("get_animation_start_frame_index", "category_index", "animation_index"), &ProceduralAnimation::get_animation_start_frame_index);
|
||||
ClassDB::bind_method(D_METHOD("set_animation_start_frame_index", "category_index", "animation_index", "value"), &ProceduralAnimation::set_animation_start_frame_index);
|
||||
|
||||
//Keyframes
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_indices", "category_index", "animation_index"), &ProceduralAnimation::get_keyframe_indices);
|
||||
|
@ -43,8 +43,8 @@ public:
|
||||
Vector2 get_animation_node_position(const int category_index, int animation_index) const;
|
||||
void set_animation_node_position(const int category_index, const int animation_index, const Vector2 &value);
|
||||
|
||||
int get_start_frame_index(const int category_index, const int animation_index) const;
|
||||
void set_start_frame_index(const int category_index, const int animation_index, const int value);
|
||||
int get_animation_start_frame_index(const int category_index, const int animation_index) const;
|
||||
void set_animation_start_frame_index(const int category_index, const int animation_index, const int value);
|
||||
|
||||
//Keyframes
|
||||
PoolVector<int> get_keyframe_indices(const int category_index, const int animation_index) const;
|
||||
|
@ -30,6 +30,7 @@ void ProceduralAnimationEditor::load_selected_animation() {
|
||||
int id = kfind[i];
|
||||
|
||||
ProceduralAnimationEditorGraphNode *gn = memnew(ProceduralAnimationEditorGraphNode);
|
||||
gn->set_name(String::num(id));
|
||||
_graph_edit->add_child(gn);
|
||||
|
||||
//gn->set_animation_keyframe_names(animation_names);
|
||||
@ -42,9 +43,25 @@ void ProceduralAnimationEditor::load_selected_animation() {
|
||||
gn->set_animation_keyframe_index(_animation->get_keyframe_animation_keyframe_index(_selected_category, _selected_animation, id));
|
||||
gn->connect("graphnode_changed", this, "on_keyframe_node_changed");
|
||||
}
|
||||
|
||||
for (int i = 0; i < kfind.size(); ++i) {
|
||||
int id = kfind[i];
|
||||
|
||||
int ni = _animation->get_keyframe_next_keyframe_index(_selected_category, _selected_animation, id);
|
||||
|
||||
if (ni != -1)
|
||||
_graph_edit->connect_node(String::num(id), 0, String::num(ni), 0);
|
||||
}
|
||||
|
||||
int st = _animation->get_animation_start_frame_index(_selected_category, _selected_animation);
|
||||
|
||||
if (st != -1)
|
||||
_graph_edit->connect_node("Start", 0, String::num(st), 0);
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::clear_keyframe_nodes() {
|
||||
_graph_edit->clear_connections();
|
||||
|
||||
for (int i = 0; i < _graph_edit->get_child_count(); ++i) {
|
||||
Node *n = _graph_edit->get_child(i);
|
||||
|
||||
@ -255,6 +272,54 @@ 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) {
|
||||
Node *f = _graph_edit->get_node_or_null(from);
|
||||
|
||||
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(f);
|
||||
|
||||
if (gn != NULL) {
|
||||
int ni = _animation->get_keyframe_next_keyframe_index(_selected_category, _selected_animation, gn->get_id());
|
||||
|
||||
if (ni != -1) {
|
||||
_graph_edit->disconnect_node(from, from_slot, String::num(ni), 0);
|
||||
}
|
||||
|
||||
_animation->set_keyframe_next_keyframe_index(_selected_category, _selected_animation, gn->get_id(), to.to_int());
|
||||
} else {
|
||||
GraphNode *g = Object::cast_to<GraphNode>(f);
|
||||
|
||||
if (g != NULL) {
|
||||
int st = _animation->get_animation_start_frame_index(_selected_category, _selected_animation);
|
||||
|
||||
if (st != -1) {
|
||||
_graph_edit->disconnect_node("Start", 0, String::num(st), 0);
|
||||
}
|
||||
|
||||
_animation->set_animation_start_frame_index(_selected_category, _selected_animation, to.to_int());
|
||||
}
|
||||
}
|
||||
|
||||
_graph_edit->connect_node(from, from_slot, to, to_slot);
|
||||
}
|
||||
void ProceduralAnimationEditor::on_disconnection_request(const String &from, const int from_slot, const String &to, const int to_slot) {
|
||||
Node *f = _graph_edit->get_node_or_null(from);
|
||||
|
||||
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(f);
|
||||
|
||||
if (gn != NULL) {
|
||||
_animation->set_keyframe_next_keyframe_index(_selected_category, _selected_animation, gn->get_id(), -1);
|
||||
} else {
|
||||
GraphNode *g = Object::cast_to<GraphNode>(f);
|
||||
|
||||
if (g != NULL) {
|
||||
_animation->set_animation_start_frame_index(_selected_category, _selected_animation, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_graph_edit->disconnect_node(from, from_slot, to, to_slot);
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::add_frame_button_pressed() {
|
||||
if (_selected_category == -1 || _selected_animation == -1)
|
||||
return;
|
||||
@ -280,6 +345,9 @@ void ProceduralAnimationEditor::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("on_animation_option_button_pressed", "index"), &ProceduralAnimationEditor::on_animation_option_button_pressed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("on_keyframe_node_changed", "node"), &ProceduralAnimationEditor::on_keyframe_node_changed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("on_connection_request", "from", "from_slot", "to", "to_slot"), &ProceduralAnimationEditor::on_connection_request);
|
||||
ClassDB::bind_method(D_METHOD("on_disconnection_request", "from", "from_slot", "to", "to_slot"), &ProceduralAnimationEditor::on_disconnection_request);
|
||||
}
|
||||
|
||||
ProceduralAnimationEditor::ProceduralAnimationEditor() {
|
||||
@ -342,12 +410,16 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
|
||||
|
||||
//bottom
|
||||
_graph_edit = memnew(GraphEdit);
|
||||
_graph_edit->set_right_disconnects(true);
|
||||
_graph_edit->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
_graph_edit->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
_graph_edit->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
|
||||
_graph_edit->connect("connection_request", this, "on_connection_request");
|
||||
_graph_edit->connect("disconnection_request", this, "on_disconnection_request");
|
||||
add_child(_graph_edit);
|
||||
|
||||
_start_node = memnew(GraphNode);
|
||||
_start_node->set_name("Start");
|
||||
_start_node->set_title("Start");
|
||||
_start_node->set_show_close_button(false);
|
||||
_graph_edit->add_child(_start_node);
|
||||
|
@ -48,6 +48,9 @@ public:
|
||||
void on_name_popup_confirmed();
|
||||
void on_delete_popup_confirmed();
|
||||
|
||||
void on_connection_request(const String &from, const int from_slot, const String &to, const int to_slot);
|
||||
void on_disconnection_request(const String &from, const int from_slot, const String &to, const int to_slot);
|
||||
|
||||
ProceduralAnimationEditor();
|
||||
ProceduralAnimationEditor(EditorNode *p_editor);
|
||||
~ProceduralAnimationEditor();
|
||||
|
Loading…
Reference in New Issue
Block a user