mirror of
https://github.com/Relintai/procedural_animations.git
synced 2024-11-08 20:22:10 +01:00
Added a method name field to to every key. Setting one will create a call method track, calling the named method without any arguments on the AnimationPlayer's root node.
This commit is contained in:
parent
8426e2c976
commit
ec465a7a68
@ -216,6 +216,19 @@ void ProceduralAnimation::set_keyframe_time(const int keyframe_index, const floa
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
String ProceduralAnimation::get_method_name(int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), "");
|
||||
|
||||
return _keyframes[keyframe_index]->method_name;
|
||||
}
|
||||
void ProceduralAnimation::set_method_name(int keyframe_index, const String &value) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
_keyframes[keyframe_index]->method_name = value;
|
||||
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
Vector2 ProceduralAnimation::get_keyframe_node_position(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), Vector2());
|
||||
|
||||
@ -269,6 +282,8 @@ void ProceduralAnimation::process_animation_data() {
|
||||
}
|
||||
}
|
||||
|
||||
int custom_call_method_track = -1;
|
||||
|
||||
float target_keyframe_time = 0;
|
||||
float key_step = 1.0 / static_cast<float>(_animation_fps);
|
||||
|
||||
@ -307,6 +322,21 @@ void ProceduralAnimation::process_animation_data() {
|
||||
found_keyframe = true;
|
||||
}
|
||||
|
||||
if (frame->method_name != "") {
|
||||
if (custom_call_method_track == -1) {
|
||||
custom_call_method_track = add_track(Animation::TYPE_METHOD);
|
||||
|
||||
track_set_path(custom_call_method_track, NodePath("."));
|
||||
track_set_enabled(custom_call_method_track, true);
|
||||
}
|
||||
|
||||
Dictionary d;
|
||||
d["method"] = frame->method_name;
|
||||
d["args"] = Array();
|
||||
|
||||
track_insert_key(custom_call_method_track, target_keyframe_time, d);
|
||||
}
|
||||
|
||||
if (!found_keyframe)
|
||||
ERR_PRINT("Could not find any keyframe! Index: " + String::num(animation_keyframe_index) + " at time: " + String::num(time));
|
||||
|
||||
@ -374,6 +404,10 @@ bool ProceduralAnimation::_set(const StringName &p_name, const Variant &p_value)
|
||||
} else if (keyframe_name == "time") {
|
||||
keyframe->time = p_value;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_name == "method_name") {
|
||||
keyframe->method_name = p_value;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_name == "position") {
|
||||
keyframe->position = p_value;
|
||||
@ -425,6 +459,10 @@ bool ProceduralAnimation::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
} else if (keyframe_prop_name == "time") {
|
||||
r_ret = keyframe->time;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_prop_name == "method_name") {
|
||||
r_ret = keyframe->method_name;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_prop_name == "position") {
|
||||
r_ret = keyframe->position;
|
||||
@ -453,6 +491,7 @@ void ProceduralAnimation::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "keyframe/" + itos(K->key()) + "/next_keyframe", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::REAL, "keyframe/" + itos(K->key()) + "/transition", PROPERTY_HINT_EXP_EASING, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::REAL, "keyframe/" + itos(K->key()) + "/time", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, "keyframe/" + itos(K->key()) + "/method_name", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR2, "keyframe/" + itos(K->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
|
||||
}
|
||||
}
|
||||
@ -498,6 +537,9 @@ void ProceduralAnimation::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_time", "keyframe_index"), &ProceduralAnimation::get_keyframe_time);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_time", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_time);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_method_name", "keyframe_index"), &ProceduralAnimation::get_method_name);
|
||||
ClassDB::bind_method(D_METHOD("set_method_name", "keyframe_index", "value"), &ProceduralAnimation::set_method_name);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_node_position", "keyframe_index"), &ProceduralAnimation::get_keyframe_node_position);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_node_position", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_node_position);
|
||||
|
||||
|
@ -52,6 +52,7 @@ protected:
|
||||
int next_keyframe;
|
||||
float transition;
|
||||
float time;
|
||||
String method_name;
|
||||
Vector2 position;
|
||||
|
||||
AnimationKeyFrame() {
|
||||
@ -104,6 +105,9 @@ public:
|
||||
float get_keyframe_time(const int keyframe_index) const;
|
||||
void set_keyframe_time(const int keyframe_index, const float value);
|
||||
|
||||
String get_method_name(const int keyframe_index) const;
|
||||
void set_method_name(const int keyframe_index, const String &value);
|
||||
|
||||
Vector2 get_keyframe_node_position(const int keyframe_index) const;
|
||||
void set_keyframe_node_position(const int keyframe_index, const Vector2 &value);
|
||||
|
||||
|
@ -537,6 +537,23 @@ void ProceduralAnimationEditorGraphNode::set_time(const float value) {
|
||||
changed();
|
||||
}
|
||||
|
||||
String ProceduralAnimationEditorGraphNode::get_method_name() const {
|
||||
return _method->get_text();
|
||||
}
|
||||
void ProceduralAnimationEditorGraphNode::set_method_name(const String &value) {
|
||||
_method->set_text(value);
|
||||
|
||||
if (!_animation.is_valid())
|
||||
return;
|
||||
|
||||
_animation->set_method_name(_id, value);
|
||||
|
||||
changed();
|
||||
}
|
||||
void ProceduralAnimationEditorGraphNode::on_method_name_modified(const String &value) {
|
||||
set_method_name(value);
|
||||
}
|
||||
|
||||
Ref<ProceduralAnimation> ProceduralAnimationEditorGraphNode::get_animation() {
|
||||
return _animation;
|
||||
}
|
||||
@ -552,6 +569,7 @@ void ProceduralAnimationEditorGraphNode::set_animation(const Ref<ProceduralAnima
|
||||
set_transition(animation->get_keyframe_transition(_id));
|
||||
set_animation_keyframe_index(animation->get_keyframe_animation_keyframe_index(_id));
|
||||
set_time(animation->get_keyframe_time(_id));
|
||||
set_method_name(animation->get_method_name(_id));
|
||||
|
||||
_animation = animation;
|
||||
}
|
||||
@ -574,13 +592,11 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode(Procedura
|
||||
add_child(l1);
|
||||
|
||||
_name = memnew(LineEdit);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
_name->connect("text_entered", this, "on_keyframe_name_modified");
|
||||
#else
|
||||
_name->connect("text_entered", callable_mp(this, &ProceduralAnimationEditorGraphNode::on_keyframe_name_modified));
|
||||
#endif
|
||||
|
||||
add_child(_name);
|
||||
|
||||
Label *l2 = memnew(Label);
|
||||
@ -626,6 +642,18 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode(Procedura
|
||||
_transition_editor->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
add_child(_transition_editor);
|
||||
|
||||
Label *lm = memnew(Label);
|
||||
lm->set_text("Method");
|
||||
add_child(lm);
|
||||
|
||||
_method = memnew(LineEdit);
|
||||
#if VERSION_MAJOR < 4
|
||||
_method->connect("text_entered", this, "on_method_name_modified");
|
||||
#else
|
||||
_method->connect("text_entered", callable_mp(this, &ProceduralAnimationEditorGraphNode::on_method_name_modified));
|
||||
#endif
|
||||
add_child(_method);
|
||||
|
||||
set_slot(0, true, 0, Color(0, 1, 0), true, 0, Color(0, 1, 0));
|
||||
}
|
||||
|
||||
@ -694,6 +722,8 @@ void ProceduralAnimationEditorGraphNode::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_transition"), &ProceduralAnimationEditorGraphNode::get_transition);
|
||||
ClassDB::bind_method(D_METHOD("set_transition", "value"), &ProceduralAnimationEditorGraphNode::set_transition);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "transition", PROPERTY_HINT_EXP_EASING), "set_transition", "get_transition");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("on_method_name_modified", "name"), &ProceduralAnimationEditorGraphNode::on_method_name_modified);
|
||||
}
|
||||
|
||||
// E -------- ProceduralAnimationEditorGraphNode --------
|
||||
|
@ -122,6 +122,10 @@ public:
|
||||
float get_time() const;
|
||||
void set_time(const float value);
|
||||
|
||||
String get_method_name() const;
|
||||
void set_method_name(const String &value);
|
||||
void on_method_name_modified(const String &value);
|
||||
|
||||
Ref<ProceduralAnimation> get_animation();
|
||||
void set_animation(const Ref<ProceduralAnimation> &animation);
|
||||
|
||||
@ -155,6 +159,8 @@ private:
|
||||
float _transition;
|
||||
float _time;
|
||||
|
||||
LineEdit *_method;
|
||||
|
||||
Ref<ProceduralAnimation> _animation;
|
||||
|
||||
ProceduralAnimationEditor *_editor;
|
||||
|
Loading…
Reference in New Issue
Block a user