diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index ebb3fd080f2..592d19cdea5 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2612,6 +2612,11 @@ void EditorNode::_dialog_action(String p_file) { } } break; + case SAVE_AND_SET_MAIN_SCENE: { + _save_scene(p_file); + _menu_option_confirm(SCENE_SET_MAIN_SCENE, true); + } break; + case FILE_EXPORT_MESH_LIBRARY: { const Dictionary &fd_options = file_export_lib->get_selected_options(); bool merge_with_existing_library = fd_options.get(TTR("Merge With Existing"), true); @@ -3344,6 +3349,19 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; + case SCENE_SET_MAIN_SCENE: { + const String scene_path = editor_data.get_scene_path(editor_data.get_edited_scene()); + if (scene_path.is_empty()) { + current_menu_option = SAVE_AND_SET_MAIN_SCENE; + _menu_option_confirm(SCENE_SAVE_AS_SCENE, true); + file->set_title(TTR("Save new main scene...")); + } else { + ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(scene_path)); + ProjectSettings::get_singleton()->save(); + FileSystemDock::get_singleton()->update_all(); + } + } break; + case SCENE_SAVE_ALL_SCENES: { _save_all_scenes(); } break; diff --git a/editor/editor_node.h b/editor/editor_node.h index 9516ff160d9..99251096d8d 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -148,6 +148,7 @@ public: SCENE_SAVE_SCENE, SCENE_SAVE_AS_SCENE, SCENE_SAVE_ALL_SCENES, + SCENE_SET_MAIN_SCENE, SCENE_MULTI_SAVE_AS_SCENE, SCENE_QUICK_OPEN, SCENE_QUICK_OPEN_SCENE, @@ -216,6 +217,7 @@ public: SCENE_TAB_CLOSE, SAVE_AND_RUN, SAVE_AND_RUN_MAIN_SCENE, + SAVE_AND_SET_MAIN_SCENE, RESOURCE_SAVE, RESOURCE_SAVE_AS, SETTINGS_PICK_MAIN_SCENE, diff --git a/editor/scene/editor_scene_tabs.cpp b/editor/scene/editor_scene_tabs.cpp index 4df429c29df..9725e13e202 100644 --- a/editor/scene/editor_scene_tabs.cpp +++ b/editor/scene/editor_scene_tabs.cpp @@ -30,6 +30,7 @@ #include "editor_scene_tabs.h" +#include "core/config/project_settings.h" #include "editor/docks/inspector_dock.h" #include "editor/editor_main_screen.h" #include "editor/editor_node.h" @@ -195,11 +196,16 @@ void EditorSceneTabs::_update_context_menu() { DISABLE_LAST_OPTION_IF(!can_save_all_scenes); if (tab_id >= 0) { + const String scene_path = EditorNode::get_editor_data().get_scene_path(tab_id); + const String main_scene_path = GLOBAL_GET("application/run/main_scene"); + scene_tabs_context_menu->add_separator(); scene_tabs_context_menu->add_item(TTR("Show in FileSystem"), SCENE_SHOW_IN_FILESYSTEM); - DISABLE_LAST_OPTION_IF(!ResourceLoader::exists(EditorNode::get_editor_data().get_scene_path(tab_id))); + DISABLE_LAST_OPTION_IF(!ResourceLoader::exists(scene_path)); scene_tabs_context_menu->add_item(TTR("Play This Scene"), SCENE_RUN); DISABLE_LAST_OPTION_IF(no_root_node); + scene_tabs_context_menu->add_item(TTR("Set as Main Scene"), EditorNode::SCENE_SET_MAIN_SCENE); + DISABLE_LAST_OPTION_IF(no_root_node || (!main_scene_path.is_empty() && ResourceUID::ensure_path(main_scene_path) == scene_path)); scene_tabs_context_menu->add_separator(); scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/close_scene"), EditorNode::SCENE_CLOSE);