diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 161 |
1 files changed, 98 insertions, 63 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 98ab1bfb54..5c08482aa4 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -340,8 +340,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (!profile_allow_editing) { break; } - Tree *tree = scene_tree->get_scene_tree(); - if (tree->is_anything_selected()) { + if (editor_selection->get_selected_node_list().size() > 1) { rename_dialog->popup_centered(); } } break; @@ -421,53 +420,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { create_dialog->popup_create(false, true, selected->get_class()); } break; + case TOOL_EXTEND_SCRIPT: { + attach_script_to_selected(true); + } break; case TOOL_ATTACH_SCRIPT: { - - if (!profile_allow_script_editing) { - break; - } - - List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) - break; - - Node *selected = scene_tree->get_selected(); - if (!selected) - selected = selection.front()->get(); - - Ref<Script> existing = selected->get_script(); - - String path = selected->get_filename(); - if (path == "") { - String root_path = editor_data->get_edited_scene_root()->get_filename(); - if (root_path == "") { - path = String("res://").plus_file(selected->get_name()); - } else { - path = root_path.get_base_dir().plus_file(selected->get_name()); - } - } - - String inherits = selected->get_class(); - if (existing.is_valid()) { - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptLanguage *l = ScriptServer::get_language(i); - if (l->get_type() == existing->get_class()) { - String name = l->get_global_class_name(existing->get_path()); - if (ScriptServer::is_global_class(name) && EDITOR_GET("interface/editors/derive_script_globals_by_name").operator bool()) { - inherits = name; - } else if (l->can_inherit_from_file()) { - inherits = "\"" + existing->get_path() + "\""; - } - break; - } - } - } - script_create_dialog->connect("script_created", this, "_script_created"); - script_create_dialog->connect("popup_hide", this, "_script_creation_closed"); - script_create_dialog->set_inheritance_base_type("Node"); - script_create_dialog->config(inherits, path); - script_create_dialog->popup_centered(); - + attach_script_to_selected(false); } break; case TOOL_CLEAR_SCRIPT: { @@ -1081,7 +1038,6 @@ void SceneTreeDock::_node_collapsed(Object *p_obj) { void SceneTreeDock::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY: { if (!first_enter) @@ -1142,8 +1098,7 @@ void SceneTreeDock::_notification(int p_what) { button_2d->set_text(TTR("2D Scene")); button_2d->set_icon(get_icon("Node2D", "EditorIcons")); button_2d->connect("pressed", this, "_tool_selected", make_binds(TOOL_CREATE_2D_SCENE, false)); - - Button *button_3d = memnew(Button); + button_3d = memnew(Button); beginner_node_shortcuts->add_child(button_3d); button_3d->set_text(TTR("3D Scene")); button_3d->set_icon(get_icon("Spatial", "EditorIcons")); @@ -2446,6 +2401,7 @@ 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) return; @@ -2480,22 +2436,40 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } if (profile_allow_script_editing) { + bool add_separator = false; - if (selection.size() == 1) { - if (!existing_script.is_valid()) { - menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT); - } else { - menu->add_icon_shortcut(get_icon("ScriptExtend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/extend_script"), TOOL_ATTACH_SCRIPT); + if (full_selection.size() == 1) { + add_separator = true; + menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT); + if (existing_script.is_valid()) { + menu->add_icon_shortcut(get_icon("ScriptExtend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/extend_script"), TOOL_EXTEND_SCRIPT); } } - if (selection.size() > 1 || (existing_script.is_valid() && exisiting_script_removable)) { + if (existing_script.is_valid() && exisiting_script_removable) { + add_separator = true; menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT); + } else if (full_selection.size() > 1) { + bool script_exists = false; + for (List<Node *>::Element *E = full_selection.front(); E; E = E->next()) { + if (!E->get()->get_script().is_null()) { + script_exists = true; + break; + } + } + + if (script_exists) { + add_separator = true; + menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT); + } + } + + if (add_separator) { + menu->add_separator(); } - menu->add_separator(); } if (profile_allow_editing) { - if (selection.size() == 1) { + if (full_selection.size() == 1) { menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/rename"), TOOL_RENAME); } menu->add_icon_shortcut(get_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE); @@ -2507,7 +2481,9 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->add_icon_shortcut(get_icon("Duplicate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/duplicate"), TOOL_DUPLICATE); menu->add_icon_shortcut(get_icon("Reparent", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/reparent"), TOOL_REPARENT); menu->add_icon_shortcut(get_icon("ReparentToNewNode", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/reparent_to_new_node"), TOOL_REPARENT_TO_NEW_NODE); - menu->add_icon_shortcut(get_icon("NewRoot", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/make_root"), TOOL_MAKE_ROOT); + if (selection.size() == 1) { + menu->add_icon_shortcut(get_icon("NewRoot", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/make_root"), TOOL_MAKE_ROOT); + } } } if (selection.size() == 1) { @@ -2516,9 +2492,11 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->add_separator(); menu->add_icon_shortcut(get_icon("Blend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE); menu->add_icon_shortcut(get_icon("CreateNewSceneFrom", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM); + } + if (full_selection.size() == 1) { menu->add_separator(); + menu->add_icon_shortcut(get_icon("CopyNodePath", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/copy_node_path"), TOOL_COPY_NODE_PATH); } - menu->add_icon_shortcut(get_icon("CopyNodePath", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/copy_node_path"), TOOL_COPY_NODE_PATH); bool is_external = (selection[0]->get_filename() != ""); if (is_external) { @@ -2595,10 +2573,64 @@ void SceneTreeDock::_focus_node() { } } -void SceneTreeDock::open_script_dialog(Node *p_for_node) { +void SceneTreeDock::attach_script_to_selected(bool p_extend) { + if (!profile_allow_script_editing) { + return; + } + + List<Node *> selection = editor_selection->get_selected_node_list(); + if (selection.empty()) + return; + + Node *selected = scene_tree->get_selected(); + if (!selected) + selected = selection.front()->get(); + + Ref<Script> existing = selected->get_script(); + + String path = selected->get_filename(); + if (path == "") { + String root_path = editor_data->get_edited_scene_root()->get_filename(); + if (root_path == "") { + path = String("res://").plus_file(selected->get_name()); + } else { + path = root_path.get_base_dir().plus_file(selected->get_name()); + } + } + + String inherits = selected->get_class(); + + if (p_extend && existing.is_valid()) { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptLanguage *l = ScriptServer::get_language(i); + if (l->get_type() == existing->get_class()) { + String name = l->get_global_class_name(existing->get_path()); + if (ScriptServer::is_global_class(name) && EDITOR_GET("interface/editors/derive_script_globals_by_name").operator bool()) { + inherits = name; + } else if (l->can_inherit_from_file()) { + inherits = "\"" + existing->get_path() + "\""; + } + break; + } + } + } + + script_create_dialog->connect("script_created", this, "_script_created"); + script_create_dialog->connect("popup_hide", this, "_script_creation_closed"); + script_create_dialog->set_inheritance_base_type("Node"); + script_create_dialog->config(inherits, path); + script_create_dialog->popup_centered(); +} + +void SceneTreeDock::open_script_dialog(Node *p_for_node, bool p_extend) { scene_tree->set_selected(p_for_node, false); - _tool_selected(TOOL_ATTACH_SCRIPT); + + if (p_extend) { + _tool_selected(TOOL_EXTEND_SCRIPT); + } else { + _tool_selected(TOOL_ATTACH_SCRIPT); + } } void SceneTreeDock::add_remote_tree_editor(Control *p_remote) { @@ -2718,12 +2750,15 @@ void SceneTreeDock::_feature_profile_changed() { 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); + button_3d->set_visible(profile_allow_3d); button_add->set_visible(profile_allow_editing); button_instance->set_visible(profile_allow_editing); scene_tree->set_can_rename(profile_allow_editing); } else { + button_3d->set_visible(true); button_add->set_visible(true); button_instance->set_visible(true); scene_tree->set_can_rename(true); |