Skip to content

Commit fc8c494

Browse files
committed
Merge pull request #113241 from KoBeWi/Audiock
Fix bottom dock offsets and change Audio to EditorDock
2 parents 5947dff + 178264c commit fc8c494

File tree

5 files changed

+44
-37
lines changed

5 files changed

+44
-37
lines changed

editor/audio/editor_audio_buses.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@
3434
#include "core/input/input.h"
3535
#include "core/io/resource_saver.h"
3636
#include "core/os/keyboard.h"
37+
#include "editor/docks/editor_dock_manager.h"
3738
#include "editor/docks/filesystem_dock.h"
3839
#include "editor/editor_node.h"
3940
#include "editor/editor_string_names.h"
4041
#include "editor/editor_undo_redo_manager.h"
41-
#include "editor/gui/editor_bottom_panel.h"
4242
#include "editor/gui/editor_file_dialog.h"
4343
#include "editor/settings/editor_command_palette.h"
4444
#include "editor/settings/editor_settings.h"
4545
#include "editor/themes/editor_scale.h"
4646
#include "editor/themes/editor_theme_manager.h"
47+
#include "scene/gui/box_container.h"
4748
#include "scene/gui/separator.h"
4849
#include "scene/main/timer.h"
4950
#include "scene/resources/font.h"
@@ -1111,7 +1112,7 @@ void EditorAudioBuses::_rebuild_buses() {
11111112

11121113
EditorAudioBuses *EditorAudioBuses::register_editor() {
11131114
EditorAudioBuses *audio_buses = memnew(EditorAudioBuses);
1114-
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));
1115+
EditorDockManager::get_singleton()->add_dock(audio_buses);
11151116
return audio_buses;
11161117
}
11171118

@@ -1158,16 +1159,6 @@ void EditorAudioBuses::_notification(int p_what) {
11581159
}
11591160

11601161
_update_file_label_size();
1161-
1162-
// Setting `the split_offset` value once to the minimum value required to display the entire contents of the `EditorAudioBuses`.
1163-
// 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).
1164-
// If `EditorAudioBuses` is selected when starting the editor, this code will be executed first and then the saved layout will load.
1165-
if (use_default_editor_size) {
1166-
use_default_editor_size = false;
1167-
int offset = EditorNode::get_bottom_panel()->get_combined_minimum_size().y + get_combined_minimum_size().y;
1168-
offset += Object::cast_to<Control>(bus_hb->get_child(0))->get_combined_minimum_size().y; // Master audio bus always exists.
1169-
EditorNode::get_singleton()->set_center_split_offset(-offset);
1170-
}
11711162
} break;
11721163
}
11731164
}
@@ -1336,8 +1327,17 @@ void EditorAudioBuses::_bind_methods() {
13361327
}
13371328

13381329
EditorAudioBuses::EditorAudioBuses() {
1330+
set_name(TTRC("Audio"));
1331+
set_icon_name("AudioStreamPlayer");
1332+
set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_audio_bottom_panel", TTRC("Toggle Audio Dock"), KeyModifierMask::ALT | Key::A));
1333+
set_default_slot(DockConstants::DOCK_SLOT_BOTTOM);
1334+
set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING);
1335+
1336+
VBoxContainer *main_vb = memnew(VBoxContainer);
1337+
add_child(main_vb);
1338+
13391339
top_hb = memnew(HBoxContainer);
1340-
add_child(top_hb);
1340+
main_vb->add_child(top_hb);
13411341

13421342
edited_path = ResourceUID::ensure_path(GLOBAL_GET("audio/buses/default_bus_layout"));
13431343

