diff options
author | Juan Linietsky <juan@godotengine.org> | 2019-03-06 10:22:38 -0300 |
---|---|---|
committer | Juan Linietsky <juan@godotengine.org> | 2019-03-06 10:22:38 -0300 |
commit | 9b5c6f539b0049cbcf12507167eb028013219c45 (patch) | |
tree | 8d8136e07ac3e6514852832a2cda655e8fac0689 /editor | |
parent | 4dd99701b087fd41a1563fb4722c61b067ef374b (diff) |
Safer way to update animation if changed, fixes #26670
Diffstat (limited to 'editor')
-rw-r--r-- | editor/animation_track_editor.cpp | 44 | ||||
-rw-r--r-- | editor/animation_track_editor.h | 5 |
2 files changed, 46 insertions, 3 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 6b863a162c..c561cdc249 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1621,10 +1621,15 @@ void AnimationTrackEdit::set_animation_and_track(const Ref<Animation> &p_animati ERR_FAIL_INDEX(track, animation->get_track_count()); + node_path = animation->track_get_path(p_track); type_icon = type_icons[animation->track_get_type(track)]; selected_icon = get_icon("KeySelected", "EditorIcons"); } +NodePath AnimationTrackEdit::get_path() const { + return node_path; +} + Size2 AnimationTrackEdit::get_minimum_size() const { Ref<Texture> texture = get_icon("Object", "EditorIcons"); @@ -1945,6 +1950,7 @@ void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { if (remove_rect.has_point(pos)) { emit_signal("remove_request", track); accept_event(); + return; } if (bezier_edit_rect.has_point(pos)) { @@ -2533,7 +2539,10 @@ void AnimationTrackEditor::_track_remove_request(int p_track) { int idx = p_track; if (idx >= 0 && idx < animation->get_track_count()) { - _clear_selection(); + selection.clear(); + _clear_key_edit(); + //all will be updated after remove anyway, and triggering update here raises error on tracks already removed + undo_redo->create_action(TTR("Remove Anim Track")); undo_redo->add_do_method(animation.ptr(), "remove_track", idx); undo_redo->add_undo_method(animation.ptr(), "add_track", animation->track_get_type(idx), idx); @@ -3392,6 +3401,10 @@ void AnimationTrackEditor::_update_tracks() { void AnimationTrackEditor::_animation_changed() { + if (animation_changing_awaiting_update) { + return; //all will be updated, dont bother with anything + } + if (key_edit && key_edit->setting) { //if editing a key, just update the edited track, makes refresh less costly if (key_edit->track < track_edits.size()) { @@ -3400,9 +3413,31 @@ void AnimationTrackEditor::_animation_changed() { return; } + animation_changing_awaiting_update = true; + call_deferred("_animation_update"); +} + +void AnimationTrackEditor::_animation_update() { + timeline->update(); timeline->update_values(); - if (undo_redo->is_commiting_action()) { + + bool same = true; + + if (track_edits.size() == animation->get_track_count()) { + //check tracks are the same + + for (int i = 0; i < track_edits.size(); i++) { + if (track_edits[i]->get_path() != animation->track_get_path(i)) { + same = false; + break; + } + } + } else { + same = false; + } + + if (same) { for (int i = 0; i < track_edits.size(); i++) { track_edits[i]->update(); } @@ -3418,6 +3453,8 @@ void AnimationTrackEditor::_animation_changed() { step->set_block_signals(true); step->set_value(animation->get_step()); step->set_block_signals(false); + + animation_changing_awaiting_update = false; } MenuButton *AnimationTrackEditor::get_edit_menu() { @@ -4712,10 +4749,12 @@ float AnimationTrackEditor::snap_time(float p_value) { void AnimationTrackEditor::_bind_methods() { ClassDB::bind_method("_animation_changed", &AnimationTrackEditor::_animation_changed); + ClassDB::bind_method("_animation_update", &AnimationTrackEditor::_animation_update); ClassDB::bind_method("_timeline_changed", &AnimationTrackEditor::_timeline_changed); ClassDB::bind_method("_track_remove_request", &AnimationTrackEditor::_track_remove_request); ClassDB::bind_method("_name_limit_changed", &AnimationTrackEditor::_name_limit_changed); ClassDB::bind_method("_update_scroll", &AnimationTrackEditor::_update_scroll); + ClassDB::bind_method("_update_tracks", &AnimationTrackEditor::_update_tracks); ClassDB::bind_method("_update_step", &AnimationTrackEditor::_update_step); ClassDB::bind_method("_update_length", &AnimationTrackEditor::_update_length); ClassDB::bind_method("_dropped_track", &AnimationTrackEditor::_dropped_track); @@ -5017,6 +5056,7 @@ AnimationTrackEditor::AnimationTrackEditor() { track_copy_select->set_hide_root(true); track_copy_dialog->add_child(track_copy_select); track_copy_dialog->connect("confirmed", this, "_edit_menu_pressed", varray(EDIT_COPY_TRACKS_CONFIRM)); + animation_changing_awaiting_update = false; } AnimationTrackEditor::~AnimationTrackEditor() { diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 4ad8b6fd68..29ce4f189e 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -141,6 +141,7 @@ class AnimationTrackEdit : public Control { Node *root; Control *play_position; //separate control used to draw so updates for only position changed are much faster float play_position_pos; + NodePath node_path; Ref<Animation> animation; int track; @@ -212,7 +213,7 @@ public: AnimationTimelineEdit *get_timeline() const { return timeline; } AnimationTrackEditor *get_editor() const { return editor; } UndoRedo *get_undo_redo() const { return undo_redo; } - + NodePath get_path() const; void set_animation_and_track(const Ref<Animation> &p_animation, int p_track); virtual Size2 get_minimum_size() const; @@ -306,6 +307,8 @@ class AnimationTrackEditor : public VBoxContainer { Vector<AnimationTrackEdit *> track_edits; Vector<AnimationTrackEditGroup *> groups; + bool animation_changing_awaiting_update; + void _animation_update(); int _get_track_selected(); void _animation_changed(); void _update_tracks(); |