Safer way to update animation if changed, fixes #26670

This commit is contained in:
Juan Linietsky 2019-03-06 10:22:38 -03:00
parent 4dd99701b0
commit 9b5c6f539b
3 changed files with 48 additions and 8 deletions

View file

@ -250,8 +250,9 @@ void UndoRedo::commit_action() {
if (action_level > 0)
return; //still nested
commiting++;
redo(); // perform action
commiting--;
if (callback && actions.size() > 0) {
callback(callback_ud, actions[actions.size() - 1].name);
}
@ -326,12 +327,10 @@ bool UndoRedo::redo() {
if ((current_action + 1) >= actions.size())
return false; //nothing to redo
commiting++;
current_action++;
_process_operation_list(actions.write[current_action].do_ops.front());
version++;
commiting--;
return true;
}
@ -341,11 +340,9 @@ bool UndoRedo::undo() {
ERR_FAIL_COND_V(action_level > 0, false);
if (current_action < 0)
return false; //nothing to redo
commiting++;
_process_operation_list(actions.write[current_action].undo_ops.front());
current_action--;
version--;
commiting--;
return true;
}

View file

@ -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() {

View file

@ -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();