scene_tree_dock.h 10 KB

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