| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  sprite_frames_editor_plugin.cpp                                      */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											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 "sprite_frames_editor_plugin.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 14:21:25 +01:00
										 |  |  | #include "editor/editor_settings.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "io/resource_loader.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-30 22:53:40 +02:00
										 |  |  | #include "project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | #include "scene/3d/sprite_3d.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | void SpriteFramesEditor::_gui_input(Ref<InputEvent> p_event) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 16:19:07 +02:00
										 |  |  | 	if (p_what == NOTIFICATION_PHYSICS_PROCESS) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_ENTER_TREE) { | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 		load->set_icon(get_icon("Load", "EditorIcons")); | 
					
						
							|  |  |  | 		_delete->set_icon(get_icon("Remove", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2017-10-13 16:39:17 -05:00
										 |  |  | 		new_anim->set_icon(get_icon("New", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 		remove_anim->set_icon(get_icon("Remove", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_READY) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 		//NodePath("/root")->connect("node_removed", this,"_node_removed",Vector<Variant>(),true);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_DRAW) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::_file_load_request(const PoolVector<String> &p_path, int p_at_pos) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	List<Ref<Texture> > resources; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_path.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<Texture> resource; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		resource = ResourceLoader::load(p_path[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (resource.is_null()) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 			dialog->set_text(TTR("ERROR: Couldn't load frame resource!")); | 
					
						
							|  |  |  | 			dialog->set_title(TTR("Error!")); | 
					
						
							| 
									
										
										
										
											2016-05-21 01:18:35 +02:00
										 |  |  | 			//dialog->get_cancel()->set_text("Close");
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 			dialog->get_ok()->set_text(TTR("Close")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 			dialog->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			return; ///beh should show an error i guess
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		resources.push_back(resource); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (resources.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		//print_line("added frames!");
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Add Frame")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int fc = frames->get_frame_count(edited_anim); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int count = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<Ref<Texture> >::Element *E = resources.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(frames, "add_frame", edited_anim, E->get(), p_at_pos == -1 ? -1 : p_at_pos + count); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(frames, "remove_frame", edited_anim, p_at_pos == -1 ? fc : p_at_pos); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		count++; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	//print_line("added frames!");
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_load_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	loading_scene = false; | 
					
						
							| 
									
										
										
										
											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("Texture", &extensions); | 
					
						
							|  |  |  | 	for (int i = 0; i < extensions.size(); i++) | 
					
						
							|  |  |  | 		file->add_filter("*." + extensions[i]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-06 09:44:38 -03:00
										 |  |  | 	file->set_mode(EditorFileDialog::MODE_OPEN_FILES); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	file->popup_centered_ratio(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_paste_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Ref<Texture> r = EditorSettings::get_singleton()->get_resource_clipboard(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (!r.is_valid()) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		dialog->set_text(TTR("Resource clipboard is empty or not a texture!")); | 
					
						
							|  |  |  | 		dialog->set_title(TTR("Error!")); | 
					
						
							| 
									
										
										
										
											2016-05-21 01:18:35 +02:00
										 |  |  | 		//dialog->get_cancel()->set_text("Close");
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		dialog->get_ok()->set_text(TTR("Close")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 		dialog->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; ///beh should show an error i guess
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Paste Frame")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "add_frame", edited_anim, r); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "remove_frame", edited_anim, frames->get_frame_count(edited_anim)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 12:25:13 +08:00
										 |  |  | void SpriteFramesEditor::_copy_pressed() { | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (tree->get_current() < 0) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	Ref<Texture> r = frames->get_frame(edited_anim, tree->get_current()); | 
					
						
							|  |  |  | 	if (!r.is_valid()) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EditorSettings::get_singleton()->set_resource_clipboard(r); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void SpriteFramesEditor::_empty_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int from = -1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (tree->get_current() >= 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		from = tree->get_current(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		sel = from; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		from = frames->get_frame_count(edited_anim); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<Texture> r; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Add Empty")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "remove_frame", edited_anim, from); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | void SpriteFramesEditor::_empty2_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int from = -1; | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (tree->get_current() >= 0) { | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		from = tree->get_current(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		sel = from; | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		from = frames->get_frame_count(edited_anim); | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<Texture> r; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Add Empty")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from + 1); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "remove_frame", edited_anim, from + 1); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void SpriteFramesEditor::_up_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (tree->get_current() < 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int to_move = tree->get_current(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (to_move < 1) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	sel = to_move; | 
					
						
							|  |  |  | 	sel -= 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Ref<Texture> r = frames->get_frame(edited_anim, to_move); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Delete Resource")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move - 1)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move - 1, frames->get_frame(edited_anim, to_move)); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move)); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move - 1, frames->get_frame(edited_anim, to_move - 1)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_down_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (tree->get_current() < 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int to_move = tree->get_current(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	sel = to_move; | 
					
						
							|  |  |  | 	sel += 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Ref<Texture> r = frames->get_frame(edited_anim, to_move); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Delete Resource")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move + 1)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move + 1, frames->get_frame(edited_anim, to_move)); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move)); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move + 1, frames->get_frame(edited_anim, to_move + 1)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_delete_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-02 17:35:42 +01:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (tree->get_current() < 0) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2017-09-02 17:35:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int to_delete = tree->get_current(); | 
					
						
							|  |  |  | 	if (to_delete < 0 || to_delete >= frames->get_frame_count(edited_anim)) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->create_action(TTR("Delete Resource")); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(frames, "remove_frame", edited_anim, to_delete); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "add_frame", edited_anim, frames->get_frame(edited_anim, to_delete), to_delete); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | void SpriteFramesEditor::_animation_select() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (updating) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *selected = animations->get_selected(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!selected); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	edited_anim = selected->get_text(0); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	_update_library(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFrames> p_sfames) { | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Node *edited = EditorNode::get_singleton()->get_edited_scene(); | 
					
						
							|  |  |  | 	if (!edited) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_node != edited && p_node->get_owner() != edited) | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (as && as->get_sprite_frames() == p_sfames) { | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 			r_nodes->push_back(p_node); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		AnimatedSprite3D *as = Object::cast_to<AnimatedSprite3D>(p_node); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (as && as->get_sprite_frames() == p_sfames) { | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 			r_nodes->push_back(p_node); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_node->get_child_count(); i++) { | 
					
						
							|  |  |  | 		_find_anim_sprites(p_node->get_child(i), r_nodes, p_sfames); | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::_animation_name_edited() { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (updating) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!frames->has_animation(edited_anim)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *edited = animations->get_edited(); | 
					
						
							|  |  |  | 	if (!edited) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String new_name = edited->get_text(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (new_name == String(edited_anim)) | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	new_name = new_name.replace("/", "_").replace(",", " "); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	String name = new_name; | 
					
						
							|  |  |  | 	int counter = 0; | 
					
						
							|  |  |  | 	while (frames->has_animation(name)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		counter++; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		name = new_name + " " + itos(counter); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	List<Node *> nodes; | 
					
						
							|  |  |  | 	_find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(), &nodes, Ref<SpriteFrames>(frames)); | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Rename Animation")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "rename_animation", edited_anim, name); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "rename_animation", name, edited_anim); | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		String current = E->get()->call("get_animation"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (current != edited_anim) | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(E->get(), "set_animation", name); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(E->get(), "set_animation", edited_anim); | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	edited_anim = new_name; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::_animation_add() { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 15:40:58 -04:00
										 |  |  | 	String name = "New Anim"; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int counter = 0; | 
					
						
							|  |  |  | 	while (frames->has_animation(name)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		counter++; | 
					
						
							| 
									
										
										
										
											2017-11-01 15:40:58 -04:00
										 |  |  | 		name = "New Anim " + itos(counter); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	List<Node *> nodes; | 
					
						
							|  |  |  | 	_find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(), &nodes, Ref<SpriteFrames>(frames)); | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	undo_redo->create_action(TTR("Add Animation")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "add_animation", name); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "remove_animation", name); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		String current = E->get()->call("get_animation"); | 
					
						
							|  |  |  | 		if (frames->has_animation(current)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(E->get(), "set_animation", name); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(E->get(), "set_animation", current); | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 15:40:58 -04:00
										 |  |  | 	edited_anim = name; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2017-11-26 20:54:26 -05:00
										 |  |  | 	animations->grab_focus(); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::_animation_remove() { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//fuck everything
 | 
					
						
							|  |  |  | 	if (updating) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!frames->has_animation(edited_anim)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->create_action(TTR("Remove Animation")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "remove_animation", edited_anim); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "add_animation", edited_anim); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_animation_speed", edited_anim, frames->get_animation_speed(edited_anim)); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_animation_loop", edited_anim, frames->get_animation_loop(edited_anim)); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	int fc = frames->get_frame_count(edited_anim); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < fc; i++) { | 
					
						
							|  |  |  | 		Ref<Texture> frame = frames->get_frame(edited_anim, i); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(frames, "add_frame", edited_anim, frame); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_animation_loop_changed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (updating) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->create_action(TTR("Change Animation Loop")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->add_do_method(frames, "set_animation_loop", edited_anim, anim_loop->is_pressed()); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_animation_loop", edited_anim, frames->get_animation_loop(edited_anim)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library", true); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library", true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_animation_fps_changed(double p_value) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (updating) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	undo_redo->create_action(TTR("Change Animation FPS"), UndoRedo::MERGE_ENDS); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(frames, "set_animation_speed", edited_anim, p_value); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(frames, "set_animation_speed", edited_anim, frames->get_animation_speed(edited_anim)); | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library", true); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library", true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_update_library(bool p_skip_selector) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = true; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!p_skip_selector) { | 
					
						
							|  |  |  | 		animations->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		TreeItem *anim_root = animations->create_item(); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		List<StringName> anim_names; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		anim_names.sort_custom<StringName::AlphCompare>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		frames->get_animation_list(&anim_names); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		anim_names.sort_custom<StringName::AlphCompare>(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (List<StringName>::Element *E = anim_names.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			String name = E->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			TreeItem *it = animations->create_item(anim_root); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			it->set_metadata(0, name); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			it->set_text(0, name); | 
					
						
							|  |  |  | 			it->set_editable(0, true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (E->get() == edited_anim) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 				it->select(0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	tree->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	if (!frames->has_animation(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		updating = false; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (sel >= frames->get_frame_count(edited_anim)) | 
					
						
							|  |  |  | 		sel = frames->get_frame_count(edited_anim) - 1; | 
					
						
							|  |  |  | 	else if (sel < 0 && frames->get_frame_count(edited_anim)) | 
					
						
							|  |  |  | 		sel = 0; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < frames->get_frame_count(edited_anim); i++) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		String name; | 
					
						
							|  |  |  | 		Ref<Texture> icon; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (frames->get_frame(edited_anim, i).is_null()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			name = itos(i) + ": " + TTR("(empty)"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			name = itos(i) + ": " + frames->get_frame(edited_anim, i)->get_name(); | 
					
						
							|  |  |  | 			icon = frames->get_frame(edited_anim, i); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		tree->add_item(name, icon); | 
					
						
							|  |  |  | 		if (frames->get_frame(edited_anim, i).is_valid()) | 
					
						
							|  |  |  | 			tree->set_item_tooltip(tree->get_item_count() - 1, frames->get_frame(edited_anim, i)->get_path()); | 
					
						
							|  |  |  | 		if (sel == i) | 
					
						
							|  |  |  | 			tree->select(tree->get_item_count() - 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 	anim_speed->set_value(frames->get_animation_speed(edited_anim)); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	anim_loop->set_pressed(frames->get_animation_loop(edited_anim)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	//player->add_resource("default",resource);
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::edit(SpriteFrames *p_frames) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (frames == p_frames) | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	frames = p_frames; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_frames) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!p_frames->has_animation(edited_anim)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			List<StringName> anim_names; | 
					
						
							|  |  |  | 			frames->get_animation_list(&anim_names); | 
					
						
							|  |  |  | 			anim_names.sort_custom<StringName::AlphCompare>(); | 
					
						
							|  |  |  | 			if (anim_names.size()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				edited_anim = anim_names.front()->get(); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				edited_anim = StringName(); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		_update_library(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		hide(); | 
					
						
							| 
									
										
										
										
											2017-09-30 16:19:07 +02:00
										 |  |  | 		//set_physics_process(false);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!frames->has_animation(edited_anim)) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	int idx = tree->get_item_at_position(p_point, true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (idx < 0 || idx >= frames->get_frame_count(edited_anim)) | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return Variant(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	RES frame = frames->get_frame(edited_anim, idx); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (frame.is_null()) | 
					
						
							|  |  |  | 		return Variant(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	return EditorNode::get_singleton()->drag_resource(frame, p_from); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!d.has("type")) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (d.has("from") && (Object *)(d["from"]) == tree) | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (String(d["type"]) == "resource" && d.has("resource")) { | 
					
						
							|  |  |  | 		RES r = d["resource"]; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Ref<Texture> texture = r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (texture.is_valid()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (String(d["type"]) == "files") { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Vector<String> files = d["files"]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (files.size() == 0) | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < files.size(); i++) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 			String file = files[0]; | 
					
						
							|  |  |  | 			String ftype = EditorFileSystem::get_singleton()->get_file_type(file); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (!ClassDB::is_parent_class(ftype, "Texture")) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (!can_drop_data_fw(p_point, p_data, p_from)) | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!d.has("type")) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	int at_pos = tree->get_item_at_position(p_point, true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (String(d["type"]) == "resource" && d.has("resource")) { | 
					
						
							|  |  |  | 		RES r = d["resource"]; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Ref<Texture> texture = r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (texture.is_valid()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			undo_redo->create_action(TTR("Add Frame")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos); | 
					
						
							|  |  |  | 			undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) : at_pos); | 
					
						
							|  |  |  | 			undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 			undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 			undo_redo->commit_action(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (String(d["type"]) == "files") { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 		PoolVector<String> files = d["files"]; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_file_load_request(files, at_pos); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void SpriteFramesEditor::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_gui_input"), &SpriteFramesEditor::_gui_input); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_load_pressed"), &SpriteFramesEditor::_load_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_empty_pressed"), &SpriteFramesEditor::_empty_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_empty2_pressed"), &SpriteFramesEditor::_empty2_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_delete_pressed"), &SpriteFramesEditor::_delete_pressed); | 
					
						
							| 
									
										
										
										
											2017-10-27 12:25:13 +08:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_copy_pressed"), &SpriteFramesEditor::_copy_pressed); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_paste_pressed"), &SpriteFramesEditor::_paste_pressed); | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_file_load_request", "files", "at_position"), &SpriteFramesEditor::_file_load_request, DEFVAL(-1)); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_update_library", "skipsel"), &SpriteFramesEditor::_update_library, DEFVAL(false)); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_up_pressed"), &SpriteFramesEditor::_up_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_down_pressed"), &SpriteFramesEditor::_down_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_select"), &SpriteFramesEditor::_animation_select); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_name_edited"), &SpriteFramesEditor::_animation_name_edited); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_add"), &SpriteFramesEditor::_animation_add); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_remove"), &SpriteFramesEditor::_animation_remove); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_loop_changed"), &SpriteFramesEditor::_animation_loop_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_animation_fps_changed"), &SpriteFramesEditor::_animation_fps_changed); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SpriteFramesEditor::can_drop_data_fw); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("drop_data_fw"), &SpriteFramesEditor::drop_data_fw); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SpriteFramesEditor::SpriteFramesEditor() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 21:41:31 +02:00
										 |  |  | 	//add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel"));
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	split = memnew(HSplitContainer); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	add_child(split); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *vbc_animlist = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	split->add_child(vbc_animlist); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	vbc_animlist->set_custom_minimum_size(Size2(150, 0) * EDSCALE); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	//vbc_animlist->set_v_size_flags(SIZE_EXPAND_FILL);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *sub_vb = memnew(VBoxContainer); | 
					
						
							|  |  |  | 	vbc_animlist->add_margin_child(TTR("Animations"), sub_vb, true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	sub_vb->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hbc_animlist = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	sub_vb->add_child(hbc_animlist); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	new_anim = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	new_anim->set_flat(true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	hbc_animlist->add_child(new_anim); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	new_anim->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	new_anim->connect("pressed", this, "_animation_add"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	remove_anim = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	remove_anim->set_flat(true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	hbc_animlist->add_child(remove_anim); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	remove_anim->connect("pressed", this, "_animation_remove"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	animations = memnew(Tree); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	sub_vb->add_child(animations); | 
					
						
							|  |  |  | 	animations->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	animations->set_hide_root(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	animations->connect("cell_selected", this, "_animation_select"); | 
					
						
							|  |  |  | 	animations->connect("item_edited", this, "_animation_name_edited"); | 
					
						
							| 
									
										
										
										
											2017-08-18 18:19:12 -03:00
										 |  |  | 	animations->set_allow_reselect(true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	anim_speed = memnew(SpinBox); | 
					
						
							|  |  |  | 	vbc_animlist->add_margin_child(TTR("Speed (FPS):"), anim_speed); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	anim_speed->set_min(0); | 
					
						
							|  |  |  | 	anim_speed->set_max(100); | 
					
						
							|  |  |  | 	anim_speed->set_step(0.01); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	anim_speed->connect("value_changed", this, "_animation_fps_changed"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	anim_loop = memnew(CheckButton); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	anim_loop->set_text(TTR("Loop")); | 
					
						
							|  |  |  | 	vbc_animlist->add_child(anim_loop); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	anim_loop->connect("pressed", this, "_animation_loop_changed"); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *vbc = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	split->add_child(vbc); | 
					
						
							|  |  |  | 	vbc->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	sub_vb = memnew(VBoxContainer); | 
					
						
							|  |  |  | 	vbc->add_margin_child(TTR("Animation Frames"), sub_vb, true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hbc = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	sub_vb->add_child(hbc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//animations = memnew( ItemList );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	load = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	load->set_flat(true); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	load->set_tooltip(TTR("Load Resource")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(load); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 12:25:13 +08:00
										 |  |  | 	copy = memnew(Button); | 
					
						
							|  |  |  | 	copy->set_text(TTR("Copy")); | 
					
						
							|  |  |  | 	hbc->add_child(copy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	paste = memnew(Button); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	paste->set_text(TTR("Paste")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(paste); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	empty = memnew(Button); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	empty->set_text(TTR("Insert Empty (Before)")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(empty); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	empty2 = memnew(Button); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	empty2->set_text(TTR("Insert Empty (After)")); | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 	hbc->add_child(empty2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	move_up = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	move_up->set_text(TTR("Move (Before)")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(move_up); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	move_down = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	move_down->set_text(TTR("Move (After)")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(move_down); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	_delete = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-10-12 13:59:25 -05:00
										 |  |  | 	_delete->set_flat(true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(_delete); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	file = memnew(EditorFileDialog); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(file); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tree = memnew(ItemList); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	tree->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	tree->set_icon_mode(ItemList::ICON_MODE_TOP); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int thumbnail_size = 96; | 
					
						
							|  |  |  | 	tree->set_max_columns(0); | 
					
						
							|  |  |  | 	tree->set_icon_mode(ItemList::ICON_MODE_TOP); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tree->set_fixed_column_width(thumbnail_size * 3 / 2); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	tree->set_max_text_lines(2); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tree->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	//tree->set_min_icon_size(Size2(thumbnail_size,thumbnail_size));
 | 
					
						
							|  |  |  | 	tree->set_drag_forwarding(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sub_vb->add_child(tree); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	dialog = memnew(AcceptDialog); | 
					
						
							|  |  |  | 	add_child(dialog); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	load->connect("pressed", this, "_load_pressed"); | 
					
						
							|  |  |  | 	_delete->connect("pressed", this, "_delete_pressed"); | 
					
						
							| 
									
										
										
										
											2017-10-27 12:25:13 +08:00
										 |  |  | 	copy->connect("pressed", this, "_copy_pressed"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	paste->connect("pressed", this, "_paste_pressed"); | 
					
						
							|  |  |  | 	empty->connect("pressed", this, "_empty_pressed"); | 
					
						
							|  |  |  | 	empty2->connect("pressed", this, "_empty2_pressed"); | 
					
						
							|  |  |  | 	move_up->connect("pressed", this, "_up_pressed"); | 
					
						
							|  |  |  | 	move_down->connect("pressed", this, "_down_pressed"); | 
					
						
							|  |  |  | 	file->connect("files_selected", this, "_file_load_request"); | 
					
						
							|  |  |  | 	loading_scene = false; | 
					
						
							|  |  |  | 	sel = -1; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	updating = false; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	edited_anim = "default"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditorPlugin::edit(Object *p_object) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	frames_editor->set_undo_redo(&get_undo_redo()); | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	SpriteFrames *s = Object::cast_to<SpriteFrames>(p_object); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (!s) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	frames_editor->edit(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool SpriteFramesEditorPlugin::handles(Object *p_object) const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 23:03:46 -03:00
										 |  |  | 	return p_object->is_class("SpriteFrames"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditorPlugin::make_visible(bool p_visible) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_visible) { | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		button->show(); | 
					
						
							|  |  |  | 		editor->make_bottom_panel_item_visible(frames_editor); | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 		//frames_editor->set_process(true);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		button->hide(); | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 		if (frames_editor->is_visible_in_tree()) | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 			editor->hide_bottom_panel(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 		//frames_editor->set_process(false);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SpriteFramesEditorPlugin::SpriteFramesEditorPlugin(EditorNode *p_node) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	editor = p_node; | 
					
						
							|  |  |  | 	frames_editor = memnew(SpriteFramesEditor); | 
					
						
							| 
									
										
										
										
											2017-10-13 16:39:17 -05:00
										 |  |  | 	frames_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE); | 
					
						
							| 
									
										
										
										
											2017-12-23 22:40:15 +08:00
										 |  |  | 	button = editor->add_bottom_panel_item(TTR("SpriteFrames"), frames_editor); | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	button->hide(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | SpriteFramesEditorPlugin::~SpriteFramesEditorPlugin() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } |