Explorar el Código

Merge pull request #85254 from TokageItLab/bind-reset-animedit

Bind `_reset`/`_restore` in AnimationMixer
Rémi Verschelde hace 1 año
padre
commit
bb63963486
Se han modificado 2 ficheros con 37 adiciones y 37 borrados
  1. 27 25
      scene/animation/animation_mixer.cpp
  2. 10 12
      scene/animation/animation_mixer.h

+ 27 - 25
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<AudioStream>());
 				}
-				track = memnew(TrackCache); // Make disable this track cache.
 			} break;
 			default: {
 			} // The rest don't matter.
@@ -1959,29 +1957,6 @@ Ref<AnimatedValuesBackup> AnimationMixer::make_backup() {
 	return backup;
 }
 
-Ref<AnimatedValuesBackup> AnimationMixer::apply_reset(bool p_user_initiated) {
-	if (!p_user_initiated && dummy) {
-		return Ref<AnimatedValuesBackup>();
-	}
-	ERR_FAIL_COND_V(!can_apply_reset(), Ref<AnimatedValuesBackup>());
-
-	Ref<Animation> reset_anim = animation_set[SceneStringNames::get_singleton()->RESET].animation;
-	ERR_FAIL_COND_V(reset_anim.is_null(), Ref<AnimatedValuesBackup>());
-
-	Ref<AnimatedValuesBackup> 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<AnimatedValuesBackup> &p_backup) {
 	track_cache = HashMap<NodePath, AnimationMixer::TrackCache *>();
 	cache_valid = false;
 }
+
+#ifdef TOOLS_ENABLED
+Ref<AnimatedValuesBackup> AnimationMixer::apply_reset(bool p_user_initiated) {
+	if (!p_user_initiated && dummy) {
+		return Ref<AnimatedValuesBackup>();
+	}
+	ERR_FAIL_COND_V(!can_apply_reset(), Ref<AnimatedValuesBackup>());
+
+	Ref<Animation> reset_anim = animation_set[SceneStringNames::get_singleton()->RESET].animation;
+	ERR_FAIL_COND_V(reset_anim.is_null(), Ref<AnimatedValuesBackup>());
+
+	Ref<AnimatedValuesBackup> 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() {

+ 10 - 12
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<AnimatedValuesBackup> make_backup();
+	void restore(const Ref<AnimatedValuesBackup> &p_backup);
+	void reset();
+
 #ifdef TOOLS_ENABLED
+	Ref<AnimatedValuesBackup> 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<AnimatedValuesBackup> make_backup();
-	Ref<AnimatedValuesBackup> apply_reset(bool p_user_initiated = false);
-	void restore(const Ref<AnimatedValuesBackup> &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);