Skip to content

Commit 94a9f7d

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 46c495c commit 94a9f7d

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
@@ -2295,6 +2295,11 @@ void EditorNode::_dialog_action(String p_file) {
22952295
}
22962296
} break;
22972297

2298+
case SAVE_AND_SET_MAIN_SCENE: {
2299+
_save_scene(p_file);
2300+
_menu_option_confirm(SCENE_SET_MAIN_SCENE, true);
2301+
} break;
2302+
22982303
case FILE_EXPORT_MESH_LIBRARY: {
22992304
const Dictionary &fd_options = file_export_lib->get_selected_options();
23002305
bool merge_with_existing_library = fd_options.get(TTR("Merge With Existing"), true);
@@ -3028,6 +3033,19 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
30283033

30293034
} break;
30303035

3036+
case SCENE_SET_MAIN_SCENE: {
3037+
const String scene_path = editor_data.get_scene_path(editor_data.get_edited_scene());
3038+
if (scene_path.is_empty()) {
3039+
current_menu_option = SAVE_AND_SET_MAIN_SCENE;
3040+
_menu_option_confirm(SCENE_SAVE_AS_SCENE, true);
3041+
file->set_title(TTR("Save new main scene..."));
3042+
} else {
3043+
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(scene_path));
3044+
ProjectSettings::get_singleton()->save();
3045+
FileSystemDock::get_singleton()->update_all();
3046+
}
3047+
} break;
3048+
30313049
case SCENE_SAVE_ALL_SCENES: {
30323050
_save_all_scenes();
30333051
} break;

editor/editor_node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class EditorNode : public Node {
146146
SCENE_SAVE_SCENE,
147147
SCENE_SAVE_AS_SCENE,
148148
SCENE_SAVE_ALL_SCENES,
149+
SCENE_SET_MAIN_SCENE,
149150
SCENE_MULTI_SAVE_AS_SCENE,
150151
SCENE_QUICK_OPEN,
151152
SCENE_QUICK_OPEN_SCENE,
@@ -213,6 +214,7 @@ class EditorNode : public Node {
213214
SCENE_TAB_CLOSE,
214215
SAVE_AND_RUN,
215216
SAVE_AND_RUN_MAIN_SCENE,
217+
SAVE_AND_SET_MAIN_SCENE,
216218
RESOURCE_SAVE,
217219
RESOURCE_SAVE_AS,
218220
SETTINGS_PICK_MAIN_SCENE,

editor/gui/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)