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