Skip to content
0.2.0-dev Download ZIP
213 lines ·8.3 KB Raw
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/tree.h"
41
42class AcceptDialog;
43class CheckBox;
44class ProgressBar;
45class EditorFileDialog;
46class EditorProperty;
47class MenuButton;
48class PanelContainer;
49class RichTextLabel;
50class EditorInspectorPluginAnimationNodeAnimation;
51
52class 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 AcceptDialog *filter_dialog = nullptr;
65 Tree *filters = nullptr;
66 CheckBox *filter_enabled = nullptr;
67 Button *filter_fill_selection = nullptr;
68 Button *filter_invert_selection = nullptr;
69 Button *filter_clear_selection = nullptr;
70
71 HashMap<StringName, ProgressBar *> animations;
72 Vector<EditorProperty *> visible_properties;
73
74 String to_node = "";
75 int to_slot = -1;
76 String from_node = "";
77
78 struct AddOption {
79 String name;
80 String type;
81 Ref<Script> script;
82 int input_port_count;
83 AddOption(const String &p_name = String(), const String &p_type = String(), int p_input_port_count = 0) :
84 name(p_name),
85 type(p_type),
86 input_port_count(p_input_port_count) {
87 }
88 };
89
90 Vector<AddOption> add_options;
91
92 void _add_node(int p_idx);
93 void _update_options_menu(bool p_has_input_ports = false);
94
95 StringName animation_node_name_meta = StringName("_animation_node_name");
96 static AnimationNodeBlendTreeEditor *singleton;
97
98 void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);
99 void _node_renamed(const String &p_text, Ref<AnimationNode> p_node, const StringName &p_name);
100 void _node_renamed_focus_out(Ref<AnimationNode> p_node, const StringName &p_name);
101 void _node_rename_lineedit_changed(const String &p_text);
102 void _node_changed(const StringName &p_node_name);
103
104 String current_node_rename_text;
105 bool graph_update_queued = false;
106 bool updating = false;
107
108 void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
109 void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
110
111 void _scroll_changed(const Vector2 &p_scroll);
112 void _node_selected(Object *p_node);
113 void _node_deselected(Object *p_node);
114 void _open_in_editor(const String &p_which);
115 void _anim_selected(int p_index, const Array &p_options, const String &p_node);
116 void _delete_node_request(const String &p_which);
117 void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
118
119 bool _update_filters(const Ref<AnimationNode> &anode);
120 void _inspect_filters(const String &p_which);
121 void _filter_edited();
122 void _filter_toggled();
123 void _filter_fill_selection();
124 void _filter_invert_selection();
125 void _filter_clear_selection();
126 void _filter_fill_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item, bool p_parent_filtered);
127 void _filter_invert_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);
128 void _filter_clear_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);
129 Ref<AnimationNode> _filter_edit;
130
131 void _popup(bool p_has_input_ports, const Vector2 &p_node_position);
132 void _popup_request(const Vector2 &p_position);
133 void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
134 void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
135 void _popup_hide();
136
137 void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
138
139 void _update_editor_settings();
140
141 EditorFileDialog *open_file = nullptr;
142 Ref<AnimationNode> file_loaded;
143 void _file_opened(const String &p_file);
144
145 enum {
146 MENU_LOAD_FILE = 1000,
147 MENU_PASTE = 1001,
148 MENU_LOAD_FILE_CONFIRM = 1002
149 };
150
151 Ref<EditorInspectorPluginAnimationNodeAnimation> animation_node_inspector_plugin;
152 Ref<Tween> pan_to_tween;
153
154protected:
155 void _notification(int p_what);
156 static void _bind_methods();
157
158public:
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 void update_graph_immediately();
171
172 void pan_to_node(const StringName &p_node_name, int p_input_index = -1);
173 AnimationNodeBlendTreeEditor();
174};
175
176// EditorPluginAnimationNodeAnimation
177
178class EditorInspectorPluginAnimationNodeAnimation : public EditorInspectorPlugin {
179 GDCLASS(EditorInspectorPluginAnimationNodeAnimation, EditorInspectorPlugin);
180
181public:
182 virtual bool can_handle(Object *p_object) override;
183 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;
184};
185
186class AnimationNodeAnimationEditorDialog : public ConfirmationDialog {
187 GDCLASS(AnimationNodeAnimationEditorDialog, ConfirmationDialog);
188
189 friend class AnimationNodeAnimationEditor;
190
191 OptionButton *select_start = nullptr;
192 OptionButton *select_end = nullptr;
193
194public:
195 AnimationNodeAnimationEditorDialog();
196};
197
198class AnimationNodeAnimationEditor : public VBoxContainer {
199 GDCLASS(AnimationNodeAnimationEditor, VBoxContainer);
200
201 Ref<AnimationNodeAnimation> animation_node_animation;
202 Button *button = nullptr;
203 AnimationNodeAnimationEditorDialog *dialog = nullptr;
204 void _open_set_custom_timeline_from_marker_dialog();
205 void _validate_markers(int p_id);
206 void _confirm_set_custom_timeline_from_marker_dialog();
207
208public:
209 AnimationNodeAnimationEditor(Ref<AnimationNodeAnimation> p_animation_node_animation);
210
211protected:
212 void _notification(int p_what);
213};