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-2019 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2019 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 33 #include "editor/editor_node.h" 34 #include "editor/editor_plugin.h" 35 #include "scene/2d/animated_sprite.h" 36 #include "scene/gui/dialogs.h" 37 #include "scene/gui/file_dialog.h" 38 #include "scene/gui/split_container.h" 39 #include "scene/gui/tree.h" 40 41 class SpriteFramesEditor : public PanelContainer { 42 43 OBJ_TYPE(SpriteFramesEditor, PanelContainer); 44 45 Button *load; 46 Button *_delete; 47 Button *copy; 48 Button *paste; 49 Button *empty; 50 Button *empty2; 51 Button *move_up; 52 Button *move_down; 53 ItemList *tree; 54 bool loading_scene; 55 int sel; 56 57 HSplitContainer *split; 58 Button *new_anim; 59 Button *remove_anim; 60 61 Tree *animations; 62 SpinBox *anim_speed; 63 CheckButton *anim_loop; 64 65 EditorFileDialog *file; 66 67 AcceptDialog *dialog; 68 69 SpriteFrames *frames; 70 71 StringName edited_anim; 72 73 void _load_pressed(); 74 void _load_scene_pressed(); 75 void _file_load_request(const DVector<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 _delete_confirm_pressed(); 82 void _up_pressed(); 83 void _down_pressed(); 84 void _update_library(bool p_skip_selector = false); 85 void _item_edited(); 86 87 void _animation_select(); 88 void _animation_name_edited(); 89 void _animation_add(); 90 void _animation_remove(); 91 void _animation_loop_changed(); 92 void _animation_fps_changed(double p_value); 93 94 bool updating; 95 96 UndoRedo *undo_redo; 97 98 bool _is_drop_valid(const Dictionary &p_drag_data, const Dictionary &p_item_data) const; 99 Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); 100 bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; 101 void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); 102 103 protected: 104 void _notification(int p_what); 105 void _input_event(InputEvent p_event); 106 static void _bind_methods(); 107 108 public: set_undo_redo(UndoRedo * p_undo_redo)109 void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } 110 111 void edit(SpriteFrames *p_frames); 112 SpriteFramesEditor(); 113 }; 114 115 class SpriteFramesEditorPlugin : public EditorPlugin { 116 117 OBJ_TYPE(SpriteFramesEditorPlugin, EditorPlugin); 118 119 SpriteFramesEditor *frames_editor; 120 EditorNode *editor; 121 Button *button; 122 123 public: get_name()124 virtual String get_name() const { return "SpriteFrames"; } has_main_screen()125 bool has_main_screen() const { return false; } 126 virtual void edit(Object *p_node); 127 virtual bool handles(Object *p_node) const; 128 virtual void make_visible(bool p_visible); 129 130 SpriteFramesEditorPlugin(EditorNode *p_node); 131 ~SpriteFramesEditorPlugin(); 132 }; 133 134 #endif // SPRITE_FRAMES_EDITOR_PLUGIN_H 135