diff --git a/editor/audio/editor_audio_buses.cpp b/editor/audio/editor_audio_buses.cpp index 6713cddca75..68a1e002eb5 100644 --- a/editor/audio/editor_audio_buses.cpp +++ b/editor/audio/editor_audio_buses.cpp @@ -34,16 +34,17 @@ #include "core/input/input.h" #include "core/io/resource_saver.h" #include "core/os/keyboard.h" +#include "editor/docks/editor_dock_manager.h" #include "editor/docks/filesystem_dock.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" -#include "editor/gui/editor_bottom_panel.h" #include "editor/gui/editor_file_dialog.h" #include "editor/settings/editor_command_palette.h" #include "editor/settings/editor_settings.h" #include "editor/themes/editor_scale.h" #include "editor/themes/editor_theme_manager.h" +#include "scene/gui/box_container.h" #include "scene/gui/separator.h" #include "scene/main/timer.h" #include "scene/resources/font.h" @@ -1111,7 +1112,7 @@ void EditorAudioBuses::_rebuild_buses() { EditorAudioBuses *EditorAudioBuses::register_editor() { EditorAudioBuses *audio_buses = memnew(EditorAudioBuses); - EditorNode::get_bottom_panel()->add_item(TTRC("Audio"), audio_buses, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_audio_bottom_panel", TTRC("Toggle Audio Bottom Panel"), KeyModifierMask::ALT | Key::A)); + EditorDockManager::get_singleton()->add_dock(audio_buses); return audio_buses; } @@ -1158,16 +1159,6 @@ void EditorAudioBuses::_notification(int p_what) { } _update_file_label_size(); - - // Setting `the split_offset` value once to the minimum value required to display the entire contents of the `EditorAudioBuses`. - // This is used instead of setting a custom_minimum_size or similar, as this may cause the panel to be outside the window (see GH-26835). - // If `EditorAudioBuses` is selected when starting the editor, this code will be executed first and then the saved layout will load. - if (use_default_editor_size) { - use_default_editor_size = false; - int offset = EditorNode::get_bottom_panel()->get_combined_minimum_size().y + get_combined_minimum_size().y; - offset += Object::cast_to(bus_hb->get_child(0))->get_combined_minimum_size().y; // Master audio bus always exists. - EditorNode::get_singleton()->set_center_split_offset(-offset); - } } break; } } @@ -1336,8 +1327,17 @@ void EditorAudioBuses::_bind_methods() { } EditorAudioBuses::EditorAudioBuses() { + set_name(TTRC("Audio")); + set_icon_name("AudioStreamPlayer"); + set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_audio_bottom_panel", TTRC("Toggle Audio Dock"), KeyModifierMask::ALT | Key::A)); + set_default_slot(DockConstants::DOCK_SLOT_BOTTOM); + set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING); + + VBoxContainer *main_vb = memnew(VBoxContainer); + add_child(main_vb); + top_hb = memnew(HBoxContainer); - add_child(top_hb); + main_vb->add_child(top_hb); edited_path = ResourceUID::ensure_path(GLOBAL_GET("audio/buses/default_bus_layout")); @@ -1390,7 +1390,7 @@ EditorAudioBuses::EditorAudioBuses() { bus_scroll = memnew(ScrollContainer); bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL); bus_scroll->set_custom_minimum_size(Size2(0, 40 * EDSCALE)); - add_child(bus_scroll); + main_vb->add_child(bus_scroll); bus_hb = memnew(HBoxContainer); bus_hb->set_v_size_flags(SIZE_EXPAND_FILL); bus_scroll->add_child(bus_hb); @@ -1398,7 +1398,7 @@ EditorAudioBuses::EditorAudioBuses() { save_timer = memnew(Timer); save_timer->set_wait_time(0.8); save_timer->set_one_shot(true); - add_child(save_timer); + main_vb->add_child(save_timer); save_timer->connect("timeout", callable_mp(this, &EditorAudioBuses::_server_save)); set_v_size_flags(SIZE_EXPAND_FILL); @@ -1418,7 +1418,7 @@ EditorAudioBuses::EditorAudioBuses() { } void EditorAudioBuses::open_layout(const String &p_path) { - EditorNode::get_bottom_panel()->make_item_visible(this); + make_visible(); const String path = ResourceUID::ensure_path(p_path); diff --git a/editor/audio/editor_audio_buses.h b/editor/audio/editor_audio_buses.h index 6e8be908c76..f66be88bd8e 100644 --- a/editor/audio/editor_audio_buses.h +++ b/editor/audio/editor_audio_buses.h @@ -30,8 +30,8 @@ #pragma once +#include "editor/docks/editor_dock.h" #include "editor/plugins/editor_plugin.h" -#include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/control.h" #include "scene/gui/line_edit.h" @@ -47,6 +47,7 @@ class EditorAudioBuses; class EditorFileDialog; +class HBoxContainer; class Timer; class EditorAudioBus : public PanelContainer { @@ -148,8 +149,8 @@ protected: void _notification(int p_what); }; -class EditorAudioBuses : public VBoxContainer { - GDCLASS(EditorAudioBuses, VBoxContainer); +class EditorAudioBuses : public EditorDock { + GDCLASS(EditorAudioBuses, EditorDock); HBoxContainer *top_hb = nullptr; @@ -194,8 +195,6 @@ class EditorAudioBuses : public VBoxContainer { EditorFileDialog *file_dialog = nullptr; bool new_layout = false; - bool use_default_editor_size = true; - void _file_dialog_callback(const String &p_string); protected: diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 2b3f78da760..d811fa85c86 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6091,6 +6091,10 @@ void EditorNode::_load_editor_layout() { if (overridden_default_layout >= 0) { _layout_menu_option(overridden_default_layout); + } else { + ep.step(TTR("Loading docks..."), 1, true); + // Initialize some default values. + bottom_panel->load_layout_from_config(default_layout, EDITOR_NODE_CONFIG_SECTION); } } else { ep.step(TTR("Loading docks..."), 1, true); @@ -8799,6 +8803,12 @@ EditorNode::EditorNode() { default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0); } + { + Dictionary offsets; + offsets["Audio"] = -450; + default_layout->set_value(EDITOR_NODE_CONFIG_SECTION, "bottom_panel_offsets", offsets); + } + _update_layouts_menu(); // Bottom panels. diff --git a/editor/gui/editor_bottom_panel.cpp b/editor/gui/editor_bottom_panel.cpp index 25d238cbcd8..2e67fa4dd8e 100644 --- a/editor/gui/editor_bottom_panel.cpp +++ b/editor/gui/editor_bottom_panel.cpp @@ -79,20 +79,16 @@ void EditorBottomPanel::_theme_changed() { } void EditorBottomPanel::set_bottom_panel_offset(int p_offset) { - Control *current_tab = get_current_tab_control(); + EditorDock *current_tab = Object::cast_to(get_current_tab_control()); if (current_tab) { - String name = current_tab->get_name(); - String key = name.to_snake_case(); - dock_offsets[key] = p_offset; + dock_offsets[current_tab->get_effective_layout_key()] = p_offset; } } int EditorBottomPanel::get_bottom_panel_offset() { - Control *current_tab = get_current_tab_control(); + EditorDock *current_tab = Object::cast_to(get_current_tab_control()); if (current_tab) { - String name = current_tab->get_name(); - String key = name.to_snake_case(); - return dock_offsets[key]; + return dock_offsets[current_tab->get_effective_layout_key()]; } return 0; } @@ -126,19 +122,21 @@ void EditorBottomPanel::_repaint() { } void EditorBottomPanel::save_layout_to_config(Ref p_config_file, const String &p_section) const { - p_config_file->set_value(p_section, "selected_bottom_panel_item", get_current_tab() != -1 ? Variant(get_current_tab()) : Variant()); - + Dictionary offsets; for (const KeyValue &E : dock_offsets) { - p_config_file->set_value(p_section, "dock_" + E.key + "_offset", E.value); + offsets[E.key] = E.value; } + p_config_file->set_value(p_section, "bottom_panel_offsets", offsets); } void EditorBottomPanel::load_layout_from_config(Ref p_config_file, const String &p_section) { - for (const Control *dock : bottom_docks) { - String name = dock->get_name(); - String key = name.to_snake_case(); - dock_offsets[key] = p_config_file->get_value(p_section, "dock_" + key + "_offset", 0); + const Dictionary offsets = p_config_file->get_value(p_section, "bottom_panel_offsets", Dictionary()); + const LocalVector offset_list = offsets.get_key_list(); + + for (const Variant &v : offset_list) { + dock_offsets[v] = offsets[v]; } + _update_center_split_offset(); } void EditorBottomPanel::make_item_visible(Control *p_item, bool p_visible, bool p_ignore_lock) { diff --git a/editor/gui/editor_bottom_panel.h b/editor/gui/editor_bottom_panel.h index 6ca2c88990f..ba9e8bf3618 100644 --- a/editor/gui/editor_bottom_panel.h +++ b/editor/gui/editor_bottom_panel.h @@ -50,7 +50,7 @@ class EditorBottomPanel : public TabContainer { int previous_tab = -1; bool lock_panel_switching = false; - LocalVector bottom_docks; + LocalVector bottom_docks; LocalVector> dock_shortcuts; HashMap dock_offsets;