1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-31 18:41:20 +00:00

Merge pull request #110422 from KoBeWi/audio_bus_factor

Fix AudioBus editor not updating layout path
This commit is contained in:
Rémi Verschelde
2025-12-21 10:40:37 +01:00
2 changed files with 52 additions and 27 deletions

View File

@@ -1078,6 +1078,16 @@ void EditorAudioBusDrop::_bind_methods() {
ADD_SIGNAL(MethodInfo("dropped")); ADD_SIGNAL(MethodInfo("dropped"));
} }
void EditorAudioBuses::_update_file_label() {
const String filename = ResourceUID::ensure_path(edited_path).get_file();
file->set_text(filename);
file->set_tooltip_text(filename);
if (is_visible_in_tree()) {
_update_file_label_size();
}
}
void EditorAudioBuses::_update_file_label_size() { void EditorAudioBuses::_update_file_label_size() {
int label_min_width = file->get_minimum_size().x + file->get_character_bounds(0).size.x; int label_min_width = file->get_minimum_size().x + file->get_character_bounds(0).size.x;
file->set_custom_minimum_size(Size2(label_min_width, 0)); file->set_custom_minimum_size(Size2(label_min_width, 0));
@@ -1120,7 +1130,9 @@ void EditorAudioBuses::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
bus_scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree"))); bus_scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
if (is_visible_in_tree()) {
_update_file_label_size(); _update_file_label_size();
}
} break; } break;
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
@@ -1154,11 +1166,9 @@ void EditorAudioBuses::_notification(int p_what) {
} }
} break; } break;
case NOTIFICATION_VISIBILITY_CHANGED: { case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) { if (is_visible_in_tree()) {
break; _update_file_label();
} }
_update_file_label_size();
} break; } break;
} }
} }
@@ -1269,17 +1279,34 @@ void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) {
void EditorAudioBuses::_server_save() { void EditorAudioBuses::_server_save() {
Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout(); Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout();
if (edited_path.is_empty()) {
ResourceSaver::save(state, "res://default_bus_layout.tres");
edited_path = ResourceUID::path_to_uid("res://default_bus_layout.tres");
ProjectSettings::get_singleton()->set_setting("audio/buses/default_bus_layout", edited_path);
_update_file_label();
} else if (!edited_path.begins_with("uid://")) {
ResourceSaver::save(state, edited_path); ResourceSaver::save(state, edited_path);
edited_path = ResourceUID::path_to_uid(edited_path);
ProjectSettings::get_singleton()->set_setting("audio/buses/default_bus_layout", edited_path);
} else {
ResourceSaver::save(state, ResourceUID::ensure_path(edited_path));
}
}
void EditorAudioBuses::_file_moved(const String &p_old_path, const String &p_new_path) {
if (is_visible_in_tree() && !edited_path.is_empty()) {
callable_mp(this, &EditorAudioBuses::_update_file_label).call_deferred();
}
} }
void EditorAudioBuses::_select_layout() { void EditorAudioBuses::_select_layout() {
FileSystemDock::get_singleton()->navigate_to_path(edited_path); FileSystemDock::get_singleton()->navigate_to_path(ResourceUID::ensure_path(edited_path));
} }
void EditorAudioBuses::_save_as_layout() { void EditorAudioBuses::_save_as_layout() {
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_dialog->set_title(TTR("Save Audio Bus Layout As...")); file_dialog->set_title(TTR("Save Audio Bus Layout As..."));
file_dialog->set_current_path(edited_path); file_dialog->set_current_path(ResourceUID::ensure_path(edited_path));
file_dialog->popup_file_dialog(); file_dialog->popup_file_dialog();
new_layout = false; new_layout = false;
} }
@@ -1287,7 +1314,7 @@ void EditorAudioBuses::_save_as_layout() {
void EditorAudioBuses::_new_layout() { void EditorAudioBuses::_new_layout() {
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_dialog->set_title(TTR("Location for New Layout...")); file_dialog->set_title(TTR("Location for New Layout..."));
file_dialog->set_current_path(edited_path); file_dialog->set_current_path("new_bus_layout.tres");
file_dialog->popup_file_dialog(); file_dialog->popup_file_dialog();
new_layout = true; new_layout = true;
} }
@@ -1295,7 +1322,7 @@ void EditorAudioBuses::_new_layout() {
void EditorAudioBuses::_load_layout() { void EditorAudioBuses::_load_layout() {
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
file_dialog->set_title(TTR("Open Audio Bus Layout")); file_dialog->set_title(TTR("Open Audio Bus Layout"));
file_dialog->set_current_path(edited_path); file_dialog->set_current_path(ResourceUID::ensure_path(edited_path));
file_dialog->popup_file_dialog(); file_dialog->popup_file_dialog();
new_layout = false; new_layout = false;
} }
@@ -1318,7 +1345,7 @@ void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
return; return;
} }
} }
open_layout(p_string); open_layout(ResourceUID::path_to_uid(p_string));
} }
void EditorAudioBuses::update_layout(EditorDock::DockLayout p_layout) { void EditorAudioBuses::update_layout(EditorDock::DockLayout p_layout) {
@@ -1355,15 +1382,12 @@ EditorAudioBuses::EditorAudioBuses() {
top_hb = memnew(HBoxContainer); top_hb = memnew(HBoxContainer);
main_vb->add_child(top_hb); main_vb->add_child(top_hb);
edited_path = ResourceUID::ensure_path(GLOBAL_GET("audio/buses/default_bus_layout")); edited_path = GLOBAL_GET("audio/buses/default_bus_layout");
Label *layout_label = memnew(Label(TTRC("Layout:"))); Label *layout_label = memnew(Label(TTRC("Layout:")));
top_hb->add_child(layout_label); top_hb->add_child(layout_label);
file = memnew(Label); file = memnew(Label);
const String _file_name = edited_path.get_file();
file->set_text(_file_name);
file->set_tooltip_text(_file_name);
file->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); file->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
file->set_mouse_filter(MOUSE_FILTER_PASS); file->set_mouse_filter(MOUSE_FILTER_PASS);
file->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); file->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
@@ -1435,6 +1459,7 @@ EditorAudioBuses::EditorAudioBuses() {
file_dialog->connect("file_selected", callable_mp(this, &EditorAudioBuses::_file_dialog_callback)); file_dialog->connect("file_selected", callable_mp(this, &EditorAudioBuses::_file_dialog_callback));
AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &EditorAudioBuses::_rebuild_buses)); AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &EditorAudioBuses::_rebuild_buses));
FileSystemDock::get_singleton()->connect("files_moved", callable_mp(this, &EditorAudioBuses::_file_moved));
set_process(true); set_process(true);
} }
@@ -1443,23 +1468,19 @@ void EditorAudioBuses::open_layout(const String &p_path) {
make_visible(); make_visible();
const String path = ResourceUID::ensure_path(p_path); const String path = ResourceUID::ensure_path(p_path);
if (!ResourceLoader::exists(path)) { if (!ResourceLoader::exists(path)) {
EditorNode::get_singleton()->show_warning(vformat(TTR(R"(Can't open audio bus layout: "%s" doesn't exist.)"), path)); EditorNode::get_singleton()->show_warning(vformat(TTR(R"(Can't open audio bus layout: "%s" doesn't exist.)"), path));
return; return;
} }
Ref<AudioBusLayout> state = ResourceLoader::load(path, "", ResourceFormatLoader::CACHE_MODE_IGNORE); Ref<AudioBusLayout> state = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE);
if (state.is_null()) { if (state.is_null()) {
EditorNode::get_singleton()->show_warning(vformat(TTR(R"(Can't open audio bus layout: "%s" is not a valid audio bus layout.)"), path)); EditorNode::get_singleton()->show_warning(vformat(TTR(R"(Can't open audio bus layout: "%s" is not a valid audio bus layout.)"), path));
return; return;
} }
edited_path = path; edited_path = p_path; // Use UID when available.
const String _file_name = edited_path.get_file(); _update_file_label();
file->set_text(_file_name);
file->set_tooltip_text(_file_name);
_update_file_label_size();
AudioServer::get_singleton()->set_bus_layout(state); AudioServer::get_singleton()->set_bus_layout(state);
_rebuild_buses(); _rebuild_buses();
@@ -1468,11 +1489,13 @@ void EditorAudioBuses::open_layout(const String &p_path) {
} }
void AudioBusesEditorPlugin::edit(Object *p_node) { void AudioBusesEditorPlugin::edit(Object *p_node) {
if (Object::cast_to<AudioBusLayout>(p_node)) { Ref<AudioBusLayout> bus_layout(p_node);
String path = Object::cast_to<AudioBusLayout>(p_node)->get_path(); if (bus_layout.is_null()) {
if (path.is_resource_file()) { return;
audio_bus_editor->open_layout(path);
} }
const String path = bus_layout->get_path();
if (path.is_resource_file()) {
audio_bus_editor->open_layout(ResourceUID::path_to_uid(path));
} }
} }

View File

@@ -172,6 +172,7 @@ class EditorAudioBuses : public EditorDock {
bool floating = false; bool floating = false;
void _update_file_label();
void _update_file_label_size(); void _update_file_label_size();
void _rebuild_buses(); void _rebuild_buses();
@@ -187,6 +188,7 @@ class EditorAudioBuses : public EditorDock {
void _drop_at_index(int p_bus, int p_index); void _drop_at_index(int p_bus, int p_index);
void _server_save(); void _server_save();
void _file_moved(const String &p_old_path, const String &p_new_path);
void _select_layout(); void _select_layout();
void _load_layout(); void _load_layout();