Skip to content

Commit

Permalink
Merge pull request #83533 from SaracenOne/bezier_edit_mode_fix
Browse files Browse the repository at this point in the history
Fix setting bezier track handle mode from inspector
  • Loading branch information
YuriSizov committed Dec 16, 2023
2 parents 4b258cc + 09a4aa3 commit 9cbe3cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 18 additions & 8 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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<int, List<float>> key_ofs_map;
RBMap<int, NodePath> base_map;
Expand Down
2 changes: 2 additions & 0 deletions editor/animation_track_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class AnimationTrackKeyEdit : public Object {
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; }
Expand Down Expand Up @@ -105,6 +106,7 @@ class AnimationMultiTrackKeyEdit : public Object {
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; }
Expand Down

0 comments on commit 9cbe3cb

Please sign in to comment.