Implement keyframe_time's bindings. Also fix saving node positions in the editor plugin.

This commit is contained in:
Relintai 2020-04-01 20:16:22 +02:00
parent 63827022bb
commit e0982ccc22
3 changed files with 21 additions and 6 deletions

View File

@ -343,6 +343,10 @@ bool ProceduralAnimation::_set(const StringName &p_name, const Variant &p_value)
} else if (keyframe_name == "transition") {
keyframe->transition = p_value;
return true;
} else if (keyframe_name == "time") {
keyframe->time = p_value;
return true;
} else if (keyframe_name == "position") {
keyframe->position = p_value;
@ -390,6 +394,10 @@ bool ProceduralAnimation::_get(const StringName &p_name, Variant &r_ret) const {
} else if (keyframe_prop_name == "transition") {
r_ret = keyframe->transition;
return true;
} else if (keyframe_prop_name == "time") {
r_ret = keyframe->time;
return true;
} else if (keyframe_prop_name == "position") {
r_ret = keyframe->position;
@ -417,6 +425,7 @@ void ProceduralAnimation::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::INT, "keyframe/" + itos(K->key()) + "/animation_keyframe_index", PROPERTY_HINT_NONE, "", property_usange));
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::VECTOR2, "keyframe/" + itos(K->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
}
}
@ -459,6 +468,9 @@ void ProceduralAnimation::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_keyframe_transition", "keyframe_index"), &ProceduralAnimation::get_keyframe_transition);
ClassDB::bind_method(D_METHOD("set_keyframe_transition", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_transition);
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_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);

View File

@ -400,8 +400,10 @@ float ProceduralAnimationEditorGraphNode::get_time() const {
return _time;
}
void ProceduralAnimationEditorGraphNode::set_time(const float value) {
_time = value;
if (Math::is_equal_approx(value, _time))
return;
_time = value;
_time_spinbox->set_value(value);
if (!_animation.is_valid())
@ -436,7 +438,7 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() {
_animation_keyframe_index = 0;
_next_keyframe = -1;
_time = 1;
_time = 0;
set_title("Animation Frame");
set_show_close_button(true);
@ -466,6 +468,7 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() {
_time_spinbox = memnew(SpinBox);
_time_spinbox->set_max(999999999);
_time_spinbox->set_min(0);
_time_spinbox->set_step(0.01);
_time_spinbox->set_h_size_flags(SIZE_EXPAND_FILL);
_time_spinbox->connect("value_changed", this, "on_time_spinbox_value_changed");
add_child(_time_spinbox);
@ -492,7 +495,7 @@ void ProceduralAnimationEditorGraphNode::on_time_spinbox_value_changed(float val
set_time(value);
}
void ProceduralAnimationEditorGraphNode::on_dragged(Vector2 from, Vector2 to) {
void ProceduralAnimationEditorGraphNode::on_offset_changed() {
if (!_animation.is_valid())
return;
@ -512,7 +515,7 @@ void ProceduralAnimationEditorGraphNode::on_transition_changed(const StringName
void ProceduralAnimationEditorGraphNode::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
connect("offset_changed", this, "changed");
connect("offset_changed", this, "on_offset_changed");
_transition_editor->connect("property_changed", this, "on_transition_changed");
break;
}
@ -526,7 +529,7 @@ void ProceduralAnimationEditorGraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("on_animation_keyframe_spinbox_value_changed", "value"), &ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_changed);
ClassDB::bind_method(D_METHOD("on_time_spinbox_value_changed", "value"), &ProceduralAnimationEditorGraphNode::on_time_spinbox_value_changed);
ClassDB::bind_method(D_METHOD("on_dragged", "from", "to"), &ProceduralAnimationEditorGraphNode::on_dragged);
ClassDB::bind_method(D_METHOD("on_offset_changed"), &ProceduralAnimationEditorGraphNode::on_offset_changed);
ClassDB::bind_method(D_METHOD("on_transition_changed", "p_property", "p_value", "p_field", "p_changing"), &ProceduralAnimationEditorGraphNode::on_transition_changed);

View File

@ -124,7 +124,7 @@ protected:
void on_animation_keyframe_spinbox_value_changed(float value);
void on_time_spinbox_value_changed(float value);
void on_dragged(Vector2 from, Vector2 to);
void on_offset_changed();
void changed();