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-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 31 #ifndef SCENE_TREE_DOCK_H 32 #define SCENE_TREE_DOCK_H 33 34 #include "editor/connections_dialog.h" 35 #include "editor/create_dialog.h" 36 #include "editor/editor_data.h" 37 #include "editor/editor_sub_scene.h" 38 #include "editor/groups_editor.h" 39 #include "editor/quick_open.h" 40 #include "editor/rename_dialog.h" 41 #include "editor/reparent_dialog.h" 42 #include "editor/script_create_dialog.h" 43 #include "scene/animation/animation_player.h" 44 #include "scene/gui/box_container.h" 45 #include "scene/gui/button.h" 46 #include "scene/gui/control.h" 47 #include "scene/gui/label.h" 48 #include "scene/gui/popup_menu.h" 49 #include "scene/gui/tool_button.h" 50 #include "scene/gui/tree.h" 51 #include "scene_tree_editor.h" 52 53 class EditorNode; 54 55 class SceneTreeDock : public VBoxContainer { 56 57 GDCLASS(SceneTreeDock, VBoxContainer); 58 59 enum Tool { 60 61 TOOL_NEW, 62 TOOL_INSTANCE, 63 TOOL_EXPAND_COLLAPSE, 64 TOOL_RENAME, 65 TOOL_BATCH_RENAME, 66 TOOL_REPLACE, 67 TOOL_EXTEND_SCRIPT, 68 TOOL_ATTACH_SCRIPT, 69 TOOL_DETACH_SCRIPT, 70 TOOL_MOVE_UP, 71 TOOL_MOVE_DOWN, 72 TOOL_DUPLICATE, 73 TOOL_REPARENT, 74 TOOL_REPARENT_TO_NEW_NODE, 75 TOOL_MAKE_ROOT, 76 TOOL_NEW_SCENE_FROM, 77 TOOL_MERGE_FROM_SCENE, 78 TOOL_MULTI_EDIT, 79 TOOL_ERASE, 80 TOOL_COPY_NODE_PATH, 81 TOOL_BUTTON_MAX, 82 TOOL_OPEN_DOCUMENTATION, 83 TOOL_SCENE_EDITABLE_CHILDREN, 84 TOOL_SCENE_USE_PLACEHOLDER, 85 TOOL_SCENE_MAKE_LOCAL, 86 TOOL_SCENE_OPEN, 87 TOOL_SCENE_CLEAR_INHERITANCE, 88 TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM, 89 TOOL_SCENE_OPEN_INHERITED, 90 91 TOOL_CREATE_2D_SCENE, 92 TOOL_CREATE_3D_SCENE, 93 TOOL_CREATE_USER_INTERFACE, 94 TOOL_CREATE_FAVORITE, 95 96 }; 97 98 enum { 99 EDIT_SUBRESOURCE_BASE = 100 100 }; 101 102 Vector<ObjectID> subresources; 103 104 bool restore_script_editor_on_drag; 105 106 int current_option; 107 CreateDialog *create_dialog; 108 RenameDialog *rename_dialog; 109 110 ToolButton *button_add; 111 ToolButton *button_instance; 112 ToolButton *button_create_script; 113 ToolButton *button_detach_script; 114 115 Button *button_3d; 116 117 HBoxContainer *button_hb; 118 ToolButton *edit_local, *edit_remote; 119 SceneTreeEditor *scene_tree; 120 Control *remote_tree; 121 122 HBoxContainer *tool_hbc; 123 void _tool_selected(int p_tool, bool p_confirm_override = false); 124 void _node_collapsed(Object *p_obj); 125 126 EditorData *editor_data; 127 EditorSelection *editor_selection; 128 129 ScriptCreateDialog *script_create_dialog; 130 AcceptDialog *accept; 131 ConfirmationDialog *delete_dialog; 132 ConfirmationDialog *editable_instance_remove_dialog; 133 ConfirmationDialog *placeholder_editable_instance_remove_dialog; 134 135 ReparentDialog *reparent_dialog; 136 EditorQuickOpen *quick_open; 137 EditorSubScene *import_subscene_dialog; 138 EditorFileDialog *new_scene_from_dialog; 139 140 LineEdit *filter; 141 TextureRect *filter_icon; 142 143 PopupMenu *menu; 144 PopupMenu *menu_subresources; 145 ConfirmationDialog *clear_inherit_confirm; 146 147 bool first_enter; 148 149 void _create(); 150 void _do_create(Node *p_parent); 151 Node *scene_root; 152 Node *edited_scene; 153 EditorNode *editor; 154 155 VBoxContainer *create_root_dialog; 156 String selected_favorite_root; 157 158 void _add_children_to_popup(Object *p_obj, int p_depth); 159 160 void _node_reparent(NodePath p_path, bool p_keep_global_xform); 161 void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform); 162 163 bool _is_collapsed_recursive(TreeItem *p_item) const; 164 void _set_collapsed_recursive(TreeItem *p_item, bool p_collapsed); 165 166 void _set_owners(Node *p_owner, const Array &p_nodes); 167 168 enum ReplaceOwnerMode { 169 MODE_BIDI, 170 MODE_DO, 171 MODE_UNDO 172 }; 173 174 void _node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode = MODE_BIDI); 175 void _load_request(const String &p_path); 176 void _script_open_request(const Ref<Script> &p_script); 177 178 bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node); 179 bool _track_inherit(const String &p_target_scene_path, Node *p_desired_node); 180 181 void _node_selected(); 182 void _node_renamed(); 183 void _script_created(Ref<Script> p_script); 184 void _script_creation_closed(); 185 186 void _delete_confirm(); 187 188 void _toggle_editable_children_from_selection(); 189 void _toggle_editable_children(Node *p_node); 190 191 void _toggle_placeholder_from_selection(); 192 193 void _node_prerenamed(Node *p_node, const String &p_new_name); 194 195 void _nodes_drag_begin(); 196 void _input(Ref<InputEvent> p_event); 197 void _unhandled_key_input(Ref<InputEvent> p_event); 198 199 void _import_subscene(); 200 201 void _new_scene_from(String p_file); 202 203 bool _validate_no_foreign(); 204 void _selection_changed(); 205 void _update_script_button(); 206 Node *_get_selection_group_tail(Node *p_node, List<Node *> p_list); 207 208 void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath> > *p_renames); 209 210 void _normalize_drop(Node *&to_node, int &to_pos, int p_type); 211 212 void _nodes_dragged(Array p_nodes, NodePath p_to, int p_type); 213 void _files_dropped(Vector<String> p_files, NodePath p_to, int p_type); 214 void _script_dropped(String p_file, NodePath p_to); 215 void _quick_open(); 216 217 void _tree_rmb(const Vector2 &p_menu_pos); 218 219 void _filter_changed(const String &p_filter); 220 221 void _perform_instance_scenes(const Vector<String> &p_files, Node *parent, int p_pos); 222 void _replace_with_branch_scene(const String &p_file, Node *base); 223 224 void _file_selected(String p_file); 225 226 void _remote_tree_selected(); 227 void _local_tree_selected(); 228 229 void _update_create_root_dialog(); 230 void _favorite_root_selected(const String &p_class); 231 232 void _feature_profile_changed(); 233 234 bool profile_allow_editing; 235 bool profile_allow_script_editing; 236 237 protected: 238 void _notification(int p_what); 239 static void _bind_methods(); 240 241 public: 242 String get_filter(); 243 void set_filter(const String &p_filter); 244 245 void _focus_node(); 246 247 void import_subscene(); 248 void set_edited_scene(Node *p_scene); 249 void instance(const String &p_file); 250 void instance_scenes(const Vector<String> &p_files, Node *p_parent = NULL); 251 void set_selected(Node *p_node, bool p_emit_selected = false); 252 void fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath> > *p_renames); 253 void perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath> > *p_renames, Map<Ref<Animation>, Set<int> > *r_rem_anims = NULL); get_tree_editor()254 SceneTreeEditor *get_tree_editor() { return scene_tree; } get_editor_data()255 EditorData *get_editor_data() { return editor_data; } 256 257 void add_remote_tree_editor(Control *p_remote); 258 void show_remote_tree(); 259 void hide_remote_tree(); 260 void show_tab_buttons(); 261 void hide_tab_buttons(); 262 263 void replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties = true, bool p_remove_old = true); 264 265 void attach_script_to_selected(bool p_extend); 266 void open_script_dialog(Node *p_for_node, bool p_extend); 267 get_script_create_dialog()268 ScriptCreateDialog *get_script_create_dialog() { return script_create_dialog; } 269 270 SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data); 271 }; 272 273 #endif // SCENE_TREE_DOCK_H 274