Skip to content

Commit 2ab70e8

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 2ab70e8

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

editor/editor_node.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,12 @@ void EditorNode::save_before_run() {
21272127
file->set_title(TTR("Save scene before running..."));
21282128
}
21292129

2130+
void EditorNode::save_then_set_main_scene() {
2131+
current_menu_option = SAVE_AND_SET_MAIN_SCENE;
2132+
_menu_option_confirm(SCENE_SAVE_AS_SCENE, true);
2133+
file->set_title(TTR("Save new main scene..."));
2134+
}
2135+
21302136
void EditorNode::try_autosave() {
21312137
if (!bool(EDITOR_GET("run/auto_save/save_before_running"))) {
21322138
return;
@@ -2295,6 +2301,17 @@ void EditorNode::_dialog_action(String p_file) {
22952301
}
22962302
} break;
22972303

2304+
case SAVE_AND_SET_MAIN_SCENE: {
2305+
if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) {
2306+
save_default_environment();
2307+
_save_scene(p_file);
2308+
}
2309+
2310+
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(p_file));
2311+
ProjectSettings::get_singleton()->save();
2312+
FileSystemDock::get_singleton()->update_all();
2313+
} break;
2314+
22982315
case FILE_EXPORT_MESH_LIBRARY: {
22992316
const Dictionary &fd_options = file_export_lib->get_selected_options();
23002317
bool merge_with_existing_library = fd_options.get(TTR("Merge With Existing"), true);
@@ -3028,6 +3045,17 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
30283045

30293046
} break;
30303047

3048+
case SCENE_SET_MAIN_SCENE: {
3049+
String scene_path = editor_data.get_scene_path(editor_data.get_edited_scene());
3050+
if (scene_path.is_empty()) {
3051+
save_then_set_main_scene();
3052+
} else {
3053+
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(scene_path));
3054+
ProjectSettings::get_singleton()->save();
3055+
FileSystemDock::get_singleton()->update_all();
3056+
}
3057+
} break;
3058+
30313059
case SCENE_SAVE_ALL_SCENES: {
30323060
_save_all_scenes();
30333061
} break;

editor/editor_node.h

Lines changed: 3 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,
@@ -973,6 +975,7 @@ class EditorNode : public Node {
973975
void save_scene_if_open(const String &p_scene_path);
974976
void save_scene_list(const HashSet<String> &p_scene_paths);
975977
void save_before_run();
978+
void save_then_set_main_scene();
976979
void try_autosave();
977980
void restart_editor(bool p_goto_project_manager = false);
978981
void unload_editor_addons();

editor/gui/editor_scene_tabs.cpp

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

194194
if (tab_id >= 0) {
195+
String scene_path = EditorNode::get_editor_data().get_scene_path(tab_id);
196+
195197
scene_tabs_context_menu->add_separator();
196198
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)));
199+
DISABLE_LAST_OPTION_IF(!ResourceLoader::exists(scene_path));
198200
scene_tabs_context_menu->add_item(TTR("Play This Scene"), SCENE_RUN);
199201
DISABLE_LAST_OPTION_IF(no_root_node);
202+
scene_tabs_context_menu->add_item(TTR("Set as Main Scene"), EditorNode::SCENE_SET_MAIN_SCENE);
203+
DISABLE_LAST_OPTION_IF(no_root_node || GLOBAL_GET("application/run/main_scene") == ResourceUID::path_to_uid(scene_path));
200204

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

0 commit comments

Comments
 (0)