diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 506 |
1 files changed, 229 insertions, 277 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 5ee5fbcf9c..e73c52047b 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -50,7 +50,6 @@ #include "servers/rendering_server.h" void SceneTreeDock::_nodes_drag_begin() { - if (restore_script_editor_on_drag) { EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); restore_script_editor_on_drag = false; @@ -65,7 +64,6 @@ void SceneTreeDock::_quick_open() { } void SceneTreeDock::_input(Ref<InputEvent> p_event) { - Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { @@ -74,12 +72,13 @@ void SceneTreeDock::_input(Ref<InputEvent> p_event) { } void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { - - if (get_focus_owner() && get_focus_owner()->is_text_field()) + if (get_focus_owner() && get_focus_owner()->is_text_field()) { return; + } - if (!p_event->is_pressed() || p_event->is_echo()) + if (!p_event->is_pressed() || p_event->is_echo()) { return; + } if (ED_IS_SHORTCUT("scene_tree/batch_rename", p_event)) { _tool_selected(TOOL_BATCH_RENAME); @@ -97,8 +96,8 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { _tool_selected(TOOL_DUPLICATE); } else if (ED_IS_SHORTCUT("scene_tree/attach_script", p_event)) { _tool_selected(TOOL_ATTACH_SCRIPT); - } else if (ED_IS_SHORTCUT("scene_tree/clear_script", p_event)) { - _tool_selected(TOOL_CLEAR_SCRIPT); + } else if (ED_IS_SHORTCUT("scene_tree/detach_script", p_event)) { + _tool_selected(TOOL_DETACH_SCRIPT); } else if (ED_IS_SHORTCUT("scene_tree/move_up", p_event)) { _tool_selected(TOOL_MOVE_UP); } else if (ED_IS_SHORTCUT("scene_tree/move_down", p_event)) { @@ -119,7 +118,6 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { } void SceneTreeDock::instance(const String &p_file) { - Node *parent = scene_tree->get_selected(); if (!parent) { @@ -127,7 +125,6 @@ void SceneTreeDock::instance(const String &p_file) { }; if (!edited_scene) { - current_option = -1; accept->set_text(TTR("No parent to instance a child at.")); accept->popup_centered(); @@ -142,7 +139,6 @@ void SceneTreeDock::instance(const String &p_file) { } void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_parent) { - Node *parent = p_parent; if (!parent) { @@ -150,7 +146,6 @@ void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_paren } if (!parent || !edited_scene) { - accept->set_text(TTR("No parent to instance the scenes at.")); accept->popup_centered(); return; @@ -160,7 +155,6 @@ void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_paren } void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node *parent, int p_pos) { - ERR_FAIL_COND(!parent); Vector<Node *> instances; @@ -168,7 +162,6 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node bool error = false; for (int i = 0; i < p_files.size(); i++) { - Ref<PackedScene> sdata = ResourceLoader::load(p_files[i]); if (!sdata.is_valid()) { current_option = -1; @@ -188,9 +181,7 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node } if (edited_scene->get_filename() != "") { - if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) { - accept->set_text(vformat(TTR("Cannot instance the scene '%s' because the current scene exists within one of its nodes."), p_files[i])); accept->popup_centered(); error = true; @@ -213,7 +204,6 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node editor_data->get_undo_redo().create_action(TTR("Instance Scene(s)")); for (int i = 0; i < instances.size(); i++) { - Node *instanced_scene = instances[i]; editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene); @@ -316,13 +306,16 @@ bool SceneTreeDock::_track_inherit(const String &p_target_scene_path, Node *p_de Ref<PackedScene> data = ResourceLoader::load(path); if (data.is_valid()) { p = data->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!p) + if (!p) { continue; + } instances.push_back(p); - } else + } else { break; - } else + } + } else { break; + } } for (int i = 0; i < instances.size(); i++) { memdelete(instances[i]); @@ -331,11 +324,9 @@ bool SceneTreeDock::_track_inherit(const String &p_target_scene_path, Node *p_de } void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { - current_option = p_tool; switch (p_tool) { - case TOOL_BATCH_RENAME: { if (!profile_allow_editing) { break; @@ -356,7 +347,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_NEW: case TOOL_REPARENT_TO_NEW_NODE: { - if (!profile_allow_editing) { break; } @@ -364,17 +354,16 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene(); if (current_edited_scene_root) { - - if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D")) + if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D")) { preferred = "Node2D"; - else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D")) + } else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D")) { preferred = "Node3D"; + } } create_dialog->set_preferred_search_result_type(preferred); create_dialog->popup_create(true); } break; case TOOL_INSTANCE: { - if (!profile_allow_editing) { break; } @@ -390,15 +379,16 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_EXPAND_COLLAPSE: { - - if (!scene_tree->get_selected()) + if (!scene_tree->get_selected()) { break; + } Tree *tree = scene_tree->get_scene_tree(); TreeItem *selected_item = tree->get_selected(); - if (!selected_item) + if (!selected_item) { selected_item = tree->get_root(); + } bool collapsed = _is_collapsed_recursive(selected_item); _set_collapsed_recursive(selected_item, !collapsed); @@ -407,17 +397,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_REPLACE: { - if (!profile_allow_editing) { break; } Node *selected = scene_tree->get_selected(); - if (!selected && !editor_selection->get_selected_node_list().empty()) + if (!selected && !editor_selection->get_selected_node_list().empty()) { selected = editor_selection->get_selected_node_list().front()->get(); + } - if (selected) + if (selected) { create_dialog->popup_create(false, true, selected->get_class()); + } } break; case TOOL_EXTEND_SCRIPT: { @@ -426,22 +417,21 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { case TOOL_ATTACH_SCRIPT: { attach_script_to_selected(false); } break; - case TOOL_CLEAR_SCRIPT: { - + case TOOL_DETACH_SCRIPT: { if (!profile_allow_script_editing) { break; } Array selection = editor_selection->get_selected_nodes(); - if (selection.empty()) + if (selection.empty()) { return; + } - editor_data->get_undo_redo().create_action(TTR("Clear Script")); + editor_data->get_undo_redo().create_action(TTR("Detach Script")); editor_data->get_undo_redo().add_do_method(editor, "push_item", (Script *)nullptr); for (int i = 0; i < selection.size(); i++) { - Node *n = Object::cast_to<Node>(selection[i]); Ref<Script> existing = n->get_script(); Ref<Script> empty = EditorNode::get_singleton()->get_object_custom_type_base(n); @@ -458,24 +448,24 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_MOVE_UP: case TOOL_MOVE_DOWN: { - if (!profile_allow_editing) { break; } - if (!scene_tree->get_selected()) + if (!scene_tree->get_selected()) { break; + } if (scene_tree->get_selected() == edited_scene) { - current_option = -1; accept->set_text(TTR("This operation can't be done on the tree root.")); accept->popup_centered(); break; } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN); bool MOVING_UP = !MOVING_DOWN; @@ -483,30 +473,37 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *common_parent = scene_tree->get_selected()->get_parent(); List<Node *> selection = editor_selection->get_selected_node_list(); selection.sort_custom<Node::Comparator>(); // sort by index - if (MOVING_DOWN) + if (MOVING_DOWN) { selection.invert(); + } int lowest_id = common_parent->get_child_count() - 1; int highest_id = 0; for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { int index = E->get()->get_index(); - if (index > highest_id) + if (index > highest_id) { highest_id = index; - if (index < lowest_id) + } + if (index < lowest_id) { lowest_id = index; + } - if (E->get()->get_parent() != common_parent) + if (E->get()->get_parent() != common_parent) { common_parent = nullptr; + } } - if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0)) + if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0)) { break; // one or more nodes can not be moved + } - if (selection.size() == 1) + if (selection.size() == 1) { editor_data->get_undo_redo().create_action(TTR("Move Node In Parent")); - if (selection.size() > 1) + } + if (selection.size() > 1) { editor_data->get_undo_redo().create_action(TTR("Move Nodes In Parent")); + } for (int i = 0; i < selection.size(); i++) { Node *top_node = selection[i]; @@ -526,28 +523,29 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_DUPLICATE: { - if (!profile_allow_editing) { break; } - if (!edited_scene) + if (!edited_scene) { break; + } if (editor_selection->is_selected(edited_scene)) { - current_option = -1; accept->set_text(TTR("This operation can't be done on the tree root.")); accept->popup_centered(); break; } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.size() == 0) + if (selection.size() == 0) { break; + } editor_data->get_undo_redo().create_action(TTR("Duplicate Node(s)")); editor_data->get_undo_redo().add_do_method(editor_selection, "clear"); @@ -560,7 +558,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *add_below_node = selection.back()->get(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node *node = E->get(); Node *parent = node->get_parent(); @@ -570,21 +567,21 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Map<const Node *, Node *> duplimap; Node *dup = node->duplicate_from_editor(duplimap); - if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node)) + if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node)) { editable_children.push_back(dup); + } ERR_CONTINUE(!dup); - if (selection.size() == 1) + if (selection.size() == 1) { dupsingle = dup; + } dup->set_name(parent->validate_child_name(dup)); editor_data->get_undo_redo().add_do_method(parent, "add_child_below_node", add_below_node, dup); for (List<Node *>::Element *F = owned.front(); F; F = F->next()) { - if (!duplimap.has(F->get())) { - continue; } Node *d = duplimap[F->get()]; @@ -604,37 +601,38 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_data->get_undo_redo().commit_action(); - if (dupsingle) + if (dupsingle) { editor->push_item(dupsingle); + } - for (List<Node *>::Element *E = editable_children.back(); E; E = E->prev()) + for (List<Node *>::Element *E = editable_children.back(); E; E = E->prev()) { _toggle_editable_children(E->get()); + } } break; case TOOL_REPARENT: { - if (!profile_allow_editing) { break; } - if (!scene_tree->get_selected()) + if (!scene_tree->get_selected()) { break; + } if (editor_selection->is_selected(edited_scene)) { - current_option = -1; accept->set_text(TTR("This operation can't be done on the tree root.")); accept->popup_centered(); break; } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } List<Node *> nodes = editor_selection->get_selected_node_list(); Set<Node *> nodeset; for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - nodeset.insert(E->get()); } reparent_dialog->popup_centered_ratio(); @@ -642,7 +640,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_MAKE_ROOT: { - if (!profile_allow_editing) { break; } @@ -653,8 +650,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *node = nodes.front()->get(); Node *root = get_tree()->get_edited_scene_root(); - if (node == root) + if (node == root) { return; + } //check that from node to root, all owners are right @@ -701,14 +699,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_data->get_undo_redo().commit_action(); } break; case TOOL_MULTI_EDIT: { - if (!profile_allow_editing) { break; } Node *root = EditorNode::get_singleton()->get_edited_scene(); - if (!root) + if (!root) { break; + } Ref<MultiNodeEdit> mne = memnew(MultiNodeEdit); for (const Map<Node *, Object *>::Element *E = EditorNode::get_singleton()->get_editor_selection()->get_selection().front(); E; E = E->next()) { mne->add_node(root->get_path_to(E->key())); @@ -719,18 +717,19 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_ERASE: { - if (!profile_allow_editing) { break; } List<Node *> remove_list = editor_selection->get_selected_node_list(); - if (remove_list.empty()) + if (remove_list.empty()) { return; + } - if (!_validate_no_foreign()) + if (!_validate_no_foreign()) { break; + } if (p_confirm_override) { _delete_confirm(); @@ -756,7 +755,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_MERGE_FROM_SCENE: { - if (!profile_allow_editing) { break; } @@ -764,7 +762,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { EditorNode::get_singleton()->merge_from_scene(); } break; case TOOL_NEW_SCENE_FROM: { - if (!profile_allow_editing) { break; } @@ -820,7 +817,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { new_scene_from_dialog->set_title(TTR("Save New Scene As...")); } break; case TOOL_COPY_NODE_PATH: { - List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *>::Element *e = selection.front(); if (e) { @@ -840,7 +836,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); } break; case TOOL_SCENE_EDITABLE_CHILDREN: { - if (!profile_allow_editing) { break; } @@ -862,7 +857,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } break; case TOOL_SCENE_USE_PLACEHOLDER: { - if (!profile_allow_editing) { break; } @@ -884,8 +878,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { placeholder = !placeholder; - if (placeholder) + if (placeholder) { EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(node, false); + } node->set_scene_instance_load_placeholder(placeholder); scene_tree->update_tree(); @@ -893,7 +888,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } break; case TOOL_SCENE_MAKE_LOCAL: { - if (!profile_allow_editing) { break; } @@ -905,8 +899,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (node) { Node *root = EditorNode::get_singleton()->get_edited_scene(); UndoRedo *undo_redo = &editor_data->get_undo_redo(); - if (!root) + if (!root) { break; + } ERR_FAIL_COND(node->get_filename() == String()); undo_redo->create_action(TTR("Make Local")); @@ -920,7 +915,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } break; case TOOL_SCENE_OPEN: { - List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *>::Element *e = selection.front(); if (e) { @@ -954,7 +948,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } break; case TOOL_SCENE_OPEN_INHERITED: { - List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *>::Element *e = selection.front(); if (e) { @@ -968,7 +961,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { case TOOL_CREATE_3D_SCENE: case TOOL_CREATE_USER_INTERFACE: case TOOL_CREATE_FAVORITE: { - Node *new_node = nullptr; if (TOOL_CREATE_FAVORITE == p_tool) { @@ -1019,9 +1011,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; default: { - if (p_tool >= EDIT_SUBRESOURCE_BASE) { - int idx = p_tool - EDIT_SUBRESOURCE_BASE; ERR_FAIL_INDEX(idx, subresources.size()); @@ -1036,10 +1026,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } void SceneTreeDock::_node_collapsed(Object *p_obj) { - TreeItem *ti = Object::cast_to<TreeItem>(p_obj); - if (!ti) + if (!ti) { return; + } if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { _set_collapsed_recursive(ti, ti->is_collapsed()); @@ -1047,12 +1037,11 @@ void SceneTreeDock::_node_collapsed(Object *p_obj) { } void SceneTreeDock::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_READY: { - - if (!first_enter) + if (!first_enter) { break; + } first_enter = false; EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &SceneTreeDock::_feature_profile_changed)); @@ -1071,7 +1060,7 @@ void SceneTreeDock::_notification(int p_what) { button_add->set_icon(get_theme_icon("Add", "EditorIcons")); button_instance->set_icon(get_theme_icon("Instance", "EditorIcons")); button_create_script->set_icon(get_theme_icon("ScriptCreate", "EditorIcons")); - button_clear_script->set_icon(get_theme_icon("ScriptRemove", "EditorIcons")); + button_detach_script->set_icon(get_theme_icon("ScriptRemove", "EditorIcons")); filter->set_right_icon(get_theme_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); @@ -1148,13 +1137,12 @@ void SceneTreeDock::_notification(int p_what) { button_add->set_icon(get_theme_icon("Add", "EditorIcons")); button_instance->set_icon(get_theme_icon("Instance", "EditorIcons")); button_create_script->set_icon(get_theme_icon("ScriptCreate", "EditorIcons")); - button_clear_script->set_icon(get_theme_icon("ScriptRemove", "EditorIcons")); + button_detach_script->set_icon(get_theme_icon("ScriptRemove", "EditorIcons")); filter->set_right_icon(get_theme_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); } break; case NOTIFICATION_PROCESS: { - bool show_create_root = bool(EDITOR_GET("interface/editors/show_scene_tree_root_selection")) && get_tree()->get_edited_scene_root() == nullptr; if (show_create_root != create_root_dialog->is_visible_in_tree() && !remote_tree->is_visible()) { @@ -1172,7 +1160,6 @@ void SceneTreeDock::_notification(int p_what) { } void SceneTreeDock::_node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode) { - if (p_node->get_owner() == p_base && p_node != p_root) { UndoRedo *undo_redo = &editor_data->get_undo_redo(); switch (p_mode) { @@ -1198,21 +1185,17 @@ void SceneTreeDock::_node_replace_owner(Node *p_base, Node *p_node, Node *p_root } void SceneTreeDock::_load_request(const String &p_path) { - editor->open_request(p_path); } void SceneTreeDock::_script_open_request(const Ref<Script> &p_script) { - editor->edit_resource(p_script); } void SceneTreeDock::_node_selected() { - Node *node = scene_tree->get_selected(); if (!node) { - editor->push_item(nullptr); return; } @@ -1225,31 +1208,30 @@ void SceneTreeDock::_node_selected() { } void SceneTreeDock::_node_renamed() { - _node_selected(); } void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) { - for (int i = 0; i < p_nodes.size(); i++) { - Node *n = Object::cast_to<Node>(p_nodes[i]); - if (!n) + if (!n) { continue; + } n->set_owner(p_owner); } } void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath>> *p_renames) { - base_path.push_back(p_node->get_name()); - if (new_base_path.size()) + if (new_base_path.size()) { new_base_path.push_back(p_node->get_name()); + } NodePath from(base_path, true); NodePath to; - if (new_base_path.size()) + if (new_base_path.size()) { to = NodePath(new_base_path, true); + } Pair<NodePath, NodePath> npp; npp.first = from; @@ -1258,15 +1240,14 @@ void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<Stri p_renames->push_back(npp); for (int i = 0; i < p_node->get_child_count(); i++) { - _fill_path_renames(base_path, new_base_path, p_node->get_child(i), p_renames); } } void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath>> *p_renames) { - - if (!bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true))) + if (!bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true))) { return; + } Vector<StringName> base_path; Node *n = p_node->get_parent(); @@ -1291,39 +1272,34 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pai } void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath>> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims) { - Map<Ref<Animation>, Set<int>> rem_anims; - if (!r_rem_anims) + if (!r_rem_anims) { r_rem_anims = &rem_anims; + } if (!p_base) { - p_base = edited_scene; } - if (!p_base) + if (!p_base) { return; + } // Renaming node paths used in script instances if (p_base->get_script_instance()) { - ScriptInstance *si = p_base->get_script_instance(); if (si) { - List<PropertyInfo> properties; si->get_property_list(&properties); for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - String propertyname = E->get().name; Variant p = p_base->get(propertyname); if (p.get_type() == Variant::NODE_PATH) { - // Goes through all paths to check if its matching for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - NodePath root_path = p_base->get_path(); NodePath rel_path_old = root_path.rel_path_to(F->get().first); @@ -1337,7 +1313,6 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP // if old path detected, then it needs to be replaced with the new one if (p == rel_path_old) { - editor_data->get_undo_redo().add_do_property(p_base, propertyname, rel_path_new); editor_data->get_undo_redo().add_undo_property(p_base, propertyname, rel_path_old); @@ -1353,19 +1328,16 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP bool autorename_animation_tracks = bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true)); if (autorename_animation_tracks && Object::cast_to<AnimationPlayer>(p_base)) { - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_base); List<StringName> anims; ap->get_animation_list(&anims); Node *root = ap->get_node(ap->get_root()); if (root) { - NodePath root_path = root->get_path(); NodePath new_root_path = root_path; for (List<Pair<NodePath, NodePath>>::Element *E = p_renames->front(); E; E = E->next()) { - if (E->get().first == root_path) { new_root_path = E->get().second; break; @@ -1376,22 +1348,22 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP //will not be erased for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { - Ref<Animation> anim = ap->get_animation(E->get()); if (!r_rem_anims->has(anim)) { r_rem_anims->insert(anim, Set<int>()); Set<int> &ran = r_rem_anims->find(anim)->get(); - for (int i = 0; i < anim->get_track_count(); i++) + for (int i = 0; i < anim->get_track_count(); i++) { ran.insert(i); + } } Set<int> &ran = r_rem_anims->find(anim)->get(); - if (anim.is_null()) + if (anim.is_null()) { continue; + } for (int i = 0; i < anim->get_track_count(); i++) { - NodePath track_np = anim->track_get_path(i); Node *n = root->get_node(track_np); if (!n) { @@ -1400,13 +1372,12 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP NodePath old_np = n->get_path(); - if (!ran.has(i)) + if (!ran.has(i)) { continue; //channel was removed + } for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - if (F->get().first == old_np) { - if (F->get().second == NodePath()) { //will be erased @@ -1424,7 +1395,6 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", idx, track_np); editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_interpolation_type", idx, anim->track_get_interpolation_type(i)); for (int j = 0; j < anim->track_get_key_count(i); j++) { - editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_insert_key", idx, anim->track_get_key_time(i, j), anim->track_get_key_value(i, j), anim->track_get_key_transition(i, j)); } @@ -1435,8 +1405,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP NodePath rel_path = new_root_path.rel_path_to(F->get().second); NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false); - if (new_path == track_np) + if (new_path == track_np) { continue; //bleh + } editor_data->get_undo_redo().add_do_method(anim.ptr(), "track_set_path", i, new_path); editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", i, track_np); } @@ -1448,12 +1419,12 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP } } - for (int i = 0; i < p_base->get_child_count(); i++) + for (int i = 0; i < p_base->get_child_count(); i++) { perform_node_renames(p_base->get_child(i), p_renames, r_rem_anims); + } } void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) { - List<Pair<NodePath, NodePath>> path_renames; Vector<StringName> base_path; @@ -1474,20 +1445,18 @@ void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) { npp.second = NodePath(new_base_path, true); path_renames.push_back(npp); - for (int i = 0; i < p_node->get_child_count(); i++) + for (int i = 0; i < p_node->get_child_count(); i++) { _fill_path_renames(base_path, new_base_path, p_node->get_child(i), &path_renames); + } perform_node_renames(nullptr, &path_renames); } bool SceneTreeDock::_validate_no_foreign() { - List<Node *> selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (E->get() != edited_scene && E->get()->get_owner() != edited_scene) { - accept->set_text(TTR("Can't operate on nodes from a foreign scene!")); accept->popup_centered(); return false; @@ -1501,7 +1470,6 @@ bool SceneTreeDock::_validate_no_foreign() { } if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(E->get())) >= 0) { - accept->set_text(TTR("Can't operate on nodes the current scene inherits from!")); accept->popup_centered(); return false; @@ -1512,14 +1480,14 @@ bool SceneTreeDock::_validate_no_foreign() { } void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) { - Node *new_parent = scene_root->get_node(p_path); ERR_FAIL_COND(!new_parent); List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) + if (selection.empty()) { return; // Nothing to reparent. + } Vector<Node *> nodes; @@ -1531,31 +1499,32 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) { } void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform) { - Node *new_parent = p_new_parent; ERR_FAIL_COND(!new_parent); - if (p_nodes.size() == 0) + if (p_nodes.size() == 0) { return; // Nothing to reparent. + } p_nodes.sort_custom<Node::Comparator>(); //Makes result reliable. bool no_change = true; for (int ni = 0; ni < p_nodes.size(); ni++) { - - if (p_nodes[ni] == p_new_parent) + if (p_nodes[ni] == p_new_parent) { return; // Attempt to reparent to itself. + } - if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index()) + if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index()) { no_change = false; + } } - if (no_change) + if (no_change) { return; // Position and parent didn't change. + } Node *validate = new_parent; while (validate) { - ERR_FAIL_COND_MSG(p_nodes.find(validate) != -1, "Selection changed at some point. Can't reparent."); validate = validate->get_parent(); } @@ -1571,7 +1540,6 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V int inc = 0; for (int ni = 0; ni < p_nodes.size(); ni++) { - // No undo implemented for this yet. Node *node = p_nodes[ni]; @@ -1585,14 +1553,16 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V owners.push_back(E->get()); } - if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) + if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) { inc--; // If the child will generate a gap when moved, adjust. + } editor_data->get_undo_redo().add_do_method(node->get_parent(), "remove_child", node); editor_data->get_undo_redo().add_do_method(new_parent, "add_child", node); - if (p_position_in_parent >= 0) + if (p_position_in_parent >= 0) { editor_data->get_undo_redo().add_do_method(new_parent, "move_child", node, p_position_in_parent + inc); + } EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); String old_name = former_names[ni]; @@ -1600,7 +1570,6 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V // Name was modified, fix the path renames. if (old_name.casecmp_to(new_name) != 0) { - // Fix the to name to have the new name. NodePath old_new_name = path_renames[ni].second; NodePath new_path; @@ -1623,18 +1592,22 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V editor_data->get_undo_redo().add_undo_method(ed, "live_debug_reparent_node", NodePath(String(edited_scene->get_path_to(new_parent)).plus_file(new_name)), edited_scene->get_path_to(node->get_parent()), node->get_name(), node->get_index()); if (p_keep_global_xform) { - if (Object::cast_to<Node2D>(node)) + if (Object::cast_to<Node2D>(node)) { editor_data->get_undo_redo().add_do_method(node, "set_global_transform", Object::cast_to<Node2D>(node)->get_global_transform()); - if (Object::cast_to<Node3D>(node)) + } + if (Object::cast_to<Node3D>(node)) { editor_data->get_undo_redo().add_do_method(node, "set_global_transform", Object::cast_to<Node3D>(node)->get_global_transform()); - if (Object::cast_to<Control>(node)) + } + if (Object::cast_to<Control>(node)) { editor_data->get_undo_redo().add_do_method(node, "set_global_position", Object::cast_to<Control>(node)->get_global_position()); + } } editor_data->get_undo_redo().add_do_method(this, "_set_owners", edited_scene, owners); - if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) + if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) { editor_data->get_undo_redo().add_do_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", node); + } editor_data->get_undo_redo().add_undo_method(new_parent, "remove_child", node); editor_data->get_undo_redo().add_undo_method(node, "set_name", former_names[ni]); @@ -1644,14 +1617,12 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V // Add and move in a second step (so old order is preserved). for (int ni = 0; ni < p_nodes.size(); ni++) { - Node *node = p_nodes[ni]; List<Node *> owned; node->get_owned_by(node->get_owner(), &owned); Array owners; for (List<Node *>::Element *E = owned.front(); E; E = E->next()) { - owners.push_back(E->get()); } @@ -1660,16 +1631,20 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node); editor_data->get_undo_redo().add_undo_method(node->get_parent(), "move_child", node, child_pos); editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners); - if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) + if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) { editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", node); + } if (p_keep_global_xform) { - if (Object::cast_to<Node2D>(node)) + if (Object::cast_to<Node2D>(node)) { editor_data->get_undo_redo().add_undo_method(node, "set_transform", Object::cast_to<Node2D>(node)->get_transform()); - if (Object::cast_to<Node3D>(node)) + } + if (Object::cast_to<Node3D>(node)) { editor_data->get_undo_redo().add_undo_method(node, "set_transform", Object::cast_to<Node3D>(node)->get_transform()); - if (Object::cast_to<Control>(node)) + } + if (Object::cast_to<Control>(node)) { editor_data->get_undo_redo().add_undo_method(node, "set_position", Object::cast_to<Control>(node)->get_position()); + } } } @@ -1679,14 +1654,12 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V } bool SceneTreeDock::_is_collapsed_recursive(TreeItem *p_item) const { - bool is_branch_collapsed = false; List<TreeItem *> needs_check; needs_check.push_back(p_item); while (!needs_check.empty()) { - TreeItem *item = needs_check.back()->get(); needs_check.pop_back(); @@ -1705,12 +1678,10 @@ bool SceneTreeDock::_is_collapsed_recursive(TreeItem *p_item) const { } void SceneTreeDock::_set_collapsed_recursive(TreeItem *p_item, bool p_collapsed) { - List<TreeItem *> to_collapse; to_collapse.push_back(p_item); while (!to_collapse.empty()) { - TreeItem *item = to_collapse.back()->get(); to_collapse.pop_back(); @@ -1725,15 +1696,14 @@ void SceneTreeDock::_set_collapsed_recursive(TreeItem *p_item, bool p_collapsed) } void SceneTreeDock::_script_created(Ref<Script> p_script) { - List<Node *> selected = editor_selection->get_selected_node_list(); - if (selected.empty()) + if (selected.empty()) { return; + } editor_data->get_undo_redo().create_action(TTR("Attach Script")); for (List<Node *>::Element *E = selected.front(); E; E = E->next()) { - Ref<Script> existing = E->get()->get_script(); editor_data->get_undo_redo().add_do_method(E->get(), "set_script", p_script); editor_data->get_undo_redo().add_undo_method(E->get(), "set_script", existing); @@ -1752,7 +1722,6 @@ void SceneTreeDock::_script_creation_closed() { } void SceneTreeDock::_toggle_editable_children_from_selection() { - List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *>::Element *e = selection.front(); @@ -1762,7 +1731,6 @@ void SceneTreeDock::_toggle_editable_children_from_selection() { } void SceneTreeDock::_toggle_placeholder_from_selection() { - List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *>::Element *e = selection.front(); @@ -1781,12 +1749,12 @@ void SceneTreeDock::_toggle_placeholder_from_selection() { } void SceneTreeDock::_toggle_editable_children(Node *p_node) { - if (p_node) { bool editable = !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node); EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(p_node, editable); - if (editable) + if (editable) { p_node->set_scene_instance_load_placeholder(false); + } Node3DEditor::get_singleton()->update_all_gizmos(p_node); @@ -1795,11 +1763,11 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) { } void SceneTreeDock::_delete_confirm() { - List<Node *> remove_list = editor_selection->get_selected_node_list(); - if (remove_list.empty()) + if (remove_list.empty()) { return; + } editor->get_editor_plugins_over()->make_visible(false); @@ -1808,14 +1776,12 @@ void SceneTreeDock::_delete_confirm() { bool entire_scene = false; for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { - if (E->get() == edited_scene) { entire_scene = true; } } if (entire_scene) { - editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", (Object *)nullptr); editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", edited_scene); editor_data->get_undo_redo().add_undo_method(edited_scene, "set_owner", edited_scene->get_owner()); @@ -1823,15 +1789,15 @@ void SceneTreeDock::_delete_confirm() { editor_data->get_undo_redo().add_undo_reference(edited_scene); } else { - remove_list.sort_custom<Node::Comparator>(); //sort nodes to keep positions List<Pair<NodePath, NodePath>> path_renames; //delete from animation for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { Node *n = E->get(); - if (!n->is_inside_tree() || !n->get_parent()) + if (!n->is_inside_tree() || !n->get_parent()) { continue; + } fill_path_renames(n, nullptr, &path_renames); } @@ -1840,22 +1806,23 @@ void SceneTreeDock::_delete_confirm() { //delete for read for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { Node *n = E->get(); - if (!n->is_inside_tree() || !n->get_parent()) + if (!n->is_inside_tree() || !n->get_parent()) { continue; + } List<Node *> owned; n->get_owned_by(n->get_owner(), &owned); Array owners; for (List<Node *>::Element *F = owned.front(); F; F = F->next()) { - owners.push_back(F->get()); } editor_data->get_undo_redo().add_do_method(n->get_parent(), "remove_child", n); editor_data->get_undo_redo().add_undo_method(n->get_parent(), "add_child", n); editor_data->get_undo_redo().add_undo_method(n->get_parent(), "move_child", n, n->get_index()); - if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == n) + if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == n) { editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", n); + } editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners); editor_data->get_undo_redo().add_undo_reference(n); @@ -1867,8 +1834,9 @@ void SceneTreeDock::_delete_confirm() { editor_data->get_undo_redo().commit_action(); // hack, force 2d editor viewport to refresh after deletion - if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) + if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) { editor->get_viewport_control()->update(); + } editor->push_item(nullptr); @@ -1879,22 +1847,20 @@ void SceneTreeDock::_delete_confirm() { } void SceneTreeDock::_update_script_button() { - if (!profile_allow_script_editing) { - button_create_script->hide(); - button_clear_script->hide(); + button_detach_script->hide(); } else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 0) { button_create_script->hide(); - button_clear_script->hide(); + button_detach_script->hide(); } else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 1) { Node *n = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list()[0]; if (n->get_script().is_null()) { button_create_script->show(); - button_clear_script->hide(); + button_detach_script->hide(); } else { button_create_script->hide(); - button_clear_script->show(); + button_detach_script->show(); } } else { button_create_script->hide(); @@ -1902,16 +1868,15 @@ void SceneTreeDock::_update_script_button() { for (int i = 0; i < selection.size(); i++) { Node *n = Object::cast_to<Node>(selection[i]); if (!n->get_script().is_null()) { - button_clear_script->show(); + button_detach_script->show(); return; } } - button_clear_script->hide(); + button_detach_script->hide(); } } void SceneTreeDock::_selection_changed() { - int selection_size = EditorNode::get_singleton()->get_editor_selection()->get_selection().size(); if (selection_size > 1) { //automatically turn on multi-edit @@ -1925,17 +1890,17 @@ void SceneTreeDock::_selection_changed() { } Node *SceneTreeDock::_get_selection_group_tail(Node *p_node, List<Node *> p_list) { - Node *tail = p_node; Node *parent = tail->get_parent(); for (int i = p_node->get_index(); i < parent->get_child_count(); i++) { Node *sibling = parent->get_child(i); - if (p_list.find(sibling)) + if (p_list.find(sibling)) { tail = sibling; - else + } else { break; + } } return tail; @@ -1951,7 +1916,6 @@ void SceneTreeDock::_do_create(Node *p_parent) { editor_data->get_undo_redo().create_action(TTR("Create Node")); if (edited_scene) { - editor_data->get_undo_redo().add_do_method(p_parent, "add_child", child); editor_data->get_undo_redo().add_do_method(child, "set_owner", edited_scene); editor_data->get_undo_redo().add_do_method(editor_selection, "clear"); @@ -1965,7 +1929,6 @@ void SceneTreeDock::_do_create(Node *p_parent) { editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(p_parent)).plus_file(new_name))); } else { - editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", child); editor_data->get_undo_redo().add_do_method(scene_tree, "update_tree"); editor_data->get_undo_redo().add_do_reference(child); @@ -1981,25 +1944,26 @@ void SceneTreeDock::_do_create(Node *p_parent) { Control *ct = Object::cast_to<Control>(c); Size2 ms = ct->get_minimum_size(); - if (ms.width < 4) + if (ms.width < 4) { ms.width = 40; - if (ms.height < 4) + } + if (ms.height < 4) { ms.height = 40; + } ct->set_size(ms); } } void SceneTreeDock::_create() { - if (current_option == TOOL_NEW) { - Node *parent = nullptr; if (edited_scene) { // If root exists in edited scene parent = scene_tree->get_selected(); - if (!parent) + if (!parent) { parent = edited_scene; + } } else { // If no root exist in edited scene @@ -2057,17 +2021,19 @@ void SceneTreeDock::_create() { smaller_path_to_top = path_length; only_one_top_node = true; } else if (smaller_path_to_top == path_length) { - if (only_one_top_node && top_node->get_parent() != n->get_parent()) + if (only_one_top_node && top_node->get_parent() != n->get_parent()) { only_one_top_node = false; + } } } } Node *parent = nullptr; - if (only_one_top_node) + if (only_one_top_node) { parent = top_node->get_parent(); - else + } else { parent = top_node->get_parent()->get_parent(); + } _do_create(parent); @@ -2085,7 +2051,6 @@ void SceneTreeDock::_create() { } void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties, bool p_remove_old) { - Node *n = p_node; Node *newnode = p_by_node; @@ -2095,10 +2060,12 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop n->get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; - if (E->get().name == "__meta__") + } + if (E->get().name == "__meta__") { continue; + } if (default_oldnode->get(E->get().name) != n->get(E->get().name)) { newnode->set(E->get().name, n->get(E->get().name)); } @@ -2114,15 +2081,14 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop n->get_signal_list(&sl); for (List<MethodInfo>::Element *E = sl.front(); E; E = E->next()) { - List<Object::Connection> cl; n->get_signal_connection_list(E->get().name, &cl); for (List<Object::Connection>::Element *F = cl.front(); F; F = F->next()) { - Object::Connection &c = F->get(); - if (!(c.flags & Object::CONNECT_PERSIST)) + if (!(c.flags & Object::CONNECT_PERSIST)) { continue; + } newnode->connect(c.signal.get_name(), c.callable, c.binds, Object::CONNECT_PERSIST); } } @@ -2149,8 +2115,9 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop c->call("set_transform", c->call("get_transform")); } //p_remove_old was added to support undo - if (p_remove_old) + if (p_remove_old) { editor_data->get_undo_redo().clear_history(); + } newnode->set_name(newname); editor->push_item(newnode); @@ -2166,22 +2133,18 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop } void SceneTreeDock::set_edited_scene(Node *p_scene) { - edited_scene = p_scene; } void SceneTreeDock::set_selected(Node *p_node, bool p_emit_selected) { - scene_tree->set_selected(p_node, p_emit_selected); } void SceneTreeDock::import_subscene() { - import_subscene_dialog->popup_centered_clamped(Size2(500, 800) * EDSCALE, 0.8); } void SceneTreeDock::_import_subscene() { - Node *parent = scene_tree->get_selected(); if (!parent) { parent = editor_data->get_edited_scene_root(); @@ -2193,7 +2156,6 @@ void SceneTreeDock::_import_subscene() { } void SceneTreeDock::_new_scene_from(String p_file) { - List<Node *> selection = editor_selection->get_selected_node_list(); if (selection.size() != 1) { @@ -2214,7 +2176,6 @@ void SceneTreeDock::_new_scene_from(String p_file) { reown[editor_data->get_edited_scene_root()] = base; Node *copy = base->duplicate_and_reown(reown); if (copy) { - Ref<PackedScene> sdata = memnew(PackedScene); Error err = sdata->pack(copy); memdelete(copy); @@ -2226,8 +2187,9 @@ void SceneTreeDock::_new_scene_from(String p_file) { } int flg = 0; - if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) + if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) { flg |= ResourceSaver::FLAG_COMPRESS; + } err = ResourceSaver::save(p_file, sdata, flg); if (err != OK) { @@ -2244,26 +2206,27 @@ void SceneTreeDock::_new_scene_from(String p_file) { } static bool _is_node_visible(Node *p_node) { - - if (!p_node->get_owner()) + if (!p_node->get_owner()) { return false; - if (p_node->get_owner() != EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner())) + } + if (p_node->get_owner() != EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner())) { return false; + } return true; } static bool _has_visible_children(Node *p_node) { - bool collapsed = p_node->is_displayed_folded(); - if (collapsed) + if (collapsed) { return false; + } for (int i = 0; i < p_node->get_child_count(); i++) { - Node *child = p_node->get_child(i); - if (!_is_node_visible(child)) + if (!_is_node_visible(child)) { continue; + } return true; } @@ -2272,7 +2235,6 @@ static bool _has_visible_children(Node *p_node) { } void SceneTreeDock::_normalize_drop(Node *&to_node, int &to_pos, int p_type) { - to_pos = -1; if (p_type == -1) { @@ -2315,7 +2277,6 @@ void SceneTreeDock::_normalize_drop(Node *&to_node, int &to_pos, int p_type) { } void SceneTreeDock::_files_dropped(Vector<String> p_files, NodePath p_to, int p_type) { - Node *node = get_node(p_to); ERR_FAIL_COND(!node); @@ -2339,15 +2300,16 @@ void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) { } void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { - List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) + if (selection.empty()) { return; //nothing to reparent + } Node *to_node = get_node(p_to); - if (!to_node) + if (!to_node) { return; + } Vector<Node *> nodes; for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -2361,25 +2323,28 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { } void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { - - if (p_depth > 8) + if (p_depth > 8) { return; + } List<PropertyInfo> pinfo; p_obj->get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) { continue; - if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) + } + if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) { continue; + } Variant value = p_obj->get(E->get().name); - if (value.get_type() != Variant::OBJECT) + if (value.get_type() != Variant::OBJECT) { continue; + } Object *obj = value; - if (!obj) + if (!obj) { continue; + } Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj); @@ -2396,9 +2361,7 @@ void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { } void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { - if (!EditorNode::get_singleton()->get_edited_scene()) { - menu->clear(); if (profile_allow_editing) { menu->add_icon_shortcut(get_theme_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); @@ -2414,15 +2377,15 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *> full_selection = editor_selection->get_full_selected_node_list(); // Above method only returns nodes with common parent. - if (selection.size() == 0) + if (selection.size() == 0) { return; + } menu->clear(); Ref<Script> existing_script; bool existing_script_removable = true; if (selection.size() == 1) { - Node *selected = selection[0]; if (profile_allow_editing) { @@ -2430,8 +2393,9 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu_subresources->clear(); menu_subresources->set_size(Size2(1, 1)); _add_children_to_popup(selection.front()->get(), 0); - if (menu->get_item_count() > 0) + if (menu->get_item_count() > 0) { menu->add_separator(); + } menu->add_icon_shortcut(get_theme_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE); @@ -2458,7 +2422,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } if (existing_script.is_valid() && existing_script_removable) { add_separator = true; - menu->add_icon_shortcut(get_theme_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT); + menu->add_icon_shortcut(get_theme_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/detach_script"), TOOL_DETACH_SCRIPT); } else if (full_selection.size() > 1) { bool script_exists = false; for (List<Node *>::Element *E = full_selection.front(); E; E = E->next()) { @@ -2470,7 +2434,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { if (script_exists) { add_separator = true; - menu->add_icon_shortcut(get_theme_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT); + menu->add_icon_shortcut(get_theme_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/detach_script"), TOOL_DETACH_SCRIPT); } } @@ -2498,7 +2462,6 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } } if (selection.size() == 1) { - if (profile_allow_editing) { menu->add_separator(); menu->add_icon_shortcut(get_theme_icon("Blend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE); @@ -2555,23 +2518,19 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } void SceneTreeDock::_filter_changed(const String &p_filter) { - scene_tree->set_filter(p_filter); } String SceneTreeDock::get_filter() { - return filter->get_text(); } void SceneTreeDock::set_filter(const String &p_filter) { - filter->set_text(p_filter); scene_tree->set_filter(p_filter); } void SceneTreeDock::_focus_node() { - Node *node = scene_tree->get_selected(); ERR_FAIL_COND(!node); @@ -2590,12 +2549,14 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) { } List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) + if (selection.empty()) { return; + } Node *selected = scene_tree->get_selected(); - if (!selected) + if (!selected) { selected = selection.front()->get(); + } Ref<Script> existing = selected->get_script(); @@ -2634,7 +2595,6 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) { } void SceneTreeDock::open_script_dialog(Node *p_for_node, bool p_extend) { - scene_tree->set_selected(p_for_node, false); if (p_extend) { @@ -2652,31 +2612,27 @@ void SceneTreeDock::add_remote_tree_editor(Control *p_remote) { } void SceneTreeDock::show_remote_tree() { - _remote_tree_selected(); } void SceneTreeDock::hide_remote_tree() { - _local_tree_selected(); } void SceneTreeDock::show_tab_buttons() { - button_hb->show(); } void SceneTreeDock::hide_tab_buttons() { - button_hb->hide(); } void SceneTreeDock::_remote_tree_selected() { - scene_tree->hide(); create_root_dialog->hide(); - if (remote_tree) + if (remote_tree) { remote_tree->show(); + } edit_remote->set_pressed(true); edit_local->set_pressed(false); @@ -2684,32 +2640,32 @@ void SceneTreeDock::_remote_tree_selected() { } void SceneTreeDock::_local_tree_selected() { - scene_tree->show(); - if (remote_tree) + if (remote_tree) { remote_tree->hide(); + } edit_remote->set_pressed(false); edit_local->set_pressed(true); } void SceneTreeDock::_update_create_root_dialog() { - BaseButton *toggle = Object::cast_to<BaseButton>(create_root_dialog->get_node(String("NodeShortcutsTopRow/NodeShortcutsToggle"))); Node *node_shortcuts = create_root_dialog->get_node(String("NodeShortcuts")); - if (!toggle || !node_shortcuts) + if (!toggle || !node_shortcuts) { return; + } Control *beginner_nodes = Object::cast_to<Control>(node_shortcuts->get_node(String("BeginnerNodeShortcuts"))); Control *favorite_nodes = Object::cast_to<Control>(node_shortcuts->get_node(String("FavoriteNodeShortcuts"))); - if (!beginner_nodes || !favorite_nodes) + if (!beginner_nodes || !favorite_nodes) { return; + } EditorSettings::get_singleton()->set_setting("_use_favorites_root_selection", toggle->is_pressed()); EditorSettings::get_singleton()->save(); if (toggle->is_pressed()) { - for (int i = 0; i < favorite_nodes->get_child_count(); i++) { favorite_nodes->get_child(i)->queue_delete(); } @@ -2717,7 +2673,6 @@ void SceneTreeDock::_update_create_root_dialog() { FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites.Node"), FileAccess::READ); if (f) { - while (!f->eof_reached()) { String l = f->get_line().strip_edges(); @@ -2726,8 +2681,9 @@ void SceneTreeDock::_update_create_root_dialog() { favorite_nodes->add_child(button); button->set_text(TTR(l)); String name = l.get_slicec(' ', 0); - if (ScriptServer::is_global_class(name)) + if (ScriptServer::is_global_class(name)) { name = ScriptServer::get_global_class_native_base(name); + } button->set_icon(EditorNode::get_singleton()->get_class_icon(name)); button->connect("pressed", callable_mp(this, &SceneTreeDock::_favorite_root_selected), make_binds(l)); } @@ -2754,11 +2710,9 @@ void SceneTreeDock::_favorite_root_selected(const String &p_class) { } void SceneTreeDock::_feature_profile_changed() { - Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_valid()) { - profile_allow_editing = !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCENE_TREE); profile_allow_script_editing = !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT); bool profile_allow_3d = !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D); @@ -2781,7 +2735,6 @@ void SceneTreeDock::_feature_profile_changed() { } void SceneTreeDock::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_owners"), &SceneTreeDock::_set_owners); ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &SceneTreeDock::_unhandled_key_input); ClassDB::bind_method(D_METHOD("_input"), &SceneTreeDock::_input); @@ -2795,7 +2748,6 @@ void SceneTreeDock::_bind_methods() { } SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data) { - set_name("Scene"); editor = p_editor; edited_scene = nullptr; @@ -2816,7 +2768,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type")); ED_SHORTCUT("scene_tree/attach_script", TTR("Attach Script")); ED_SHORTCUT("scene_tree/extend_script", TTR("Extend Script")); - ED_SHORTCUT("scene_tree/clear_script", TTR("Clear Script")); + ED_SHORTCUT("scene_tree/detach_script", TTR("Detach Script")); ED_SHORTCUT("scene_tree/move_up", TTR("Move Up"), KEY_MASK_CMD | KEY_UP); ED_SHORTCUT("scene_tree/move_down", TTR("Move Down"), KEY_MASK_CMD | KEY_DOWN); ED_SHORTCUT("scene_tree/duplicate", TTR("Duplicate"), KEY_MASK_CMD | KEY_D); @@ -2851,17 +2803,17 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel button_create_script = memnew(ToolButton); button_create_script->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_ATTACH_SCRIPT, false)); - button_create_script->set_tooltip(TTR("Attach a new or existing script for the selected node.")); + button_create_script->set_tooltip(TTR("Attach a new or existing script to the selected node.")); button_create_script->set_shortcut(ED_GET_SHORTCUT("scene_tree/attach_script")); filter_hbc->add_child(button_create_script); button_create_script->hide(); - button_clear_script = memnew(ToolButton); - button_clear_script->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_CLEAR_SCRIPT, false)); - button_clear_script->set_tooltip(TTR("Clear a script for the selected node.")); - button_clear_script->set_shortcut(ED_GET_SHORTCUT("scene_tree/clear_script")); - filter_hbc->add_child(button_clear_script); - button_clear_script->hide(); + button_detach_script = memnew(ToolButton); + button_detach_script->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_DETACH_SCRIPT, false)); + button_detach_script->set_tooltip(TTR("Detach the script from the selected node.")); + button_detach_script->set_shortcut(ED_GET_SHORTCUT("scene_tree/detach_script")); + filter_hbc->add_child(button_detach_script); + button_detach_script->hide(); button_hb = memnew(HBoxContainer); vbc->add_child(button_hb); |