Browse Source

Split pause() from AnimationPlayer's stop()

kobewi 2 years ago
parent
commit
da9396881e

+ 9 - 3
doc/classes/AnimationPlayer.xml

@@ -137,6 +137,13 @@
 				Returns [code]true[/code] if playing an animation.
 			</description>
 		</method>
+		<method name="pause">
+			<return type="void" />
+			<description>
+				Pauses the currently playing animation. The [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation.
+				See also [method stop].
+			</description>
+		</method>
 		<method name="play">
 			<return type="void" />
 			<param index="0" name="name" type="StringName" default="&quot;&quot;" />
@@ -201,10 +208,9 @@
 		</method>
 		<method name="stop">
 			<return type="void" />
-			<param index="0" name="reset" type="bool" default="true" />
 			<description>
-				Stops or pauses the currently playing animation. If [param reset] is [code]true[/code], the animation position is reset to [code]0[/code] and the playback speed is reset to [code]1.0[/code].
-				If [param reset] is [code]false[/code], the [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation.
+				Stops the currently playing animation. The animation position is reset to [code]0[/code] and the playback speed is reset to [code]1.0[/code].
+				See also [method pause].
 			</description>
 		</method>
 	</methods>

+ 2 - 2
editor/plugins/animation_player_editor_plugin.cpp

@@ -267,7 +267,7 @@ void AnimationPlayerEditor::_stop_pressed() {
 		return;
 	}
 
-	player->stop(false);
+	player->pause();
 	play->set_pressed(false);
 	stop->set_pressed(true);
 }
@@ -1155,7 +1155,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set, bool
 
 			player->seek_delta(pos, pos - cpos);
 		} else {
-			player->stop(true);
+			player->stop();
 			player->seek(pos, true);
 		}
 	}

+ 22 - 13
scene/animation/animation_player.cpp

@@ -1731,18 +1731,12 @@ String AnimationPlayer::get_assigned_animation() const {
 	return playback.assigned;
 }
 
-void AnimationPlayer::stop(bool p_reset) {
-	_stop_playing_caches();
-	Playback &c = playback;
-	c.blend.clear();
-	if (p_reset) {
-		c.current.from = nullptr;
-		c.current.speed_scale = 1;
-		c.current.pos = 0;
-	}
-	_set_process(false);
-	queued.clear();
-	playing = false;
+void AnimationPlayer::pause() {
+	_stop_internal(false);
+}
+
+void AnimationPlayer::stop() {
+	_stop_internal(true);
 }
 
 void AnimationPlayer::set_speed_scale(float p_speed) {
@@ -1957,6 +1951,20 @@ void AnimationPlayer::_set_process(bool p_process, bool p_force) {
 	processing = p_process;
 }
 
+void AnimationPlayer::_stop_internal(bool p_reset) {
+	_stop_playing_caches();
+	Playback &c = playback;
+	c.blend.clear();
+	if (p_reset) {
+		c.current.from = nullptr;
+		c.current.speed_scale = 1;
+		c.current.pos = 0;
+	}
+	_set_process(false);
+	queued.clear();
+	playing = false;
+}
+
 void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) {
 	ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation));
 	animation_set[p_animation].next = p_next;
@@ -2119,7 +2127,8 @@ void AnimationPlayer::_bind_methods() {
 
 	ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
 	ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1));
-	ClassDB::bind_method(D_METHOD("stop", "reset"), &AnimationPlayer::stop, DEFVAL(true));
+	ClassDB::bind_method(D_METHOD("pause"), &AnimationPlayer::pause);
+	ClassDB::bind_method(D_METHOD("stop"), &AnimationPlayer::stop);
 	ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing);
 
 	ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation);

+ 3 - 1
scene/animation/animation_player.h

@@ -294,6 +294,7 @@ private:
 	void _animation_changed(const StringName &p_name);
 
 	void _set_process(bool p_process, bool p_force = false);
+	void _stop_internal(bool p_reset);
 
 	bool playing = false;
 
@@ -346,7 +347,8 @@ public:
 	void queue(const StringName &p_name);
 	Vector<String> get_queue();
 	void clear_queue();
-	void stop(bool p_reset = true);
+	void pause();
+	void stop();
 	bool is_playing() const;
 	String get_current_animation() const;
 	void set_current_animation(const String &p_anim);