Debian Codegraph @

editor/animation/animation_blend_tree_editor_plugin.h

raw symbols SCIP
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) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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 #pragma once
32
33 #include "core/object/script_language.h"
34 #include "editor/animation/animation_tree_editor_plugin.h"
35 #include "editor/inspector/editor_inspector.h"
36 #include "scene/animation/animation_blend_tree.h"
37 #include "scene/gui/button.h"
38 #include "scene/gui/dialogs.h"
39 #include "scene/gui/graph_edit.h"
40 #include "scene/gui/panel_container.h"
41 #include "scene/gui/tree.h"
42
43 class AcceptDialog;
44 class CheckBox;
45 class ProgressBar;
46 class EditorFileDialog;
47 class EditorProperty;
48 class MenuButton;
49 class PanelContainer;
50 class EditorInspectorPluginAnimationNodeAnimation;
51
52 class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
53 GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin);
54
55 Ref<AnimationNodeBlendTree> blend_tree;
56
57 bool read_only = false;
58
59 GraphEdit *graph = nullptr;
60 MenuButton *add_node = nullptr;
61 Vector2 position_from_popup_menu;
62 bool use_position_from_popup_menu;
63
64 PanelContainer *error_panel = nullptr;
65 Label *error_label = nullptr;
66
67 AcceptDialog *filter_dialog = nullptr;
68 Tree *filters = nullptr;
69 CheckBox *filter_enabled = nullptr;
70 Button *filter_fill_selection = nullptr;
71 Button *filter_invert_selection = nullptr;
72 Button *filter_clear_selection = nullptr;
73
74 HashMap<StringName, ProgressBar *> animations;
75 Vector<EditorProperty *> visible_properties;
76
77 String to_node = "";
78 int to_slot = -1;
79 String from_node = "";
80
81 struct AddOption {
82 String name;
83 String type;
84 Ref<Script> script;
85 int input_port_count;
86 AddOption(const String &p_name = String(), const String &p_type = String(), int p_input_port_count = 0) :
87 name(p_name),
88 type(p_type),
89 input_port_count(p_input_port_count) {
90 }
91 };
92
93 Vector<AddOption> add_options;
94
95 void _add_node(int p_idx);
96 void _update_options_menu(bool p_has_input_ports = false);
97
98 static AnimationNodeBlendTreeEditor *singleton;
99
100 void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);
101 void _node_renamed(const String &p_text, Ref<AnimationNode> p_node);
102 void _node_renamed_focus_out(Ref<AnimationNode> p_node);
103 void _node_rename_lineedit_changed(const String &p_text);
104 void _node_changed(const StringName &p_node_name);
105
106 String current_node_rename_text;
107 bool updating;
108
109 void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
110 void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
111
112 void _scroll_changed(const Vector2 &p_scroll);
113 void _node_selected(Object *p_node);
114 void _node_deselected(Object *p_node);
115 void _open_in_editor(const String &p_which);
116 void _anim_selected(int p_index, const Array &p_options, const String &p_node);
117 void _delete_node_request(const String &p_which);
118 void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
119
120 bool _update_filters(const Ref<AnimationNode> &anode);
121 void _inspect_filters(const String &p_which);
122 void _filter_edited();
123 void _filter_toggled();
124 void _filter_fill_selection();
125 void _filter_invert_selection();
126 void _filter_clear_selection();
127 void _filter_fill_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item, bool p_parent_filtered);
128 void _filter_invert_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);
129 void _filter_clear_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);
130 Ref<AnimationNode> _filter_edit;
131
132 void _popup(bool p_has_input_ports, const Vector2 &p_node_position);
133 void _popup_request(const Vector2 &p_position);
134 void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
135 void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
136 void _popup_hide();
137
138 void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
139
140 void _update_editor_settings();
141
142 EditorFileDialog *open_file = nullptr;
143 Ref<AnimationNode> file_loaded;
144 void _file_opened(const String &p_file);
145
146 enum {
147 MENU_LOAD_FILE = 1000,
148 MENU_PASTE = 1001,
149 MENU_LOAD_FILE_CONFIRM = 1002
150 };
151
152 Ref<EditorInspectorPluginAnimationNodeAnimation> animation_node_inspector_plugin;
153
154 protected:
155 void _notification(int p_what);
156 static void _bind_methods();
157
158 public:
159 static AnimationNodeBlendTreeEditor *get_singleton() { return singleton; }
160
161 void add_custom_type(const String &p_name, const Ref<Script> &p_script);
162 void remove_custom_type(const Ref<Script> &p_script);
163
164 virtual Size2 get_minimum_size() const override;
165
166 virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
167 virtual void edit(const Ref<AnimationNode> &p_node) override;
168
169 void update_graph();
170
171 AnimationNodeBlendTreeEditor();
172 };
173
174 // EditorPluginAnimationNodeAnimation
175
176 class EditorInspectorPluginAnimationNodeAnimation : public EditorInspectorPlugin {
177 GDCLASS(EditorInspectorPluginAnimationNodeAnimation, EditorInspectorPlugin);
178
179 public:
180 virtual bool can_handle(Object *p_object) override;
181 virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) override;
182 };
183
184 class AnimationNodeAnimationEditorDialog : public ConfirmationDialog {
185 GDCLASS(AnimationNodeAnimationEditorDialog, ConfirmationDialog);
186
187 friend class AnimationNodeAnimationEditor;
188
189 OptionButton *select_start = nullptr;
190 OptionButton *select_end = nullptr;
191
192 public:
193 AnimationNodeAnimationEditorDialog();
194 };
195
196 class AnimationNodeAnimationEditor : public VBoxContainer {
197 GDCLASS(AnimationNodeAnimationEditor, VBoxContainer);
198
199 Ref<AnimationNodeAnimation> animation_node_animation;
200 Button *button = nullptr;
201 AnimationNodeAnimationEditorDialog *dialog = nullptr;
202 void _open_set_custom_timeline_from_marker_dialog();
203 void _validate_markers(int p_id);
204 void _confirm_set_custom_timeline_from_marker_dialog();
205
206 public:
207 AnimationNodeAnimationEditor(Ref<AnimationNodeAnimation> p_animation_node_animation);
208
209 protected:
210 void _notification(int p_what);
211 };