diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index a100e9fc55..921befbb6b 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -47,6 +47,7 @@ #include "editor/plugins/script_editor_plugin.h" #include "editor/shader_create_dialog.h" #include "scene/main/window.h" +#include "scene/property_utils.h" #include "scene/resources/packed_scene.h" #include "servers/display_server.h" #include "servers/rendering_server.h" @@ -411,10 +412,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } break; case TOOL_EXPAND_COLLAPSE: { - if (!scene_tree->get_selected()) { - break; - } - Tree *tree = scene_tree->get_scene_tree(); TreeItem *selected_item = tree->get_selected(); @@ -979,6 +976,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); } break; + case TOOL_AUTO_EXPAND: { + scene_tree->set_auto_expand_selected(!EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), true); + } break; case TOOL_SCENE_EDITABLE_CHILDREN: { if (!profile_allow_editing) { break; @@ -1223,6 +1223,7 @@ void SceneTreeDock::_notification(int p_what) { button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons"))); button_detach_script->set_icon(get_theme_icon(SNAME("ScriptRemove"), SNAME("EditorIcons"))); + button_tree_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); filter->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); filter->set_clear_button_enabled(true); @@ -1291,12 +1292,14 @@ void SceneTreeDock::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { clear_inherit_confirm->connect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM, false)); + scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false); } break; case NOTIFICATION_EXIT_TREE: { clear_inherit_confirm->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected)); } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false); button_add->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons"))); @@ -1833,8 +1836,8 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V editor_data->get_undo_redo().add_do_method(this, "_set_owners", edited_scene, owners); - 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); + if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == node) { + editor_data->get_undo_redo().add_do_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", node); } editor_data->get_undo_redo().add_undo_method(new_parent, "remove_child", node); @@ -1859,8 +1862,8 @@ 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) { - editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", node); + if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == node) { + editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", node); } if (p_keep_global_xform) { @@ -2071,8 +2074,8 @@ void SceneTreeDock::_delete_confirm(bool p_cut) { 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) { - editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", n); + if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == n) { + editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::get_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); @@ -2151,7 +2154,7 @@ 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(p_parent, "add_child", child, true); editor_data->get_undo_redo().add_do_method(child, "set_owner", edited_scene); editor_data->get_undo_redo().add_do_method(editor_selection, "clear"); editor_data->get_undo_redo().add_do_method(editor_selection, "add_node", child); @@ -2694,7 +2697,6 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->add_icon_shortcut(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); menu->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANTIATE); } - menu->add_icon_shortcut(get_theme_icon(SNAME("Collapse"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE); menu->add_separator(); existing_script = selected->get_script(); @@ -2832,6 +2834,18 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->popup(); } +void SceneTreeDock::_open_tree_menu() { + menu->clear(); + + menu->add_icon_shortcut(get_theme_icon(SNAME("Collapse"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE); + menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND); + menu->set_item_checked(menu->get_item_idx_from_text(TTR("Auto Expand to Selected")), EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected")); + + menu->set_size(Size2(1, 1)); + menu->set_position(get_screen_position() + get_local_mouse_position()); + menu->popup(); +} + void SceneTreeDock::_filter_changed(const String &p_filter) { scene_tree->set_filter(p_filter); } @@ -2930,7 +2944,7 @@ void SceneTreeDock::open_script_dialog(Node *p_for_node, bool p_extend) { } } -void SceneTreeDock::attach_shader_to_selected() { +void SceneTreeDock::attach_shader_to_selected(int p_preferred_mode) { if (selected_shader_material.is_null()) { return; } @@ -2957,13 +2971,13 @@ void SceneTreeDock::attach_shader_to_selected() { shader_create_dialog->connect("shader_created", callable_mp(this, &SceneTreeDock::_shader_created)); shader_create_dialog->connect("confirmed", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); shader_create_dialog->connect("cancelled", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); - shader_create_dialog->config(path); + shader_create_dialog->config(path, true, true, p_preferred_mode); shader_create_dialog->popup_centered(); } -void SceneTreeDock::open_shader_dialog(Ref<ShaderMaterial> &p_for_material) { +void SceneTreeDock::open_shader_dialog(Ref<ShaderMaterial> &p_for_material, int p_preferred_mode) { selected_shader_material = p_for_material; - attach_shader_to_selected(); + attach_shader_to_selected(p_preferred_mode); } void SceneTreeDock::open_add_child_dialog() { @@ -3119,7 +3133,9 @@ void SceneTreeDock::_clear_clipboard() { void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<RES, RES> &r_remap) { List<PropertyInfo> props; p_node->get_property_list(&props); - bool is_instantiated = EditorPropertyRevert::may_node_be_in_instance(p_node); + + Vector<SceneState::PackState> states_stack; + bool states_stack_ready = false; for (const PropertyInfo &E : props) { if (!(E.usage & PROPERTY_USAGE_STORAGE)) { @@ -3130,16 +3146,17 @@ void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<RES, RES> &r_remap) if (v.is_ref()) { RES res = v; if (res.is_valid()) { - if (is_instantiated) { - Variant orig; - if (EditorPropertyRevert::get_instantiated_node_original_property(p_node, E.name, orig)) { - if (!EditorPropertyRevert::is_node_property_different(p_node, v, orig)) { - continue; - } - } + if (!states_stack_ready) { + states_stack = PropertyUtils::get_node_states_stack(p_node); + states_stack_ready = true; } - if ((res->get_path() == "" || res->get_path().find("::") > -1) && !r_remap.has(res)) { + Variant orig = PropertyUtils::get_property_default_value(p_node, E.name, &states_stack); + if (!PropertyUtils::is_property_value_different(v, orig)) { + continue; + } + + if (res->is_built_in() && !r_remap.has(res)) { _create_remap_for_resource(res, r_remap); } } @@ -3166,7 +3183,7 @@ void SceneTreeDock::_create_remap_for_resource(RES p_resource, Map<RES, RES> &r_ if (v.is_ref()) { RES res = v; if (res.is_valid()) { - if ((res->get_path() == "" || res->get_path().find("::") > -1) && !r_remap.has(res)) { + if (res->is_built_in() && !r_remap.has(res)) { _create_remap_for_resource(res, r_remap); } } @@ -3271,6 +3288,11 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel filter_hbc->add_child(button_detach_script); button_detach_script->hide(); + button_tree_menu = memnew(Button); + button_tree_menu->set_flat(true); + button_tree_menu->connect("pressed", callable_mp(this, &SceneTreeDock::_open_tree_menu)); + filter_hbc->add_child(button_tree_menu); + button_hb = memnew(HBoxContainer); vbc->add_child(button_hb); |