@@ -1390,15 +1390,15 @@ EditorAudioBuses::EditorAudioBuses() {
13901390
bus_scroll = memnew(ScrollContainer);
13911391
bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
13921392
bus_scroll->set_custom_minimum_size(Size2(0, 40 * EDSCALE));
1393-
add_child(bus_scroll);
1393+
main_vb->add_child(bus_scroll);
13941394
bus_hb = memnew(HBoxContainer);
13951395
bus_hb->set_v_size_flags(SIZE_EXPAND_FILL);
13961396
bus_scroll->add_child(bus_hb);
13971397

13981398
save_timer = memnew(Timer);
13991399
save_timer->set_wait_time(0.8);
14001400
save_timer->set_one_shot(true);
1401-
add_child(save_timer);
1401+
main_vb->add_child(save_timer);
14021402
save_timer->connect("timeout", callable_mp(this, &EditorAudioBuses::_server_save));
14031403

14041404
set_v_size_flags(SIZE_EXPAND_FILL);
@@ -1418,7 +1418,7 @@ EditorAudioBuses::EditorAudioBuses() {
14181418
}
14191419

14201420
void EditorAudioBuses::open_layout(const String &p_path) {
1421-
EditorNode::get_bottom_panel()->make_item_visible(this);
1421+
make_visible();
14221422

14231423
const String path = ResourceUID::ensure_path(p_path);
14241424

editor/audio/editor_audio_buses.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
#pragma once
3232

33+
#include "editor/docks/editor_dock.h"
3334
#include "editor/plugins/editor_plugin.h"
34-
#include "scene/gui/box_container.h"
3535
#include "scene/gui/button.h"
3636
#include "scene/gui/control.h"
3737
#include "scene/gui/line_edit.h"
@@ -47,6 +47,7 @@
4747

4848
class EditorAudioBuses;
4949
class EditorFileDialog;
50+
class HBoxContainer;
5051
class Timer;
5152

5253
class EditorAudioBus : public PanelContainer {
@@ -148,8 +149,8 @@ class EditorAudioBusDrop : public Control {
148149
void _notification(int p_what);
149150
};
150151

151-
class EditorAudioBuses : public VBoxContainer {
152-
GDCLASS(EditorAudioBuses, VBoxContainer);
152+
class EditorAudioBuses : public EditorDock {
153+
GDCLASS(EditorAudioBuses, EditorDock);
153154

154155
HBoxContainer *top_hb = nullptr;
155156

@@ -194,8 +195,6 @@ class EditorAudioBuses : public VBoxContainer {
194195
EditorFileDialog *file_dialog = nullptr;
195196
bool new_layout = false;
196197

197-
bool use_default_editor_size = true;
198-
199198
void _file_dialog_callback(const String &p_string);
200199

201200
protected:

editor/editor_node.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6081,6 +6081,10 @@ void EditorNode::_load_editor_layout() {
60816081

60826082
if (overridden_default_layout >= 0) {
60836083
_layout_menu_option(overridden_default_layout);
6084+
} else {
6085+
ep.step(TTR("Loading docks..."), 1, true);
6086+
// Initialize some default values.
6087+
bottom_panel->load_layout_from_config(default_layout, EDITOR_NODE_CONFIG_SECTION);
60846088
}
60856089
} else {
60866090
ep.step(TTR("Loading docks..."), 1, true);
@@ -8799,6 +8803,12 @@ EditorNode::EditorNode() {
87998803
default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0);
88008804
}
88018805

8806+
{
8807+
Dictionary offsets;
8808+
offsets["Audio"] = -450;
8809+
default_layout->set_value(EDITOR_NODE_CONFIG_SECTION, "bottom_panel_offsets", offsets);
8810+
}
8811+
88028812
_update_layouts_menu();
88038813

88048814
// Bottom panels.

editor/gui/editor_bottom_panel.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,16 @@ void EditorBottomPanel::_theme_changed() {
7979
}
8080

8181
void EditorBottomPanel::set_bottom_panel_offset(int p_offset) {
82-
Control *current_tab = get_current_tab_control();
82+
EditorDock *current_tab = Object::cast_to<EditorDock>(get_current_tab_control());
8383
if (current_tab) {
84-
String name = current_tab->get_name();
85-
String key = name.to_snake_case();
86-
dock_offsets[key] = p_offset;
84+
dock_offsets[current_tab->get_effective_layout_key()] = p_offset;
8785
}
8886
}
8987

9088
int EditorBottomPanel::get_bottom_panel_offset() {
91-
Control *current_tab = get_current_tab_control();
89+
EditorDock *current_tab = Object::cast_to<EditorDock>(get_current_tab_control());
9290
if (current_tab) {
93-
String name = current_tab->get_name();
94-
String key = name.to_snake_case();
95-
return dock_offsets[key];
91+
return dock_offsets[current_tab->get_effective_layout_key()];
9692
}
9793
return 0;
9894
}
@@ -126,19 +122,21 @@ void EditorBottomPanel::_repaint() {
126122
}
127123

128124
void EditorBottomPanel::save_layout_to_config(Ref<ConfigFile> p_config_file, const String &p_section) const {
129-
p_config_file->set_value(p_section, "selected_bottom_panel_item", get_current_tab() != -1 ? Variant(get_current_tab()) : Variant());
130-
125+
Dictionary offsets;
131126
for (const KeyValue<String, int> &E : dock_offsets) {
132-
p_config_file->set_value(p_section, "dock_" + E.key + "_offset", E.value);
127+
offsets[E.key] = E.value;
133128
}
129+
p_config_file->set_value(p_section, "bottom_panel_offsets", offsets);
134130
}
135131

136132
void EditorBottomPanel::load_layout_from_config(Ref<ConfigFile> p_config_file, const String &p_section) {
137-
for (const Control *dock : bottom_docks) {
138-
String name = dock->get_name();
139-
String key = name.to_snake_case();
140-
dock_offsets[key] = p_config_file->get_value(p_section, "dock_" + key + "_offset", 0);
133+
const Dictionary offsets = p_config_file->get_value(p_section, "bottom_panel_offsets", Dictionary());
134+
const LocalVector<Variant> offset_list = offsets.get_key_list();
135+
136+
for (const Variant &v : offset_list) {
137+
dock_offsets[v] = offsets[v];
141138
}
139+
_update_center_split_offset();
142140
}
143141

144142
void EditorBottomPanel::make_item_visible(Control *p_item, bool p_visible, bool p_ignore_lock) {

editor/gui/editor_bottom_panel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EditorBottomPanel : public TabContainer {
5050

5151
int previous_tab = -1;
5252
bool lock_panel_switching = false;
53-
LocalVector<Control *> bottom_docks;
53+
LocalVector<EditorDock *> bottom_docks;
5454
LocalVector<Ref<Shortcut>> dock_shortcuts;
5555
HashMap<String, int> dock_offsets;
5656

0 commit comments

Comments
 (0)