scene_tree_dock.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*************************************************************************/
  2. /* scene_tree_dock.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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_DOCK_H
  31. #define SCENE_TREE_DOCK_H
  32. #include "editor/create_dialog.h"
  33. #include "editor/editor_data.h"
  34. #include "editor/editor_quick_open.h"
  35. #include "editor/groups_editor.h"
  36. #include "editor/reparent_dialog.h"
  37. #include "editor/script_create_dialog.h"
  38. #include "scene/animation/animation_player.h"
  39. #include "scene/gui/box_container.h"
  40. #include "scene/gui/button.h"
  41. #include "scene/gui/control.h"
  42. #include "scene/gui/label.h"
  43. #include "scene/gui/popup_menu.h"
  44. #include "scene/gui/tree.h"
  45. #include "scene_tree_editor.h"
  46. #include "modules/modules_enabled.gen.h" // For regex.
  47. #ifdef MODULE_REGEX_ENABLED
  48. class RenameDialog;
  49. #endif // MODULE_REGEX_ENABLED
  50. class ShaderCreateDialog;
  51. class SceneTreeDock : public VBoxContainer {
  52. GDCLASS(SceneTreeDock, VBoxContainer);
  53. enum Tool {
  54. TOOL_NEW,
  55. TOOL_INSTANTIATE,
  56. TOOL_EXPAND_COLLAPSE,
  57. TOOL_CUT,
  58. TOOL_COPY,
  59. TOOL_PASTE,
  60. TOOL_RENAME,
  61. #ifdef MODULE_REGEX_ENABLED
  62. TOOL_BATCH_RENAME,
  63. #endif // MODULE_REGEX_ENABLED
  64. TOOL_REPLACE,
  65. TOOL_EXTEND_SCRIPT,
  66. TOOL_ATTACH_SCRIPT,
  67. TOOL_DETACH_SCRIPT,
  68. TOOL_MOVE_UP,
  69. TOOL_MOVE_DOWN,
  70. TOOL_DUPLICATE,
  71. TOOL_REPARENT,
  72. TOOL_REPARENT_TO_NEW_NODE,
  73. TOOL_MAKE_ROOT,
  74. TOOL_NEW_SCENE_FROM,
  75. TOOL_MULTI_EDIT,
  76. TOOL_ERASE,
  77. TOOL_COPY_NODE_PATH,
  78. TOOL_BUTTON_MAX,
  79. TOOL_OPEN_DOCUMENTATION,
  80. TOOL_AUTO_EXPAND,
  81. TOOL_SCENE_EDITABLE_CHILDREN,
  82. TOOL_SCENE_USE_PLACEHOLDER,
  83. TOOL_SCENE_MAKE_LOCAL,
  84. TOOL_SCENE_OPEN,
  85. TOOL_SCENE_CLEAR_INHERITANCE,
  86. TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM,
  87. TOOL_SCENE_OPEN_INHERITED,
  88. TOOL_TOGGLE_SCENE_UNIQUE_NAME,
  89. TOOL_CREATE_2D_SCENE,
  90. TOOL_CREATE_3D_SCENE,
  91. TOOL_CREATE_USER_INTERFACE,
  92. TOOL_CREATE_FAVORITE,
  93. };
  94. enum {
  95. EDIT_SUBRESOURCE_BASE = 100
  96. };
  97. Vector<ObjectID> subresources;
  98. bool reset_create_dialog = false;
  99. int current_option = 0;
  100. CreateDialog *create_dialog = nullptr;
  101. #ifdef MODULE_REGEX_ENABLED
  102. RenameDialog *rename_dialog = nullptr;
  103. #endif // MODULE_REGEX_ENABLED
  104. Button *button_add = nullptr;
  105. Button *button_instance = nullptr;
  106. Button *button_create_script = nullptr;
  107. Button *button_detach_script = nullptr;
  108. MenuButton *button_tree_menu = nullptr;
  109. Button *button_2d = nullptr;
  110. Button *button_3d = nullptr;
  111. Button *button_ui = nullptr;
  112. Button *button_custom = nullptr;
  113. Button *button_clipboard = nullptr;
  114. HBoxContainer *button_hb = nullptr;
  115. Button *edit_local, *edit_remote;
  116. SceneTreeEditor *scene_tree = nullptr;
  117. Control *remote_tree = nullptr;
  118. HBoxContainer *tool_hbc = nullptr;
  119. void _tool_selected(int p_tool, bool p_confirm_override = false);
  120. void _property_selected(int p_idx);
  121. void _node_collapsed(Object *p_obj);
  122. Node *property_drop_node = nullptr;
  123. String resource_drop_path;
  124. void _perform_property_drop(Node *p_node, String p_property, Ref<Resource> p_res);
  125. EditorData *editor_data = nullptr;
  126. EditorSelection *editor_selection = nullptr;
  127. List<Node *> node_clipboard;
  128. String clipboard_source_scene;
  129. HashMap<String, HashMap<Ref<Resource>, Ref<Resource>>> clipboard_resource_remap;
  130. ScriptCreateDialog *script_create_dialog = nullptr;
  131. ShaderCreateDialog *shader_create_dialog = nullptr;
  132. AcceptDialog *accept = nullptr;
  133. ConfirmationDialog *delete_dialog = nullptr;
  134. ConfirmationDialog *editable_instance_remove_dialog = nullptr;
  135. ConfirmationDialog *placeholder_editable_instance_remove_dialog = nullptr;
  136. ReparentDialog *reparent_dialog = nullptr;
  137. EditorQuickOpen *quick_open = nullptr;
  138. EditorFileDialog *new_scene_from_dialog = nullptr;
  139. LineEdit *filter = nullptr;
  140. TextureRect *filter_icon = nullptr;
  141. PopupMenu *menu = nullptr;
  142. PopupMenu *menu_subresources = nullptr;
  143. PopupMenu *menu_properties = nullptr;
  144. ConfirmationDialog *clear_inherit_confirm = nullptr;
  145. bool first_enter = true;
  146. void _create();
  147. void _do_create(Node *p_parent);
  148. Node *scene_root = nullptr;
  149. Node *edited_scene = nullptr;
  150. Node *pending_click_select = nullptr;
  151. bool tree_clicked = false;
  152. VBoxContainer *create_root_dialog = nullptr;
  153. String selected_favorite_root;
  154. Ref<ShaderMaterial> selected_shader_material;
  155. void _add_children_to_popup(Object *p_obj, int p_depth);
  156. void _node_reparent(NodePath p_path, bool p_keep_global_xform);
  157. void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform);
  158. bool _is_collapsed_recursive(TreeItem *p_item) const;
  159. void _set_collapsed_recursive(TreeItem *p_item, bool p_collapsed);
  160. void _set_owners(Node *p_owner, const Array &p_nodes);
  161. enum ReplaceOwnerMode {
  162. MODE_BIDI,
  163. MODE_DO,
  164. MODE_UNDO
  165. };
  166. void _node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode = MODE_BIDI);
  167. void _load_request(const String &p_path);
  168. void _script_open_request(const Ref<Script> &p_script);
  169. void _push_item(Object *p_object);
  170. void _handle_select(Node *p_node);
  171. bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
  172. bool _track_inherit(const String &p_target_scene_path, Node *p_desired_node);
  173. void _node_selected();
  174. void _node_renamed();
  175. void _script_created(Ref<Script> p_script);
  176. void _shader_created(Ref<Shader> p_shader);
  177. void _script_creation_closed();
  178. void _shader_creation_closed();
  179. void _delete_confirm(bool p_cut = false);
  180. void _toggle_editable_children_from_selection();
  181. void _toggle_editable_children(Node *p_node);
  182. void _toggle_placeholder_from_selection();
  183. void _node_prerenamed(Node *p_node, const String &p_new_name);
  184. void _nodes_drag_begin();
  185. virtual void input(const Ref<InputEvent> &p_event) override;
  186. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  187. void _import_subscene();
  188. void _new_scene_from(String p_file);
  189. void _set_node_owner_recursive(Node *p_node, Node *p_owner);
  190. bool _validate_no_foreign();
  191. bool _validate_no_instance();
  192. void _selection_changed();
  193. void _update_script_button();
  194. void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, HashMap<Node *, NodePath> *p_renames);
  195. void _normalize_drop(Node *&to_node, int &to_pos, int p_type);
  196. void _nodes_dragged(Array p_nodes, NodePath p_to, int p_type);
  197. void _files_dropped(Vector<String> p_files, NodePath p_to, int p_type);
  198. void _script_dropped(String p_file, NodePath p_to);
  199. void _quick_open();
  200. void _tree_rmb(const Vector2 &p_menu_pos);
  201. void _update_tree_menu();
  202. void _filter_changed(const String &p_filter);
  203. void _perform_instantiate_scenes(const Vector<String> &p_files, Node *parent, int p_pos);
  204. void _replace_with_branch_scene(const String &p_file, Node *base);
  205. void _remote_tree_selected();
  206. void _local_tree_selected();
  207. void _update_create_root_dialog();
  208. void _favorite_root_selected(const String &p_class);
  209. void _feature_profile_changed();
  210. void _clear_clipboard();
  211. void _create_remap_for_node(Node *p_node, HashMap<Ref<Resource>, Ref<Resource>> &r_remap);
  212. void _create_remap_for_resource(Ref<Resource> p_resource, HashMap<Ref<Resource>, Ref<Resource>> &r_remap);
  213. bool profile_allow_editing = true;
  214. bool profile_allow_script_editing = true;
  215. static void _update_configuration_warning();
  216. bool _update_node_path(Node *p_root_node, NodePath &r_node_path, HashMap<Node *, NodePath> *p_renames) const;
  217. bool _check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames) const;
  218. private:
  219. static SceneTreeDock *singleton;
  220. public:
  221. static SceneTreeDock *get_singleton() { return singleton; }
  222. protected:
  223. void _notification(int p_what);
  224. static void _bind_methods();
  225. public:
  226. String get_filter();
  227. void set_filter(const String &p_filter);
  228. void save_branch_to_file(String p_directory);
  229. void _focus_node();
  230. void import_subscene();
  231. void add_root_node(Node *p_node);
  232. void set_edited_scene(Node *p_scene);
  233. void instantiate(const String &p_file);
  234. void instantiate_scenes(const Vector<String> &p_files, Node *p_parent = nullptr);
  235. void set_selected(Node *p_node, bool p_emit_selected = false);
  236. void fill_path_renames(Node *p_node, Node *p_new_parent, HashMap<Node *, NodePath> *p_renames);
  237. void perform_node_renames(Node *p_base, HashMap<Node *, NodePath> *p_renames, HashMap<Ref<Animation>, HashSet<int>> *r_rem_anims = nullptr);
  238. SceneTreeEditor *get_tree_editor() { return scene_tree; }
  239. EditorData *get_editor_data() { return editor_data; }
  240. void add_remote_tree_editor(Control *p_remote);
  241. void show_remote_tree();
  242. void hide_remote_tree();
  243. void show_tab_buttons();
  244. void hide_tab_buttons();
  245. void replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties = true, bool p_remove_old = true);
  246. void attach_script_to_selected(bool p_extend);
  247. void open_script_dialog(Node *p_for_node, bool p_extend);
  248. void attach_shader_to_selected(int p_preferred_mode = -1);
  249. void open_shader_dialog(const Ref<ShaderMaterial> &p_for_material, int p_preferred_mode = -1);
  250. void open_add_child_dialog();
  251. void open_instance_child_dialog();
  252. List<Node *> paste_nodes();
  253. List<Node *> get_node_clipboard() const;
  254. ScriptCreateDialog *get_script_create_dialog() {
  255. return script_create_dialog;
  256. }
  257. SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data);
  258. ~SceneTreeDock();
  259. };
  260. #endif // SCENE_TREE_DOCK_H