scene_tree_editor.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*************************************************************************/
  2. /* scene_tree_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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 "editor_data.h"
  33. #include "editor_settings.h"
  34. #include "scene/gui/button.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/tree.h"
  37. #include "undo_redo.h"
  38. /**
  39. @author Juan Linietsky <reduzio@gmail.com>
  40. */
  41. class SceneTreeEditor : public Control {
  42. OBJ_TYPE(SceneTreeEditor, Control);
  43. EditorSelection *editor_selection;
  44. enum {
  45. BUTTON_SUBSCENE = 0,
  46. BUTTON_VISIBILITY = 1,
  47. BUTTON_SCRIPT = 2,
  48. BUTTON_LOCK = 3,
  49. BUTTON_GROUP = 4,
  50. BUTTON_WARNING = 5,
  51. BUTTON_SIGNALS = 6,
  52. BUTTON_GROUPS = 7,
  53. };
  54. enum {
  55. SCENE_MENU_EDITABLE_CHILDREN,
  56. SCENE_MENU_USE_PLACEHOLDER,
  57. SCENE_MENU_OPEN,
  58. SCENE_MENU_CLEAR_INHERITANCE,
  59. SCENE_MENU_OPEN_INHERITED,
  60. SCENE_MENU_CLEAR_INHERITANCE_CONFIRM,
  61. SCENE_MENU_CLEAR_INSTANCING,
  62. };
  63. Tree *tree;
  64. Node *selected;
  65. PopupMenu *instance_menu;
  66. PopupMenu *inheritance_menu;
  67. ObjectID instance_node;
  68. String filter;
  69. AcceptDialog *error;
  70. AcceptDialog *warning;
  71. ConfirmationDialog *clear_inherit_confirm;
  72. int blocked;
  73. void _compute_hash(Node *p_node, uint64_t &hash);
  74. bool _add_nodes(Node *p_node, TreeItem *p_parent);
  75. void _test_update_tree();
  76. void _update_tree();
  77. void _tree_changed();
  78. void _node_removed(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 _rename_node(ObjectID p_node, const String &p_name);
  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;
  88. bool show_enabled_subscene;
  89. void _renamed();
  90. UndoRedo *undo_redo;
  91. Set<Node *> marked;
  92. bool marked_selectable;
  93. bool marked_children_selectable;
  94. bool display_foreign;
  95. bool tree_dirty;
  96. bool pending_test_update;
  97. static void _bind_methods();
  98. void _cell_button_pressed(Object *p_item, int p_column, int p_id);
  99. void _toggle_visible(Node *p_node);
  100. void _cell_multi_selected(Object *p_object, int p_cel, bool p_selected);
  101. void _update_selection(TreeItem *item);
  102. void _node_script_changed(Node *p_node);
  103. void _node_visibility_changed(Node *p_node);
  104. void _update_visibility_color(Node *p_node, TreeItem *p_item);
  105. void _subscene_option(int p_idx);
  106. void _node_replace_owner(Node *p_base, Node *p_node, Node *p_root);
  107. void _selection_changed();
  108. Node *get_scene_node();
  109. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  110. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  111. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  112. void _rmb_select(const Vector2 &p_pos);
  113. void _warning_changed(Node *p_for_node);
  114. void _editor_settings_changed();
  115. Timer *update_timer;
  116. List<StringName> *script_types;
  117. bool _is_script_type(const StringName &p_type) const;
  118. public:
  119. void set_filter(const String &p_filter);
  120. String get_filter() const;
  121. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; };
  122. void set_display_foreign_nodes(bool p_display);
  123. bool get_display_foreign_nodes() const;
  124. void set_marked(const Set<Node *> &p_marked, bool p_selectable = false, bool p_children_selectable = true);
  125. void set_marked(Node *p_marked, bool p_selectable = false, bool p_children_selectable = true);
  126. void set_selected(Node *p_node, bool p_emit_selected = true);
  127. Node *get_selected();
  128. void set_can_rename(bool p_can_rename) { can_rename = p_can_rename; }
  129. void set_editor_selection(EditorSelection *p_selection);
  130. void set_show_enabled_subscene(bool p_show) { show_enabled_subscene = p_show; }
  131. void update_tree() { _update_tree(); }
  132. Tree *get_scene_tree() { return tree; }
  133. SceneTreeEditor(bool p_label = true, bool p_can_rename = false, bool p_can_open_instance = false);
  134. ~SceneTreeEditor();
  135. };
  136. class SceneTreeDialog : public ConfirmationDialog {
  137. OBJ_TYPE(SceneTreeDialog, ConfirmationDialog);
  138. SceneTreeEditor *tree;
  139. // Button *select;
  140. // Button *cancel;
  141. void update_tree();
  142. void _select();
  143. void _cancel();
  144. protected:
  145. void _notification(int p_what);
  146. static void _bind_methods();
  147. public:
  148. SceneTreeEditor *get_scene_tree() { return tree; }
  149. SceneTreeDialog();
  150. ~SceneTreeDialog();
  151. };
  152. #endif