sprite_frames_editor_plugin.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. /*************************************************************************/
  2. /* sprite_frames_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "sprite_frames_editor_plugin.h"
  31. #include "core/io/resource_loader.h"
  32. #include "core/os/input.h"
  33. #include "core/os/keyboard.h"
  34. #include "core/project_settings.h"
  35. #include "editor/editor_scale.h"
  36. #include "editor/editor_settings.h"
  37. #include "scene/3d/sprite_3d.h"
  38. #include "scene/gui/center_container.h"
  39. void SpriteFramesEditor::_gui_input(Ref<InputEvent> p_event) {
  40. }
  41. void SpriteFramesEditor::_open_sprite_sheet() {
  42. file_split_sheet->clear_filters();
  43. List<String> extensions;
  44. ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions);
  45. for (int i = 0; i < extensions.size(); i++) {
  46. file_split_sheet->add_filter("*." + extensions[i]);
  47. }
  48. file_split_sheet->popup_centered_ratio();
  49. }
  50. void SpriteFramesEditor::_sheet_preview_draw() {
  51. Size2i size = split_sheet_preview->get_size();
  52. int h = split_sheet_h->get_value();
  53. int v = split_sheet_v->get_value();
  54. int width = size.width / h;
  55. int height = size.height / v;
  56. const float a = 0.3;
  57. for (int i = 1; i < h; i++) {
  58. int x = i * width;
  59. split_sheet_preview->draw_line(Point2(x, 0), Point2(x, size.height), Color(1, 1, 1, a));
  60. split_sheet_preview->draw_line(Point2(x + 1, 0), Point2(x + 1, size.height), Color(0, 0, 0, a));
  61. for (int j = 1; j < v; j++) {
  62. int y = j * height;
  63. split_sheet_preview->draw_line(Point2(0, y), Point2(size.width, y), Color(1, 1, 1, a));
  64. split_sheet_preview->draw_line(Point2(0, y + 1), Point2(size.width, y + 1), Color(0, 0, 0, a));
  65. }
  66. }
  67. if (frames_selected.size() == 0) {
  68. split_sheet_dialog->get_ok()->set_disabled(true);
  69. split_sheet_dialog->get_ok()->set_text(TTR("No Frames Selected"));
  70. return;
  71. }
  72. Color accent = get_color("accent_color", "Editor");
  73. for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) {
  74. int idx = E->get();
  75. int xp = idx % h;
  76. int yp = (idx - xp) / h;
  77. int x = xp * width;
  78. int y = yp * height;
  79. split_sheet_preview->draw_rect(Rect2(x + 5, y + 5, width - 10, height - 10), Color(0, 0, 0, 0.35), true);
  80. split_sheet_preview->draw_rect(Rect2(x + 0, y + 0, width - 0, height - 0), Color(0, 0, 0, 1), false);
  81. split_sheet_preview->draw_rect(Rect2(x + 1, y + 1, width - 2, height - 2), Color(0, 0, 0, 1), false);
  82. split_sheet_preview->draw_rect(Rect2(x + 2, y + 2, width - 4, height - 4), accent, false);
  83. split_sheet_preview->draw_rect(Rect2(x + 3, y + 3, width - 6, height - 6), accent, false);
  84. split_sheet_preview->draw_rect(Rect2(x + 4, y + 4, width - 8, height - 8), Color(0, 0, 0, 1), false);
  85. split_sheet_preview->draw_rect(Rect2(x + 5, y + 5, width - 10, height - 10), Color(0, 0, 0, 1), false);
  86. }
  87. split_sheet_dialog->get_ok()->set_disabled(false);
  88. split_sheet_dialog->get_ok()->set_text(vformat(TTR("Add %d Frame(s)"), frames_selected.size()));
  89. }
  90. void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {
  91. Ref<InputEventMouseButton> mb = p_event;
  92. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  93. Size2i size = split_sheet_preview->get_size();
  94. int h = split_sheet_h->get_value();
  95. int v = split_sheet_v->get_value();
  96. int x = CLAMP(int(mb->get_position().x) * h / size.width, 0, h - 1);
  97. int y = CLAMP(int(mb->get_position().y) * v / size.height, 0, v - 1);
  98. int idx = h * y + x;
  99. if (mb->get_shift() && last_frame_selected >= 0) {
  100. //select multiple
  101. int from = idx;
  102. int to = last_frame_selected;
  103. if (from > to) {
  104. SWAP(from, to);
  105. }
  106. for (int i = from; i <= to; i++) {
  107. if (mb->get_control()) {
  108. frames_selected.erase(i);
  109. } else {
  110. frames_selected.insert(i);
  111. }
  112. }
  113. } else {
  114. if (frames_selected.has(idx)) {
  115. frames_selected.erase(idx);
  116. } else {
  117. frames_selected.insert(idx);
  118. }
  119. }
  120. last_frame_selected = idx;
  121. split_sheet_preview->update();
  122. }
  123. }
  124. void SpriteFramesEditor::_sheet_add_frames() {
  125. Size2i size = split_sheet_preview->get_size();
  126. int h = split_sheet_h->get_value();
  127. int v = split_sheet_v->get_value();
  128. undo_redo->create_action(TTR("Add Frame"));
  129. int fc = frames->get_frame_count(edited_anim);
  130. AtlasTexture *atlas_source = Object::cast_to<AtlasTexture>(*split_sheet_preview->get_texture());
  131. Rect2 region_rect = Rect2();
  132. if (atlas_source && atlas_source->get_atlas().is_valid())
  133. region_rect = atlas_source->get_region();
  134. for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) {
  135. int idx = E->get();
  136. int width = size.width / h;
  137. int height = size.height / v;
  138. int xp = idx % h;
  139. int yp = (idx - xp) / h;
  140. int x = (xp * width) + region_rect.position.x;
  141. int y = (yp * height) + region_rect.position.y;
  142. Ref<AtlasTexture> at;
  143. at.instance();
  144. at->set_atlas(split_sheet_preview->get_texture());
  145. at->set_region(Rect2(x, y, width, height));
  146. undo_redo->add_do_method(frames, "add_frame", edited_anim, at, -1);
  147. undo_redo->add_undo_method(frames, "remove_frame", edited_anim, fc);
  148. }
  149. undo_redo->add_do_method(this, "_update_library");
  150. undo_redo->add_undo_method(this, "_update_library");
  151. undo_redo->commit_action();
  152. }
  153. void SpriteFramesEditor::_sheet_select_clear_all_frames() {
  154. bool should_clear = true;
  155. for (int i = 0; i < split_sheet_h->get_value() * split_sheet_v->get_value(); i++) {
  156. if (!frames_selected.has(i)) {
  157. frames_selected.insert(i);
  158. should_clear = false;
  159. }
  160. }
  161. if (should_clear) {
  162. frames_selected.clear();
  163. }
  164. split_sheet_preview->update();
  165. }
  166. void SpriteFramesEditor::_sheet_spin_changed(double) {
  167. frames_selected.clear();
  168. last_frame_selected = -1;
  169. split_sheet_preview->update();
  170. }
  171. void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) {
  172. Ref<Resource> texture = ResourceLoader::load(p_file);
  173. if (!texture.is_valid()) {
  174. EditorNode::get_singleton()->show_warning(TTR("Unable to load images"));
  175. ERR_FAIL_COND(!texture.is_valid());
  176. }
  177. if (texture != split_sheet_preview->get_texture()) {
  178. //different texture, reset to 4x4
  179. split_sheet_h->set_value(4);
  180. split_sheet_v->set_value(4);
  181. }
  182. frames_selected.clear();
  183. last_frame_selected = -1;
  184. split_sheet_preview->set_texture(texture);
  185. split_sheet_dialog->popup_centered_ratio(0.65);
  186. }
  187. void SpriteFramesEditor::_notification(int p_what) {
  188. switch (p_what) {
  189. case NOTIFICATION_ENTER_TREE: {
  190. load->set_icon(get_icon("Load", "EditorIcons"));
  191. load_sheet->set_icon(get_icon("SpriteSheet", "EditorIcons"));
  192. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  193. paste->set_icon(get_icon("ActionPaste", "EditorIcons"));
  194. empty->set_icon(get_icon("InsertBefore", "EditorIcons"));
  195. empty2->set_icon(get_icon("InsertAfter", "EditorIcons"));
  196. move_up->set_icon(get_icon("MoveLeft", "EditorIcons"));
  197. move_down->set_icon(get_icon("MoveRight", "EditorIcons"));
  198. _delete->set_icon(get_icon("Remove", "EditorIcons"));
  199. new_anim->set_icon(get_icon("New", "EditorIcons"));
  200. remove_anim->set_icon(get_icon("Remove", "EditorIcons"));
  201. FALLTHROUGH;
  202. }
  203. case NOTIFICATION_THEME_CHANGED: {
  204. splite_sheet_scroll->add_style_override("bg", get_stylebox("bg", "Tree"));
  205. } break;
  206. case NOTIFICATION_READY: {
  207. add_constant_override("autohide", 1); // Fixes the dragger always showing up.
  208. } break;
  209. }
  210. }
  211. void SpriteFramesEditor::_file_load_request(const PoolVector<String> &p_path, int p_at_pos) {
  212. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  213. List<Ref<Texture> > resources;
  214. for (int i = 0; i < p_path.size(); i++) {
  215. Ref<Texture> resource;
  216. resource = ResourceLoader::load(p_path[i]);
  217. if (resource.is_null()) {
  218. dialog->set_text(TTR("ERROR: Couldn't load frame resource!"));
  219. dialog->set_title(TTR("Error!"));
  220. //dialog->get_cancel()->set_text("Close");
  221. dialog->get_ok()->set_text(TTR("Close"));
  222. dialog->popup_centered_minsize();
  223. return; ///beh should show an error i guess
  224. }
  225. resources.push_back(resource);
  226. }
  227. if (resources.empty()) {
  228. return;
  229. }
  230. undo_redo->create_action(TTR("Add Frame"));
  231. int fc = frames->get_frame_count(edited_anim);
  232. int count = 0;
  233. for (List<Ref<Texture> >::Element *E = resources.front(); E; E = E->next()) {
  234. undo_redo->add_do_method(frames, "add_frame", edited_anim, E->get(), p_at_pos == -1 ? -1 : p_at_pos + count);
  235. undo_redo->add_undo_method(frames, "remove_frame", edited_anim, p_at_pos == -1 ? fc : p_at_pos);
  236. count++;
  237. }
  238. undo_redo->add_do_method(this, "_update_library");
  239. undo_redo->add_undo_method(this, "_update_library");
  240. undo_redo->commit_action();
  241. }
  242. void SpriteFramesEditor::_load_pressed() {
  243. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  244. loading_scene = false;
  245. file->clear_filters();
  246. List<String> extensions;
  247. ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions);
  248. for (int i = 0; i < extensions.size(); i++)
  249. file->add_filter("*." + extensions[i]);
  250. file->set_mode(EditorFileDialog::MODE_OPEN_FILES);
  251. file->popup_centered_ratio();
  252. }
  253. void SpriteFramesEditor::_paste_pressed() {
  254. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  255. Ref<Texture> r = EditorSettings::get_singleton()->get_resource_clipboard();
  256. if (!r.is_valid()) {
  257. dialog->set_text(TTR("Resource clipboard is empty or not a texture!"));
  258. dialog->set_title(TTR("Error!"));
  259. //dialog->get_cancel()->set_text("Close");
  260. dialog->get_ok()->set_text(TTR("Close"));
  261. dialog->popup_centered_minsize();
  262. return; ///beh should show an error i guess
  263. }
  264. undo_redo->create_action(TTR("Paste Frame"));
  265. undo_redo->add_do_method(frames, "add_frame", edited_anim, r);
  266. undo_redo->add_undo_method(frames, "remove_frame", edited_anim, frames->get_frame_count(edited_anim));
  267. undo_redo->add_do_method(this, "_update_library");
  268. undo_redo->add_undo_method(this, "_update_library");
  269. undo_redo->commit_action();
  270. }
  271. void SpriteFramesEditor::_copy_pressed() {
  272. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  273. if (tree->get_current() < 0)
  274. return;
  275. Ref<Texture> r = frames->get_frame(edited_anim, tree->get_current());
  276. if (!r.is_valid()) {
  277. return;
  278. }
  279. EditorSettings::get_singleton()->set_resource_clipboard(r);
  280. }
  281. void SpriteFramesEditor::_empty_pressed() {
  282. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  283. int from = -1;
  284. if (tree->get_current() >= 0) {
  285. from = tree->get_current();
  286. sel = from;
  287. } else {
  288. from = frames->get_frame_count(edited_anim);
  289. }
  290. Ref<Texture> r;
  291. undo_redo->create_action(TTR("Add Empty"));
  292. undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from);
  293. undo_redo->add_undo_method(frames, "remove_frame", edited_anim, from);
  294. undo_redo->add_do_method(this, "_update_library");
  295. undo_redo->add_undo_method(this, "_update_library");
  296. undo_redo->commit_action();
  297. }
  298. void SpriteFramesEditor::_empty2_pressed() {
  299. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  300. int from = -1;
  301. if (tree->get_current() >= 0) {
  302. from = tree->get_current();
  303. sel = from;
  304. } else {
  305. from = frames->get_frame_count(edited_anim);
  306. }
  307. Ref<Texture> r;
  308. undo_redo->create_action(TTR("Add Empty"));
  309. undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from + 1);
  310. undo_redo->add_undo_method(frames, "remove_frame", edited_anim, from + 1);
  311. undo_redo->add_do_method(this, "_update_library");
  312. undo_redo->add_undo_method(this, "_update_library");
  313. undo_redo->commit_action();
  314. }
  315. void SpriteFramesEditor::_up_pressed() {
  316. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  317. if (tree->get_current() < 0)
  318. return;
  319. int to_move = tree->get_current();
  320. if (to_move < 1)
  321. return;
  322. sel = to_move;
  323. sel -= 1;
  324. undo_redo->create_action(TTR("Delete Resource"));
  325. undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move - 1));
  326. undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move - 1, frames->get_frame(edited_anim, to_move));
  327. undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move));
  328. undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move - 1, frames->get_frame(edited_anim, to_move - 1));
  329. undo_redo->add_do_method(this, "_update_library");
  330. undo_redo->add_undo_method(this, "_update_library");
  331. undo_redo->commit_action();
  332. }
  333. void SpriteFramesEditor::_down_pressed() {
  334. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  335. if (tree->get_current() < 0)
  336. return;
  337. int to_move = tree->get_current();
  338. if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1)
  339. return;
  340. sel = to_move;
  341. sel += 1;
  342. undo_redo->create_action(TTR("Delete Resource"));
  343. undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move + 1));
  344. undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move + 1, frames->get_frame(edited_anim, to_move));
  345. undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move));
  346. undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move + 1, frames->get_frame(edited_anim, to_move + 1));
  347. undo_redo->add_do_method(this, "_update_library");
  348. undo_redo->add_undo_method(this, "_update_library");
  349. undo_redo->commit_action();
  350. }
  351. void SpriteFramesEditor::_delete_pressed() {
  352. ERR_FAIL_COND(!frames->has_animation(edited_anim));
  353. if (tree->get_current() < 0)
  354. return;
  355. int to_delete = tree->get_current();
  356. if (to_delete < 0 || to_delete >= frames->get_frame_count(edited_anim)) {
  357. return;
  358. }
  359. undo_redo->create_action(TTR("Delete Resource"));
  360. undo_redo->add_do_method(frames, "remove_frame", edited_anim, to_delete);
  361. undo_redo->add_undo_method(frames, "add_frame", edited_anim, frames->get_frame(edited_anim, to_delete), to_delete);
  362. undo_redo->add_do_method(this, "_update_library");
  363. undo_redo->add_undo_method(this, "_update_library");
  364. undo_redo->commit_action();
  365. }
  366. void SpriteFramesEditor::_animation_select() {
  367. if (updating)
  368. return;
  369. if (frames->has_animation(edited_anim)) {
  370. double value = anim_speed->get_line_edit()->get_text().to_double();
  371. if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim)))
  372. _animation_fps_changed(value);
  373. }
  374. TreeItem *selected = animations->get_selected();
  375. ERR_FAIL_COND(!selected);
  376. edited_anim = selected->get_text(0);
  377. _update_library(true);
  378. }
  379. static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFrames> p_sfames) {
  380. Node *edited = EditorNode::get_singleton()->get_edited_scene();
  381. if (!edited)
  382. return;
  383. if (p_node != edited && p_node->get_owner() != edited)
  384. return;
  385. {
  386. AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node);
  387. if (as && as->get_sprite_frames() == p_sfames) {
  388. r_nodes->push_back(p_node);
  389. }
  390. }
  391. {
  392. AnimatedSprite3D *as = Object::cast_to<AnimatedSprite3D>(p_node);
  393. if (as && as->get_sprite_frames() == p_sfames) {
  394. r_nodes->push_back(p_node);
  395. }
  396. }
  397. for (int i = 0; i < p_node->get_child_count(); i++) {
  398. _find_anim_sprites(p_node->get_child(i), r_nodes, p_sfames);
  399. }
  400. }
  401. void SpriteFramesEditor::_animation_name_edited() {
  402. if (updating)
  403. return;
  404. if (!frames->has_animation(edited_anim))
  405. return;
  406. TreeItem *edited = animations->get_edited();
  407. if (!edited)
  408. return;
  409. String new_name = edited->get_text(0);
  410. if (new_name == String(edited_anim))
  411. return;
  412. new_name = new_name.replace("/", "_").replace(",", " ");
  413. String name = new_name;
  414. int counter = 0;
  415. while (frames->has_animation(name)) {
  416. counter++;
  417. name = new_name + " " + itos(counter);
  418. }
  419. List<Node *> nodes;
  420. _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(), &nodes, Ref<SpriteFrames>(frames));
  421. undo_redo->create_action(TTR("Rename Animation"));
  422. undo_redo->add_do_method(frames, "rename_animation", edited_anim, name);
  423. undo_redo->add_undo_method(frames, "rename_animation", name, edited_anim);
  424. for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) {
  425. String current = E->get()->call("get_animation");
  426. undo_redo->add_do_method(E->get(), "set_animation", name);
  427. undo_redo->add_undo_method(E->get(), "set_animation", edited_anim);
  428. }
  429. undo_redo->add_do_method(this, "_update_library");
  430. undo_redo->add_undo_method(this, "_update_library");
  431. edited_anim = new_name;
  432. undo_redo->commit_action();
  433. }
  434. void SpriteFramesEditor::_animation_add() {
  435. String name = "New Anim";
  436. int counter = 0;
  437. while (frames->has_animation(name)) {
  438. counter++;
  439. name = "New Anim " + itos(counter);
  440. }
  441. List<Node *> nodes;
  442. _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(), &nodes, Ref<SpriteFrames>(frames));
  443. undo_redo->create_action(TTR("Add Animation"));
  444. undo_redo->add_do_method(frames, "add_animation", name);
  445. undo_redo->add_undo_method(frames, "remove_animation", name);
  446. undo_redo->add_do_method(this, "_update_library");
  447. undo_redo->add_undo_method(this, "_update_library");
  448. for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) {
  449. String current = E->get()->call("get_animation");
  450. undo_redo->add_do_method(E->get(), "set_animation", name);
  451. undo_redo->add_undo_method(E->get(), "set_animation", current);
  452. }
  453. edited_anim = name;
  454. undo_redo->commit_action();
  455. animations->grab_focus();
  456. }
  457. void SpriteFramesEditor::_animation_remove() {
  458. if (updating)
  459. return;
  460. if (!frames->has_animation(edited_anim))
  461. return;
  462. delete_dialog->set_text(TTR("Delete Animation?"));
  463. delete_dialog->popup_centered_minsize();
  464. }
  465. void SpriteFramesEditor::_animation_remove_confirmed() {
  466. undo_redo->create_action(TTR("Remove Animation"));
  467. undo_redo->add_do_method(frames, "remove_animation", edited_anim);
  468. undo_redo->add_undo_method(frames, "add_animation", edited_anim);
  469. undo_redo->add_undo_method(frames, "set_animation_speed", edited_anim, frames->get_animation_speed(edited_anim));
  470. undo_redo->add_undo_method(frames, "set_animation_loop", edited_anim, frames->get_animation_loop(edited_anim));
  471. int fc = frames->get_frame_count(edited_anim);
  472. for (int i = 0; i < fc; i++) {
  473. Ref<Texture> frame = frames->get_frame(edited_anim, i);
  474. undo_redo->add_undo_method(frames, "add_frame", edited_anim, frame);
  475. }
  476. undo_redo->add_do_method(this, "_update_library");
  477. undo_redo->add_undo_method(this, "_update_library");
  478. edited_anim = StringName();
  479. undo_redo->commit_action();
  480. }
  481. void SpriteFramesEditor::_animation_loop_changed() {
  482. if (updating)
  483. return;
  484. undo_redo->create_action(TTR("Change Animation Loop"));
  485. undo_redo->add_do_method(frames, "set_animation_loop", edited_anim, anim_loop->is_pressed());
  486. undo_redo->add_undo_method(frames, "set_animation_loop", edited_anim, frames->get_animation_loop(edited_anim));
  487. undo_redo->add_do_method(this, "_update_library", true);
  488. undo_redo->add_undo_method(this, "_update_library", true);
  489. undo_redo->commit_action();
  490. }
  491. void SpriteFramesEditor::_animation_fps_changed(double p_value) {
  492. if (updating)
  493. return;
  494. undo_redo->create_action(TTR("Change Animation FPS"), UndoRedo::MERGE_ENDS);
  495. undo_redo->add_do_method(frames, "set_animation_speed", edited_anim, p_value);
  496. undo_redo->add_undo_method(frames, "set_animation_speed", edited_anim, frames->get_animation_speed(edited_anim));
  497. undo_redo->add_do_method(this, "_update_library", true);
  498. undo_redo->add_undo_method(this, "_update_library", true);
  499. undo_redo->commit_action();
  500. }
  501. void SpriteFramesEditor::_update_library(bool p_skip_selector) {
  502. updating = true;
  503. if (!p_skip_selector) {
  504. animations->clear();
  505. TreeItem *anim_root = animations->create_item();
  506. List<StringName> anim_names;
  507. frames->get_animation_list(&anim_names);
  508. anim_names.sort_custom<StringName::AlphCompare>();
  509. for (List<StringName>::Element *E = anim_names.front(); E; E = E->next()) {
  510. String name = E->get();
  511. TreeItem *it = animations->create_item(anim_root);
  512. it->set_metadata(0, name);
  513. it->set_text(0, name);
  514. it->set_editable(0, true);
  515. if (E->get() == edited_anim) {
  516. it->select(0);
  517. }
  518. }
  519. }
  520. tree->clear();
  521. if (!frames->has_animation(edited_anim)) {
  522. updating = false;
  523. return;
  524. }
  525. if (sel >= frames->get_frame_count(edited_anim))
  526. sel = frames->get_frame_count(edited_anim) - 1;
  527. else if (sel < 0 && frames->get_frame_count(edited_anim))
  528. sel = 0;
  529. for (int i = 0; i < frames->get_frame_count(edited_anim); i++) {
  530. String name;
  531. Ref<Texture> icon;
  532. if (frames->get_frame(edited_anim, i).is_null()) {
  533. name = itos(i) + ": " + TTR("(empty)");
  534. } else {
  535. name = itos(i) + ": " + frames->get_frame(edited_anim, i)->get_name();
  536. icon = frames->get_frame(edited_anim, i);
  537. }
  538. tree->add_item(name, icon);
  539. if (frames->get_frame(edited_anim, i).is_valid())
  540. tree->set_item_tooltip(tree->get_item_count() - 1, frames->get_frame(edited_anim, i)->get_path());
  541. if (sel == i)
  542. tree->select(tree->get_item_count() - 1);
  543. }
  544. anim_speed->set_value(frames->get_animation_speed(edited_anim));
  545. anim_loop->set_pressed(frames->get_animation_loop(edited_anim));
  546. updating = false;
  547. //player->add_resource("default",resource);
  548. }
  549. void SpriteFramesEditor::edit(SpriteFrames *p_frames) {
  550. if (frames == p_frames)
  551. return;
  552. frames = p_frames;
  553. if (p_frames) {
  554. if (!p_frames->has_animation(edited_anim)) {
  555. List<StringName> anim_names;
  556. frames->get_animation_list(&anim_names);
  557. anim_names.sort_custom<StringName::AlphCompare>();
  558. if (anim_names.size()) {
  559. edited_anim = anim_names.front()->get();
  560. } else {
  561. edited_anim = StringName();
  562. }
  563. }
  564. _update_library();
  565. } else {
  566. hide();
  567. }
  568. }
  569. Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  570. if (!frames->has_animation(edited_anim))
  571. return false;
  572. int idx = tree->get_item_at_position(p_point, true);
  573. if (idx < 0 || idx >= frames->get_frame_count(edited_anim))
  574. return Variant();
  575. RES frame = frames->get_frame(edited_anim, idx);
  576. if (frame.is_null())
  577. return Variant();
  578. Dictionary drag_data = EditorNode::get_singleton()->drag_resource(frame, p_from);
  579. drag_data["frame"] = idx; // store the frame, in case we want to reorder frames inside 'drop_data_fw'
  580. return drag_data;
  581. }
  582. bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  583. Dictionary d = p_data;
  584. if (!d.has("type"))
  585. return false;
  586. // reordering frames
  587. if (d.has("from") && (Object *)(d["from"]) == tree)
  588. return true;
  589. if (String(d["type"]) == "resource" && d.has("resource")) {
  590. RES r = d["resource"];
  591. Ref<Texture> texture = r;
  592. if (texture.is_valid()) {
  593. return true;
  594. }
  595. }
  596. if (String(d["type"]) == "files") {
  597. Vector<String> files = d["files"];
  598. if (files.size() == 0)
  599. return false;
  600. for (int i = 0; i < files.size(); i++) {
  601. String file = files[i];
  602. String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
  603. if (!ClassDB::is_parent_class(ftype, "Texture")) {
  604. return false;
  605. }
  606. }
  607. return true;
  608. }
  609. return false;
  610. }
  611. void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  612. if (!can_drop_data_fw(p_point, p_data, p_from))
  613. return;
  614. Dictionary d = p_data;
  615. if (!d.has("type"))
  616. return;
  617. int at_pos = tree->get_item_at_position(p_point, true);
  618. if (String(d["type"]) == "resource" && d.has("resource")) {
  619. RES r = d["resource"];
  620. Ref<Texture> texture = r;
  621. if (texture.is_valid()) {
  622. bool reorder = false;
  623. if (d.has("from") && (Object *)(d["from"]) == tree)
  624. reorder = true;
  625. if (reorder) { //drop is from reordering frames
  626. int from_frame = -1;
  627. if (d.has("frame"))
  628. from_frame = d["frame"];
  629. undo_redo->create_action(TTR("Move Frame"));
  630. undo_redo->add_do_method(frames, "remove_frame", edited_anim, from_frame == -1 ? frames->get_frame_count(edited_anim) : from_frame);
  631. undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos);
  632. undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) - 1 : at_pos);
  633. undo_redo->add_undo_method(frames, "add_frame", edited_anim, texture, from_frame);
  634. undo_redo->add_do_method(this, "_update_library");
  635. undo_redo->add_undo_method(this, "_update_library");
  636. undo_redo->commit_action();
  637. } else {
  638. undo_redo->create_action(TTR("Add Frame"));
  639. undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos);
  640. undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) : at_pos);
  641. undo_redo->add_do_method(this, "_update_library");
  642. undo_redo->add_undo_method(this, "_update_library");
  643. undo_redo->commit_action();
  644. }
  645. }
  646. }
  647. if (String(d["type"]) == "files") {
  648. PoolVector<String> files = d["files"];
  649. if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
  650. _prepare_sprite_sheet(files[0]);
  651. } else {
  652. _file_load_request(files, at_pos);
  653. }
  654. }
  655. }
  656. void SpriteFramesEditor::_bind_methods() {
  657. ClassDB::bind_method(D_METHOD("_load_pressed"), &SpriteFramesEditor::_load_pressed);
  658. ClassDB::bind_method(D_METHOD("_empty_pressed"), &SpriteFramesEditor::_empty_pressed);
  659. ClassDB::bind_method(D_METHOD("_empty2_pressed"), &SpriteFramesEditor::_empty2_pressed);
  660. ClassDB::bind_method(D_METHOD("_delete_pressed"), &SpriteFramesEditor::_delete_pressed);
  661. ClassDB::bind_method(D_METHOD("_copy_pressed"), &SpriteFramesEditor::_copy_pressed);
  662. ClassDB::bind_method(D_METHOD("_paste_pressed"), &SpriteFramesEditor::_paste_pressed);
  663. ClassDB::bind_method(D_METHOD("_file_load_request", "files", "at_position"), &SpriteFramesEditor::_file_load_request, DEFVAL(-1));
  664. ClassDB::bind_method(D_METHOD("_update_library", "skipsel"), &SpriteFramesEditor::_update_library, DEFVAL(false));
  665. ClassDB::bind_method(D_METHOD("_up_pressed"), &SpriteFramesEditor::_up_pressed);
  666. ClassDB::bind_method(D_METHOD("_down_pressed"), &SpriteFramesEditor::_down_pressed);
  667. ClassDB::bind_method(D_METHOD("_animation_select"), &SpriteFramesEditor::_animation_select);
  668. ClassDB::bind_method(D_METHOD("_animation_name_edited"), &SpriteFramesEditor::_animation_name_edited);
  669. ClassDB::bind_method(D_METHOD("_animation_add"), &SpriteFramesEditor::_animation_add);
  670. ClassDB::bind_method(D_METHOD("_animation_remove"), &SpriteFramesEditor::_animation_remove);
  671. ClassDB::bind_method(D_METHOD("_animation_remove_confirmed"), &SpriteFramesEditor::_animation_remove_confirmed);
  672. ClassDB::bind_method(D_METHOD("_animation_loop_changed"), &SpriteFramesEditor::_animation_loop_changed);
  673. ClassDB::bind_method(D_METHOD("_animation_fps_changed"), &SpriteFramesEditor::_animation_fps_changed);
  674. ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw);
  675. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SpriteFramesEditor::can_drop_data_fw);
  676. ClassDB::bind_method(D_METHOD("drop_data_fw"), &SpriteFramesEditor::drop_data_fw);
  677. ClassDB::bind_method(D_METHOD("_prepare_sprite_sheet"), &SpriteFramesEditor::_prepare_sprite_sheet);
  678. ClassDB::bind_method(D_METHOD("_open_sprite_sheet"), &SpriteFramesEditor::_open_sprite_sheet);
  679. ClassDB::bind_method(D_METHOD("_sheet_preview_draw"), &SpriteFramesEditor::_sheet_preview_draw);
  680. ClassDB::bind_method(D_METHOD("_sheet_preview_input"), &SpriteFramesEditor::_sheet_preview_input);
  681. ClassDB::bind_method(D_METHOD("_sheet_spin_changed"), &SpriteFramesEditor::_sheet_spin_changed);
  682. ClassDB::bind_method(D_METHOD("_sheet_add_frames"), &SpriteFramesEditor::_sheet_add_frames);
  683. ClassDB::bind_method(D_METHOD("_sheet_select_clear_all_frames"), &SpriteFramesEditor::_sheet_select_clear_all_frames);
  684. }
  685. SpriteFramesEditor::SpriteFramesEditor() {
  686. VBoxContainer *vbc_animlist = memnew(VBoxContainer);
  687. add_child(vbc_animlist);
  688. vbc_animlist->set_custom_minimum_size(Size2(150, 0) * EDSCALE);
  689. VBoxContainer *sub_vb = memnew(VBoxContainer);
  690. vbc_animlist->add_margin_child(TTR("Animations:"), sub_vb, true);
  691. sub_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  692. HBoxContainer *hbc_animlist = memnew(HBoxContainer);
  693. sub_vb->add_child(hbc_animlist);
  694. new_anim = memnew(ToolButton);
  695. new_anim->set_tooltip(TTR("New Animation"));
  696. hbc_animlist->add_child(new_anim);
  697. new_anim->connect("pressed", this, "_animation_add");
  698. remove_anim = memnew(ToolButton);
  699. remove_anim->set_tooltip(TTR("Remove Animation"));
  700. hbc_animlist->add_child(remove_anim);
  701. remove_anim->connect("pressed", this, "_animation_remove");
  702. animations = memnew(Tree);
  703. sub_vb->add_child(animations);
  704. animations->set_v_size_flags(SIZE_EXPAND_FILL);
  705. animations->set_hide_root(true);
  706. animations->connect("cell_selected", this, "_animation_select");
  707. animations->connect("item_edited", this, "_animation_name_edited");
  708. animations->set_allow_reselect(true);
  709. HBoxContainer *hbc_anim_speed = memnew(HBoxContainer);
  710. hbc_anim_speed->add_child(memnew(Label(TTR("Speed:"))));
  711. vbc_animlist->add_child(hbc_anim_speed);
  712. anim_speed = memnew(SpinBox);
  713. anim_speed->set_suffix(TTR("FPS"));
  714. anim_speed->set_min(0);
  715. anim_speed->set_max(100);
  716. anim_speed->set_step(0.01);
  717. anim_speed->set_h_size_flags(SIZE_EXPAND_FILL);
  718. hbc_anim_speed->add_child(anim_speed);
  719. anim_speed->connect("value_changed", this, "_animation_fps_changed");
  720. anim_loop = memnew(CheckButton);
  721. anim_loop->set_text(TTR("Loop"));
  722. vbc_animlist->add_child(anim_loop);
  723. anim_loop->connect("pressed", this, "_animation_loop_changed");
  724. VBoxContainer *vbc = memnew(VBoxContainer);
  725. add_child(vbc);
  726. vbc->set_h_size_flags(SIZE_EXPAND_FILL);
  727. sub_vb = memnew(VBoxContainer);
  728. vbc->add_margin_child(TTR("Animation Frames:"), sub_vb, true);
  729. HBoxContainer *hbc = memnew(HBoxContainer);
  730. sub_vb->add_child(hbc);
  731. load = memnew(ToolButton);
  732. load->set_tooltip(TTR("Add a Texture from File"));
  733. hbc->add_child(load);
  734. load_sheet = memnew(ToolButton);
  735. load_sheet->set_tooltip(TTR("Add Frames from a Sprite Sheet"));
  736. hbc->add_child(load_sheet);
  737. hbc->add_child(memnew(VSeparator));
  738. copy = memnew(ToolButton);
  739. copy->set_tooltip(TTR("Copy"));
  740. hbc->add_child(copy);
  741. paste = memnew(ToolButton);
  742. paste->set_tooltip(TTR("Paste"));
  743. hbc->add_child(paste);
  744. hbc->add_child(memnew(VSeparator));
  745. empty = memnew(ToolButton);
  746. empty->set_tooltip(TTR("Insert Empty (Before)"));
  747. hbc->add_child(empty);
  748. empty2 = memnew(ToolButton);
  749. empty2->set_tooltip(TTR("Insert Empty (After)"));
  750. hbc->add_child(empty2);
  751. hbc->add_child(memnew(VSeparator));
  752. move_up = memnew(ToolButton);
  753. move_up->set_tooltip(TTR("Move (Before)"));
  754. hbc->add_child(move_up);
  755. move_down = memnew(ToolButton);
  756. move_down->set_tooltip(TTR("Move (After)"));
  757. hbc->add_child(move_down);
  758. _delete = memnew(ToolButton);
  759. _delete->set_tooltip(TTR("Delete"));
  760. hbc->add_child(_delete);
  761. file = memnew(EditorFileDialog);
  762. add_child(file);
  763. tree = memnew(ItemList);
  764. tree->set_v_size_flags(SIZE_EXPAND_FILL);
  765. tree->set_icon_mode(ItemList::ICON_MODE_TOP);
  766. int thumbnail_size = 96;
  767. tree->set_max_columns(0);
  768. tree->set_icon_mode(ItemList::ICON_MODE_TOP);
  769. tree->set_fixed_column_width(thumbnail_size * 3 / 2);
  770. tree->set_max_text_lines(2);
  771. tree->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size));
  772. tree->set_drag_forwarding(this);
  773. sub_vb->add_child(tree);
  774. dialog = memnew(AcceptDialog);
  775. add_child(dialog);
  776. load->connect("pressed", this, "_load_pressed");
  777. load_sheet->connect("pressed", this, "_open_sprite_sheet");
  778. _delete->connect("pressed", this, "_delete_pressed");
  779. copy->connect("pressed", this, "_copy_pressed");
  780. paste->connect("pressed", this, "_paste_pressed");
  781. empty->connect("pressed", this, "_empty_pressed");
  782. empty2->connect("pressed", this, "_empty2_pressed");
  783. move_up->connect("pressed", this, "_up_pressed");
  784. move_down->connect("pressed", this, "_down_pressed");
  785. file->connect("files_selected", this, "_file_load_request");
  786. loading_scene = false;
  787. sel = -1;
  788. updating = false;
  789. edited_anim = "default";
  790. delete_dialog = memnew(ConfirmationDialog);
  791. add_child(delete_dialog);
  792. delete_dialog->connect("confirmed", this, "_animation_remove_confirmed");
  793. split_sheet_dialog = memnew(ConfirmationDialog);
  794. add_child(split_sheet_dialog);
  795. VBoxContainer *split_sheet_vb = memnew(VBoxContainer);
  796. split_sheet_dialog->add_child(split_sheet_vb);
  797. split_sheet_dialog->set_title(TTR("Select Frames"));
  798. split_sheet_dialog->connect("confirmed", this, "_sheet_add_frames");
  799. HBoxContainer *split_sheet_hb = memnew(HBoxContainer);
  800. Label *ss_label = memnew(Label(TTR("Horizontal:")));
  801. split_sheet_hb->add_child(ss_label);
  802. split_sheet_h = memnew(SpinBox);
  803. split_sheet_h->set_min(1);
  804. split_sheet_h->set_max(128);
  805. split_sheet_h->set_step(1);
  806. split_sheet_hb->add_child(split_sheet_h);
  807. split_sheet_h->connect("value_changed", this, "_sheet_spin_changed");
  808. ss_label = memnew(Label(TTR("Vertical:")));
  809. split_sheet_hb->add_child(ss_label);
  810. split_sheet_v = memnew(SpinBox);
  811. split_sheet_v->set_min(1);
  812. split_sheet_v->set_max(128);
  813. split_sheet_v->set_step(1);
  814. split_sheet_hb->add_child(split_sheet_v);
  815. split_sheet_v->connect("value_changed", this, "_sheet_spin_changed");
  816. split_sheet_hb->add_spacer();
  817. Button *select_clear_all = memnew(Button);
  818. select_clear_all->set_text(TTR("Select/Clear All Frames"));
  819. select_clear_all->connect("pressed", this, "_sheet_select_clear_all_frames");
  820. split_sheet_hb->add_child(select_clear_all);
  821. split_sheet_vb->add_child(split_sheet_hb);
  822. split_sheet_preview = memnew(TextureRect);
  823. split_sheet_preview->set_expand(false);
  824. split_sheet_preview->set_mouse_filter(MOUSE_FILTER_PASS);
  825. split_sheet_preview->connect("draw", this, "_sheet_preview_draw");
  826. split_sheet_preview->connect("gui_input", this, "_sheet_preview_input");
  827. splite_sheet_scroll = memnew(ScrollContainer);
  828. splite_sheet_scroll->set_enable_h_scroll(true);
  829. splite_sheet_scroll->set_enable_v_scroll(true);
  830. splite_sheet_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
  831. CenterContainer *cc = memnew(CenterContainer);
  832. cc->add_child(split_sheet_preview);
  833. cc->set_h_size_flags(SIZE_EXPAND_FILL);
  834. cc->set_v_size_flags(SIZE_EXPAND_FILL);
  835. splite_sheet_scroll->add_child(cc);
  836. split_sheet_vb->add_child(splite_sheet_scroll);
  837. file_split_sheet = memnew(EditorFileDialog);
  838. file_split_sheet->set_title(TTR("Create Frames from Sprite Sheet"));
  839. file_split_sheet->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  840. add_child(file_split_sheet);
  841. file_split_sheet->connect("file_selected", this, "_prepare_sprite_sheet");
  842. }
  843. void SpriteFramesEditorPlugin::edit(Object *p_object) {
  844. frames_editor->set_undo_redo(&get_undo_redo());
  845. SpriteFrames *s;
  846. AnimatedSprite *animated_sprite = Object::cast_to<AnimatedSprite>(p_object);
  847. if (animated_sprite) {
  848. s = *animated_sprite->get_sprite_frames();
  849. } else {
  850. s = Object::cast_to<SpriteFrames>(p_object);
  851. }
  852. frames_editor->edit(s);
  853. }
  854. bool SpriteFramesEditorPlugin::handles(Object *p_object) const {
  855. AnimatedSprite *animated_sprite = Object::cast_to<AnimatedSprite>(p_object);
  856. if (animated_sprite && *animated_sprite->get_sprite_frames()) {
  857. return true;
  858. } else {
  859. return p_object->is_class("SpriteFrames");
  860. }
  861. }
  862. void SpriteFramesEditorPlugin::make_visible(bool p_visible) {
  863. if (p_visible) {
  864. button->show();
  865. editor->make_bottom_panel_item_visible(frames_editor);
  866. } else {
  867. button->hide();
  868. if (frames_editor->is_visible_in_tree())
  869. editor->hide_bottom_panel();
  870. }
  871. }
  872. SpriteFramesEditorPlugin::SpriteFramesEditorPlugin(EditorNode *p_node) {
  873. editor = p_node;
  874. frames_editor = memnew(SpriteFramesEditor);
  875. frames_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE);
  876. button = editor->add_bottom_panel_item(TTR("SpriteFrames"), frames_editor);
  877. button->hide();
  878. }
  879. SpriteFramesEditorPlugin::~SpriteFramesEditorPlugin() {
  880. }