scene_tree_dock.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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/editor_sub_scene.h"
  36. #include "editor/groups_editor.h"
  37. #include "editor/quick_open.h"
  38. #include "editor/rename_dialog.h"
  39. #include "editor/reparent_dialog.h"
  40. #include "editor/script_create_dialog.h"
  41. #include "scene/animation/animation_player.h"
  42. #include "scene/gui/box_container.h"
  43. #include "scene/gui/button.h"
  44. #include "scene/gui/control.h"
  45. #include "scene/gui/label.h"
  46. #include "scene/gui/popup_menu.h"
  47. #include "scene/gui/tool_button.h"
  48. #include "scene/gui/tree.h"
  49. #include "scene_tree_editor.h"
  50. class EditorNode;
  51. class SceneTreeDock : public VBoxContainer {
  52. GDCLASS(SceneTreeDock, VBoxContainer);
  53. enum Tool {
  54. TOOL_NEW,
  55. TOOL_INSTANCE,
  56. TOOL_RENAME,
  57. TOOL_BATCH_RENAME,
  58. TOOL_REPLACE,
  59. TOOL_ATTACH_SCRIPT,
  60. TOOL_CLEAR_SCRIPT,
  61. TOOL_MOVE_UP,
  62. TOOL_MOVE_DOWN,
  63. TOOL_DUPLICATE,
  64. TOOL_REPARENT,
  65. TOOL_MAKE_ROOT,
  66. TOOL_NEW_SCENE_FROM,
  67. TOOL_MERGE_FROM_SCENE,
  68. TOOL_MULTI_EDIT,
  69. TOOL_ERASE,
  70. TOOL_COPY_NODE_PATH,
  71. TOOL_BUTTON_MAX,
  72. TOOL_OPEN_DOCUMENTATION,
  73. TOOL_SCENE_EDITABLE_CHILDREN,
  74. TOOL_SCENE_USE_PLACEHOLDER,
  75. TOOL_SCENE_MAKE_LOCAL,
  76. TOOL_SCENE_OPEN,
  77. TOOL_SCENE_CLEAR_INHERITANCE,
  78. TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM,
  79. TOOL_SCENE_OPEN_INHERITED,
  80. TOOL_CREATE_2D_SCENE,
  81. TOOL_CREATE_3D_SCENE,
  82. TOOL_CREATE_USER_INTERFACE,
  83. TOOL_CREATE_FAVORITE,
  84. };
  85. enum {
  86. EDIT_SUBRESOURCE_BASE = 100
  87. };
  88. Vector<ObjectID> subresources;
  89. bool restore_script_editor_on_drag;
  90. int current_option;
  91. CreateDialog *create_dialog;
  92. RenameDialog *rename_dialog;
  93. ToolButton *button_add;
  94. ToolButton *button_instance;
  95. ToolButton *button_create_script;
  96. ToolButton *button_clear_script;
  97. HBoxContainer *button_hb;
  98. ToolButton *edit_local, *edit_remote;
  99. SceneTreeEditor *scene_tree;
  100. Control *remote_tree;
  101. HBoxContainer *tool_hbc;
  102. void _tool_selected(int p_tool, bool p_confirm_override = false);
  103. EditorData *editor_data;
  104. EditorSelection *editor_selection;
  105. ScriptCreateDialog *script_create_dialog;
  106. AcceptDialog *accept;
  107. ConfirmationDialog *delete_dialog;
  108. ConfirmationDialog *editable_instance_remove_dialog;
  109. ReparentDialog *reparent_dialog;
  110. EditorQuickOpen *quick_open;
  111. EditorSubScene *import_subscene_dialog;
  112. EditorFileDialog *new_scene_from_dialog;
  113. LineEdit *filter;
  114. TextureRect *filter_icon;
  115. PopupMenu *menu;
  116. PopupMenu *menu_subresources;
  117. ConfirmationDialog *clear_inherit_confirm;
  118. bool first_enter;
  119. void _create();
  120. Node *scene_root;
  121. Node *edited_scene;
  122. EditorNode *editor;
  123. VBoxContainer *create_root_dialog;
  124. String selected_favorite_root;
  125. void _add_children_to_popup(Object *p_obj, int p_depth);
  126. void _node_reparent(NodePath p_path, bool p_keep_global_xform);
  127. void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform);
  128. void _set_owners(Node *p_owner, const Array &p_nodes);
  129. enum ReplaceOwnerMode {
  130. MODE_BIDI,
  131. MODE_DO,
  132. MODE_UNDO
  133. };
  134. void _node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode = MODE_BIDI);
  135. void _load_request(const String &p_path);
  136. void _script_open_request(const Ref<Script> &p_script);
  137. bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
  138. void _node_selected();
  139. void _node_renamed();
  140. void _script_created(Ref<Script> p_script);
  141. void _delete_confirm();
  142. void _toggle_editable_children();
  143. void _node_prerenamed(Node *p_node, const String &p_new_name);
  144. void _nodes_drag_begin();
  145. void _input(Ref<InputEvent> p_event);
  146. void _unhandled_key_input(Ref<InputEvent> p_event);
  147. void _import_subscene();
  148. void _new_scene_from(String p_file);
  149. bool _validate_no_foreign();
  150. void _selection_changed();
  151. void _update_script_button();
  152. void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath> > *p_renames);
  153. void _normalize_drop(Node *&to_node, int &to_pos, int p_type);
  154. void _nodes_dragged(Array p_nodes, NodePath p_to, int p_type);
  155. void _files_dropped(Vector<String> p_files, NodePath p_to, int p_type);
  156. void _script_dropped(String p_file, NodePath p_to);
  157. void _quick_open();
  158. void _tree_rmb(const Vector2 &p_menu_pos);
  159. void _filter_changed(const String &p_filter);
  160. void _perform_instance_scenes(const Vector<String> &p_files, Node *parent, int p_pos);
  161. void _replace_with_branch_scene(const String &p_file, Node *base);
  162. void _file_selected(String p_file);
  163. void _remote_tree_selected();
  164. void _local_tree_selected();
  165. void _update_create_root_dialog();
  166. void _favorite_root_selected(const String &p_class);
  167. protected:
  168. void _notification(int p_what);
  169. static void _bind_methods();
  170. public:
  171. String get_filter();
  172. void set_filter(const String &p_filter);
  173. void _focus_node();
  174. void import_subscene();
  175. void set_edited_scene(Node *p_scene);
  176. void instance(const String &p_file);
  177. void instance_scenes(const Vector<String> &p_files, Node *p_parent = NULL);
  178. void set_selected(Node *p_node, bool p_emit_selected = false);
  179. void fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath> > *p_renames);
  180. void perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath> > *p_renames, Map<Ref<Animation>, Set<int> > *r_rem_anims = NULL);
  181. SceneTreeEditor *get_tree_editor() { return scene_tree; }
  182. EditorData *get_editor_data() { return editor_data; }
  183. void add_remote_tree_editor(Control *p_remote);
  184. void show_remote_tree();
  185. void hide_remote_tree();
  186. void show_tab_buttons();
  187. void hide_tab_buttons();
  188. void replace_node(Node *p_node, Node *p_by_node);
  189. void open_script_dialog(Node *p_for_node);
  190. ScriptCreateDialog *get_script_create_dialog() { return script_create_dialog; }
  191. SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data);
  192. };
  193. #endif // SCENE_TREE_DOCK_H