| 1 | /**************************************************************************/ |
| 2 | /* scene_tree_editor.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 SCENE_TREE_EDITOR_H |
| 32 | #define SCENE_TREE_EDITOR_H |
| 33 | |
| 34 | #include "scene/gui/check_button.h" |
| 35 | #include "scene/gui/dialogs.h" |
| 36 | #include "scene/gui/tree.h" |
| 37 | |
| 38 | class EditorSelection; |
| 39 | class TextureRect; |
| 40 | |
| 41 | class SceneTreeEditor : public Control { |
| 42 | GDCLASS(SceneTreeEditor, Control); |
| 43 | |
| 44 | EditorSelection *editor_selection = nullptr; |
| 45 | |
| 46 | enum SceneTreeEditorButton { |
| 47 | BUTTON_SUBSCENE = 0, |
| 48 | BUTTON_VISIBILITY = 1, |
| 49 | BUTTON_SCRIPT = 2, |
| 50 | BUTTON_LOCK = 3, |
| 51 | BUTTON_GROUP = 4, |
| 52 | BUTTON_WARNING = 5, |
| 53 | BUTTON_SIGNALS = 6, |
| 54 | BUTTON_GROUPS = 7, |
| 55 | BUTTON_PIN = 8, |
| 56 | BUTTON_UNIQUE = 9, |
| 57 | }; |
| 58 | |
| 59 | Tree *tree = nullptr; |
| 60 | Node *selected = nullptr; |
| 61 | ObjectID instance_node; |
| 62 | |
| 63 | String filter; |
| 64 | String filter_term_warning; |
| 65 | bool show_all_nodes = false; |
| 66 | |
| 67 | AcceptDialog *error = nullptr; |
| 68 | AcceptDialog *warning = nullptr; |
| 69 | |
| 70 | bool auto_expand_selected = true; |
| 71 | bool connect_to_script_mode = false; |
| 72 | bool connecting_signal = false; |
| 73 | |
| 74 | int blocked; |
| 75 | |
| 76 | void _compute_hash(Node *p_node, uint64_t &hash); |
| 77 | |
| 78 | void _add_nodes(Node *p_node, TreeItem *p_parent); |
| 79 | void _test_update_tree(); |
| 80 | bool _update_filter(TreeItem *p_parent = nullptr, bool p_scroll_to_selected = false); |
| 81 | bool _item_matches_all_terms(TreeItem *p_item, PackedStringArray p_terms); |
| 82 | void _tree_changed(); |
| 83 | void _tree_process_mode_changed(); |
| 84 | void _node_removed(Node *p_node); |
| 85 | void _node_renamed(Node *p_node); |
| 86 | |
| 87 | TreeItem *_find(TreeItem *p_node, const NodePath &p_path); |
| 88 | void _notification(int p_what); |
| 89 | void _selected_changed(); |
| 90 | void _deselect_items(); |
| 91 | void _rename_node(Node *p_node, const String &p_name); |
| 92 | |
| 93 | void _cell_collapsed(Object *p_obj); |
| 94 | |
| 95 | uint64_t last_hash; |
| 96 | |
| 97 | bool can_rename; |
| 98 | bool can_open_instance; |
| 99 | bool updating_tree = false; |
| 100 | bool show_enabled_subscene = false; |
| 101 | bool is_scene_tree_dock = false; |
| 102 | |
| 103 | void _renamed(); |
| 104 | |
| 105 | HashSet<Node *> marked; |
| 106 | bool marked_selectable = false; |
| 107 | bool marked_children_selectable = false; |
| 108 | bool display_foreign = false; |
| 109 | bool tree_dirty = true; |
| 110 | bool pending_test_update = false; |
| 111 | static void _bind_methods(); |
| 112 | |
| 113 | void _cell_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button); |
| 114 | void _toggle_visible(Node *p_node); |
| 115 | void _cell_multi_selected(Object *p_object, int p_cell, bool p_selected); |
| 116 | void _update_selection(TreeItem *item); |
| 117 | void _node_script_changed(Node *p_node); |
| 118 | void _node_visibility_changed(Node *p_node); |
| 119 | void _update_visibility_color(Node *p_node, TreeItem *p_item); |
| 120 | void _set_item_custom_color(TreeItem *p_item, Color p_color); |
| 121 | |
| 122 | void _selection_changed(); |
| 123 | Node *get_scene_node(); |
| 124 | |
| 125 | Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |
| 126 | bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
| 127 | void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
| 128 | |
| 129 | void _empty_clicked(const Vector2 &p_pos, MouseButton p_button); |
| 130 | void _rmb_select(const Vector2 &p_pos, MouseButton p_button = MouseButton::RIGHT); |
| 131 | |
| 132 | void _warning_changed(Node *p_for_node); |
| 133 | |
| 134 | Timer *update_timer = nullptr; |
| 135 | |
| 136 | List<StringName> *script_types; |
| 137 | bool _is_script_type(const StringName &p_type) const; |
| 138 | |
| 139 | Vector<StringName> valid_types; |
| 140 | |
| 141 | public: |
| 142 | // Public for use with callable_mp. |
| 143 | void _update_tree(bool p_scroll_to_selected = false); |
| 144 | |
| 145 | void set_filter(const String &p_filter); |
| 146 | String get_filter() const; |
| 147 | String get_filter_term_warning(); |
| 148 | void set_show_all_nodes(bool p_show_all_nodes); |
| 149 | |
| 150 | void set_as_scene_tree_dock(); |
| 151 | void set_display_foreign_nodes(bool p_display); |
| 152 | |
| 153 | void set_marked(const HashSet<Node *> &p_marked, bool p_selectable = false, bool p_children_selectable = true); |
| 154 | void set_marked(Node *p_marked, bool p_selectable = false, bool p_children_selectable = true); |
| 155 | void set_selected(Node *p_node, bool p_emit_selected = true); |
| 156 | Node *get_selected(); |
| 157 | void set_can_rename(bool p_can_rename) { can_rename = p_can_rename; } |
| 158 | void set_editor_selection(EditorSelection *p_selection); |
| 159 | |
| 160 | void set_show_enabled_subscene(bool p_show) { show_enabled_subscene = p_show; } |
| 161 | void set_valid_types(const Vector<StringName> &p_valid); |
| 162 | |
| 163 | void update_tree() { _update_tree(); } |
| 164 | |
| 165 | void set_auto_expand_selected(bool p_auto, bool p_update_settings); |
| 166 | void set_connect_to_script_mode(bool p_enable); |
| 167 | void set_connecting_signal(bool p_enable); |
| 168 | |
| 169 | Tree *get_scene_tree() { return tree; } |
| 170 | |
| 171 | void update_warning(); |
| 172 | |
| 173 | SceneTreeEditor(bool p_label = true, bool p_can_rename = false, bool p_can_open_instance = false); |
| 174 | ~SceneTreeEditor(); |
| 175 | }; |
| 176 | |
| 177 | class SceneTreeDialog : public ConfirmationDialog { |
| 178 | GDCLASS(SceneTreeDialog, ConfirmationDialog); |
| 179 | |
| 180 | VBoxContainer *content = nullptr; |
| 181 | SceneTreeEditor *tree = nullptr; |
| 182 | LineEdit *filter = nullptr; |
| 183 | CheckButton *show_all_nodes = nullptr; |
| 184 | LocalVector<TextureRect *> valid_type_icons; |
| 185 | |
| 186 | void _select(); |
| 187 | void _cancel(); |
| 188 | void _selected_changed(); |
| 189 | void _filter_changed(const String &p_filter); |
| 190 | void _show_all_nodes_changed(bool p_button_pressed); |
| 191 | void _update_theme(); |
| 192 | |
| 193 | protected: |
| 194 | void _notification(int p_what); |
| 195 | static void _bind_methods(); |
| 196 | |
| 197 | public: |
| 198 | void (); |
| 199 | void set_valid_types(const Vector<StringName> &p_valid); |
| 200 | |
| 201 | SceneTreeEditor *get_scene_tree() { return tree; } |
| 202 | LineEdit *get_filter_line_edit() { return filter; } |
| 203 | |
| 204 | SceneTreeDialog(); |
| 205 | ~SceneTreeDialog(); |
| 206 | }; |
| 207 | |
| 208 | #endif // SCENE_TREE_EDITOR_H |
| 209 | |