| 
									
										
										
										
											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
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-01-01 11:16:22 +01:00
										 |  |  | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2020 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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "sprite_frames_editor_plugin.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-07 19:33:38 -03:00
										 |  |  | #include "core/config/project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/io/resource_loader.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-24 15:17:23 +08:00
										 |  |  | #include "editor/editor_scale.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 14:21:25 +01:00
										 |  |  | #include "editor/editor_settings.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | #include "scene/3d/sprite_3d.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-24 15:17:23 +08:00
										 |  |  | #include "scene/gui/center_container.h"
 | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | #include "scene/gui/margin_container.h"
 | 
					
						
							|  |  |  | #include "scene/gui/panel_container.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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | void SpriteFramesEditor::_open_sprite_sheet() { | 
					
						
							|  |  |  | 	file_split_sheet->clear_filters(); | 
					
						
							|  |  |  | 	List<String> extensions; | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	for (int i = 0; i < extensions.size(); i++) { | 
					
						
							|  |  |  | 		file_split_sheet->add_filter("*." + extensions[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-11 18:45:19 +02:00
										 |  |  | 	file_split_sheet->popup_file_dialog(); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_sheet_preview_draw() { | 
					
						
							|  |  |  | 	Size2i size = split_sheet_preview->get_size(); | 
					
						
							|  |  |  | 	int h = split_sheet_h->get_value(); | 
					
						
							|  |  |  | 	int v = split_sheet_v->get_value(); | 
					
						
							| 
									
										
										
										
											2019-05-11 22:18:12 +02:00
										 |  |  | 	int width = size.width / h; | 
					
						
							|  |  |  | 	int height = size.height / v; | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	const float a = 0.3; | 
					
						
							|  |  |  | 	for (int i = 1; i < h; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-11 22:18:12 +02:00
										 |  |  | 		int x = i * width; | 
					
						
							|  |  |  | 		split_sheet_preview->draw_line(Point2(x, 0), Point2(x, size.height), Color(1, 1, 1, a)); | 
					
						
							|  |  |  | 		split_sheet_preview->draw_line(Point2(x + 1, 0), Point2(x + 1, size.height), Color(0, 0, 0, a)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int j = 1; j < v; j++) { | 
					
						
							|  |  |  | 			int y = j * height; | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			split_sheet_preview->draw_line(Point2(0, y), Point2(size.width, y), Color(1, 1, 1, a)); | 
					
						
							|  |  |  | 			split_sheet_preview->draw_line(Point2(0, y + 1), Point2(size.width, y + 1), Color(0, 0, 0, a)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-11 22:18:12 +02:00
										 |  |  | 	if (frames_selected.size() == 0) { | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 		split_sheet_dialog->get_ok_button()->set_disabled(true); | 
					
						
							|  |  |  | 		split_sheet_dialog->get_ok_button()->set_text(TTR("No Frames Selected")); | 
					
						
							| 
									
										
										
										
											2019-05-11 22:18:12 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	Color accent = get_theme_color("accent_color", "Editor"); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 		int idx = E->get(); | 
					
						
							| 
									
										
										
										
											2019-05-11 22:18:12 +02:00
										 |  |  | 		int xp = idx % h; | 
					
						
							|  |  |  | 		int yp = (idx - xp) / h; | 
					
						
							|  |  |  | 		int x = xp * width; | 
					
						
							|  |  |  | 		int y = yp * height; | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		split_sheet_preview->draw_rect(Rect2(x + 5, y + 5, width - 10, height - 10), Color(0, 0, 0, 0.35), true); | 
					
						
							|  |  |  | 		split_sheet_preview->draw_rect(Rect2(x + 0, y + 0, width - 0, height - 0), Color(0, 0, 0, 1), false); | 
					
						
							|  |  |  | 		split_sheet_preview->draw_rect(Rect2(x + 1, y + 1, width - 2, height - 2), Color(0, 0, 0, 1), false); | 
					
						
							|  |  |  | 		split_sheet_preview->draw_rect(Rect2(x + 2, y + 2, width - 4, height - 4), accent, false); | 
					
						
							|  |  |  | 		split_sheet_preview->draw_rect(Rect2(x + 3, y + 3, width - 6, height - 6), accent, false); | 
					
						
							|  |  |  | 		split_sheet_preview->draw_rect(Rect2(x + 4, y + 4, width - 8, height - 8), Color(0, 0, 0, 1), false); | 
					
						
							|  |  |  | 		split_sheet_preview->draw_rect(Rect2(x + 5, y + 5, width - 10, height - 10), Color(0, 0, 0, 1), false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 	split_sheet_dialog->get_ok_button()->set_disabled(false); | 
					
						
							|  |  |  | 	split_sheet_dialog->get_ok_button()->set_text(vformat(TTR("Add %d Frame(s)"), frames_selected.size())); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) { | 
					
						
							|  |  |  | 	Ref<InputEventMouseButton> mb = p_event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { | 
					
						
							|  |  |  | 		Size2i size = split_sheet_preview->get_size(); | 
					
						
							|  |  |  | 		int h = split_sheet_h->get_value(); | 
					
						
							|  |  |  | 		int v = split_sheet_v->get_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int x = CLAMP(int(mb->get_position().x) * h / size.width, 0, h - 1); | 
					
						
							|  |  |  | 		int y = CLAMP(int(mb->get_position().y) * v / size.height, 0, v - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int idx = h * y + x; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (mb->get_shift() && last_frame_selected >= 0) { | 
					
						
							|  |  |  | 			//select multiple
 | 
					
						
							|  |  |  | 			int from = idx; | 
					
						
							|  |  |  | 			int to = last_frame_selected; | 
					
						
							|  |  |  | 			if (from > to) { | 
					
						
							|  |  |  | 				SWAP(from, to); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (int i = from; i <= to; i++) { | 
					
						
							|  |  |  | 				if (mb->get_control()) { | 
					
						
							|  |  |  | 					frames_selected.erase(i); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					frames_selected.insert(i); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (frames_selected.has(idx)) { | 
					
						
							|  |  |  | 				frames_selected.erase(idx); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				frames_selected.insert(idx); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		last_frame_selected = idx; | 
					
						
							|  |  |  | 		split_sheet_preview->update(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | void SpriteFramesEditor::_sheet_scroll_input(const Ref<InputEvent> &p_event) { | 
					
						
							|  |  |  | 	const Ref<InputEventMouseButton> mb = p_event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mb.is_valid()) { | 
					
						
							|  |  |  | 		// Zoom in/out using Ctrl + mouse wheel. This is done on the ScrollContainer
 | 
					
						
							|  |  |  | 		// to allow performing this action anywhere, even if the cursor isn't
 | 
					
						
							|  |  |  | 		// hovering the texture in the workspace.
 | 
					
						
							|  |  |  | 		if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed() && mb->get_control()) { | 
					
						
							|  |  |  | 			_sheet_zoom_in(); | 
					
						
							|  |  |  | 			// Don't scroll up after zooming in.
 | 
					
						
							|  |  |  | 			accept_event(); | 
					
						
							|  |  |  | 		} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed() && mb->get_control()) { | 
					
						
							|  |  |  | 			_sheet_zoom_out(); | 
					
						
							|  |  |  | 			// Don't scroll down after zooming out.
 | 
					
						
							|  |  |  | 			accept_event(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | void SpriteFramesEditor::_sheet_add_frames() { | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	Size2i size = split_sheet_preview->get_texture()->get_size(); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	int h = split_sheet_h->get_value(); | 
					
						
							|  |  |  | 	int v = split_sheet_v->get_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->create_action(TTR("Add Frame")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int fc = frames->get_frame_count(edited_anim); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-16 18:25:59 +02:00
										 |  |  | 	AtlasTexture *atlas_source = Object::cast_to<AtlasTexture>(*split_sheet_preview->get_texture()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Rect2 region_rect = Rect2(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (atlas_source && atlas_source->get_atlas().is_valid()) { | 
					
						
							| 
									
										
										
										
											2020-04-16 18:25:59 +02:00
										 |  |  | 		region_rect = atlas_source->get_region(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-04-16 18:25:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 		int idx = E->get(); | 
					
						
							|  |  |  | 		int width = size.width / h; | 
					
						
							|  |  |  | 		int height = size.height / v; | 
					
						
							| 
									
										
										
										
											2019-05-11 22:18:12 +02:00
										 |  |  | 		int xp = idx % h; | 
					
						
							|  |  |  | 		int yp = (idx - xp) / h; | 
					
						
							| 
									
										
										
										
											2020-04-16 18:25:59 +02:00
										 |  |  | 		int x = (xp * width) + region_rect.position.x; | 
					
						
							|  |  |  | 		int y = (yp * height) + region_rect.position.y; | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Ref<AtlasTexture> at; | 
					
						
							|  |  |  | 		at.instance(); | 
					
						
							|  |  |  | 		at->set_atlas(split_sheet_preview->get_texture()); | 
					
						
							|  |  |  | 		at->set_region(Rect2(x, y, width, height)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		undo_redo->add_do_method(frames, "add_frame", edited_anim, at, -1); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(frames, "remove_frame", edited_anim, fc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							|  |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | void SpriteFramesEditor::_sheet_zoom_in() { | 
					
						
							|  |  |  | 	if (sheet_zoom < max_sheet_zoom) { | 
					
						
							|  |  |  | 		sheet_zoom *= scale_ratio; | 
					
						
							|  |  |  | 		Size2 texture_size = split_sheet_preview->get_texture()->get_size(); | 
					
						
							|  |  |  | 		split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_sheet_zoom_out() { | 
					
						
							|  |  |  | 	if (sheet_zoom > min_sheet_zoom) { | 
					
						
							|  |  |  | 		sheet_zoom /= scale_ratio; | 
					
						
							|  |  |  | 		Size2 texture_size = split_sheet_preview->get_texture()->get_size(); | 
					
						
							|  |  |  | 		split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_sheet_zoom_reset() { | 
					
						
							|  |  |  | 	sheet_zoom = 1.f; | 
					
						
							|  |  |  | 	Size2 texture_size = split_sheet_preview->get_texture()->get_size(); | 
					
						
							|  |  |  | 	split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | void SpriteFramesEditor::_sheet_select_clear_all_frames() { | 
					
						
							|  |  |  | 	bool should_clear = true; | 
					
						
							|  |  |  | 	for (int i = 0; i < split_sheet_h->get_value() * split_sheet_v->get_value(); i++) { | 
					
						
							|  |  |  | 		if (!frames_selected.has(i)) { | 
					
						
							|  |  |  | 			frames_selected.insert(i); | 
					
						
							|  |  |  | 			should_clear = false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (should_clear) { | 
					
						
							|  |  |  | 		frames_selected.clear(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	split_sheet_preview->update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | void SpriteFramesEditor::_sheet_spin_changed(double) { | 
					
						
							|  |  |  | 	frames_selected.clear(); | 
					
						
							|  |  |  | 	last_frame_selected = -1; | 
					
						
							|  |  |  | 	split_sheet_preview->update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) { | 
					
						
							|  |  |  | 	Ref<Resource> texture = ResourceLoader::load(p_file); | 
					
						
							|  |  |  | 	if (!texture.is_valid()) { | 
					
						
							| 
									
										
										
										
											2019-12-27 10:31:55 +08:00
										 |  |  | 		EditorNode::get_singleton()->show_warning(TTR("Unable to load images")); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 		ERR_FAIL_COND(!texture.is_valid()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	bool new_texture = texture != split_sheet_preview->get_texture(); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	frames_selected.clear(); | 
					
						
							|  |  |  | 	last_frame_selected = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	split_sheet_preview->set_texture(texture); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	if (new_texture) { | 
					
						
							|  |  |  | 		//different texture, reset to 4x4
 | 
					
						
							|  |  |  | 		split_sheet_h->set_value(4); | 
					
						
							|  |  |  | 		split_sheet_v->set_value(4); | 
					
						
							|  |  |  | 		//reset zoom
 | 
					
						
							|  |  |  | 		_sheet_zoom_reset(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	split_sheet_dialog->popup_centered_ratio(0.65); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void SpriteFramesEditor::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	switch (p_what) { | 
					
						
							|  |  |  | 		case NOTIFICATION_ENTER_TREE: { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			load->set_icon(get_theme_icon("Load", "EditorIcons")); | 
					
						
							|  |  |  | 			load_sheet->set_icon(get_theme_icon("SpriteSheet", "EditorIcons")); | 
					
						
							|  |  |  | 			copy->set_icon(get_theme_icon("ActionCopy", "EditorIcons")); | 
					
						
							|  |  |  | 			paste->set_icon(get_theme_icon("ActionPaste", "EditorIcons")); | 
					
						
							|  |  |  | 			empty->set_icon(get_theme_icon("InsertBefore", "EditorIcons")); | 
					
						
							|  |  |  | 			empty2->set_icon(get_theme_icon("InsertAfter", "EditorIcons")); | 
					
						
							|  |  |  | 			move_up->set_icon(get_theme_icon("MoveLeft", "EditorIcons")); | 
					
						
							|  |  |  | 			move_down->set_icon(get_theme_icon("MoveRight", "EditorIcons")); | 
					
						
							|  |  |  | 			_delete->set_icon(get_theme_icon("Remove", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 			zoom_out->set_icon(get_theme_icon("ZoomLess", "EditorIcons")); | 
					
						
							|  |  |  | 			zoom_1->set_icon(get_theme_icon("ZoomReset", "EditorIcons")); | 
					
						
							|  |  |  | 			zoom_in->set_icon(get_theme_icon("ZoomMore", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			new_anim->set_icon(get_theme_icon("New", "EditorIcons")); | 
					
						
							|  |  |  | 			remove_anim->set_icon(get_theme_icon("Remove", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 			split_sheet_zoom_out->set_icon(get_theme_icon("ZoomLess", "EditorIcons")); | 
					
						
							|  |  |  | 			split_sheet_zoom_1->set_icon(get_theme_icon("ZoomReset", "EditorIcons")); | 
					
						
							|  |  |  | 			split_sheet_zoom_in->set_icon(get_theme_icon("ZoomMore", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2020-02-22 20:47:50 +01:00
										 |  |  | 			[[fallthrough]]; | 
					
						
							| 
									
										
										
										
											2019-06-28 23:09:59 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 		case NOTIFICATION_THEME_CHANGED: { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			splite_sheet_scroll->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_READY: { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			add_theme_constant_override("autohide", 1); // Fixes the dragger always showing up.
 | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | void SpriteFramesEditor::_file_load_request(const Vector<String> &p_path, int p_at_pos) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	List<Ref<Texture2D>> 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++) { | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 		Ref<Texture2D> 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!")); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-21 01:18:35 +02:00
										 |  |  | 			//dialog->get_cancel()->set_text("Close");
 | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 			dialog->get_ok_button()->set_text(TTR("Close")); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 			dialog->popup_centered(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			return; ///beh should show an error i guess
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		resources.push_back(resource); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	if (resources.is_empty()) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	for (List<Ref<Texture2D>>::Element *E = resources.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	for (int i = 0; i < extensions.size(); i++) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		file->add_filter("*." + extensions[i]); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES); | 
					
						
							| 
									
										
										
										
											2020-07-11 18:45:19 +02:00
										 |  |  | 	file->popup_file_dialog(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_paste_pressed() { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	ERR_FAIL_COND(!frames->has_animation(edited_anim)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	Ref<Texture2D> 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");
 | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 		dialog->get_ok_button()->set_text(TTR("Close")); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		dialog->popup_centered(); | 
					
						
							| 
									
										
										
										
											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)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (tree->get_current() < 0) { | 
					
						
							| 
									
										
										
										
											2017-10-27 12:25:13 +08:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	Ref<Texture2D> r = frames->get_frame(edited_anim, tree->get_current()); | 
					
						
							| 
									
										
										
										
											2017-10-27 12:25:13 +08:00
										 |  |  | 	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) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	Ref<Texture2D> r; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	Ref<Texture2D> r; | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (tree->get_current() < 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int to_move = tree->get_current(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (to_move < 1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	sel = to_move; | 
					
						
							|  |  |  | 	sel -= 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (tree->get_current() < 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int to_move = tree->get_current(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	sel = to_move; | 
					
						
							|  |  |  | 	sel += 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (tree->get_current() < 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											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() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 	if (frames->has_animation(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2020-07-24 14:07:57 -04:00
										 |  |  | 		double value = anim_speed->get_line_edit()->get_text().to_float(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim))) { | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 			_animation_fps_changed(value); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-05-06 18:42:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	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(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!edited) { | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (p_node != edited && p_node->get_owner() != edited) { | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-29 17:51:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 		AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(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() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!frames->has_animation(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *edited = animations->get_edited(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!edited) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String new_name = edited->get_text(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (new_name == String(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 		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(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::_animation_add() { | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void SpriteFramesEditor::_animation_remove() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!frames->has_animation(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 	delete_dialog->set_text(TTR("Delete Animation?")); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	delete_dialog->popup_centered(); | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_animation_remove_confirmed() { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	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++) { | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 		Ref<Texture2D> frame = frames->get_frame(edited_anim, i); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 	edited_anim = StringName(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	undo_redo->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_animation_loop_changed() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | void SpriteFramesEditor::_tree_input(const Ref<InputEvent> &p_event) { | 
					
						
							|  |  |  | 	const Ref<InputEventMouseButton> mb = p_event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mb.is_valid()) { | 
					
						
							|  |  |  | 		if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed() && mb->get_control()) { | 
					
						
							|  |  |  | 			_zoom_in(); | 
					
						
							|  |  |  | 			// Don't scroll up after zooming in.
 | 
					
						
							|  |  |  | 			accept_event(); | 
					
						
							|  |  |  | 		} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed() && mb->get_control()) { | 
					
						
							|  |  |  | 			_zoom_out(); | 
					
						
							|  |  |  | 			// Don't scroll down after zooming out.
 | 
					
						
							|  |  |  | 			accept_event(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_zoom_in() { | 
					
						
							|  |  |  | 	// Do not zoom in or out with no visible frames
 | 
					
						
							|  |  |  | 	if (frames->get_frame_count(edited_anim) <= 0) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (thumbnail_zoom < max_thumbnail_zoom) { | 
					
						
							|  |  |  | 		thumbnail_zoom *= scale_ratio; | 
					
						
							|  |  |  | 		int thumbnail_size = (int)(thumbnail_default_size * thumbnail_zoom); | 
					
						
							|  |  |  | 		tree->set_fixed_column_width(thumbnail_size * 3 / 2); | 
					
						
							|  |  |  | 		tree->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_zoom_out() { | 
					
						
							|  |  |  | 	// Do not zoom in or out with no visible frames
 | 
					
						
							|  |  |  | 	if (frames->get_frame_count(edited_anim) <= 0) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (thumbnail_zoom > min_thumbnail_zoom) { | 
					
						
							|  |  |  | 		thumbnail_zoom /= scale_ratio; | 
					
						
							|  |  |  | 		int thumbnail_size = (int)(thumbnail_default_size * thumbnail_zoom); | 
					
						
							|  |  |  | 		tree->set_fixed_column_width(thumbnail_size * 3 / 2); | 
					
						
							|  |  |  | 		tree->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditor::_zoom_reset() { | 
					
						
							|  |  |  | 	thumbnail_zoom = 1.0f; | 
					
						
							|  |  |  | 	tree->set_fixed_column_width(thumbnail_default_size * 3 / 2); | 
					
						
							|  |  |  | 	tree->set_fixed_icon_size(Size2(thumbnail_default_size, thumbnail_default_size)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (sel >= frames->get_frame_count(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		sel = frames->get_frame_count(edited_anim) - 1; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else if (sel < 0 && frames->get_frame_count(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		sel = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 		Ref<Texture2D> 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()) { | 
					
						
							|  |  |  | 			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); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (frames->get_frame(edited_anim, i).is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			tree->set_item_tooltip(tree->get_item_count() - 1, frames->get_frame(edited_anim, i)->get_path()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (sel == i) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			tree->select(tree->get_item_count() - 1); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (frames == p_frames) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 		// Clear zoom and split sheet texture
 | 
					
						
							|  |  |  | 		split_sheet_preview->set_texture(Ref<Texture2D>()); | 
					
						
							|  |  |  | 		_zoom_reset(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		hide(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!frames->has_animation(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (idx < 0 || idx >= frames->get_frame_count(edited_anim)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return Variant(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	RES frame = frames->get_frame(edited_anim, idx); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (frame.is_null()) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return Variant(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 	Dictionary drag_data = EditorNode::get_singleton()->drag_resource(frame, p_from); | 
					
						
							| 
									
										
										
										
											2019-11-22 08:35:03 +01:00
										 |  |  | 	drag_data["frame"] = idx; // store the frame, in case we want to reorder frames inside 'drop_data_fw'
 | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 	return drag_data; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!d.has("type")) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 	// reordering frames
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (d.has("from") && (Object *)(d["from"]) == tree) { | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 		Ref<Texture2D> texture = r; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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"]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (files.size() == 0) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < files.size(); i++) { | 
					
						
							| 
									
										
										
											
												Fix many errors found by PVS-Studio
Fix errors 2, 3, 4, 6, 8, 9, 11, 12, 13, 14, and 15.
											
										 
											2018-11-27 21:58:00 -05:00
										 |  |  | 			String file = files[i]; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 			String ftype = EditorFileSystem::get_singleton()->get_file_type(file); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 			if (!ClassDB::is_parent_class(ftype, "Texture2D")) { | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!can_drop_data_fw(p_point, p_data, p_from)) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!d.has("type")) { | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 		Ref<Texture2D> texture = r; | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (texture.is_valid()) { | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 			bool reorder = false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (d.has("from") && (Object *)(d["from"]) == tree) { | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 				reorder = true; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (reorder) { //drop is from reordering frames
 | 
					
						
							|  |  |  | 				int from_frame = -1; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (d.has("frame")) { | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 					from_frame = d["frame"]; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-09-05 16:53:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				undo_redo->create_action(TTR("Move Frame")); | 
					
						
							|  |  |  | 				undo_redo->add_do_method(frames, "remove_frame", edited_anim, from_frame == -1 ? frames->get_frame_count(edited_anim) : from_frame); | 
					
						
							|  |  |  | 				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) - 1 : at_pos); | 
					
						
							|  |  |  | 				undo_redo->add_undo_method(frames, "add_frame", edited_anim, texture, from_frame); | 
					
						
							|  |  |  | 				undo_redo->add_do_method(this, "_update_library"); | 
					
						
							|  |  |  | 				undo_redo->add_undo_method(this, "_update_library"); | 
					
						
							|  |  |  | 				undo_redo->commit_action(); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				undo_redo->create_action(TTR("Add Frame")); | 
					
						
							|  |  |  | 				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"); | 
					
						
							|  |  |  | 				undo_redo->commit_action(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (String(d["type"]) == "files") { | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		Vector<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("_update_library", "skipsel"), &SpriteFramesEditor::_update_library, DEFVAL(false)); | 
					
						
							| 
									
										
										
										
											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-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *vbc_animlist = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2019-02-07 22:54:59 -02:00
										 |  |  | 	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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *sub_vb = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2019-02-07 22:54:59 -02:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	new_anim = memnew(Button); | 
					
						
							|  |  |  | 	new_anim->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-02-07 22:54:59 -02:00
										 |  |  | 	new_anim->set_tooltip(TTR("New Animation")); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	hbc_animlist->add_child(new_anim); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	new_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_add)); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	remove_anim = memnew(Button); | 
					
						
							|  |  |  | 	remove_anim->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-02-07 22:54:59 -02:00
										 |  |  | 	remove_anim->set_tooltip(TTR("Remove Animation")); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	hbc_animlist->add_child(remove_anim); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	remove_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_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); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	animations->connect("cell_selected", callable_mp(this, &SpriteFramesEditor::_animation_select)); | 
					
						
							|  |  |  | 	animations->connect("item_edited", callable_mp(this, &SpriteFramesEditor::_animation_name_edited)); | 
					
						
							| 
									
										
										
										
											2017-08-18 18:19:12 -03:00
										 |  |  | 	animations->set_allow_reselect(true); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 17:25:41 +02:00
										 |  |  | 	HBoxContainer *hbc_anim_speed = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	hbc_anim_speed->add_child(memnew(Label(TTR("Speed:")))); | 
					
						
							|  |  |  | 	vbc_animlist->add_child(hbc_anim_speed); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	anim_speed = memnew(SpinBox); | 
					
						
							| 
									
										
										
										
											2020-08-05 17:25:41 +02:00
										 |  |  | 	anim_speed->set_suffix(TTR("FPS")); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	anim_speed->set_min(0); | 
					
						
							|  |  |  | 	anim_speed->set_max(100); | 
					
						
							|  |  |  | 	anim_speed->set_step(0.01); | 
					
						
							| 
									
										
										
										
											2020-08-05 17:25:41 +02:00
										 |  |  | 	anim_speed->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	hbc_anim_speed->add_child(anim_speed); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	anim_speed->connect("value_changed", callable_mp(this, &SpriteFramesEditor::_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); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	anim_loop->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_loop_changed)); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *vbc = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2019-02-07 22:54:59 -02:00
										 |  |  | 	add_child(vbc); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 	vbc->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	sub_vb = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2019-02-07 22:54:59 -02:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	load = memnew(Button); | 
					
						
							|  |  |  | 	load->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	load->set_tooltip(TTR("Add a Texture from File")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(load); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	load_sheet = memnew(Button); | 
					
						
							|  |  |  | 	load_sheet->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	load_sheet->set_tooltip(TTR("Add Frames from a Sprite Sheet")); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	hbc->add_child(load_sheet); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hbc->add_child(memnew(VSeparator)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	copy = memnew(Button); | 
					
						
							|  |  |  | 	copy->set_flat(true); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:43:08 -05:00
										 |  |  | 	copy->set_tooltip(TTR("Copy")); | 
					
						
							| 
									
										
										
										
											2017-10-27 12:25:13 +08:00
										 |  |  | 	hbc->add_child(copy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	paste = memnew(Button); | 
					
						
							|  |  |  | 	paste->set_flat(true); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:43:08 -05:00
										 |  |  | 	paste->set_tooltip(TTR("Paste")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(paste); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 	hbc->add_child(memnew(VSeparator)); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	empty = memnew(Button); | 
					
						
							|  |  |  | 	empty->set_flat(true); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:43:08 -05:00
										 |  |  | 	empty->set_tooltip(TTR("Insert Empty (Before)")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(empty); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	empty2 = memnew(Button); | 
					
						
							|  |  |  | 	empty2->set_flat(true); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:43:08 -05:00
										 |  |  | 	empty2->set_tooltip(TTR("Insert Empty (After)")); | 
					
						
							| 
									
										
										
										
											2015-04-02 07:22:17 -03:00
										 |  |  | 	hbc->add_child(empty2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	hbc->add_child(memnew(VSeparator)); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:43:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	move_up = memnew(Button); | 
					
						
							|  |  |  | 	move_up->set_flat(true); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:43:08 -05:00
										 |  |  | 	move_up->set_tooltip(TTR("Move (Before)")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(move_up); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	move_down = memnew(Button); | 
					
						
							|  |  |  | 	move_down->set_flat(true); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:43:08 -05:00
										 |  |  | 	move_down->set_tooltip(TTR("Move (After)")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(move_down); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	_delete = memnew(Button); | 
					
						
							|  |  |  | 	_delete->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-02-07 22:54:59 -02:00
										 |  |  | 	_delete->set_tooltip(TTR("Delete")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(_delete); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	hbc->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	zoom_out = memnew(Button); | 
					
						
							|  |  |  | 	zoom_out->connect("pressed", callable_mp(this, &SpriteFramesEditor::_zoom_out)); | 
					
						
							|  |  |  | 	zoom_out->set_flat(true); | 
					
						
							|  |  |  | 	zoom_out->set_tooltip(TTR("Zoom Out")); | 
					
						
							|  |  |  | 	hbc->add_child(zoom_out); | 
					
						
							|  |  |  | 	zoom_1 = memnew(Button); | 
					
						
							|  |  |  | 	zoom_1->connect("pressed", callable_mp(this, &SpriteFramesEditor::_zoom_reset)); | 
					
						
							|  |  |  | 	zoom_1->set_flat(true); | 
					
						
							|  |  |  | 	zoom_1->set_tooltip(TTR("Zoom Reset")); | 
					
						
							|  |  |  | 	hbc->add_child(zoom_1); | 
					
						
							|  |  |  | 	zoom_in = memnew(Button); | 
					
						
							|  |  |  | 	zoom_in->connect("pressed", callable_mp(this, &SpriteFramesEditor::_zoom_in)); | 
					
						
							|  |  |  | 	zoom_in->set_flat(true); | 
					
						
							|  |  |  | 	zoom_in->set_tooltip(TTR("Zoom In")); | 
					
						
							|  |  |  | 	hbc->add_child(zoom_in); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tree->set_max_columns(0); | 
					
						
							|  |  |  | 	tree->set_icon_mode(ItemList::ICON_MODE_TOP); | 
					
						
							|  |  |  | 	tree->set_max_text_lines(2); | 
					
						
							|  |  |  | 	tree->set_drag_forwarding(this); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	tree->connect("gui_input", callable_mp(this, &SpriteFramesEditor::_tree_input)); | 
					
						
							| 
									
										
										
										
											2016-05-14 23:48:23 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	load->connect("pressed", callable_mp(this, &SpriteFramesEditor::_load_pressed)); | 
					
						
							|  |  |  | 	load_sheet->connect("pressed", callable_mp(this, &SpriteFramesEditor::_open_sprite_sheet)); | 
					
						
							|  |  |  | 	_delete->connect("pressed", callable_mp(this, &SpriteFramesEditor::_delete_pressed)); | 
					
						
							|  |  |  | 	copy->connect("pressed", callable_mp(this, &SpriteFramesEditor::_copy_pressed)); | 
					
						
							|  |  |  | 	paste->connect("pressed", callable_mp(this, &SpriteFramesEditor::_paste_pressed)); | 
					
						
							|  |  |  | 	empty->connect("pressed", callable_mp(this, &SpriteFramesEditor::_empty_pressed)); | 
					
						
							|  |  |  | 	empty2->connect("pressed", callable_mp(this, &SpriteFramesEditor::_empty2_pressed)); | 
					
						
							|  |  |  | 	move_up->connect("pressed", callable_mp(this, &SpriteFramesEditor::_up_pressed)); | 
					
						
							|  |  |  | 	move_down->connect("pressed", callable_mp(this, &SpriteFramesEditor::_down_pressed)); | 
					
						
							| 
									
										
										
										
											2020-03-03 10:46:03 +01:00
										 |  |  | 	file->connect("files_selected", callable_mp(this, &SpriteFramesEditor::_file_load_request), make_binds(-1)); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	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"; | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 	delete_dialog = memnew(ConfirmationDialog); | 
					
						
							|  |  |  | 	add_child(delete_dialog); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	delete_dialog->connect("confirmed", callable_mp(this, &SpriteFramesEditor::_animation_remove_confirmed)); | 
					
						
							| 
									
										
										
										
											2019-09-06 11:07:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	split_sheet_dialog = memnew(ConfirmationDialog); | 
					
						
							|  |  |  | 	add_child(split_sheet_dialog); | 
					
						
							|  |  |  | 	VBoxContainer *split_sheet_vb = memnew(VBoxContainer); | 
					
						
							|  |  |  | 	split_sheet_dialog->add_child(split_sheet_vb); | 
					
						
							|  |  |  | 	split_sheet_dialog->set_title(TTR("Select Frames")); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	split_sheet_dialog->connect("confirmed", callable_mp(this, &SpriteFramesEditor::_sheet_add_frames)); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	HBoxContainer *split_sheet_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	Label *ss_label = memnew(Label(TTR("Horizontal:"))); | 
					
						
							|  |  |  | 	split_sheet_hb->add_child(ss_label); | 
					
						
							|  |  |  | 	split_sheet_h = memnew(SpinBox); | 
					
						
							|  |  |  | 	split_sheet_h->set_min(1); | 
					
						
							|  |  |  | 	split_sheet_h->set_max(128); | 
					
						
							|  |  |  | 	split_sheet_h->set_step(1); | 
					
						
							|  |  |  | 	split_sheet_hb->add_child(split_sheet_h); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	split_sheet_h->connect("value_changed", callable_mp(this, &SpriteFramesEditor::_sheet_spin_changed)); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ss_label = memnew(Label(TTR("Vertical:"))); | 
					
						
							|  |  |  | 	split_sheet_hb->add_child(ss_label); | 
					
						
							|  |  |  | 	split_sheet_v = memnew(SpinBox); | 
					
						
							|  |  |  | 	split_sheet_v->set_min(1); | 
					
						
							|  |  |  | 	split_sheet_v->set_max(128); | 
					
						
							|  |  |  | 	split_sheet_v->set_step(1); | 
					
						
							|  |  |  | 	split_sheet_hb->add_child(split_sheet_v); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	split_sheet_v->connect("value_changed", callable_mp(this, &SpriteFramesEditor::_sheet_spin_changed)); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	split_sheet_hb->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Button *select_clear_all = memnew(Button); | 
					
						
							|  |  |  | 	select_clear_all->set_text(TTR("Select/Clear All Frames")); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	select_clear_all->connect("pressed", callable_mp(this, &SpriteFramesEditor::_sheet_select_clear_all_frames)); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	split_sheet_hb->add_child(select_clear_all); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	split_sheet_vb->add_child(split_sheet_hb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	PanelContainer *split_sheet_panel = memnew(PanelContainer); | 
					
						
							|  |  |  | 	split_sheet_panel->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	split_sheet_panel->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	split_sheet_vb->add_child(split_sheet_panel); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	split_sheet_preview = memnew(TextureRect); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	split_sheet_preview->set_expand(true); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	split_sheet_preview->set_mouse_filter(MOUSE_FILTER_PASS); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	split_sheet_preview->connect("draw", callable_mp(this, &SpriteFramesEditor::_sheet_preview_draw)); | 
					
						
							|  |  |  | 	split_sheet_preview->connect("gui_input", callable_mp(this, &SpriteFramesEditor::_sheet_preview_input)); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	splite_sheet_scroll = memnew(ScrollContainer); | 
					
						
							|  |  |  | 	splite_sheet_scroll->set_enable_h_scroll(true); | 
					
						
							|  |  |  | 	splite_sheet_scroll->set_enable_v_scroll(true); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	splite_sheet_scroll->connect("gui_input", callable_mp(this, &SpriteFramesEditor::_sheet_scroll_input)); | 
					
						
							|  |  |  | 	split_sheet_panel->add_child(splite_sheet_scroll); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	CenterContainer *cc = memnew(CenterContainer); | 
					
						
							|  |  |  | 	cc->add_child(split_sheet_preview); | 
					
						
							|  |  |  | 	cc->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	cc->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	splite_sheet_scroll->add_child(cc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 	MarginContainer *split_sheet_zoom_margin = memnew(MarginContainer); | 
					
						
							|  |  |  | 	split_sheet_panel->add_child(split_sheet_zoom_margin); | 
					
						
							|  |  |  | 	split_sheet_zoom_margin->set_h_size_flags(0); | 
					
						
							|  |  |  | 	split_sheet_zoom_margin->set_v_size_flags(0); | 
					
						
							|  |  |  | 	split_sheet_zoom_margin->add_theme_constant_override("margin_top", 5); | 
					
						
							|  |  |  | 	split_sheet_zoom_margin->add_theme_constant_override("margin_left", 5); | 
					
						
							|  |  |  | 	HBoxContainer *split_sheet_zoom_hb = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	split_sheet_zoom_margin->add_child(split_sheet_zoom_hb); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	split_sheet_zoom_out = memnew(Button); | 
					
						
							|  |  |  | 	split_sheet_zoom_out->set_flat(true); | 
					
						
							|  |  |  | 	split_sheet_zoom_out->set_focus_mode(FOCUS_NONE); | 
					
						
							|  |  |  | 	split_sheet_zoom_out->set_tooltip(TTR("Zoom Out")); | 
					
						
							|  |  |  | 	split_sheet_zoom_out->connect("pressed", callable_mp(this, &SpriteFramesEditor::_sheet_zoom_out)); | 
					
						
							|  |  |  | 	split_sheet_zoom_hb->add_child(split_sheet_zoom_out); | 
					
						
							|  |  |  | 	split_sheet_zoom_1 = memnew(Button); | 
					
						
							|  |  |  | 	split_sheet_zoom_1->set_flat(true); | 
					
						
							|  |  |  | 	split_sheet_zoom_1->set_focus_mode(FOCUS_NONE); | 
					
						
							|  |  |  | 	split_sheet_zoom_1->set_tooltip(TTR("Zoom Reset")); | 
					
						
							|  |  |  | 	split_sheet_zoom_1->connect("pressed", callable_mp(this, &SpriteFramesEditor::_sheet_zoom_reset)); | 
					
						
							|  |  |  | 	split_sheet_zoom_hb->add_child(split_sheet_zoom_1); | 
					
						
							|  |  |  | 	split_sheet_zoom_in = memnew(Button); | 
					
						
							|  |  |  | 	split_sheet_zoom_in->set_flat(true); | 
					
						
							|  |  |  | 	split_sheet_zoom_in->set_focus_mode(FOCUS_NONE); | 
					
						
							|  |  |  | 	split_sheet_zoom_in->set_tooltip(TTR("Zoom In")); | 
					
						
							|  |  |  | 	split_sheet_zoom_in->connect("pressed", callable_mp(this, &SpriteFramesEditor::_sheet_zoom_in)); | 
					
						
							|  |  |  | 	split_sheet_zoom_hb->add_child(split_sheet_zoom_in); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	file_split_sheet = memnew(EditorFileDialog); | 
					
						
							| 
									
										
										
										
											2019-04-14 03:24:22 -03:00
										 |  |  | 	file_split_sheet->set_title(TTR("Create Frames from Sprite Sheet")); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	file_split_sheet->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); | 
					
						
							| 
									
										
										
										
											2019-04-13 22:15:31 -03:00
										 |  |  | 	add_child(file_split_sheet); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	file_split_sheet->connect("file_selected", callable_mp(this, &SpriteFramesEditor::_prepare_sprite_sheet)); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:15:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Config scale.
 | 
					
						
							|  |  |  | 	scale_ratio = 1.2f; | 
					
						
							|  |  |  | 	thumbnail_default_size = 96; | 
					
						
							|  |  |  | 	thumbnail_zoom = 1.0f; | 
					
						
							|  |  |  | 	max_thumbnail_zoom = 8.0f; | 
					
						
							|  |  |  | 	min_thumbnail_zoom = 0.1f; | 
					
						
							|  |  |  | 	sheet_zoom = 1.0f; | 
					
						
							|  |  |  | 	max_sheet_zoom = 16.0f; | 
					
						
							|  |  |  | 	min_sheet_zoom = 0.01f; | 
					
						
							|  |  |  | 	_zoom_reset(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SpriteFramesEditorPlugin::edit(Object *p_object) { | 
					
						
							|  |  |  | 	frames_editor->set_undo_redo(&get_undo_redo()); | 
					
						
							| 
									
										
										
										
											2018-10-11 17:03:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	SpriteFrames *s; | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	AnimatedSprite2D *animated_sprite = Object::cast_to<AnimatedSprite2D>(p_object); | 
					
						
							| 
									
										
										
										
											2018-10-11 17:03:14 +02:00
										 |  |  | 	if (animated_sprite) { | 
					
						
							|  |  |  | 		s = *animated_sprite->get_sprite_frames(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 		AnimatedSprite3D *animated_sprite_3d = Object::cast_to<AnimatedSprite3D>(p_object); | 
					
						
							|  |  |  | 		if (animated_sprite_3d) { | 
					
						
							|  |  |  | 			s = *animated_sprite_3d->get_sprite_frames(); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			s = Object::cast_to<SpriteFrames>(p_object); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-11 17:03:14 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	frames_editor->edit(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool SpriteFramesEditorPlugin::handles(Object *p_object) const { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	AnimatedSprite2D *animated_sprite = Object::cast_to<AnimatedSprite2D>(p_object); | 
					
						
							|  |  |  | 	AnimatedSprite3D *animated_sprite_3d = Object::cast_to<AnimatedSprite3D>(p_object); | 
					
						
							| 
									
										
										
										
											2018-10-11 17:03:14 +02:00
										 |  |  | 	if (animated_sprite && *animated_sprite->get_sprite_frames()) { | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	} else if (animated_sprite_3d && *animated_sprite_3d->get_sprite_frames()) { | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2018-10-11 17:03:14 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		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); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 		button->hide(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (frames_editor->is_visible_in_tree()) { | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 			editor->hide_bottom_panel(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } |