Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AnimationPlayer in real-time when keyframe properties change #91599

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ bool AnimationTrackKeyEdit::_set(const StringName &p_name, const Variant &p_valu
float val = p_value;
float prev_val = animation->track_get_key_transition(track, key);
setting = true;

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Animation Change Transition"), UndoRedo::MERGE_ENDS);
undo_redo->add_do_method(animation.ptr(), "track_set_key_transition", track, key, val);
undo_redo->add_undo_method(animation.ptr(), "track_set_key_transition", track, key, prev_val);
undo_redo->add_do_method(this, "_update_obj", animation);
undo_redo->add_undo_method(this, "_update_obj", animation);
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
undo_redo->add_do_method(ape, "_animation_update_key_frame");
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
undo_redo->commit_action();

setting = false;
Expand Down Expand Up @@ -174,12 +178,16 @@ bool AnimationTrackKeyEdit::_set(const StringName &p_name, const Variant &p_valu
}

setting = true;

undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS);
Variant prev = animation->track_get_key_value(track, key);
undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, value);
undo_redo->add_undo_method(animation.ptr(), "track_set_key_value", track, key, prev);
undo_redo->add_do_method(this, "_update_obj", animation);
undo_redo->add_undo_method(this, "_update_obj", animation);
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
undo_redo->add_do_method(ape, "_animation_update_key_frame");
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
dnllowe marked this conversation as resolved.
Show resolved Hide resolved
undo_redo->commit_action();

setting = false;
Expand Down Expand Up @@ -3127,6 +3135,10 @@ bool AnimationTrackEdit::_try_select_at_ui_pos(const Point2 &p_pos, bool p_aggre
moving_selection_effective = false;
moving_selection_pivot = animation->track_get_key_time(track, key_idx);
moving_selection_mouse_begin_x = p_pos.x;

AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
player->seek(moving_selection_pivot, true, true);
emit_signal(SNAME("timeline_changed"), moving_selection_pivot, false);
}

if (read_only) {
Expand Down
5 changes: 5 additions & 0 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,10 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_timel
_seek_value_changed(p_pos, p_timeline_only);
}

void AnimationPlayerEditor::_animation_update_key_frame() {
_animation_key_editor_seek(timeline_position, false);
}

void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
String current = _get_current();

Expand Down Expand Up @@ -1877,6 +1881,7 @@ bool AnimationPlayerEditor::_validate_tracks(const Ref<Animation> p_anim) {
void AnimationPlayerEditor::_bind_methods() {
// Needed for UndoRedo.
ClassDB::bind_method(D_METHOD("_animation_player_changed"), &AnimationPlayerEditor::_animation_player_changed);
ClassDB::bind_method(D_METHOD("_animation_update_key_frame"), &AnimationPlayerEditor::_animation_update_key_frame);
ClassDB::bind_method(D_METHOD("_start_onion_skinning"), &AnimationPlayerEditor::_start_onion_skinning);
ClassDB::bind_method(D_METHOD("_stop_onion_skinning"), &AnimationPlayerEditor::_stop_onion_skinning);

Expand Down
1 change: 1 addition & 0 deletions editor/plugins/animation_player_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class AnimationPlayerEditor : public VBoxContainer {

void _animation_key_editor_seek(float p_pos, bool p_timeline_only = false);
void _animation_key_editor_anim_len_changed(float p_len);
void _animation_update_key_frame();

virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
void _animation_tool_menu(int p_option);
Expand Down