From 49031b24e550309b1dd717eb5130240176c140c7 Mon Sep 17 00:00:00 2001 From: Saracen Date: Wed, 18 Oct 2023 02:29:02 +0100 Subject: [PATCH] Fix setting bezier track handle mode from inspector. (cherry picked from commit 09a4aa3ce80343587080e057677e31359039b7f8) --- editor/animation_track_editor.cpp | 26 ++++++++++++++++++-------- editor/animation_track_editor.h | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index faffbb631fc..8268cf10aec 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -306,10 +306,14 @@ 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); - int prev = animation->bezier_track_get_key_handle_mode(track, key); - undo_redo->add_do_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, value); - undo_redo->add_undo_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, prev); + int prev_mode = animation->bezier_track_get_key_handle_mode(track, key); + Vector2 prev_in_handle = animation->bezier_track_get_key_in_handle(track, key); + Vector2 prev_out_handle = animation->bezier_track_get_key_out_handle(track, key); + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, value); undo_redo->add_do_method(this, "_update_obj", animation); + undo_redo->add_undo_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, prev_mode); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, prev_in_handle); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, prev_out_handle); undo_redo->add_undo_method(this, "_update_obj", animation); undo_redo->commit_action(); @@ -857,8 +861,8 @@ bool AnimationMultiTrackKeyEdit::_set(const StringName &p_name, const Variant &p undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } Vector2 prev = animation->bezier_track_get_key_in_handle(track, key); - undo_redo->add_do_method(this, "_bezier_track_set_key_in_handle", track, key, value); - undo_redo->add_undo_method(this, "_bezier_track_set_key_in_handle", track, key, prev); + undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, value); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, prev); update_obj = true; } else if (name == "out_handle") { const Variant &value = p_value; @@ -878,9 +882,13 @@ bool AnimationMultiTrackKeyEdit::_set(const StringName &p_name, const Variant &p setting = true; undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } - int prev = animation->bezier_track_get_key_handle_mode(track, key); - undo_redo->add_do_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, value); - undo_redo->add_undo_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, prev); + int prev_mode = animation->bezier_track_get_key_handle_mode(track, key); + Vector2 prev_in_handle = animation->bezier_track_get_key_in_handle(track, key); + Vector2 prev_out_handle = animation->bezier_track_get_key_out_handle(track, key); + undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, value); + undo_redo->add_undo_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, prev_mode); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, prev_in_handle); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, prev_out_handle); update_obj = true; } } break; @@ -5175,6 +5183,7 @@ void AnimationTrackEditor::_update_key_edit() { key_edit->animation_read_only = read_only; key_edit->track = selection.front()->key().track; key_edit->use_fps = timeline->is_using_fps(); + key_edit->editor = this; int key_id = selection.front()->key().key; if (key_id >= animation->track_get_key_count(key_edit->track)) { @@ -5194,6 +5203,7 @@ void AnimationTrackEditor::_update_key_edit() { multi_key_edit = memnew(AnimationMultiTrackKeyEdit); multi_key_edit->animation = animation; multi_key_edit->animation_read_only = read_only; + multi_key_edit->editor = this; RBMap> key_ofs_map; RBMap base_map; diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index eb2cb2a4e44..4b9849b26c8 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -68,6 +68,7 @@ public: PropertyInfo hint; NodePath base; bool use_fps = false; + AnimationTrackEditor *editor = nullptr; bool _hide_script_from_inspector() { return true; } bool _hide_metadata_from_inspector() { return true; } @@ -105,6 +106,7 @@ public: Node *root_path = nullptr; bool use_fps = false; + AnimationTrackEditor *editor = nullptr; bool _hide_script_from_inspector() { return true; } bool _hide_metadata_from_inspector() { return true; }