Skip to content

Commit 9d0944b

Browse files
Dowsleyakien-mga
authored andcommitted
Update AnimationPlayer in real-time when bezier curve properties or bezier editor changes
1 parent 18cdfb8 commit 9d0944b

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

editor/animation_bezier_editor.cpp

+52-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "editor/editor_string_names.h"
3636
#include "editor/editor_undo_redo_manager.h"
3737
#include "editor/gui/editor_spin_slider.h"
38+
#include "editor/plugins/animation_player_editor_plugin.h"
3839
#include "editor/themes/editor_scale.h"
3940
#include "scene/gui/view_panner.h"
4041
#include "scene/resources/text_line.h"
@@ -869,6 +870,11 @@ void AnimationBezierTrackEdit::_change_selected_keys_handle_mode(Animation::Hand
869870
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track_key_pair.first, track_key_pair.second, animation->bezier_track_get_key_out_handle(track_key_pair.first, track_key_pair.second));
870871
undo_redo->add_do_method(editor, "_bezier_track_set_key_handle_mode", animation.ptr(), track_key_pair.first, track_key_pair.second, p_mode, p_auto ? Animation::HANDLE_SET_MODE_AUTO : Animation::HANDLE_SET_MODE_RESET);
871872
}
873+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
874+
if (ape) {
875+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
876+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
877+
}
872878
undo_redo->commit_action();
873879
}
874880

@@ -1560,6 +1566,11 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
15601566
undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, moving_handle_right, ratio);
15611567
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, animation->bezier_track_get_key_out_handle(moving_handle_track, moving_handle_key), ratio);
15621568
}
1569+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
1570+
if (ape) {
1571+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
1572+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
1573+
}
15631574
undo_redo->commit_action();
15641575
moving_handle = 0;
15651576
queue_redraw();
@@ -1673,6 +1684,11 @@ void AnimationBezierTrackEdit::_menu_selected(int p_index) {
16731684
undo_redo->add_do_method(animation.ptr(), "track_insert_key", selected_track, time, new_point);
16741685
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
16751686
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", selected_track, time);
1687+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
1688+
if (ape) {
1689+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
1690+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
1691+
}
16761692
undo_redo->commit_action();
16771693
queue_redraw();
16781694
}
@@ -1773,6 +1789,11 @@ void AnimationBezierTrackEdit::duplicate_selected_keys(real_t p_ofs, bool p_ofs_
17731789
i++;
17741790
}
17751791

1792+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
1793+
if (ape) {
1794+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
1795+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
1796+
}
17761797
undo_redo->add_do_method(this, "queue_redraw");
17771798
undo_redo->add_undo_method(this, "queue_redraw");
17781799
undo_redo->commit_action();
@@ -1822,6 +1843,15 @@ void AnimationBezierTrackEdit::copy_selected_keys(bool p_cut) {
18221843
undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, E->value().pos, i == 0);
18231844
i++;
18241845
}
1846+
1847+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
1848+
if (ape) {
1849+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
1850+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
1851+
}
1852+
undo_redo->add_do_method(this, "queue_redraw");
1853+
undo_redo->add_undo_method(this, "queue_redraw");
1854+
18251855
undo_redo->commit_action();
18261856
}
18271857
}
@@ -1900,9 +1930,15 @@ void AnimationBezierTrackEdit::paste_keys(real_t p_ofs, bool p_ofs_valid) {
19001930
i++;
19011931
}
19021932

1903-
undo_redo->commit_action();
1933+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
1934+
if (ape) {
1935+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
1936+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
1937+
}
1938+
undo_redo->add_do_method(this, "queue_redraw");
1939+
undo_redo->add_undo_method(this, "queue_redraw");
19041940

1905-
queue_redraw();
1941+
undo_redo->commit_action();
19061942
}
19071943
}
19081944

@@ -1917,6 +1953,11 @@ void AnimationBezierTrackEdit::delete_selection() {
19171953
}
19181954
undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
19191955
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
1956+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
1957+
if (ape) {
1958+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
1959+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
1960+
}
19201961
undo_redo->commit_action();
19211962

19221963
//selection.clear();
@@ -1926,6 +1967,15 @@ void AnimationBezierTrackEdit::delete_selection() {
19261967
void AnimationBezierTrackEdit::_bezier_track_insert_key_at_anim(const Ref<Animation> &p_anim, int p_track, double p_time, real_t p_value, const Vector2 &p_in_handle, const Vector2 &p_out_handle, const Animation::HandleMode p_handle_mode) {
19271968
int idx = p_anim->bezier_track_insert_key(p_track, p_time, p_value, p_in_handle, p_out_handle);
19281969
p_anim->bezier_track_set_key_handle_mode(p_track, idx, p_handle_mode);
1970+
1971+
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
1972+
undo_redo->create_action(TTR("Animation Bezier Curve Change Call"));
1973+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
1974+
if (ape) {
1975+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
1976+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
1977+
}
1978+
undo_redo->commit_action();
19291979
}
19301980

19311981
void AnimationBezierTrackEdit::_bind_methods() {

editor/animation_track_editor.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ bool AnimationTrackKeyEdit::_set(const StringName &p_name, const Variant &p_valu
279279
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_value", track, key, prev);
280280
undo_redo->add_do_method(this, "_update_obj", animation);
281281
undo_redo->add_undo_method(this, "_update_obj", animation);
282+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
283+
if (ape) {
284+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
285+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
286+
}
282287
undo_redo->commit_action();
283288

284289
setting = false;
@@ -295,6 +300,11 @@ bool AnimationTrackKeyEdit::_set(const StringName &p_name, const Variant &p_valu
295300
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, prev);
296301
undo_redo->add_do_method(this, "_update_obj", animation);
297302
undo_redo->add_undo_method(this, "_update_obj", animation);
303+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
304+
if (ape) {
305+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
306+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
307+
}
298308
undo_redo->commit_action();
299309

300310
setting = false;
@@ -311,6 +321,11 @@ bool AnimationTrackKeyEdit::_set(const StringName &p_name, const Variant &p_valu
311321
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, prev);
312322
undo_redo->add_do_method(this, "_update_obj", animation);
313323
undo_redo->add_undo_method(this, "_update_obj", animation);
324+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
325+
if (ape) {
326+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
327+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
328+
}
314329
undo_redo->commit_action();
315330

316331
setting = false;
@@ -331,6 +346,11 @@ bool AnimationTrackKeyEdit::_set(const StringName &p_name, const Variant &p_valu
331346
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, prev_in_handle);
332347
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, prev_out_handle);
333348
undo_redo->add_undo_method(this, "_update_obj", animation);
349+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
350+
if (ape) {
351+
undo_redo->add_do_method(ape, "_animation_update_key_frame");
352+
undo_redo->add_undo_method(ape, "_animation_update_key_frame");
353+
}
334354
undo_redo->commit_action();
335355

336356
setting = false;

0 commit comments

Comments
 (0)