From 8aea5136f8923f1437cd44c048ddf78ac08152da Mon Sep 17 00:00:00 2001 From: vaner-org Date: Thu, 29 May 2025 03:57:17 +0530 Subject: [PATCH] Adds "Set as Main Scene" option to EditorSceneTabs context menu Adds the option to quickly set main scene by right-clicking a scene tab. If the scene has no root, then the option is greyed out. If the scene is unsaved, the file is saved and then set as main scene. Co-Authored-By: Alex Tam <65537185+altamkp@users.noreply.github.com> --- editor/editor_node.cpp | 18 ++++++++++++++++++ editor/editor_node.h | 2 ++ editor/scene/editor_scene_tabs.cpp | 8 +++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index ce1c82faf70..301244c82a3 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2600,6 +2600,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); @@ -3332,6 +3337,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 35b0a18c672..7c2f0131014 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 cb5f88a5352..ced86f6b5e0 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" @@ -192,11 +193,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);