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-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 ANIMATION_TREE_EDITOR_PLUGIN_H 31 #define ANIMATION_TREE_EDITOR_PLUGIN_H 32 33 #include "editor/editor_node.h" 34 #include "editor/editor_plugin.h" 35 #include "editor/property_editor.h" 36 #include "scene/animation/animation_tree_player.h" 37 #include "scene/gui/button.h" 38 #include "scene/gui/popup.h" 39 #include "scene/gui/tree.h" 40 /** 41 @author Juan Linietsky <reduzio@gmail.com> 42 */ 43 44 class AnimationTreeEditor : public Control { 45 46 OBJ_TYPE(AnimationTreeEditor, Control); 47 48 static const char *_node_type_names[]; 49 50 enum ClickType { 51 CLICK_NONE, 52 CLICK_NAME, 53 CLICK_NODE, 54 CLICK_INPUT_SLOT, 55 CLICK_OUTPUT_SLOT, 56 CLICK_PARAMETER 57 }; 58 59 enum { 60 61 MENU_GRAPH_CLEAR = 100, 62 MENU_IMPORT_ANIMATIONS = 101, 63 NODE_DISCONNECT, 64 NODE_RENAME, 65 NODE_ERASE, 66 NODE_ADD_INPUT, 67 NODE_DELETE_INPUT, 68 NODE_SET_AUTOADVANCE, 69 NODE_CLEAR_AUTOADVANCE 70 }; 71 72 bool renaming_edit; 73 StringName edited_node; 74 bool updating_edit; 75 Popup *edit_dialog; 76 HSlider *edit_scroll[2]; 77 LineEdit *edit_line[4]; 78 OptionButton *edit_option; 79 Label *edit_label[4]; 80 Button *edit_button; 81 Button *filter_button; 82 CheckButton *edit_check; 83 EditorFileDialog *file_dialog; 84 int file_op; 85 86 void _popup_edit_dialog(); 87 88 void _setup_edit_dialog(const StringName &p_node); 89 PopupMenu *master_anim_popup; 90 PopupMenu *node_popup; 91 PopupMenu *add_popup; 92 HScrollBar *h_scroll; 93 VScrollBar *v_scroll; 94 MenuButton *add_menu; 95 96 CustomPropertyEditor *property_editor; 97 98 AnimationTreePlayer *anim_tree; 99 List<StringName> order; 100 Set<StringName> active_nodes; 101 102 int last_x, last_y; 103 104 Point2 offset; 105 ClickType click_type; 106 Point2 click_pos; 107 StringName click_node; 108 int click_slot; 109 Point2 click_motion; 110 ClickType rclick_type; 111 StringName rclick_node; 112 int rclick_slot; 113 114 Button *play_button; 115 116 Size2 _get_maximum_size(); 117 Size2 get_node_size(const StringName &p_node) const; 118 void _draw_node(const StringName &p_node); 119 120 AcceptDialog *filter_dialog; 121 Tree *filter; 122 123 void _draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color); 124 void _update_scrollbars(); 125 void _scroll_moved(float); 126 void _play_toggled(); 127 /* 128 void _node_param_changed(); 129 void _node_add_callback(); 130 void _node_add(VisualServer::AnimationTreeNodeType p_type); 131 void _node_edit_property(const StringName& p_node); 132 */ 133 134 void _master_anim_menu_item(int p_item); 135 void _node_menu_item(int p_item); 136 void _add_menu_item(int p_item); 137 138 void _filter_edited(); 139 void _find_paths_for_filter(const StringName &p_node, Set<String> &paths); 140 void _edit_filters(); 141 142 void _edit_oneshot_start(); 143 void _edit_dialog_animation_changed(); 144 void _edit_dialog_edit_animation(); 145 void _edit_dialog_changeds(String); 146 void _edit_dialog_changede(String); 147 void _edit_dialog_changedf(float); 148 void _edit_dialog_changed(); 149 void _dialog_changed() const; 150 ClickType _locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const; 151 Point2 _get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot); 152 153 StringName _add_node(int p_item); 154 void _file_dialog_selected(String p_path); 155 156 protected: 157 void _notification(int p_what); 158 void _input_event(InputEvent p_event); 159 static void _bind_methods(); 160 161 public: 162 virtual Size2 get_minimum_size() const; 163 void edit(AnimationTreePlayer *p_player); 164 AnimationTreeEditor(); 165 }; 166 167 class AnimationTreeEditorPlugin : public EditorPlugin { 168 169 OBJ_TYPE(AnimationTreeEditorPlugin, EditorPlugin); 170 171 AnimationTreeEditor *anim_tree_editor; 172 EditorNode *editor; 173 Button *button; 174 175 public: get_name()176 virtual String get_name() const { return "AnimTree"; } has_main_screen()177 bool has_main_screen() const { return false; } 178 virtual void edit(Object *p_node); 179 virtual bool handles(Object *p_node) const; 180 virtual void make_visible(bool p_visible); 181 182 AnimationTreeEditorPlugin(EditorNode *p_node); 183 ~AnimationTreeEditorPlugin(); 184 }; 185 186 #endif // ANIMATION_TREE_EDITOR_PLUGIN_H 187