sprite_frames_editor_plugin.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*************************************************************************/
  2. /* sprite_frames_editor_plugin.h */
  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. #ifndef SPRITE_FRAMES_EDITOR_PLUGIN_H
  31. #define SPRITE_FRAMES_EDITOR_PLUGIN_H
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "scene/2d/animated_sprite.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/file_dialog.h"
  37. #include "scene/gui/split_container.h"
  38. #include "scene/gui/texture_rect.h"
  39. #include "scene/gui/tree.h"
  40. class SpriteFramesEditor : public HSplitContainer {
  41. GDCLASS(SpriteFramesEditor, HSplitContainer);
  42. ToolButton *load;
  43. ToolButton *load_sheet;
  44. ToolButton *_delete;
  45. ToolButton *copy;
  46. ToolButton *paste;
  47. ToolButton *empty;
  48. ToolButton *empty2;
  49. ToolButton *move_up;
  50. ToolButton *move_down;
  51. ItemList *tree;
  52. bool loading_scene;
  53. int sel;
  54. HSplitContainer *split;
  55. ToolButton *new_anim;
  56. ToolButton *remove_anim;
  57. Tree *animations;
  58. SpinBox *anim_speed;
  59. CheckButton *anim_loop;
  60. EditorFileDialog *file;
  61. AcceptDialog *dialog;
  62. SpriteFrames *frames;
  63. StringName edited_anim;
  64. ConfirmationDialog *delete_dialog;
  65. ConfirmationDialog *split_sheet_dialog;
  66. ScrollContainer *splite_sheet_scroll;
  67. TextureRect *split_sheet_preview;
  68. SpinBox *split_sheet_h;
  69. SpinBox *split_sheet_v;
  70. EditorFileDialog *file_split_sheet;
  71. Set<int> frames_selected;
  72. int last_frame_selected;
  73. void _load_pressed();
  74. void _load_scene_pressed();
  75. void _file_load_request(const PoolVector<String> &p_path, int p_at_pos = -1);
  76. void _copy_pressed();
  77. void _paste_pressed();
  78. void _empty_pressed();
  79. void _empty2_pressed();
  80. void _delete_pressed();
  81. void _up_pressed();
  82. void _down_pressed();
  83. void _update_library(bool p_skip_selector = false);
  84. void _animation_select();
  85. void _animation_name_edited();
  86. void _animation_add();
  87. void _animation_remove();
  88. void _animation_remove_confirmed();
  89. void _animation_loop_changed();
  90. void _animation_fps_changed(double p_value);
  91. bool updating;
  92. UndoRedo *undo_redo;
  93. bool _is_drop_valid(const Dictionary &p_drag_data, const Dictionary &p_item_data) const;
  94. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  95. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  96. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  97. void _open_sprite_sheet();
  98. void _prepare_sprite_sheet(const String &p_file);
  99. void _sheet_preview_draw();
  100. void _sheet_spin_changed(double);
  101. void _sheet_preview_input(const Ref<InputEvent> &p_event);
  102. void _sheet_add_frames();
  103. void _sheet_select_clear_all_frames();
  104. protected:
  105. void _notification(int p_what);
  106. void _gui_input(Ref<InputEvent> p_event);
  107. static void _bind_methods();
  108. public:
  109. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  110. void edit(SpriteFrames *p_frames);
  111. SpriteFramesEditor();
  112. };
  113. class SpriteFramesEditorPlugin : public EditorPlugin {
  114. GDCLASS(SpriteFramesEditorPlugin, EditorPlugin);
  115. SpriteFramesEditor *frames_editor;
  116. EditorNode *editor;
  117. Button *button;
  118. public:
  119. virtual String get_name() const { return "SpriteFrames"; }
  120. bool has_main_screen() const { return false; }
  121. virtual void edit(Object *p_object);
  122. virtual bool handles(Object *p_object) const;
  123. virtual void make_visible(bool p_visible);
  124. SpriteFramesEditorPlugin(EditorNode *p_node);
  125. ~SpriteFramesEditorPlugin();
  126. };
  127. #endif // SPRITE_FRAMES_EDITOR_PLUGIN_H