1 /*************************************************************************/ 2 /* animation_tree_editor_plugin.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 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 31 #ifndef ANIMATION_TREE_EDITOR_PLUGIN_H 32 #define ANIMATION_TREE_EDITOR_PLUGIN_H 33 34 #include "editor/editor_node.h" 35 #include "editor/editor_plugin.h" 36 #include "editor/property_editor.h" 37 #include "scene/animation/animation_tree.h" 38 #include "scene/gui/button.h" 39 #include "scene/gui/graph_edit.h" 40 #include "scene/gui/popup.h" 41 #include "scene/gui/tree.h" 42 43 class AnimationTreeNodeEditorPlugin : public VBoxContainer { 44 GDCLASS(AnimationTreeNodeEditorPlugin, VBoxContainer); 45 46 public: 47 virtual bool can_edit(const Ref<AnimationNode> &p_node) = 0; 48 virtual void edit(const Ref<AnimationNode> &p_node) = 0; 49 }; 50 51 class AnimationTreeEditor : public VBoxContainer { 52 53 GDCLASS(AnimationTreeEditor, VBoxContainer); 54 55 ScrollContainer *path_edit; 56 HBoxContainer *path_hb; 57 58 AnimationTree *tree; 59 MarginContainer *editor_base; 60 61 Vector<String> button_path; 62 Vector<String> edited_path; 63 Vector<AnimationTreeNodeEditorPlugin *> editors; 64 65 void _update_path(); 66 void _about_to_show_root(); 67 ObjectID current_root; 68 69 void _path_button_pressed(int p_path); 70 71 static Vector<String> get_animation_list(); 72 73 protected: 74 void _notification(int p_what); 75 static void _bind_methods(); 76 77 static AnimationTreeEditor *singleton; 78 79 public: get_tree()80 AnimationTree *get_tree() { return tree; } 81 void add_plugin(AnimationTreeNodeEditorPlugin *p_editor); 82 void remove_plugin(AnimationTreeNodeEditorPlugin *p_editor); 83 84 String get_base_path(); 85 86 bool can_edit(const Ref<AnimationNode> &p_node) const; 87 88 void edit_path(const Vector<String> &p_path); 89 Vector<String> get_edited_path() const; 90 91 void enter_editor(const String &p_path = ""); get_singleton()92 static AnimationTreeEditor *get_singleton() { return singleton; } 93 void edit(AnimationTree *p_tree); 94 AnimationTreeEditor(); 95 }; 96 97 class AnimationTreeEditorPlugin : public EditorPlugin { 98 99 GDCLASS(AnimationTreeEditorPlugin, EditorPlugin); 100 101 AnimationTreeEditor *anim_tree_editor; 102 EditorNode *editor; 103 Button *button; 104 105 public: get_name()106 virtual String get_name() const { return "AnimationTree"; } has_main_screen()107 bool has_main_screen() const { return false; } 108 virtual void edit(Object *p_object); 109 virtual bool handles(Object *p_object) const; 110 virtual void make_visible(bool p_visible); 111 112 AnimationTreeEditorPlugin(EditorNode *p_node); 113 ~AnimationTreeEditorPlugin(); 114 }; 115 116 #endif // ANIMATION_TREE_EDITOR_PLUGIN_H 117