mirror of
https://github.com/Relintai/procedural_animations.git
synced 2024-11-13 08:27:19 +01:00
Implement keyframe time.
This commit is contained in:
parent
52873cd45b
commit
63827022bb
@ -179,6 +179,19 @@ void ProceduralAnimation::set_keyframe_transition(const int keyframe_index, cons
|
||||
process_animation_data();
|
||||
}
|
||||
|
||||
float ProceduralAnimation::get_keyframe_time(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), 0);
|
||||
|
||||
return _keyframes[keyframe_index]->time;
|
||||
}
|
||||
void ProceduralAnimation::set_keyframe_time(const int keyframe_index, const float value) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
_keyframes[keyframe_index]->time = value;
|
||||
|
||||
process_animation_data();
|
||||
}
|
||||
|
||||
Vector2 ProceduralAnimation::get_keyframe_node_position(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), Vector2());
|
||||
|
||||
@ -194,6 +207,8 @@ void ProceduralAnimation::process_animation_data() {
|
||||
if (!_animation.is_valid())
|
||||
return;
|
||||
|
||||
bool looping = has_loop();
|
||||
|
||||
clear();
|
||||
|
||||
for (int i = 0; i < _animation->get_track_count(); ++i) {
|
||||
@ -268,9 +283,11 @@ void ProceduralAnimation::process_animation_data() {
|
||||
if (!found_keyframe)
|
||||
ERR_PRINT("Could not find any keyframe! Index: " + String::num(animation_keyframe_index) + " at time: " + String::num(time));
|
||||
|
||||
//TODO add param
|
||||
target_keyframe_time += 1.0;
|
||||
target_keyframe_time += frame->time;
|
||||
}
|
||||
|
||||
set_length(target_keyframe_time);
|
||||
set_loop(looping);
|
||||
}
|
||||
|
||||
ProceduralAnimation::ProceduralAnimation() {
|
||||
|
@ -41,13 +41,15 @@ protected:
|
||||
String name;
|
||||
int animation_keyframe_index;
|
||||
int next_keyframe;
|
||||
Vector2 position;
|
||||
float transition;
|
||||
float time;
|
||||
Vector2 position;
|
||||
|
||||
AnimationKeyFrame() {
|
||||
animation_keyframe_index = 0;
|
||||
transition = 1.0;
|
||||
next_keyframe = -1;
|
||||
time = 1;
|
||||
}
|
||||
|
||||
~AnimationKeyFrame() {
|
||||
@ -90,6 +92,9 @@ public:
|
||||
float get_keyframe_transition(const int keyframe_index) const;
|
||||
void set_keyframe_transition(const int keyframe_index, const float value);
|
||||
|
||||
float get_keyframe_time(const int keyframe_index) const;
|
||||
void set_keyframe_time(const int keyframe_index, const float value);
|
||||
|
||||
Vector2 get_keyframe_node_position(const int keyframe_index) const;
|
||||
void set_keyframe_node_position(const int keyframe_index, const Vector2 &value);
|
||||
|
||||
|
@ -396,6 +396,22 @@ void ProceduralAnimationEditorGraphNode::set_transition(const float value) {
|
||||
changed();
|
||||
}
|
||||
|
||||
float ProceduralAnimationEditorGraphNode::get_time() const {
|
||||
return _time;
|
||||
}
|
||||
void ProceduralAnimationEditorGraphNode::set_time(const float value) {
|
||||
_time = value;
|
||||
|
||||
_time_spinbox->set_value(value);
|
||||
|
||||
if (!_animation.is_valid())
|
||||
return;
|
||||
|
||||
_animation->set_keyframe_time(_id, value);
|
||||
|
||||
changed();
|
||||
}
|
||||
|
||||
Ref<ProceduralAnimation> ProceduralAnimationEditorGraphNode::get_animation() {
|
||||
return _animation;
|
||||
}
|
||||
@ -410,6 +426,7 @@ void ProceduralAnimationEditorGraphNode::set_animation(const Ref<ProceduralAnima
|
||||
set_next_keyframe(animation->get_keyframe_next_keyframe_index(_id));
|
||||
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));
|
||||
|
||||
_animation = animation;
|
||||
}
|
||||
@ -418,7 +435,8 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() {
|
||||
_id = 0;
|
||||
|
||||
_animation_keyframe_index = 0;
|
||||
_next_keyframe = 0;
|
||||
_next_keyframe = -1;
|
||||
_time = 1;
|
||||
|
||||
set_title("Animation Frame");
|
||||
set_show_close_button(true);
|
||||
@ -441,6 +459,17 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() {
|
||||
_animation_keyframe_spinbox->connect("value_changed", this, "on_animation_keyframe_spinbox_value_changed");
|
||||
add_child(_animation_keyframe_spinbox);
|
||||
|
||||
Label *lt = memnew(Label);
|
||||
lt->set_text("Time");
|
||||
add_child(lt);
|
||||
|
||||
_time_spinbox = memnew(SpinBox);
|
||||
_time_spinbox->set_max(999999999);
|
||||
_time_spinbox->set_min(0);
|
||||
_time_spinbox->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
_time_spinbox->connect("value_changed", this, "on_time_spinbox_value_changed");
|
||||
add_child(_time_spinbox);
|
||||
|
||||
_transition_editor = memnew(EditorPropertyEasing);
|
||||
_transition_editor->set_margin(MARGIN_TOP, 5 * EDSCALE);
|
||||
_transition_editor->set_margin(MARGIN_BOTTOM, 5 * EDSCALE);
|
||||
@ -459,6 +488,10 @@ void ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_cha
|
||||
set_animation_keyframe_index(value);
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditorGraphNode::on_time_spinbox_value_changed(float value) {
|
||||
set_time(value);
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditorGraphNode::on_dragged(Vector2 from, Vector2 to) {
|
||||
if (!_animation.is_valid())
|
||||
return;
|
||||
@ -491,6 +524,7 @@ void ProceduralAnimationEditorGraphNode::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("on_keyframe_name_modified", "name"), &ProceduralAnimationEditorGraphNode::on_keyframe_name_modified);
|
||||
ClassDB::bind_method(D_METHOD("changed"), &ProceduralAnimationEditorGraphNode::changed);
|
||||
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);
|
||||
|
||||
|
@ -111,6 +111,9 @@ public:
|
||||
float get_transition() const;
|
||||
void set_transition(const float value);
|
||||
|
||||
float get_time() const;
|
||||
void set_time(const float value);
|
||||
|
||||
Ref<ProceduralAnimation> get_animation();
|
||||
void set_animation(const Ref<ProceduralAnimation> &animation);
|
||||
|
||||
@ -119,6 +122,8 @@ public:
|
||||
|
||||
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 changed();
|
||||
@ -132,11 +137,13 @@ private:
|
||||
int _id;
|
||||
LineEdit *_name;
|
||||
SpinBox *_animation_keyframe_spinbox;
|
||||
SpinBox *_time_spinbox;
|
||||
|
||||
int _animation_keyframe_index;
|
||||
int _next_keyframe;
|
||||
EditorPropertyEasing *_transition_editor;
|
||||
float _transition;
|
||||
float _time;
|
||||
|
||||
Ref<ProceduralAnimation> _animation;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user