scene_tree_dock.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /**************************************************************************/
  2. /* scene_tree_dock.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_DOCK_H
  31. #define SCENE_TREE_DOCK_H
  32. #include "editor/gui/scene_tree_editor.h"
  33. #include "editor/script_create_dialog.h"
  34. #include "scene/gui/box_container.h"
  35. #include "scene/resources/animation.h"
  36. class CheckBox;
  37. class EditorData;
  38. class EditorSelection;
  39. class MenuButton;
  40. class ReparentDialog;
  41. class ShaderCreateDialog;
  42. class TextureRect;
  43. #include "modules/modules_enabled.gen.h" // For regex.
  44. #ifdef MODULE_REGEX_ENABLED
  45. class RenameDialog;
  46. #endif // MODULE_REGEX_ENABLED
  47. class SceneTreeDock : public VBoxContainer {
  48. GDCLASS(SceneTreeDock, VBoxContainer);
  49. enum Tool {
  50. TOOL_NEW,
  51. TOOL_INSTANTIATE,
  52. TOOL_EXPAND_COLLAPSE,
  53. TOOL_CUT,
  54. TOOL_COPY,
  55. TOOL_PASTE,
  56. TOOL_PASTE_AS_SIBLING,
  57. TOOL_RENAME,
  58. #ifdef MODULE_REGEX_ENABLED
  59. TOOL_BATCH_RENAME,
  60. #endif // MODULE_REGEX_ENABLED
  61. TOOL_REPLACE,
  62. TOOL_EXTEND_SCRIPT,
  63. TOOL_ATTACH_SCRIPT,
  64. TOOL_DETACH_SCRIPT,
  65. TOOL_MOVE_UP,
  66. TOOL_MOVE_DOWN,
  67. TOOL_DUPLICATE,
  68. TOOL_REPARENT,
  69. TOOL_REPARENT_TO_NEW_NODE,
  70. TOOL_MAKE_ROOT,
  71. TOOL_NEW_SCENE_FROM,
  72. TOOL_MULTI_EDIT,
  73. TOOL_ERASE,
  74. TOOL_COPY_NODE_PATH,
  75. TOOL_SHOW_IN_FILE_SYSTEM,
  76. TOOL_OPEN_DOCUMENTATION,
  77. TOOL_AUTO_EXPAND,
  78. TOOL_SCENE_EDITABLE_CHILDREN,
  79. TOOL_SCENE_USE_PLACEHOLDER,
  80. TOOL_SCENE_MAKE_LOCAL,
  81. TOOL_SCENE_OPEN,
  82. TOOL_SCENE_CLEAR_INHERITANCE,
  83. TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM,
  84. TOOL_SCENE_OPEN_INHERITED,
  85. TOOL_TOGGLE_SCENE_UNIQUE_NAME,
  86. TOOL_CREATE_2D_SCENE,
  87. TOOL_CREATE_3D_SCENE,
  88. TOOL_CREATE_USER_INTERFACE,
  89. TOOL_CREATE_FAVORITE,
  90. TOOL_CENTER_PARENT,
  91. };
  92. enum {
  93. EDIT_SUBRESOURCE_BASE = 100
  94. };
  95. Vector<ObjectID> subresources;
  96. bool reset_create_dialog = false;
  97. int current_option = 0;
  98. CreateDialog *create_dialog = nullptr;
  99. #ifdef MODULE_REGEX_ENABLED
  100. RenameDialog *rename_dialog = nullptr;
  101. #endif // MODULE_REGEX_ENABLED
  102. Button *button_add = nullptr;
  103. Button *button_instance = nullptr;
  104. Button *button_create_script = nullptr;
  105. Button *button_detach_script = nullptr;
  106. Button *button_extend_script = nullptr;
  107. MenuButton *button_tree_menu = nullptr;
  108. Button *node_shortcuts_toggle = nullptr;
  109. VBoxContainer *beginner_node_shortcuts = nullptr;
  110. VBoxContainer *favorite_node_shortcuts = nullptr;
  111. Button *button_2d = nullptr;
  112. Button *button_3d = nullptr;
  113. Button *button_ui = nullptr;
  114. Button *button_custom = nullptr;
  115. Button *button_clipboard = nullptr;
  116. HBoxContainer *button_hb = nullptr;
  117. Button *edit_local, *edit_remote;
  118. SceneTreeEditor *scene_tree = nullptr;
  119. Control *remote_tree = nullptr;
  120. HBoxContainer *tool_hbc = nullptr;
  121. void _tool_selected(int p_tool, bool p_confirm_override = false);
  122. void _property_selected(int p_idx);
  123. Node *property_drop_node = nullptr;
  124. String resource_drop_path;
  125. void _perform_property_drop(Node *p_node, const String &p_property, Ref<Resource> p_res);
  126. EditorData *editor_data = nullptr;
  127. EditorSelection *editor_selection = nullptr;
  128. List<Node *> node_clipboard;
  129. HashSet<Node *> node_clipboard_edited_scene_owned;
  130. String clipboard_source_scene;
  131. HashMap<String, HashMap<Ref<Resource>, Ref<Resource>>> clipboard_resource_remap;
  132. ScriptCreateDialog *script_create_dialog = nullptr;
  133. ShaderCreateDialog *shader_create_dialog = nullptr;
  134. AcceptDialog *accept = nullptr;
  135. ConfirmationDialog *delete_dialog = nullptr;
  136. Label *delete_dialog_label = nullptr;
  137. CheckBox *delete_tracks_checkbox = nullptr;
  138. ConfirmationDialog *editable_instance_remove_dialog = nullptr;
  139. ConfirmationDialog *placeholder_editable_instance_remove_dialog = nullptr;
  140. ReparentDialog *reparent_dialog = nullptr;
  141. EditorFileDialog *new_scene_from_dialog = nullptr;
  142. enum FilterMenuItems {
  143. FILTER_BY_TYPE = 64, // Used in the same menus as the Tool enum.
  144. FILTER_BY_GROUP,
  145. };
  146. LineEdit *filter = nullptr;
  147. PopupMenu *filter_quick_menu = nullptr;
  148. TextureRect *filter_icon = nullptr;
  149. PopupMenu *menu = nullptr;
  150. PopupMenu *menu_subresources = nullptr;
  151. PopupMenu *menu_properties = nullptr;
  152. ConfirmationDialog *clear_inherit_confirm = nullptr;
  153. bool first_enter = true;
  154. void _create();
  155. Node *_do_create(Node *p_parent);
  156. void _post_do_create(Node *p_child);
  157. Node *scene_root = nullptr;
  158. Node *edited_scene = nullptr;
  159. Node *pending_click_select = nullptr;
  160. bool tree_clicked = false;
  161. VBoxContainer *create_root_dialog = nullptr;
  162. String selected_favorite_root;
  163. Ref<ShaderMaterial> selected_shader_material;
  164. void _add_children_to_popup(Object *p_obj, int p_depth);
  165. void _node_reparent(NodePath p_path, bool p_keep_global_xform);
  166. void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform);
  167. void _set_owners(Node *p_owner, const Array &p_nodes);
  168. enum ReplaceOwnerMode {
  169. MODE_BIDI,
  170. MODE_DO,
  171. MODE_UNDO
  172. };
  173. void _node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode = MODE_BIDI);
  174. void _node_strip_signal_inheritance(Node *p_node);
  175. void _load_request(const String &p_path);
  176. void _script_open_request(const Ref<Script> &p_script);
  177. void _push_item(Object *p_object);
  178. void _handle_select(Node *p_node);
  179. bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
  180. bool _track_inherit(const String &p_target_scene_path, Node *p_desired_node);
  181. void _node_selected();
  182. void _node_renamed();
  183. void _script_created(Ref<Script> p_script);
  184. void _shader_created(Ref<Shader> p_shader);
  185. void _script_creation_closed();
  186. void _shader_creation_closed();
  187. void _delete_confirm(bool p_cut = false);
  188. void _delete_dialog_closed();
  189. void _toggle_editable_children_from_selection();
  190. void _reparent_nodes_to_root(Node *p_root, const Array &p_nodes, Node *p_owner);
  191. void _reparent_nodes_to_paths_with_transform_and_name(Node *p_root, const Array &p_nodes, const Array &p_paths, const Array &p_transforms, const Array &p_names, Node *p_owner);
  192. void _toggle_editable_children(Node *p_node);
  193. void _toggle_placeholder_from_selection();
  194. void _node_prerenamed(Node *p_node, const String &p_new_name);
  195. void _nodes_drag_begin();
  196. void _handle_hover_to_inspect();
  197. void _inspect_hovered_node();
  198. void _reset_hovering_timer();
  199. Timer *inspect_hovered_node_delay = nullptr;
  200. TreeItem *tree_item_inspected = nullptr;
  201. Node *node_hovered_now = nullptr;
  202. Node *node_hovered_previously = nullptr;
  203. bool select_node_hovered_at_end_of_drag = false;
  204. bool hovered_but_reparenting = false;
  205. virtual void input(const Ref<InputEvent> &p_event) override;
  206. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  207. void _scene_tree_gui_input(Ref<InputEvent> p_event);
  208. void _new_scene_from(const String &p_file);
  209. void _set_node_owner_recursive(Node *p_node, Node *p_owner, const HashMap<const Node *, Node *> &p_inverse_duplimap);
  210. bool _validate_no_foreign();
  211. bool _validate_no_instance();
  212. void _selection_changed();
  213. void _update_script_button();
  214. void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, HashMap<Node *, NodePath> *p_renames);
  215. bool _has_tracks_to_delete(Node *p_node, List<Node *> &p_to_delete) const;
  216. void _normalize_drop(Node *&to_node, int &to_pos, int p_type);
  217. Array _get_selection_array();
  218. void _nodes_dragged(const Array &p_nodes, NodePath p_to, int p_type);
  219. void _files_dropped(const Vector<String> &p_files, NodePath p_to, int p_type);
  220. void _script_dropped(const String &p_file, NodePath p_to);
  221. void _quick_open(const String &p_file_path);
  222. void _tree_rmb(const Vector2 &p_menu_pos);
  223. void _update_tree_menu();
  224. void _filter_changed(const String &p_filter);
  225. void _filter_gui_input(const Ref<InputEvent> &p_event);
  226. void _filter_option_selected(int option);
  227. void _append_filter_options_to(PopupMenu *p_menu, bool p_include_separator = true);
  228. void _perform_instantiate_scenes(const Vector<String> &p_files, Node *p_parent, int p_pos);
  229. void _perform_create_audio_stream_players(const Vector<String> &p_files, Node *p_parent, int p_pos);
  230. void _replace_with_branch_scene(const String &p_file, Node *base);
  231. void _remote_tree_selected();
  232. void _local_tree_selected();
  233. void _update_create_root_dialog(bool p_initializing = false);
  234. void _favorite_root_selected(const String &p_class);
  235. void _feature_profile_changed();
  236. void _clear_clipboard();
  237. void _create_remap_for_node(Node *p_node, HashMap<Ref<Resource>, Ref<Resource>> &r_remap);
  238. void _create_remap_for_resource(Ref<Resource> p_resource, HashMap<Ref<Resource>, Ref<Resource>> &r_remap);
  239. void _list_all_subresources(PopupMenu *p_menu);
  240. void _gather_resources(Node *p_node, List<Pair<Ref<Resource>, Node *>> &r_resources);
  241. void _edit_subresource(int p_idx, const PopupMenu *p_from_menu);
  242. bool profile_allow_editing = true;
  243. bool profile_allow_script_editing = true;
  244. static void _update_configuration_warning();
  245. bool _update_node_path(Node *p_root_node, NodePath &r_node_path, HashMap<Node *, NodePath> *p_renames) const;
  246. bool _check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames, bool p_inside_resource = false) const;
  247. bool _check_node_recursive(Variant &r_variant, Node *p_node, Node *p_by_node, const String type_hint, String &r_warn_message);
  248. void _replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties = true, bool p_remove_old = true);
  249. private:
  250. static SceneTreeDock *singleton;
  251. public:
  252. static SceneTreeDock *get_singleton() { return singleton; }
  253. protected:
  254. void _notification(int p_what);
  255. static void _bind_methods();
  256. public:
  257. String get_filter();
  258. void set_filter(const String &p_filter);
  259. void save_branch_to_file(const String &p_directory);
  260. void _focus_node();
  261. void add_root_node(Node *p_node);
  262. void set_edited_scene(Node *p_scene);
  263. void instantiate(const String &p_file);
  264. void instantiate_scenes(const Vector<String> &p_files, Node *p_parent = nullptr);
  265. void set_selection(const Vector<Node *> &p_nodes);
  266. void set_selected(Node *p_node, bool p_emit_selected = false);
  267. void fill_path_renames(Node *p_node, Node *p_new_parent, HashMap<Node *, NodePath> *p_renames);
  268. void perform_node_renames(Node *p_base, HashMap<Node *, NodePath> *p_renames, HashMap<Ref<Animation>, HashSet<int>> *r_rem_anims = nullptr);
  269. void perform_node_replace(Node *p_base, Node *p_node, Node *p_by_node);
  270. SceneTreeEditor *get_tree_editor() { return scene_tree; }
  271. EditorData *get_editor_data() { return editor_data; }
  272. void add_remote_tree_editor(Control *p_remote);
  273. void show_remote_tree();
  274. void hide_remote_tree();
  275. void show_tab_buttons();
  276. void hide_tab_buttons();
  277. void replace_node(Node *p_node, Node *p_by_node);
  278. void attach_script_to_selected(bool p_extend);
  279. void open_script_dialog(Node *p_for_node, bool p_extend);
  280. void attach_shader_to_selected(int p_preferred_mode = -1);
  281. void open_shader_dialog(const Ref<ShaderMaterial> &p_for_material, int p_preferred_mode = -1);
  282. void open_add_child_dialog();
  283. void open_instance_child_dialog();
  284. List<Node *> paste_nodes(bool p_paste_as_sibling = false);
  285. List<Node *> get_node_clipboard() const;
  286. ScriptCreateDialog *get_script_create_dialog() {
  287. return script_create_dialog;
  288. }
  289. SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data);
  290. ~SceneTreeDock();
  291. };
  292. #endif // SCENE_TREE_DOCK_H