@@ -1265,60 +1265,24 @@ void EditorAudioBuses::_load_layout() {
12651265}
12661266
12671267void EditorAudioBuses::_load_default_layout () {
1268- String layout_path = GLOBAL_GET (" audio/buses/default_bus_layout" );
1269-
1270- Ref<AudioBusLayout> state;
1271- if (ResourceLoader::exists (layout_path)) {
1272- state = ResourceLoader::load (layout_path, " " , ResourceFormatLoader::CACHE_MODE_IGNORE);
1273- }
1274- if (state.is_null ()) {
1275- EditorNode::get_singleton ()->show_warning (vformat (TTR (" There is no '%s' file." ), layout_path));
1276- return ;
1277- }
1278-
1279- edited_path = layout_path;
1280- file->set_text (String (TTR (" Layout:" )) + " " + layout_path.get_file ());
1281- AudioServer::get_singleton ()->set_bus_layout (state);
1282- _rebuild_buses ();
1283- EditorUndoRedoManager::get_singleton ()->clear_history (EditorUndoRedoManager::GLOBAL_HISTORY);
1284- callable_mp (this , &EditorAudioBuses::_select_layout).call_deferred ();
1268+ open_layout (GLOBAL_GET (" audio/buses/default_bus_layout" ));
12851269}
12861270
12871271void EditorAudioBuses::_file_dialog_callback (const String &p_string) {
1288- if (file_dialog->get_file_mode () == EditorFileDialog::FILE_MODE_OPEN_FILE) {
1289- Ref<AudioBusLayout> state = ResourceLoader::load (p_string, " " , ResourceFormatLoader::CACHE_MODE_IGNORE);
1290- if (state.is_null ()) {
1291- EditorNode::get_singleton ()->show_warning (TTR (" Invalid file, not an audio bus layout." ));
1292- return ;
1293- }
1294-
1295- edited_path = p_string;
1296- file->set_text (String (TTR (" Layout:" )) + " " + p_string.get_file ());
1297- AudioServer::get_singleton ()->set_bus_layout (state);
1298- _rebuild_buses ();
1299- EditorUndoRedoManager::get_singleton ()->clear_history (EditorUndoRedoManager::GLOBAL_HISTORY);
1300- callable_mp (this , &EditorAudioBuses::_select_layout).call_deferred ();
1301-
1302- } else if (file_dialog->get_file_mode () == EditorFileDialog::FILE_MODE_SAVE_FILE) {
1272+ if (file_dialog->get_file_mode () == EditorFileDialog::FILE_MODE_SAVE_FILE) {
13031273 if (new_layout) {
13041274 Ref<AudioBusLayout> empty_state;
13051275 empty_state.instantiate ();
13061276 AudioServer::get_singleton ()->set_bus_layout (empty_state);
13071277 }
13081278
13091279 Error err = ResourceSaver::save (AudioServer::get_singleton ()->generate_bus_layout (), p_string);
1310-
13111280 if (err != OK) {
13121281 EditorNode::get_singleton ()->show_warning (vformat (TTR (" Error saving file: %s" ), p_string));
13131282 return ;
13141283 }
1315-
1316- edited_path = p_string;
1317- file->set_text (String (TTR (" Layout:" )) + " " + p_string.get_file ());
1318- _rebuild_buses ();
1319- EditorUndoRedoManager::get_singleton ()->clear_history (EditorUndoRedoManager::GLOBAL_HISTORY);
1320- callable_mp (this , &EditorAudioBuses::_select_layout).call_deferred ();
13211284 }
1285+ open_layout (p_string);
13221286}
13231287
13241288void EditorAudioBuses::_bind_methods () {
@@ -1330,9 +1294,10 @@ EditorAudioBuses::EditorAudioBuses() {
13301294 top_hb = memnew (HBoxContainer);
13311295 add_child (top_hb);
13321296
1297+ edited_path = ResourceUID::ensure_path (GLOBAL_GET (" audio/buses/default_bus_layout" ));
1298+
13331299 file = memnew (Label);
1334- String layout_path = GLOBAL_GET (" audio/buses/default_bus_layout" );
1335- file->set_text (String (TTR (" Layout:" )) + " " + layout_path.get_file ());
1300+ file->set_text (vformat (" %s %s" , TTR (" Layout:" ), edited_path.get_file ()));
13361301 file->set_clip_text (true );
13371302 file->set_h_size_flags (SIZE_EXPAND_FILL);
13381303 top_hb->add_child (file);
@@ -1386,8 +1351,6 @@ EditorAudioBuses::EditorAudioBuses() {
13861351
13871352 set_v_size_flags (SIZE_EXPAND_FILL);
13881353
1389- edited_path = GLOBAL_GET (" audio/buses/default_bus_layout" );
1390-
13911354 file_dialog = memnew (EditorFileDialog);
13921355 List<String> ext;
13931356 ResourceLoader::get_recognized_extensions_for_type (" AudioBusLayout" , &ext);
@@ -1405,14 +1368,21 @@ EditorAudioBuses::EditorAudioBuses() {
14051368void EditorAudioBuses::open_layout (const String &p_path) {
14061369 EditorNode::get_bottom_panel ()->make_item_visible (this );
14071370
1408- Ref<AudioBusLayout> state = ResourceLoader::load (p_path, " " , ResourceFormatLoader::CACHE_MODE_IGNORE);
1371+ const String path = ResourceUID::ensure_path (p_path);
1372+
1373+ if (!ResourceLoader::exists (path)) {
1374+ EditorNode::get_singleton ()->show_warning (vformat (TTR (R"( Can't open audio bus layout: "%s" doesn't exist.)" ), path));
1375+ return ;
1376+ }
1377+
1378+ Ref<AudioBusLayout> state = ResourceLoader::load (path, " " , ResourceFormatLoader::CACHE_MODE_IGNORE);
14091379 if (state.is_null ()) {
1410- EditorNode::get_singleton ()->show_warning (TTR (" Invalid file, not an audio bus layout." ));
1380+ EditorNode::get_singleton ()->show_warning (vformat ( TTR (R"( Can't open audio bus layout: "%s" is not a valid audio bus layout.)" ), path ));
14111381 return ;
14121382 }
14131383
1414- edited_path = p_path ;
1415- file->set_text (p_path .get_file ());
1384+ edited_path = path ;
1385+ file->set_text (vformat ( " %s %s " , TTR ( " Layout: " ), path .get_file () ));
14161386 AudioServer::get_singleton ()->set_bus_layout (state);
14171387 _rebuild_buses ();
14181388 EditorUndoRedoManager::get_singleton ()->clear_history (EditorUndoRedoManager::GLOBAL_HISTORY);
0 commit comments