Skip to content

Commit 544ec51

Browse files
vaner-orgaltamkp
andcommitted
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 <[email protected]>
1 parent bd2ca13 commit 544ec51

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

editor/editor_node.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,11 @@ void EditorNode::_dialog_action(String p_file) {
26002600
}
26012601
} break;
26022602

2603+
case SAVE_AND_SET_MAIN_SCENE: {
2604+
_save_scene(p_file);
2605+
_menu_option_confirm(SCENE_SET_MAIN_SCENE, true);
2606+
} break;
2607+
26032608
case FILE_EXPORT_MESH_LIBRARY: {
26042609
const Dictionary &fd_options = file_export_lib->get_selected_options();
26052610
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) {
33323337

33333338
} break;
33343339

3340+
case SCENE_SET_MAIN_SCENE: {
3341+
const String scene_path = editor_data.get_scene_path(editor_data.get_edited_scene());
3342+
if (scene_path.is_empty()) {
3343+
current_menu_option = SAVE_AND_SET_MAIN_SCENE;
3344+
_menu_option_confirm(SCENE_SAVE_AS_SCENE, true);
3345+
file->set_title(TTR("Save new main scene..."));
3346+
} else {
3347+
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(scene_path));
3348+
ProjectSettings::get_singleton()->save();
3349+
FileSystemDock::get_singleton()->update_all();
3350+
}
3351+
} break;
3352+
33353353
case SCENE_SAVE_ALL_SCENES: {
33363354
_save_all_scenes();
33373355
} break;

editor/editor_node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class EditorNode : public Node {
148148
SCENE_SAVE_SCENE,
149149
SCENE_SAVE_AS_SCENE,
150150
SCENE_SAVE_ALL_SCENES,
151+
SCENE_SET_MAIN_SCENE,
151152
SCENE_MULTI_SAVE_AS_SCENE,
152153
SCENE_QUICK_OPEN,
153154
SCENE_QUICK_OPEN_SCENE,
@@ -216,6 +217,7 @@ class EditorNode : public Node {
216217
SCENE_TAB_CLOSE,
217218
SAVE_AND_RUN,
218219
SAVE_AND_RUN_MAIN_SCENE,
220+
SAVE_AND_SET_MAIN_SCENE,
219221
RESOURCE_SAVE,
220222
RESOURCE_SAVE_AS,
221223
SETTINGS_PICK_MAIN_SCENE,

editor/scene/editor_scene_tabs.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,16 @@ void EditorSceneTabs::_update_context_menu() {
192192
DISABLE_LAST_OPTION_IF(!can_save_all_scenes);
193193

194194
if (tab_id >= 0) {
195+
const String scene_path = EditorNode::get_editor_data().get_scene_path(tab_id);
196+
const String main_scene_path = GLOBAL_GET("application/run/main_scene");
197+
195198
scene_tabs_context_menu->add_separator();
196199
scene_tabs_context_menu->add_item(TTR("Show in FileSystem"), SCENE_SHOW_IN_FILESYSTEM);
197-
DISABLE_LAST_OPTION_IF(!ResourceLoader::exists(EditorNode::get_editor_data().get_scene_path(tab_id)));
200+
DISABLE_LAST_OPTION_IF(!ResourceLoader::exists(scene_path));
198201
scene_tabs_context_menu->add_item(TTR("Play This Scene"), SCENE_RUN);
199202
DISABLE_LAST_OPTION_IF(no_root_node);
203+
scene_tabs_context_menu->add_item(TTR("Set as Main Scene"), EditorNode::SCENE_SET_MAIN_SCENE);
204+
DISABLE_LAST_OPTION_IF(no_root_node || (!main_scene_path.is_empty() && ResourceUID::ensure_path(main_scene_path) == scene_path));
200205

201206
scene_tabs_context_menu->add_separator();
202207
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/close_scene"), EditorNode::SCENE_CLOSE);

0 commit comments

Comments
 (0)