scene_tree_editor.h 8.1 KB

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