Browse Source

Merge pull request #15696 from bojidar-bg/15646-assigned-animation

Fix an issue with the animation editor not seeking to the target time
Rémi Verschelde 7 years ago
parent
commit
05b1843818

+ 3 - 0
doc/classes/AnimationPlayer.xml

@@ -208,6 +208,9 @@
 		</method>
 		</method>
 	</methods>
 	</methods>
 	<members>
 	<members>
+		<member name="assigned_animation" type="String" setter="set_assigned_animation" getter="get_assigned_animation">
+			If playing, the current animation; otherwise, the animation last played. When set, would change the animation, but would not play it unless currently playing. See also [member current_animation].
+		</member>
 		<member name="autoplay" type="String" setter="set_autoplay" getter="get_autoplay">
 		<member name="autoplay" type="String" setter="set_autoplay" getter="get_autoplay">
 			The name of the animation to play when the scene loads. Default value: [code]""[/code].
 			The name of the animation to play when the scene loads. Default value: [code]""[/code].
 		</member>
 		</member>

+ 11 - 13
editor/plugins/animation_player_editor_plugin.cpp

@@ -73,7 +73,7 @@ void AnimationPlayerEditor::_notification(int p_what) {
 			if (player->is_playing()) {
 			if (player->is_playing()) {
 
 
 				{
 				{
-					String animname = player->get_current_animation();
+					String animname = player->get_assigned_animation();
 
 
 					if (player->has_animation(animname)) {
 					if (player->has_animation(animname)) {
 						Ref<Animation> anim = player->get_animation(animname);
 						Ref<Animation> anim = player->get_animation(animname);
@@ -186,7 +186,7 @@ void AnimationPlayerEditor::_play_pressed() {
 
 
 	if (current != "") {
 	if (current != "") {
 
 
-		if (current == player->get_current_animation())
+		if (current == player->get_assigned_animation())
 			player->stop(); //so it wont blend with itself
 			player->stop(); //so it wont blend with itself
 		player->play(current);
 		player->play(current);
 	}
 	}
@@ -209,7 +209,7 @@ void AnimationPlayerEditor::_play_from_pressed() {
 
 
 		float time = player->get_current_animation_position();
 		float time = player->get_current_animation_position();
 
 
-		if (current == player->get_current_animation() && player->is_playing()) {
+		if (current == player->get_assigned_animation() && player->is_playing()) {
 
 
 			player->stop(); //so it wont blend with itself
 			player->stop(); //so it wont blend with itself
 		}
 		}
@@ -234,7 +234,7 @@ void AnimationPlayerEditor::_play_bw_pressed() {
 
 
 	if (current != "") {
 	if (current != "") {
 
 
-		if (current == player->get_current_animation())
+		if (current == player->get_assigned_animation())
 			player->stop(); //so it wont blend with itself
 			player->stop(); //so it wont blend with itself
 		player->play(current, -1, -1, true);
 		player->play(current, -1, -1, true);
 	}
 	}
@@ -256,7 +256,7 @@ void AnimationPlayerEditor::_play_bw_from_pressed() {
 	if (current != "") {
 	if (current != "") {
 
 
 		float time = player->get_current_animation_position();
 		float time = player->get_current_animation_position();
-		if (current == player->get_current_animation())
+		if (current == player->get_assigned_animation())
 			player->stop(); //so it wont blend with itself
 			player->stop(); //so it wont blend with itself
 
 
 		player->play(current, -1, -1, true);
 		player->play(current, -1, -1, true);
@@ -299,7 +299,7 @@ void AnimationPlayerEditor::_animation_selected(int p_which) {
 
 
 	if (current != "") {
 	if (current != "") {
 
 
-		// player->set_current_animation(current, false);
+		player->set_assigned_animation(current);
 
 
 		Ref<Animation> anim = player->get_animation(current);
 		Ref<Animation> anim = player->get_animation(current);
 		{
 		{
@@ -654,9 +654,7 @@ Dictionary AnimationPlayerEditor::get_state() const {
 	d["visible"] = is_visible_in_tree();
 	d["visible"] = is_visible_in_tree();
 	if (EditorNode::get_singleton()->get_edited_scene() && is_visible_in_tree() && player) {
 	if (EditorNode::get_singleton()->get_edited_scene() && is_visible_in_tree() && player) {
 		d["player"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(player);
 		d["player"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(player);
-	}
-	if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) {
-		d["animation"] = animation->get_item_text(animation->get_selected());
+		d["animation"] = player->get_assigned_animation();
 	}
 	}
 
 
 	return d;
 	return d;
@@ -784,7 +782,7 @@ void AnimationPlayerEditor::_update_animation() {
 	}
 	}
 
 
 	scale->set_text(String::num(player->get_speed_scale(), 2));
 	scale->set_text(String::num(player->get_speed_scale(), 2));
-	String current = player->get_current_animation();
+	String current = player->get_assigned_animation();
 
 
 	for (int i = 0; i < animation->get_item_count(); i++) {
 	for (int i = 0; i < animation->get_item_count(); i++) {
 
 
@@ -831,7 +829,7 @@ void AnimationPlayerEditor::_update_player() {
 		else
 		else
 			animation->add_item(E->get());
 			animation->add_item(E->get());
 
 
-		if (player->get_current_animation() == E->get())
+		if (player->get_assigned_animation() == E->get())
 			active_idx = animation->get_item_count() - 1;
 			active_idx = animation->get_item_count() - 1;
 	}
 	}
 
 
@@ -988,7 +986,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) {
 	};
 	};
 
 
 	updating = true;
 	updating = true;
-	String current = player->get_current_animation(); //animation->get_item_text( animation->get_selected() );
+	String current = player->get_assigned_animation(); //animation->get_item_text( animation->get_selected() );
 	if (current == "" || !player->has_animation(current)) {
 	if (current == "" || !player->has_animation(current)) {
 		updating = false;
 		updating = false;
 		current = "";
 		current = "";
@@ -1338,7 +1336,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_1() {
 
 
 void AnimationPlayerEditor::_prepare_onion_layers_2() {
 void AnimationPlayerEditor::_prepare_onion_layers_2() {
 
 
-	Ref<Animation> anim = player->get_animation(player->get_current_animation());
+	Ref<Animation> anim = player->get_animation(player->get_assigned_animation());
 	if (!anim.is_valid())
 	if (!anim.is_valid())
 		return;
 		return;
 
 

+ 21 - 7
scene/animation/animation_player.cpp

@@ -977,6 +977,7 @@ bool AnimationPlayer::is_playing() const {
 	return true;
 	return true;
 	*/
 	*/
 }
 }
+
 void AnimationPlayer::set_current_animation(const String &p_anim) {
 void AnimationPlayer::set_current_animation(const String &p_anim) {
 
 
 	if (p_anim == "[stop]" || p_anim == "") {
 	if (p_anim == "[stop]" || p_anim == "") {
@@ -986,13 +987,6 @@ void AnimationPlayer::set_current_animation(const String &p_anim) {
 	} else {
 	} else {
 		// Same animation, do not replay from start
 		// Same animation, do not replay from start
 	}
 	}
-
-	/*
-	ERR_FAIL_COND(!animation_set.has(p_anim));
-	playback.current.pos = 0;
-	playback.current.from = &animation_set[p_anim];
-	playback.assigned = p_anim;
-	*/
 }
 }
 
 
 String AnimationPlayer::get_current_animation() const {
 String AnimationPlayer::get_current_animation() const {
@@ -1000,6 +994,23 @@ String AnimationPlayer::get_current_animation() const {
 	return (is_playing() ? playback.assigned : "");
 	return (is_playing() ? playback.assigned : "");
 }
 }
 
 
+void AnimationPlayer::set_assigned_animation(const String &p_anim) {
+
+	if (is_playing()) {
+		play(p_anim);
+	} else {
+		ERR_FAIL_COND(!animation_set.has(p_anim));
+		playback.current.pos = 0;
+		playback.current.from = &animation_set[p_anim];
+		playback.assigned = p_anim;
+	}
+}
+
+String AnimationPlayer::get_assigned_animation() const {
+
+	return playback.assigned;
+}
+
 void AnimationPlayer::stop(bool p_reset) {
 void AnimationPlayer::stop(bool p_reset) {
 
 
 	Playback &c = playback;
 	Playback &c = playback;
@@ -1301,6 +1312,8 @@ void AnimationPlayer::_bind_methods() {
 
 
 	ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation);
 	ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation);
 	ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation);
 	ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation);
+	ClassDB::bind_method(D_METHOD("set_assigned_animation", "anim"), &AnimationPlayer::set_assigned_animation);
+	ClassDB::bind_method(D_METHOD("get_assigned_animation"), &AnimationPlayer::get_assigned_animation);
 	ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue);
 	ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue);
 	ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue);
 	ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue);
 
 
@@ -1331,6 +1344,7 @@ void AnimationPlayer::_bind_methods() {
 
 
 	ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root");
 	ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root");
 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER), "set_current_animation", "get_current_animation");
 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER), "set_current_animation", "get_current_animation");
+	ADD_PROPERTY(PropertyInfo(Variant::STRING, "assigned_animation", PROPERTY_HINT_NONE, "", 0), "set_assigned_animation", "get_assigned_animation");
 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_autoplay", "get_autoplay");
 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_autoplay", "get_autoplay");
 	ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_length", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_length");
 	ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_length", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_length");
 	ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position");
 	ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position");

+ 2 - 0
scene/animation/animation_player.h

@@ -284,6 +284,8 @@ public:
 	bool is_playing() const;
 	bool is_playing() const;
 	String get_current_animation() const;
 	String get_current_animation() const;
 	void set_current_animation(const String &p_anim);
 	void set_current_animation(const String &p_anim);
+	String get_assigned_animation() const;
+	void set_assigned_animation(const String &p_anim);
 	void stop_all();
 	void stop_all();
 	void set_active(bool p_active);
 	void set_active(bool p_active);
 	bool is_active() const;
 	bool is_active() const;