| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  animation_player_editor_plugin.cpp                                   */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                    http://www.godotengine.org                         */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-01-01 22:01:57 +01:00
										 |  |  | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							| 
									
										
										
										
											2017-04-08 00:11:42 +02:00
										 |  |  | /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md)    */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | #include "animation_player_editor_plugin.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-16 08:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "editor/animation_editor.h"
 | 
					
						
							|  |  |  | #include "editor/editor_settings.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "io/resource_loader.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | #include "io/resource_saver.h"
 | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | #include "os/keyboard.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-30 22:53:40 +02:00
										 |  |  | #include "project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_node_removed(Node *p_node) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (player && player == p_node) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player = NULL; | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		set_process(false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		key_editor->set_animation(Ref<Animation>()); | 
					
						
							|  |  |  | 		key_editor->set_root(NULL); | 
					
						
							| 
									
										
										
										
											2016-07-22 09:42:12 -03:00
										 |  |  | 		key_editor->show_select_node_warning(true); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		_update_player(); | 
					
						
							|  |  |  | 		//editor->animation_editor_make_visible(false);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | void AnimationPlayerEditor::_gui_input(Ref<InputEvent> p_event) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_PROCESS) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!player) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		updating = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (player->is_playing()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				String animname = player->get_current_animation(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if (player->has_animation(animname)) { | 
					
						
							|  |  |  | 					Ref<Animation> anim = player->get_animation(animname); | 
					
						
							|  |  |  | 					if (!anim.is_null()) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 						frame->set_max(anim->get_length()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 			frame->set_value(player->get_current_animation_pos()); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 			key_editor->set_anim_pos(player->get_current_animation_pos()); | 
					
						
							| 
									
										
										
										
											2015-01-03 15:39:01 -03:00
										 |  |  | 			EditorNode::get_singleton()->get_property_editor()->refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} else if (last_active) { | 
					
						
							|  |  |  | 			//need the last frame after it stopped
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 			frame->set_value(player->get_current_animation_pos()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		last_active = player->is_playing(); | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 		//seek->set_val(player->get_position());
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		updating = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_ENTER_TREE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 		//editor->connect("hide_animation_player_editors",this,"_hide_anim_editors");
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		add_anim->set_icon(get_icon("New", "EditorIcons")); | 
					
						
							|  |  |  | 		rename_anim->set_icon(get_icon("Rename", "EditorIcons")); | 
					
						
							|  |  |  | 		duplicate_anim->set_icon(get_icon("Duplicate", "EditorIcons")); | 
					
						
							|  |  |  | 		autoplay->set_icon(get_icon("AutoPlay", "EditorIcons")); | 
					
						
							|  |  |  | 		load_anim->set_icon(get_icon("Folder", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 		save_anim->set_icon(get_icon("Save", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2017-01-08 18:18:54 -03:00
										 |  |  | 		save_anim->get_popup()->connect("id_pressed", this, "_animation_save_menu"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		remove_anim->set_icon(get_icon("Remove", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		blend_anim->set_icon(get_icon("Blend", "EditorIcons")); | 
					
						
							|  |  |  | 		play->set_icon(get_icon("PlayStart", "EditorIcons")); | 
					
						
							|  |  |  | 		play_from->set_icon(get_icon("Play", "EditorIcons")); | 
					
						
							|  |  |  | 		play_bw->set_icon(get_icon("PlayStartBackwards", "EditorIcons")); | 
					
						
							|  |  |  | 		play_bw_from->set_icon(get_icon("PlayBackwards", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		autoplay_icon = get_icon("AutoPlay", "EditorIcons"); | 
					
						
							|  |  |  | 		stop->set_icon(get_icon("Stop", "EditorIcons")); | 
					
						
							|  |  |  | 		resource_edit_anim->set_icon(get_icon("EditResource", "EditorIcons")); | 
					
						
							|  |  |  | 		pin->set_icon(get_icon("Pin", "EditorIcons")); | 
					
						
							|  |  |  | 		tool_anim->set_icon(get_icon("Tools", "EditorIcons")); | 
					
						
							|  |  |  | 		tool_anim->get_popup()->connect("id_pressed", this, "_animation_tool_menu"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 17:27:52 +01:00
										 |  |  | 		blend_editor.next->connect("item_selected", this, "_blend_editor_next_changed"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 06:02:06 +09:00
										 |  |  | 		/*
 | 
					
						
							|  |  |  | 		anim_editor_load->set_normal_texture( get_icon("AnimGet","EditorIcons")); | 
					
						
							|  |  |  | 		anim_editor_store->set_normal_texture( get_icon("AnimSet","EditorIcons")); | 
					
						
							|  |  |  | 		anim_editor_load->set_pressed_texture( get_icon("AnimGet","EditorIcons")); | 
					
						
							|  |  |  | 		anim_editor_store->set_pressed_texture( get_icon("AnimSet","EditorIcons")); | 
					
						
							|  |  |  | 		anim_editor_load->set_hover_texture( get_icon("AnimGetHl","EditorIcons")); | 
					
						
							|  |  |  | 		anim_editor_store->set_hover_texture( get_icon("AnimSetHl","EditorIcons")); | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		get_tree()->connect("node_removed", this, "_node_removed"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_autoplay_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (updating) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_item_count() == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 	if (player->get_autoplay() == current) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		//unset
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		undo_redo->create_action(TTR("Toggle Autoplay")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(player, "set_autoplay", ""); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(player, "set_autoplay", player->get_autoplay()); | 
					
						
							|  |  |  | 		undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		//set
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		undo_redo->create_action(TTR("Toggle Autoplay")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(player, "set_autoplay", current); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(player, "set_autoplay", player->get_autoplay()); | 
					
						
							|  |  |  | 		undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		undo_redo->commit_action(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_play_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (current != "") { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (current == player->get_current_animation()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			player->stop(); //so it wont blend with itself
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player->play(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//unstop
 | 
					
						
							|  |  |  | 	stop->set_pressed(false); | 
					
						
							|  |  |  | 	//unpause
 | 
					
						
							|  |  |  | 	//pause->set_pressed(false);
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_play_from_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (current != "") { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		float time = player->get_current_animation_pos(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (current == player->get_current_animation() && player->is_playing()) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			player->stop(); //so it wont blend with itself
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player->play(current); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 		player->seek(time); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//unstop
 | 
					
						
							|  |  |  | 	stop->set_pressed(false); | 
					
						
							|  |  |  | 	//unpause
 | 
					
						
							|  |  |  | 	//pause->set_pressed(false);
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_play_bw_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (current != "") { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (current == player->get_current_animation()) | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			player->stop(); //so it wont blend with itself
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player->play(current, -1, -1, true); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//unstop
 | 
					
						
							|  |  |  | 	stop->set_pressed(false); | 
					
						
							|  |  |  | 	//unpause
 | 
					
						
							|  |  |  | 	//pause->set_pressed(false);
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_play_bw_from_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (current != "") { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		float time = player->get_current_animation_pos(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (current == player->get_current_animation()) | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			player->stop(); //so it wont blend with itself
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player->play(current, -1, -1, true); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 		player->seek(time); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//unstop
 | 
					
						
							|  |  |  | 	stop->set_pressed(false); | 
					
						
							|  |  |  | 	//unpause
 | 
					
						
							|  |  |  | 	//pause->set_pressed(false);
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void AnimationPlayerEditor::_stop_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 17:49:43 +02:00
										 |  |  | 	if (!player) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	player->stop(false); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	play->set_pressed(false); | 
					
						
							|  |  |  | 	stop->set_pressed(true); | 
					
						
							|  |  |  | 	//pause->set_pressed(false);
 | 
					
						
							|  |  |  | 	//player->set_pause(false);
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_pause_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//player->set_pause( pause->is_pressed() );
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_selected(int p_which) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (updating) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	// when selecting an animation, the idea is that the only interesting behavior
 | 
					
						
							|  |  |  | 	// ui-wise is that it should play/blend the next one if currently playing
 | 
					
						
							|  |  |  | 	String current; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (current != "") { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player->set_current_animation(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			key_editor->set_animation(anim); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			Node *root = player->get_node(player->get_root()); | 
					
						
							|  |  |  | 			if (root) { | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 				key_editor->set_root(root); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		frame->set_max(anim->get_length()); | 
					
						
							|  |  |  | 		if (anim->get_step()) | 
					
						
							|  |  |  | 			frame->set_step(anim->get_step()); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			frame->set_step(0.00001); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		key_editor->set_animation(Ref<Animation>()); | 
					
						
							|  |  |  | 		key_editor->set_root(NULL); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	autoplay->set_pressed(current == player->get_autoplay()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_new() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	renaming = false; | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	name_title->set_text(TTR("New Animation Name:")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int count = 1; | 
					
						
							|  |  |  | 	String base = TTR("New Anim"); | 
					
						
							|  |  |  | 	while (true) { | 
					
						
							|  |  |  | 		String attempt = base; | 
					
						
							|  |  |  | 		if (count > 1) | 
					
						
							|  |  |  | 			attempt += " (" + itos(count) + ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (player->has_animation(attempt)) { | 
					
						
							|  |  |  | 			count++; | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		base = attempt; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	name->set_text(base); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	name_dialog->popup_centered(Size2(300, 90)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	name->select_all(); | 
					
						
							|  |  |  | 	name->grab_focus(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_rename() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_item_count() == 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	int selected = animation->get_selected(); | 
					
						
							|  |  |  | 	String selected_name = animation->get_item_text(selected); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	name_title->set_text(TTR("Change Animation Name:")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	name->set_text(selected_name); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	renaming = true; | 
					
						
							|  |  |  | 	name_dialog->popup_centered(Size2(300, 90)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	name->select_all(); | 
					
						
							|  |  |  | 	name->grab_focus(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_load() { | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!player); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	file->set_mode(EditorFileDialog::MODE_OPEN_FILE); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	file->clear_filters(); | 
					
						
							|  |  |  | 	List<String> extensions; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ResourceLoader::get_recognized_extensions_for_type("Animation", &extensions); | 
					
						
							|  |  |  | 	for (List<String>::Element *E = extensions.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		file->add_filter("*." + E->get() + " ; " + E->get().to_upper()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	file->popup_centered_ratio(); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	current_option = RESOURCE_LOAD; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path) { | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int flg = 0; | 
					
						
							| 
									
										
										
										
											2017-01-05 19:41:36 -03:00
										 |  |  | 	if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 		flg |= ResourceSaver::FLAG_COMPRESS; | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	if (EditorSettings::get_singleton()->get("filesystem/on_save/save_paths_as_relative")) | 
					
						
							|  |  |  | 		flg |= ResourceSaver::FLAG_RELATIVE_PATHS; | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | 	String path = ProjectSettings::get_singleton()->localize_path(p_path); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (err != OK) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		accept->set_text(TTR("Error saving resource!")); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 		accept->popup_centered_minsize(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 	//EditorFileSystem::get_singleton()->update_file(path,p_resource->get_type());
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	((Resource *)p_resource.ptr())->set_path(path); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	editor->emit_signal("resource_saved", p_resource); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::_animation_save(const Ref<Resource> &p_resource) { | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_resource->get_path().is_resource_file()) { | 
					
						
							|  |  |  | 		_animation_save_in_path(p_resource, p_resource->get_path()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 		_animation_save_as(p_resource); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource) { | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	file->set_mode(EditorFileDialog::MODE_SAVE_FILE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<String> extensions; | 
					
						
							|  |  |  | 	ResourceSaver::get_recognized_extensions(p_resource, &extensions); | 
					
						
							|  |  |  | 	file->clear_filters(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < extensions.size(); i++) { | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	//file->set_current_path(current_path);
 | 
					
						
							|  |  |  | 	if (p_resource->get_path() != "") { | 
					
						
							|  |  |  | 		file->set_current_path(p_resource->get_path()); | 
					
						
							|  |  |  | 		if (extensions.size()) { | 
					
						
							| 
									
										
										
										
											2017-01-14 00:51:09 -03:00
										 |  |  | 			String ext = p_resource->get_path().get_extension().to_lower(); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 			if (extensions.find(ext) == NULL) { | 
					
						
							|  |  |  | 				file->set_current_path(p_resource->get_path().replacen("." + ext, "." + extensions.front()->get())); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 		String existing; | 
					
						
							|  |  |  | 		if (extensions.size()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (p_resource->get_name() != "") { | 
					
						
							| 
									
										
										
										
											2017-01-14 14:45:42 -05:00
										 |  |  | 				existing = p_resource->get_name() + "." + extensions.front()->get().to_lower(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-14 14:45:42 -05:00
										 |  |  | 				existing = "new_" + p_resource->get_class().to_lower() + "." + extensions.front()->get().to_lower(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		file->set_current_path(existing); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	file->popup_centered_ratio(); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	file->set_title(TTR("Save Resource As..")); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	current_option = RESOURCE_SAVE; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-25 21:22:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void AnimationPlayerEditor::_animation_remove() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 21:22:16 +01:00
										 |  |  | 	if (animation->get_item_count() == 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 21:22:16 +01:00
										 |  |  | 	delete_dialog->set_text(TTR("Delete Animation?")); | 
					
						
							|  |  |  | 	delete_dialog->popup_centered_minsize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_remove_confirmed() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 21:22:16 +01:00
										 |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 	Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Remove Animation")); | 
					
						
							| 
									
										
										
										
											2017-01-25 21:22:16 +01:00
										 |  |  | 	undo_redo->add_do_method(player, "remove_animation", current); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(player, "add_animation", current, anim); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::_select_anim_by_name(const String &p_anim) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int idx = -1; | 
					
						
							|  |  |  | 	for (int i = 0; i < animation->get_item_count(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (animation->get_item_text(i) == p_anim) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			idx = i; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND(idx == -1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	animation->select(idx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_animation_selected(idx); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_name_edited() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	player->stop(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String new_name = name->get_text(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (new_name == "" || new_name.find(":") != -1 || new_name.find("/") != -1) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		error_dialog->set_text(TTR("ERROR: Invalid animation name!")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 		error_dialog->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (renaming && animation->get_item_count() > 0 && animation->get_item_text(animation->get_selected()) == new_name) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		name_dialog->hide(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (player->has_animation(new_name)) { | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 		error_dialog->set_text(TTR("ERROR: Animation name already exists!")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 		error_dialog->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (renaming) { | 
					
						
							|  |  |  | 		String current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		undo_redo->create_action(TTR("Rename Animation")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(player, "rename_animation", current, new_name); | 
					
						
							|  |  |  | 		undo_redo->add_do_method(anim.ptr(), "set_name", new_name); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(player, "rename_animation", new_name, current); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(anim.ptr(), "set_name", current); | 
					
						
							|  |  |  | 		undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		_select_anim_by_name(new_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<Animation> new_anim = Ref<Animation>(memnew(Animation)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		new_anim->set_name(new_name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		undo_redo->create_action(TTR("Add Animation")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(player, "add_animation", new_name, new_anim); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(player, "remove_animation", new_name); | 
					
						
							|  |  |  | 		undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		_select_anim_by_name(new_name); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	name_dialog->hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 17:27:52 +01:00
										 |  |  | void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_item_count() == 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 17:27:52 +01:00
										 |  |  | 	undo_redo->create_action(TTR("Blend Next Changed")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(player, "animation_set_next", current, blend_editor.next->get_item_text(p_idx)); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(player, "animation_set_next", current, player->animation_get_next(current)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2016-05-07 17:27:52 +01:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_blend() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (updating_blends) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	blend_editor.tree->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_item_count() == 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_editor.dialog->popup_centered(Size2(400, 400)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	blend_editor.tree->set_hide_root(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_editor.tree->set_column_min_width(0, 10); | 
					
						
							|  |  |  | 	blend_editor.tree->set_column_min_width(1, 3); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	List<StringName> anims; | 
					
						
							|  |  |  | 	player->get_animation_list(&anims); | 
					
						
							|  |  |  | 	TreeItem *root = blend_editor.tree->create_item(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating_blends = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 17:27:52 +01:00
										 |  |  | 	int i = 0; | 
					
						
							|  |  |  | 	bool anim_found = false; | 
					
						
							|  |  |  | 	blend_editor.next->clear(); | 
					
						
							|  |  |  | 	blend_editor.next->add_item("", i); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		String to = E->get(); | 
					
						
							|  |  |  | 		TreeItem *blend = blend_editor.tree->create_item(root); | 
					
						
							|  |  |  | 		blend->set_editable(0, false); | 
					
						
							|  |  |  | 		blend->set_editable(1, true); | 
					
						
							|  |  |  | 		blend->set_text(0, to); | 
					
						
							|  |  |  | 		blend->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); | 
					
						
							|  |  |  | 		blend->set_range_config(1, 0, 3600, 0.001); | 
					
						
							|  |  |  | 		blend->set_range(1, player->get_blend_time(current, to)); | 
					
						
							| 
									
										
										
										
											2016-05-07 17:27:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 		blend_editor.next->add_item(to, i); | 
					
						
							|  |  |  | 		if (to == player->animation_get_next(current)) { | 
					
						
							|  |  |  | 			blend_editor.next->select(i); | 
					
						
							|  |  |  | 			anim_found = true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 17:27:52 +01:00
										 |  |  | 	// make sure we reset it else it becomes out of sync and could contain a deleted animation
 | 
					
						
							|  |  |  | 	if (!anim_found) { | 
					
						
							|  |  |  | 		blend_editor.next->select(0); | 
					
						
							|  |  |  | 		player->animation_set_next(current, blend_editor.next->get_item_text(0)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating_blends = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_blend_edited() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (updating_blends) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (animation->get_item_count() == 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *selected = blend_editor.tree->get_edited(); | 
					
						
							|  |  |  | 	if (!selected) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating_blends = true; | 
					
						
							|  |  |  | 	String to = selected->get_text(0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	float blend_time = selected->get_range(1); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	float prev_blend_time = player->get_blend_time(current, to); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Change Blend Time")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(player, "set_blend_time", current, to, blend_time); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(player, "set_blend_time", current, to, prev_blend_time); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating_blends = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::ensure_visibility() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 11:37:58 +02:00
										 |  |  | 	if (player && pin->is_pressed()) | 
					
						
							|  |  |  | 		return; // another player is pinned, don't reset
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	_animation_edit(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 22:59:25 -03:00
										 |  |  | Dictionary AnimationPlayerEditor::get_state() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary d; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	d["visible"] = is_visible_in_tree(); | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 	if (EditorNode::get_singleton()->get_edited_scene() && is_visible_in_tree() && player) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		d["player"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(player); | 
					
						
							|  |  |  | 		d["animation"] = player->get_current_animation(); | 
					
						
							| 
									
										
										
										
											2015-08-29 22:59:25 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return d; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::set_state(const Dictionary &p_state) { | 
					
						
							| 
									
										
										
										
											2015-08-29 22:59:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_state.has("visible") && p_state["visible"]) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-21 11:52:11 -03:00
										 |  |  | 		if (!EditorNode::get_singleton()->get_edited_scene()) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 22:59:25 -03:00
										 |  |  | 		Node *n = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["player"]); | 
					
						
							| 
									
										
										
										
											2016-10-13 12:31:45 +02:00
										 |  |  | 		if (n && n->cast_to<AnimationPlayer>() && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			player = n->cast_to<AnimationPlayer>(); | 
					
						
							| 
									
										
										
										
											2015-08-29 22:59:25 -03:00
										 |  |  | 			_update_player(); | 
					
						
							|  |  |  | 			show(); | 
					
						
							|  |  |  | 			set_process(true); | 
					
						
							|  |  |  | 			ensure_visibility(); | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 			//EditorNode::get_singleton()->animation_panel_make_visible(true);
 | 
					
						
							| 
									
										
										
										
											2015-08-29 22:59:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (p_state.has("animation")) { | 
					
						
							|  |  |  | 				String anim = p_state["animation"]; | 
					
						
							|  |  |  | 				_select_anim_by_name(anim); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 				_animation_edit(); | 
					
						
							| 
									
										
										
										
											2015-08-29 22:59:25 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void AnimationPlayerEditor::_animation_resource_edit() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (animation->get_item_count()) { | 
					
						
							|  |  |  | 		String current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		editor->edit_resource(anim); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_edit() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	if (animation->get_item_count()) { | 
					
						
							|  |  |  | 		String current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		key_editor->set_animation(anim); | 
					
						
							|  |  |  | 		Node *root = player->get_node(player->get_root()); | 
					
						
							|  |  |  | 		if (root) { | 
					
						
							|  |  |  | 			key_editor->set_root(root); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		key_editor->set_animation(Ref<Animation>()); | 
					
						
							|  |  |  | 		key_editor->set_root(NULL); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | void AnimationPlayerEditor::_dialog_action(String p_file) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	switch (current_option) { | 
					
						
							|  |  |  | 		case RESOURCE_LOAD: { | 
					
						
							|  |  |  | 			ERR_FAIL_COND(!player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 			Ref<Resource> res = ResourceLoader::load(p_file, "Animation"); | 
					
						
							|  |  |  | 			ERR_FAIL_COND(res.is_null()); | 
					
						
							| 
									
										
										
										
											2017-01-02 23:03:46 -03:00
										 |  |  | 			ERR_FAIL_COND(!res->is_class("Animation")); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 			if (p_file.find_last("/") != -1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 				p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length()); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (p_file.find_last("\\") != -1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 				p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length()); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 			if (p_file.find(".") != -1) | 
					
						
							|  |  |  | 				p_file = p_file.substr(0, p_file.find(".")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 			undo_redo->create_action(TTR("Load Animation")); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 			undo_redo->add_do_method(player, "add_animation", p_file, res); | 
					
						
							|  |  |  | 			undo_redo->add_undo_method(player, "remove_animation", p_file); | 
					
						
							|  |  |  | 			if (player->has_animation(p_file)) { | 
					
						
							|  |  |  | 				undo_redo->add_undo_method(player, "add_animation", p_file, player->get_animation(p_file)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 			undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 			undo_redo->commit_action(); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case RESOURCE_SAVE: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 			if (current != "") { | 
					
						
							|  |  |  | 				Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 				ERR_FAIL_COND(!anim->cast_to<Resource>()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				RES current_res = RES(anim->cast_to<Resource>()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 				_animation_save_in_path(current_res, p_file); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::_scale_changed(const String &p_scale) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 19:36:04 -03:00
										 |  |  | 	player->set_speed_scale(p_scale.to_double()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_update_animation() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// the purpose of _update_animation is to reflect the current state
 | 
					
						
							|  |  |  | 	// of the animation player in the current editor..
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (player->is_playing()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		play->set_pressed(true); | 
					
						
							|  |  |  | 		stop->set_pressed(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		play->set_pressed(false); | 
					
						
							|  |  |  | 		stop->set_pressed(true); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	scale->set_text(String::num(player->get_speed_scale(), 2)); | 
					
						
							|  |  |  | 	String current = player->get_current_animation(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < animation->get_item_count(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (animation->get_item_text(i) == current) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			animation->select(i); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_update_player() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	List<StringName> animlist; | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	if (player) | 
					
						
							|  |  |  | 		player->get_animation_list(&animlist); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	animation->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	add_anim->set_disabled(player == NULL); | 
					
						
							|  |  |  | 	load_anim->set_disabled(player == NULL); | 
					
						
							|  |  |  | 	stop->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	play->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	play_bw->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	play_bw_from->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	play_from->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	autoplay->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	duplicate_anim->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	rename_anim->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	blend_anim->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	remove_anim->set_disabled(animlist.size() == 0); | 
					
						
							|  |  |  | 	resource_edit_anim->set_disabled(animlist.size() == 0); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	save_anim->set_disabled(animlist.size() == 0); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tool_anim->set_disabled(player == NULL); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int active_idx = -1; | 
					
						
							|  |  |  | 	for (List<StringName>::Element *E = animlist.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (player->get_autoplay() == E->get()) | 
					
						
							|  |  |  | 			animation->add_icon_item(autoplay_icon, E->get()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			animation->add_item(E->get()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (player->get_current_animation() == E->get()) | 
					
						
							|  |  |  | 			active_idx = animation->get_item_count() - 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	if (!player) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = false; | 
					
						
							|  |  |  | 	if (active_idx != -1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		animation->select(active_idx); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		autoplay->set_pressed(animation->get_item_text(active_idx) == player->get_autoplay()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		_animation_selected(active_idx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (animation->get_item_count() > 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		animation->select(0); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		autoplay->set_pressed(animation->get_item_text(0) == player->get_autoplay()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		_animation_selected(0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//pause->set_pressed(player->is_paused());
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	if (animation->get_item_count()) { | 
					
						
							|  |  |  | 		String current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		key_editor->set_animation(anim); | 
					
						
							|  |  |  | 		Node *root = player->get_node(player->get_root()); | 
					
						
							|  |  |  | 		if (root) { | 
					
						
							|  |  |  | 			key_editor->set_root(root); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_update_animation(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::edit(AnimationPlayer *p_player) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (player && pin->is_pressed()) | 
					
						
							|  |  |  | 		return; //ignore, pinned
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	player = p_player; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-22 09:42:12 -03:00
										 |  |  | 	if (player) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		_update_player(); | 
					
						
							| 
									
										
										
										
											2016-07-22 09:42:12 -03:00
										 |  |  | 		key_editor->show_select_node_warning(false); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		key_editor->show_select_node_warning(true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 		//hide();
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_duplicate() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!animation->get_item_count()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (!anim.is_valid()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Ref<Animation> new_anim = memnew(Animation); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	List<PropertyInfo> plist; | 
					
						
							|  |  |  | 	anim->get_property_list(&plist); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (E->get().usage & PROPERTY_USAGE_STORAGE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			new_anim->set(E->get().name, anim->get(E->get().name)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	new_anim->set_path(""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String new_name = current; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	while (player->has_animation(new_name)) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		new_name = new_name + " (copy)"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Duplicate Animation")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(player, "add_animation", new_name, new_anim); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(player, "remove_animation", new_name); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(player, "animation_set_next", new_name, player->animation_get_next(current)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < animation->get_item_count(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (animation->get_item_text(i) == new_name) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			animation->select(i); | 
					
						
							|  |  |  | 			_animation_selected(i); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (updating || !player || player->is_playing()) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = true; | 
					
						
							|  |  |  | 	String current = player->get_current_animation(); //animation->get_item_text( animation->get_selected() );
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (current == "" || !player->has_animation(current)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		updating = false; | 
					
						
							|  |  |  | 		current = ""; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<Animation> anim; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	float pos = anim->get_length() * (p_value / frame->get_max()); | 
					
						
							| 
									
										
										
										
											2016-02-09 15:02:57 -05:00
										 |  |  | 	float step = anim->get_step(); | 
					
						
							|  |  |  | 	if (step) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		pos = Math::stepify(pos, step); | 
					
						
							|  |  |  | 		if (pos < 0) | 
					
						
							|  |  |  | 			pos = 0; | 
					
						
							|  |  |  | 		if (pos >= anim->get_length()) | 
					
						
							|  |  |  | 			pos = anim->get_length(); | 
					
						
							| 
									
										
										
										
											2016-02-09 15:02:57 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-19 01:43:02 -03:00
										 |  |  | 	if (player->is_valid() && !p_set) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		float cpos = player->get_current_animation_pos(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player->seek_delta(pos, pos - cpos); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		player->seek(pos, true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	key_editor->set_anim_pos(pos); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (player == p_pl && is_visible_in_tree()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		_update_player(); | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 		if (blend_editor.dialog->is_visible_in_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			_animation_blend(); //update
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_list_changed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (is_visible_in_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		_update_player(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_editor_store() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (animation->get_item_count()==0) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 	Ref<Animation> anim =  player->get_animation(current); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	if (key_editor->get_current_animation()==anim) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; //already there
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	undo_redo->create_action("Store anim in editor"); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	undo_redo->add_do_method(key_editor,"set_animation",anim); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(key_editor,"remove_animation",anim); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_editor_load(){ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	Ref<Animation> anim = key_editor->get_current_animation(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (anim.is_null()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String existing = player->find_animation(anim); | 
					
						
							|  |  |  | 	if (existing!="") { | 
					
						
							|  |  |  | 		_select_anim_by_name(existing); | 
					
						
							|  |  |  | 		return; //already has
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int count=1; | 
					
						
							|  |  |  | 	String base=anim->get_name(); | 
					
						
							|  |  |  | 	bool noname=false; | 
					
						
							|  |  |  | 	if (base=="") { | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 		base="New Anim"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		noname=true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(true) { | 
					
						
							|  |  |  | 		String attempt  = base; | 
					
						
							|  |  |  | 		if (count>1) | 
					
						
							|  |  |  | 			attempt+=" ("+itos(count)+")"; | 
					
						
							|  |  |  | 		if (player->has_animation(attempt)) { | 
					
						
							|  |  |  | 			count++; | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		base=attempt; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (noname) | 
					
						
							|  |  |  | 		anim->set_name(base); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	undo_redo->create_action("Add Animation From Editor"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->add_do_method(player,"add_animation",base,anim); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(player,"remove_animation",base); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this,"_animation_player_changed",player); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this,"_animation_player_changed",player); | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_select_anim_by_name(base); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	frame->set_max(p_len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_animation_key_editor_anim_step_changed(float p_len) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_len) | 
					
						
							|  |  |  | 		frame->set_step(p_len); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		frame->set_step(0.00001); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 	if (!is_visible_in_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	if (!player) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (player->is_playing()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = true; | 
					
						
							|  |  |  | 	frame->set_value(p_pos); | 
					
						
							|  |  |  | 	updating = false; | 
					
						
							|  |  |  | 	_seek_value_changed(p_pos, !p_drag); | 
					
						
							| 
									
										
										
										
											2016-06-19 01:43:02 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-03 15:39:01 -03:00
										 |  |  | 	EditorNode::get_singleton()->get_property_editor()->refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	//seekit
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditor::_hide_anim_editors() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	player = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hide(); | 
					
						
							|  |  |  | 	set_process(false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	key_editor->set_animation(Ref<Animation>()); | 
					
						
							|  |  |  | 	key_editor->set_root(NULL); | 
					
						
							| 
									
										
										
										
											2016-07-22 09:42:12 -03:00
										 |  |  | 	key_editor->show_select_node_warning(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	//editor->animation_editor_make_visible(false);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | void AnimationPlayerEditor::_animation_tool_menu(int p_option) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_option) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case TOOL_COPY_ANIM: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!animation->get_item_count()) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 				error_dialog->set_text(TTR("ERROR: No animation to copy!")); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 				error_dialog->popup_centered_minsize(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			String current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			//editor->edit_resource(anim);
 | 
					
						
							|  |  |  | 			EditorSettings::get_singleton()->set_resource_clipboard(anim); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_PASTE_ANIM: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Ref<Animation> anim = EditorSettings::get_singleton()->get_resource_clipboard(); | 
					
						
							|  |  |  | 			if (!anim.is_valid()) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 				error_dialog->set_text(TTR("ERROR: No animation resource on clipboard!")); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 				error_dialog->popup_centered_minsize(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			String name = anim->get_name(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (name == "") { | 
					
						
							|  |  |  | 				name = TTR("Pasted Animation"); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int idx = 1; | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			String base = name; | 
					
						
							|  |  |  | 			while (player->has_animation(name)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				idx++; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				name = base + " " + itos(idx); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 			undo_redo->create_action(TTR("Paste Animation")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			undo_redo->add_do_method(player, "add_animation", name, anim); | 
					
						
							|  |  |  | 			undo_redo->add_undo_method(player, "remove_animation", name); | 
					
						
							|  |  |  | 			undo_redo->add_do_method(this, "_animation_player_changed", player); | 
					
						
							|  |  |  | 			undo_redo->add_undo_method(this, "_animation_player_changed", player); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			_select_anim_by_name(name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_EDIT_RESOURCE: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!animation->get_item_count()) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 				error_dialog->set_text(TTR("ERROR: No animation to edit!")); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 				error_dialog->popup_centered_minsize(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			String current = animation->get_item_text(animation->get_selected()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			Ref<Animation> anim = player->get_animation(current); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 			editor->edit_resource(anim); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | void AnimationPlayerEditor::_animation_save_menu(int p_option) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String current = animation->get_item_text(animation->get_selected()); | 
					
						
							|  |  |  | 	if (current != "") { | 
					
						
							|  |  |  | 		Ref<Animation> anim = player->get_animation(current); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (p_option) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			case ANIM_SAVE: | 
					
						
							|  |  |  | 				_animation_save(anim); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case ANIM_SAVE_AS: | 
					
						
							|  |  |  | 				_animation_save_as(anim); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventKey> k = p_ev; | 
					
						
							|  |  |  | 	if (is_visible_in_tree() && k.is_valid() && k->is_pressed() && !k->is_echo() && !k->get_alt() && !k->get_control() && !k->get_metakey()) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		switch (k->get_scancode()) { | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			case KEY_A: { | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (!k->get_shift()) | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 					_play_bw_from_pressed(); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					_play_bw_pressed(); | 
					
						
							|  |  |  | 			} break; | 
					
						
							|  |  |  | 			case KEY_S: { | 
					
						
							|  |  |  | 				_stop_pressed(); | 
					
						
							|  |  |  | 			} break; | 
					
						
							|  |  |  | 			case KEY_D: { | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (!k->get_shift()) | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 					_play_from_pressed(); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					_play_pressed(); | 
					
						
							|  |  |  | 			} break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void AnimationPlayerEditor::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_gui_input"), &AnimationPlayerEditor::_gui_input); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationPlayerEditor::_node_removed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_play_pressed"), &AnimationPlayerEditor::_play_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_play_from_pressed"), &AnimationPlayerEditor::_play_from_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_play_bw_pressed"), &AnimationPlayerEditor::_play_bw_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_play_bw_from_pressed"), &AnimationPlayerEditor::_play_bw_from_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_stop_pressed"), &AnimationPlayerEditor::_stop_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_autoplay_pressed"), &AnimationPlayerEditor::_autoplay_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_pause_pressed"), &AnimationPlayerEditor::_pause_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_selected"), &AnimationPlayerEditor::_animation_selected); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_name_edited"), &AnimationPlayerEditor::_animation_name_edited); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_new"), &AnimationPlayerEditor::_animation_new); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_rename"), &AnimationPlayerEditor::_animation_rename); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_load"), &AnimationPlayerEditor::_animation_load); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_remove"), &AnimationPlayerEditor::_animation_remove); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_remove_confirmed"), &AnimationPlayerEditor::_animation_remove_confirmed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_blend"), &AnimationPlayerEditor::_animation_blend); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_edit"), &AnimationPlayerEditor::_animation_edit); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_resource_edit"), &AnimationPlayerEditor::_animation_resource_edit); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_dialog_action"), &AnimationPlayerEditor::_dialog_action); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_seek_value_changed"), &AnimationPlayerEditor::_seek_value_changed, DEFVAL(true)); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_player_changed"), &AnimationPlayerEditor::_animation_player_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_blend_edited"), &AnimationPlayerEditor::_blend_edited); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 	//ClassDB::bind_method(D_METHOD("_seek_frame_changed"),&AnimationPlayerEditor::_seek_frame_changed);
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_scale_changed"), &AnimationPlayerEditor::_scale_changed); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 	//ClassDB::bind_method(D_METHOD("_editor_store_all"),&AnimationPlayerEditor::_editor_store_all);
 | 
					
						
							|  |  |  | 	//ClassDB::bind_method(D_METHOD("_editor_load_all"),&AnimationPlayerEditor::_editor_load_all);
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_list_changed"), &AnimationPlayerEditor::_list_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_key_editor_seek"), &AnimationPlayerEditor::_animation_key_editor_seek); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_len_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_len_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_step_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_step_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_hide_anim_editors"), &AnimationPlayerEditor::_hide_anim_editors); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_duplicate"), &AnimationPlayerEditor::_animation_duplicate); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_blend_editor_next_changed"), &AnimationPlayerEditor::_blend_editor_next_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &AnimationPlayerEditor::_unhandled_key_input); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_tool_menu"), &AnimationPlayerEditor::_animation_tool_menu); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_animation_save_menu"), &AnimationPlayerEditor::_animation_save_menu); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | AnimationPlayerEditor *AnimationPlayerEditor::singleton = NULL; | 
					
						
							| 
									
										
										
										
											2015-12-05 14:18:22 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | AnimationPlayer *AnimationPlayerEditor::get_player() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return player; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	editor = p_editor; | 
					
						
							|  |  |  | 	singleton = this; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	set_focus_mode(FOCUS_ALL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	player = NULL; | 
					
						
							|  |  |  | 	add_style_override("panel", get_stylebox("panel", "Panel")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Label *l; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*l= memnew( Label );
 | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	l->set_text("Animation Player:"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(l);*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(hb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	play_bw_from = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	play_bw_from->set_tooltip(TTR("Play selected animation backwards from current pos. (A)")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	hb->add_child(play_bw_from); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	play_bw = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	play_bw->set_tooltip(TTR("Play selected animation backwards from end. (Shift+A)")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	hb->add_child(play_bw); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	stop = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	stop->set_toggle_mode(true); | 
					
						
							|  |  |  | 	hb->add_child(stop); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	stop->set_tooltip(TTR("Stop animation playback. (S)")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	play = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	play->set_tooltip(TTR("Play selected animation from start. (Shift+D)")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	hb->add_child(play); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	play_from = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	play_from->set_tooltip(TTR("Play selected animation from current pos. (D)")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	hb->add_child(play_from); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//pause = memnew( Button );
 | 
					
						
							|  |  |  | 	//pause->set_toggle_mode(true);
 | 
					
						
							|  |  |  | 	//hb->add_child(pause);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	frame = memnew(SpinBox); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	hb->add_child(frame); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	frame->set_custom_minimum_size(Size2(60, 0)); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	frame->set_stretch_ratio(2); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	frame->set_tooltip(TTR("Animation position (in seconds).")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	hb->add_child(memnew(VSeparator)); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	scale = memnew(LineEdit); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	hb->add_child(scale); | 
					
						
							|  |  |  | 	scale->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	scale->set_stretch_ratio(1); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	scale->set_tooltip(TTR("Scale animation playback globally for the node.")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	scale->hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	add_anim = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-06-11 20:29:12 -05:00
										 |  |  | 	ED_SHORTCUT("animation_player_editor/add_animation", TTR("Create new animation in player.")); | 
					
						
							|  |  |  | 	add_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/add_animation")); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	add_anim->set_tooltip(TTR("Create new animation in player.")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hb->add_child(add_anim); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	load_anim = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-06-11 20:29:12 -05:00
										 |  |  | 	ED_SHORTCUT("animation_player_editor/load_from_disk", TTR("Load animation from disk.")); | 
					
						
							|  |  |  | 	add_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/load_from_disk")); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	load_anim->set_tooltip(TTR("Load an animation from disk.")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hb->add_child(load_anim); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	save_anim = memnew(MenuButton); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	save_anim->set_tooltip(TTR("Save the current animation")); | 
					
						
							| 
									
										
										
										
											2016-06-11 20:29:12 -05:00
										 |  |  | 	save_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/save", TTR("Save")), ANIM_SAVE); | 
					
						
							|  |  |  | 	save_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/save_as", TTR("Save As")), ANIM_SAVE_AS); | 
					
						
							| 
									
										
										
										
											2015-10-19 20:40:24 +01:00
										 |  |  | 	save_anim->set_focus_mode(Control::FOCUS_NONE); | 
					
						
							|  |  |  | 	hb->add_child(save_anim); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	accept = memnew(AcceptDialog); | 
					
						
							|  |  |  | 	add_child(accept); | 
					
						
							|  |  |  | 	accept->connect("confirmed", this, "_menu_confirm_current"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 21:22:16 +01:00
										 |  |  | 	delete_dialog = memnew(ConfirmationDialog); | 
					
						
							|  |  |  | 	add_child(delete_dialog); | 
					
						
							|  |  |  | 	delete_dialog->connect("confirmed", this, "_animation_remove_confirmed"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	duplicate_anim = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hb->add_child(duplicate_anim); | 
					
						
							| 
									
										
										
										
											2016-06-11 20:29:12 -05:00
										 |  |  | 	ED_SHORTCUT("animation_player_editor/duplicate_animation", TTR("Duplicate Animation")); | 
					
						
							|  |  |  | 	duplicate_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/duplicate_animation")); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	duplicate_anim->set_tooltip(TTR("Duplicate Animation")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	rename_anim = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	hb->add_child(rename_anim); | 
					
						
							| 
									
										
										
										
											2016-06-11 20:29:12 -05:00
										 |  |  | 	ED_SHORTCUT("animation_player_editor/rename_animation", TTR("Rename Animation")); | 
					
						
							|  |  |  | 	rename_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/rename_animation")); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	rename_anim->set_tooltip(TTR("Rename Animation")); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	remove_anim = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	hb->add_child(remove_anim); | 
					
						
							| 
									
										
										
										
											2016-06-11 20:29:12 -05:00
										 |  |  | 	ED_SHORTCUT("animation_player_editor/remove_animation", TTR("Remove Animation")); | 
					
						
							|  |  |  | 	remove_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/remove_animation")); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	remove_anim->set_tooltip(TTR("Remove Animation")); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	animation = memnew(OptionButton); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hb->add_child(animation); | 
					
						
							|  |  |  | 	animation->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	animation->set_tooltip(TTR("Display list of animations in player.")); | 
					
						
							| 
									
										
										
										
											2016-06-29 20:11:14 -03:00
										 |  |  | 	animation->set_clip_text(true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	autoplay = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hb->add_child(autoplay); | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	autoplay->set_tooltip(TTR("Autoplay on Load")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_anim = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hb->add_child(blend_anim); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	blend_anim->set_tooltip(TTR("Edit Target Blend Times")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tool_anim = memnew(MenuButton); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	//tool_anim->set_flat(false);
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	tool_anim->set_tooltip(TTR("Animation Tools")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/copy_animation", TTR("Copy Animation")), TOOL_COPY_ANIM); | 
					
						
							|  |  |  | 	tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/paste_animation", TTR("Paste Animation")), TOOL_PASTE_ANIM); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	//tool_anim->get_popup()->add_separator();
 | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	//tool_anim->get_popup()->add_item("Edit Anim Resource",TOOL_PASTE_ANIM);
 | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	hb->add_child(tool_anim); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	pin = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	pin->set_toggle_mode(true); | 
					
						
							|  |  |  | 	hb->add_child(pin); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	resource_edit_anim = memnew(Button); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hb->add_child(resource_edit_anim); | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 	resource_edit_anim->hide(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-06 09:44:38 -03:00
										 |  |  | 	file = memnew(EditorFileDialog); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(file); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	name_dialog = memnew(ConfirmationDialog); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	name_dialog->set_title(TTR("Create New Animation")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	name_dialog->set_hide_on_ok(false); | 
					
						
							|  |  |  | 	add_child(name_dialog); | 
					
						
							| 
									
										
										
										
											2017-06-13 14:04:15 +08:00
										 |  |  | 	VBoxContainer *vb = memnew(VBoxContainer); | 
					
						
							|  |  |  | 	name_dialog->add_child(vb); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	l = memnew(Label); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	l->set_text(TTR("Animation Name:")); | 
					
						
							| 
									
										
										
										
											2017-06-13 14:04:15 +08:00
										 |  |  | 	vb->add_child(l); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	name_title = l; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 14:04:15 +08:00
										 |  |  | 	name = memnew(LineEdit); | 
					
						
							|  |  |  | 	vb->add_child(name); | 
					
						
							|  |  |  | 	name_dialog->register_text_enter(name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	error_dialog = memnew(ConfirmationDialog); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	error_dialog->get_ok()->set_text(TTR("Close")); | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	//error_dialog->get_cancel()->set_text("Close");
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	error_dialog->set_text(TTR("Error!")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(error_dialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	name_dialog->connect("confirmed", this, "_animation_name_edited"); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_editor.dialog = memnew(AcceptDialog); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(blend_editor.dialog); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	blend_editor.dialog->get_ok()->set_text(TTR("Close")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	blend_editor.dialog->set_hide_on_ok(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *blend_vb = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	blend_editor.dialog->add_child(blend_vb); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 	//blend_editor.dialog->set_child_rect(blend_vb);
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_editor.tree = memnew(Tree); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	blend_editor.tree->set_columns(2); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_vb->add_margin_child(TTR("Blend Times:"), blend_editor.tree, true); | 
					
						
							|  |  |  | 	blend_editor.next = memnew(OptionButton); | 
					
						
							|  |  |  | 	blend_vb->add_margin_child(TTR("Next (Auto Queue):"), blend_editor.next); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	blend_editor.dialog->set_title(TTR("Cross-Animation Blend Times")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating_blends = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_editor.tree->connect("item_edited", this, "_blend_edited"); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	autoplay->connect("pressed", this, "_autoplay_pressed"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	autoplay->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	play->connect("pressed", this, "_play_pressed"); | 
					
						
							|  |  |  | 	play_from->connect("pressed", this, "_play_from_pressed"); | 
					
						
							|  |  |  | 	play_bw->connect("pressed", this, "_play_bw_pressed"); | 
					
						
							|  |  |  | 	play_bw_from->connect("pressed", this, "_play_bw_from_pressed"); | 
					
						
							|  |  |  | 	stop->connect("pressed", this, "_stop_pressed"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	//pause->connect("pressed", this,"_pause_pressed");
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	add_anim->connect("pressed", this, "_animation_new"); | 
					
						
							|  |  |  | 	rename_anim->connect("pressed", this, "_animation_rename"); | 
					
						
							|  |  |  | 	load_anim->connect("pressed", this, "_animation_load"); | 
					
						
							|  |  |  | 	duplicate_anim->connect("pressed", this, "_animation_duplicate"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	//frame->connect("text_entered", this,"_seek_frame_changed");
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	blend_anim->connect("pressed", this, "_animation_blend"); | 
					
						
							|  |  |  | 	remove_anim->connect("pressed", this, "_animation_remove"); | 
					
						
							|  |  |  | 	animation->connect("item_selected", this, "_animation_selected", Vector<Variant>(), true); | 
					
						
							|  |  |  | 	resource_edit_anim->connect("pressed", this, "_animation_resource_edit"); | 
					
						
							|  |  |  | 	file->connect("file_selected", this, "_dialog_action"); | 
					
						
							|  |  |  | 	frame->connect("value_changed", this, "_seek_value_changed", Vector<Variant>(), true); | 
					
						
							|  |  |  | 	scale->connect("text_entered", this, "_scale_changed", Vector<Variant>(), true); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	renaming = false; | 
					
						
							|  |  |  | 	last_active = false; | 
					
						
							| 
									
										
										
										
											2015-05-25 01:46:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	set_process_unhandled_key_input(true); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	key_editor = memnew(AnimationKeyEditor); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	add_child(key_editor); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	add_constant_override("separation", get_constant("separation", "VBoxContainer")); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	key_editor->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	key_editor->connect("timeline_changed", this, "_animation_key_editor_seek"); | 
					
						
							|  |  |  | 	key_editor->connect("animation_len_changed", this, "_animation_key_editor_anim_len_changed"); | 
					
						
							|  |  |  | 	key_editor->connect("animation_step_changed", this, "_animation_key_editor_anim_step_changed"); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_update_player(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditorPlugin::edit(Object *p_object) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	anim_editor->set_undo_redo(&get_undo_redo()); | 
					
						
							|  |  |  | 	if (!p_object) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	anim_editor->edit(p_object->cast_to<AnimationPlayer>()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationPlayerEditorPlugin::handles(Object *p_object) const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 23:03:46 -03:00
										 |  |  | 	return p_object->is_class("AnimationPlayer"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationPlayerEditorPlugin::make_visible(bool p_visible) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_visible) { | 
					
						
							| 
									
										
										
										
											2016-03-15 15:15:50 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		editor->make_bottom_panel_item_visible(anim_editor); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		anim_editor->set_process(true); | 
					
						
							|  |  |  | 		anim_editor->ensure_visibility(); | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 		//editor->animation_panel_make_visible(true);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 		//anim_editor->hide();
 | 
					
						
							|  |  |  | 		//anim_editor->set_idle_process(false);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	editor = p_node; | 
					
						
							|  |  |  | 	anim_editor = memnew(AnimationPlayerEditor(editor)); | 
					
						
							| 
									
										
										
										
											2015-09-13 16:21:09 -03:00
										 |  |  | 	anim_editor->set_undo_redo(editor->get_undo_redo()); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	editor->add_bottom_panel_item(TTR("Animation"), anim_editor); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	editor->get_viewport()->add_child(anim_editor); | 
					
						
							|  |  |  | 	anim_editor->set_area_as_parent_rect(); | 
					
						
							|  |  |  | 	anim_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END); | 
					
						
							|  |  |  | 	anim_editor->set_margin( MARGIN_TOP, 75 ); | 
					
						
							|  |  |  | 	anim_editor->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END); | 
					
						
							|  |  |  | 	anim_editor->set_margin( MARGIN_RIGHT, 0 );*/ | 
					
						
							|  |  |  | 	anim_editor->hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | AnimationPlayerEditorPlugin::~AnimationPlayerEditorPlugin() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } |