| 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 | #ifndef ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H |
| 32 | #define ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H |
| 33 | |
| 34 | #include "core/object/script_language.h" |
| 35 | #include "editor/plugins/animation_tree_editor_plugin.h" |
| 36 | #include "scene/animation/animation_blend_tree.h" |
| 37 | #include "scene/gui/button.h" |
| 38 | #include "scene/gui/graph_edit.h" |
| 39 | #include "scene/gui/panel_container.h" |
| 40 | #include "scene/gui/popup.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 ; |
| 49 | class PanelContainer; |
| 50 | |
| 51 | class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { |
| 52 | GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin); |
| 53 | |
| 54 | Ref<AnimationNodeBlendTree> blend_tree; |
| 55 | |
| 56 | bool read_only = false; |
| 57 | |
| 58 | GraphEdit *graph = nullptr; |
| 59 | MenuButton *add_node = nullptr; |
| 60 | Vector2 ; |
| 61 | bool ; |
| 62 | |
| 63 | PanelContainer *error_panel = nullptr; |
| 64 | Label *error_label = nullptr; |
| 65 | |
| 66 | AcceptDialog *filter_dialog = nullptr; |
| 67 | Tree *filters = nullptr; |
| 68 | CheckBox *filter_enabled = nullptr; |
| 69 | |
| 70 | HashMap<StringName, ProgressBar *> animations; |
| 71 | Vector<EditorProperty *> visible_properties; |
| 72 | |
| 73 | String to_node = "" ; |
| 74 | int to_slot = -1; |
| 75 | String from_node = "" ; |
| 76 | |
| 77 | struct AddOption { |
| 78 | String name; |
| 79 | String type; |
| 80 | Ref<Script> script; |
| 81 | int input_port_count; |
| 82 | AddOption(const String &p_name = String(), const String &p_type = String(), int p_input_port_count = 0) : |
| 83 | name(p_name), |
| 84 | type(p_type), |
| 85 | input_port_count(p_input_port_count) { |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | Vector<AddOption> add_options; |
| 90 | |
| 91 | void _add_node(int p_idx); |
| 92 | void (bool p_has_input_ports = false); |
| 93 | |
| 94 | static AnimationNodeBlendTreeEditor *singleton; |
| 95 | |
| 96 | void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which); |
| 97 | void _node_renamed(const String &p_text, Ref<AnimationNode> p_node); |
| 98 | void _node_renamed_focus_out(Ref<AnimationNode> p_node); |
| 99 | void _node_rename_lineedit_changed(const String &p_text); |
| 100 | void _node_changed(const StringName &p_node_name); |
| 101 | |
| 102 | String current_node_rename_text; |
| 103 | bool updating; |
| 104 | |
| 105 | void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index); |
| 106 | void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index); |
| 107 | |
| 108 | void _scroll_changed(const Vector2 &p_scroll); |
| 109 | void _node_selected(Object *p_node); |
| 110 | void _open_in_editor(const String &p_which); |
| 111 | void _anim_selected(int p_index, Array p_options, const String &p_node); |
| 112 | void _close_request(const String &p_which); |
| 113 | void _close_nodes_request(const TypedArray<StringName> &p_nodes); |
| 114 | |
| 115 | bool _update_filters(const Ref<AnimationNode> &anode); |
| 116 | void _inspect_filters(const String &p_which); |
| 117 | void _filter_edited(); |
| 118 | void _filter_toggled(); |
| 119 | Ref<AnimationNode> _filter_edit; |
| 120 | |
| 121 | void (bool p_has_input_ports, const Vector2 &p_node_position); |
| 122 | void (const Vector2 &p_position); |
| 123 | void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position); |
| 124 | void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position); |
| 125 | void (); |
| 126 | |
| 127 | void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); |
| 128 | |
| 129 | void _update_editor_settings(); |
| 130 | void _update_theme(); |
| 131 | |
| 132 | EditorFileDialog *open_file = nullptr; |
| 133 | Ref<AnimationNode> file_loaded; |
| 134 | void _file_opened(const String &p_file); |
| 135 | |
| 136 | enum { |
| 137 | = 1000, |
| 138 | = 1001, |
| 139 | = 1002 |
| 140 | }; |
| 141 | |
| 142 | protected: |
| 143 | void _notification(int p_what); |
| 144 | static void _bind_methods(); |
| 145 | |
| 146 | public: |
| 147 | static AnimationNodeBlendTreeEditor *get_singleton() { return singleton; } |
| 148 | |
| 149 | void add_custom_type(const String &p_name, const Ref<Script> &p_script); |
| 150 | void remove_custom_type(const Ref<Script> &p_script); |
| 151 | |
| 152 | virtual Size2 get_minimum_size() const override; |
| 153 | |
| 154 | virtual bool can_edit(const Ref<AnimationNode> &p_node) override; |
| 155 | virtual void edit(const Ref<AnimationNode> &p_node) override; |
| 156 | |
| 157 | void update_graph(); |
| 158 | |
| 159 | AnimationNodeBlendTreeEditor(); |
| 160 | }; |
| 161 | |
| 162 | #endif // ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H |
| 163 | |