diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index f88c95238ce..e23fc56a23b 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -1868,7 +1868,6 @@ bool AnimationMixer::is_reset_on_save_enabled() const { return reset_on_save; } -#ifdef TOOLS_ENABLED bool AnimationMixer::can_apply_reset() const { return has_animation(SceneStringNames::get_singleton()->RESET); } @@ -1929,7 +1928,6 @@ void AnimationMixer::_build_backup_track_cache() { if (asp) { t->object->call(SNAME("set_stream"), Ref()); } - track = memnew(TrackCache); // Make disable this track cache. } break; default: { } // The rest don't matter. @@ -1959,29 +1957,6 @@ Ref AnimationMixer::make_backup() { return backup; } -Ref AnimationMixer::apply_reset(bool p_user_initiated) { - if (!p_user_initiated && dummy) { - return Ref(); - } - ERR_FAIL_COND_V(!can_apply_reset(), Ref()); - - Ref reset_anim = animation_set[SceneStringNames::get_singleton()->RESET].animation; - ERR_FAIL_COND_V(reset_anim.is_null(), Ref()); - - Ref backup_current = make_backup(); - if (p_user_initiated) { - EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); - ur->create_action(TTR("Animation Apply Reset")); - ur->add_do_method(this, "_reset"); - ur->add_undo_method(this, "_restore", backup_current); - ur->commit_action(); - } else { - reset(); - } - - return backup_current; -} - void AnimationMixer::reset() { ERR_FAIL_COND(!can_apply_reset()); @@ -2010,6 +1985,30 @@ void AnimationMixer::restore(const Ref &p_backup) { track_cache = HashMap(); cache_valid = false; } + +#ifdef TOOLS_ENABLED +Ref AnimationMixer::apply_reset(bool p_user_initiated) { + if (!p_user_initiated && dummy) { + return Ref(); + } + ERR_FAIL_COND_V(!can_apply_reset(), Ref()); + + Ref reset_anim = animation_set[SceneStringNames::get_singleton()->RESET].animation; + ERR_FAIL_COND_V(reset_anim.is_null(), Ref()); + + Ref backup_current = make_backup(); + if (p_user_initiated) { + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); + ur->create_action(TTR("Animation Apply Reset")); + ur->add_do_method(this, "_reset"); + ur->add_undo_method(this, "_restore", backup_current); + ur->commit_action(); + } else { + reset(); + } + + return backup_current; +} #endif // TOOLS_ENABLED /* -------------------------------------------- */ @@ -2128,6 +2127,9 @@ void AnimationMixer::_bind_methods() { ADD_SIGNAL(MethodInfo(SNAME("animation_finished"), PropertyInfo(Variant::STRING_NAME, "anim_name"))); ADD_SIGNAL(MethodInfo(SNAME("animation_started"), PropertyInfo(Variant::STRING_NAME, "anim_name"))); ADD_SIGNAL(MethodInfo(SNAME("caches_cleared"))); + + ClassDB::bind_method(D_METHOD("_reset"), &AnimationMixer::reset); + ClassDB::bind_method(D_METHOD("_restore", "backup"), &AnimationMixer::restore); } AnimationMixer::AnimationMixer() { diff --git a/scene/animation/animation_mixer.h b/scene/animation/animation_mixer.h index 3962974a8c7..247462b8adb 100644 --- a/scene/animation/animation_mixer.h +++ b/scene/animation/animation_mixer.h @@ -38,14 +38,12 @@ #include "scene/resources/animation_library.h" #include "scene/resources/audio_stream_polyphonic.h" -#ifdef TOOLS_ENABLED class AnimatedValuesBackup; -#endif // TOOLS_ENABLED class AnimationMixer : public Node { GDCLASS(AnimationMixer, Node); -#ifdef TOOLS_ENABLED friend AnimatedValuesBackup; +#ifdef TOOLS_ENABLED bool editing = false; bool dummy = false; #endif // TOOLS_ENABLED @@ -364,25 +362,26 @@ public: void set_reset_on_save_enabled(bool p_enabled); bool is_reset_on_save_enabled() const; + bool can_apply_reset() const; + void _build_backup_track_cache(); + Ref make_backup(); + void restore(const Ref &p_backup); + void reset(); + #ifdef TOOLS_ENABLED + Ref apply_reset(bool p_user_initiated = false); + void set_editing(bool p_editing); bool is_editing() const; void set_dummy(bool p_dummy); bool is_dummy() const; - - bool can_apply_reset() const; - void _build_backup_track_cache(); - Ref make_backup(); - Ref apply_reset(bool p_user_initiated = false); - void restore(const Ref &p_backup); - void reset(); #endif // TOOLS_ENABLED + AnimationMixer(); ~AnimationMixer(); }; -#ifdef TOOLS_ENABLED class AnimatedValuesBackup : public RefCounted { GDCLASS(AnimatedValuesBackup, RefCounted); @@ -398,7 +397,6 @@ public: } } }; -#endif VARIANT_ENUM_CAST(AnimationMixer::AnimationCallbackModeProcess); VARIANT_ENUM_CAST(AnimationMixer::AnimationCallbackModeMethod);