1 /*************************************************************************/
2 /*  animation_blend_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_BLEND_TREE_EDITOR_PLUGIN_H
32 #define ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H
33 
34 #include "editor/editor_node.h"
35 #include "editor/editor_plugin.h"
36 #include "editor/plugins/animation_tree_editor_plugin.h"
37 #include "editor/property_editor.h"
38 #include "scene/animation/animation_blend_tree.h"
39 #include "scene/gui/button.h"
40 #include "scene/gui/graph_edit.h"
41 #include "scene/gui/popup.h"
42 #include "scene/gui/tree.h"
43 
44 class ProgressBar;
45 
46 class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
47 
48 	GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin);
49 
50 	Ref<AnimationNodeBlendTree> blend_tree;
51 	GraphEdit *graph;
52 	MenuButton *add_node;
53 	Vector2 popup_menu_position;
54 	bool use_popup_menu_position;
55 
56 	PanelContainer *error_panel;
57 	Label *error_label;
58 
59 	UndoRedo *undo_redo;
60 
61 	AcceptDialog *filter_dialog;
62 	Tree *filters;
63 	CheckBox *filter_enabled;
64 
65 	Map<StringName, ProgressBar *> animations;
66 	Vector<EditorProperty *> visible_properties;
67 
68 	void _update_graph();
69 
70 	struct AddOption {
71 		String name;
72 		String type;
73 		Ref<Script> script;
74 		AddOption(const String &p_name = String(), const String &p_type = String()) :
nameAddOption75 				name(p_name),
76 				type(p_type) {
77 		}
78 	};
79 
80 	Vector<AddOption> add_options;
81 
82 	void _add_node(int p_idx);
83 	void _update_options_menu();
84 
85 	static AnimationNodeBlendTreeEditor *singleton;
86 
87 	void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);
88 	void _node_renamed(const String &p_text, Ref<AnimationNode> p_node);
89 	void _node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node);
90 
91 	bool updating;
92 
93 	void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
94 	void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
95 
96 	void _scroll_changed(const Vector2 &p_scroll);
97 	void _node_selected(Object *p_node);
98 	void _open_in_editor(const String &p_which);
99 	void _anim_selected(int p_index, Array p_options, const String &p_node);
100 	void _delete_request(const String &p_which);
101 	void _delete_nodes_request();
102 	void _popup_request(const Vector2 &p_position);
103 
104 	bool _update_filters(const Ref<AnimationNode> &anode);
105 	void _edit_filters(const String &p_which);
106 	void _filter_edited();
107 	void _filter_toggled();
108 	Ref<AnimationNode> _filter_edit;
109 
110 	void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
111 	void _removed_from_graph();
112 
113 	EditorFileDialog *open_file;
114 	Ref<AnimationNode> file_loaded;
115 	void _file_opened(const String &p_file);
116 
117 	enum {
118 		MENU_LOAD_FILE = 1000,
119 		MENU_PASTE = 1001,
120 		MENU_LOAD_FILE_CONFIRM = 1002
121 	};
122 
123 protected:
124 	void _notification(int p_what);
125 	static void _bind_methods();
126 
127 public:
get_singleton()128 	static AnimationNodeBlendTreeEditor *get_singleton() { return singleton; }
129 
130 	void add_custom_type(const String &p_name, const Ref<Script> &p_script);
131 	void remove_custom_type(const Ref<Script> &p_script);
132 
133 	virtual Size2 get_minimum_size() const;
134 
135 	virtual bool can_edit(const Ref<AnimationNode> &p_node);
136 	virtual void edit(const Ref<AnimationNode> &p_node);
137 
138 	AnimationNodeBlendTreeEditor();
139 };
140 
141 #endif // ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H
142