Skip to content

Commit 522fa8d

Browse files
committed
Merge pull request #106164 from lodetrick/refactor-bottom-panel
Refactor editor `EditorBottomPanel` to be a `TabContainer`
2 parents f3c44f0 + e2caff9 commit 522fa8d

18 files changed

+242
-328
lines changed

doc/classes/EditorPlugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@
430430
<param index="1" name="title" type="String" />
431431
<param index="2" name="shortcut" type="Shortcut" default="null" />
432432
<description>
433-
Adds a control to the bottom panel (together with Output, Debug, Animation, etc.). Returns a reference to the button added. It's up to you to hide/show the button when needed. When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_bottom_panel] and free it with [method Node.queue_free].
433+
Adds a control to the bottom panel (together with Output, Debug, Animation, etc.). Returns a reference to a button that is outside the scene tree. It's up to you to hide/show the button when needed. When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_bottom_panel] and free it with [method Node.queue_free].
434434
Optionally, you can specify a shortcut parameter. When pressed, this shortcut will toggle the bottom panel's visibility. See the default editor bottom panel shortcuts in the Editor Settings for inspiration. Per convention, they all use [kbd]Alt[/kbd] modifier.
435435
</description>
436436
</method>

editor/debugger/debugger_editor_plugin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) {
5555
file_server = memnew(EditorFileServer);
5656

5757
EditorDebuggerNode *debugger = memnew(EditorDebuggerNode);
58-
Button *db = EditorNode::get_bottom_panel()->add_item(TTRC("Debugger"), debugger, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_debugger_bottom_panel", TTRC("Toggle Debugger Bottom Panel"), KeyModifierMask::ALT | Key::D));
59-
debugger->set_tool_button(db);
58+
EditorNode::get_bottom_panel()->add_item(TTRC("Debugger"), debugger, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_debugger_bottom_panel", TTRC("Toggle Debugger Bottom Panel"), KeyModifierMask::ALT | Key::D));
6059

6160
// Main editor debug menu.
6261
debug_menu = p_debug_menu;

editor/debugger/editor_debugger_node.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,26 +441,35 @@ void EditorDebuggerNode::_update_errors() {
441441
dbg->update_tabs();
442442
});
443443

444+
last_error_count = error_count;
445+
last_warning_count = warning_count;
446+
447+
// TODO: Replace logic when EditorDock class is merged to be more flexible.
448+
TabContainer *parent = Object::cast_to<TabContainer>(get_parent());
449+
if (!parent) {
450+
return;
451+
}
452+
453+
int idx = parent->get_tab_idx_from_control(this);
454+
444455
if (error_count == 0 && warning_count == 0) {
445-
debugger_button->set_text(TTR("Debugger"));
446-
debugger_button->remove_theme_color_override(SceneStringName(font_color));
447-
debugger_button->set_button_icon(Ref<Texture2D>());
456+
set_name(TTR("Debugger"));
457+
parent->set_tab_icon(idx, Ref<Texture2D>());
458+
parent->get_tab_bar()->set_font_color_override_all(idx, Color(0, 0, 0, 0));
448459
} else {
449-
debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")");
460+
set_name(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")");
450461
if (error_count >= 1 && warning_count >= 1) {
451-
debugger_button->set_button_icon(get_editor_theme_icon(SNAME("ErrorWarning")));
462+
parent->set_tab_icon(idx, get_editor_theme_icon(SNAME("ErrorWarning")));
452463
// Use error color to represent the highest level of severity reported.
453-
debugger_button->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
464+
parent->get_tab_bar()->set_font_color_override_all(idx, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
454465
} else if (error_count >= 1) {
455-
debugger_button->set_button_icon(get_editor_theme_icon(SNAME("Error")));
456-
debugger_button->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
466+
parent->set_tab_icon(idx, get_editor_theme_icon(SNAME("Error")));
467+
parent->get_tab_bar()->set_font_color_override_all(idx, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
457468
} else {
458-
debugger_button->set_button_icon(get_editor_theme_icon(SNAME("Warning")));
459-
debugger_button->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
469+
parent->set_tab_icon(idx, get_editor_theme_icon(SNAME("Warning")));
470+
parent->get_tab_bar()->set_font_color_override_all(idx, get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
460471
}
461472
}
462-
last_error_count = error_count;
463-
last_warning_count = warning_count;
464473
}
465474
}
466475

editor/debugger/editor_debugger_node.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class EditorDebuggerNode : public MarginContainer {
9393

9494
Ref<EditorDebuggerServer> server;
9595
TabContainer *tabs = nullptr;
96-
Button *debugger_button = nullptr;
9796
MenuButton *script_menu = nullptr;
9897

9998
Ref<Script> stack_script; // Why?!?
@@ -180,10 +179,6 @@ class EditorDebuggerNode : public MarginContainer {
180179

181180
void set_script_debug_button(MenuButton *p_button);
182181

183-
void set_tool_button(Button *p_button) {
184-
debugger_button = p_button;
185-
}
186-
187182
String get_var_value(const String &p_var) const;
188183
Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this?
189184

editor/docks/editor_dock_manager.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,14 @@ void EditorDockManager::_dock_container_gui_input(const Ref<InputEvent> &p_input
298298
return;
299299
}
300300

301-
// Right click context menu.
302-
dock_context_popup->set_dock(Object::cast_to<EditorDock>(p_dock_container->get_tab_control(tab_id)));
303-
dock_context_popup->set_position(p_dock_container->get_screen_position() + mb->get_position());
304-
dock_context_popup->popup();
305-
}
306-
}
307-
308-
void EditorDockManager::_bottom_dock_button_gui_input(const Ref<InputEvent> &p_input, EditorDock *p_dock, Button *p_bottom_button) {
309-
Ref<InputEventMouseButton> mb = p_input;
301+
EditorDock *hovered_dock = Object::cast_to<EditorDock>(p_dock_container->get_tab_control(tab_id));
302+
if (hovered_dock == nullptr) {
303+
return;
304+
}
310305

311-
if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
312306
// Right click context menu.
313-
dock_context_popup->set_dock(p_dock);
314-
dock_context_popup->set_position(p_bottom_button->get_screen_position() + mb->get_position());
307+
dock_context_popup->set_dock(hovered_dock);
308+
dock_context_popup->set_position(p_dock_container->get_tab_bar()->get_screen_position() + mb->get_position());
315309
dock_context_popup->popup();
316310
}
317311
}
@@ -467,8 +461,7 @@ void EditorDockManager::_dock_move_to_bottom(EditorDock *p_dock, bool p_visible)
467461
p_dock->update_layout(EditorDock::DOCK_LAYOUT_HORIZONTAL);
468462

469463
// Force docks moved to the bottom to appear first in the list, and give them their associated shortcut to toggle their bottom panel.
470-
Button *bottom_button = EditorNode::get_bottom_panel()->add_item(p_dock->get_display_title(), p_dock, p_dock->shortcut, true);
471-
bottom_button->connect(SceneStringName(gui_input), callable_mp(this, &EditorDockManager::_bottom_dock_button_gui_input).bind(bottom_button).bind(p_dock));
464+
EditorNode::get_bottom_panel()->add_item(p_dock->get_display_title(), p_dock, p_dock->shortcut, true);
472465
EditorNode::get_bottom_panel()->make_item_visible(p_dock, p_visible);
473466
}
474467

editor/docks/editor_dock_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class EditorDockManager : public Object {
8383
private:
8484
friend class DockContextPopup;
8585
friend class EditorDockDragHint;
86+
friend class EditorBottomPanel; // TODO: Temporary until DOCK_SLOT_BOTTOM registered. Used to connect signals.
8687

8788
static inline EditorDockManager *singleton = nullptr;
8889

@@ -106,7 +107,6 @@ class EditorDockManager : public Object {
106107
void _dock_drag_stopped();
107108
void _dock_split_dragged(int p_offset);
108109
void _dock_container_gui_input(const Ref<InputEvent> &p_input, TabContainer *p_dock_container);
109-
void _bottom_dock_button_gui_input(const Ref<InputEvent> &p_input, EditorDock *p_dock, Button *p_bottom_button);
110110
void _dock_container_update_visibility(TabContainer *p_dock_container);
111111
void _update_layout();
112112

editor/editor_log.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "editor/themes/editor_scale.h"
4343
#include "modules/regex/regex.h"
4444
#include "scene/gui/separator.h"
45+
#include "scene/gui/tab_container.h"
4546
#include "scene/main/timer.h"
4647
#include "scene/resources/font.h"
4748

@@ -233,7 +234,7 @@ void EditorLog::_clear_request() {
233234
log->clear();
234235
messages.clear();
235236
_reset_message_counts();
236-
tool_button->set_button_icon(Ref<Texture2D>());
237+
_set_dock_tab_icon(Ref<Texture2D>());
237238
}
238239

239240
void EditorLog::_copy_request() {
@@ -284,8 +285,13 @@ void EditorLog::add_message(const String &p_msg, MessageType p_type) {
284285
}
285286
}
286287

287-
void EditorLog::set_tool_button(Button *p_tool_button) {
288-
tool_button = p_tool_button;
288+
void EditorLog::_set_dock_tab_icon(Ref<Texture2D> p_icon) {
289+
// This is the sole reason to include "tab_container.h" here.
290+
TabContainer *parent = Object::cast_to<TabContainer>(get_parent());
291+
if (parent) {
292+
int idx = parent->get_tab_idx_from_control(this);
293+
parent->set_tab_icon(idx, p_icon);
294+
}
289295
}
290296

291297
void EditorLog::register_undo_redo(UndoRedo *p_undo_redo) {
@@ -411,7 +417,7 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
411417
log->push_bold();
412418
log->add_text(" ERROR: ");
413419
log->pop(); // bold
414-
tool_button->set_button_icon(icon);
420+
_set_dock_tab_icon(icon);
415421
} break;
416422
case MSG_TYPE_WARNING: {
417423
log->push_color(theme_cache.warning_color);
@@ -420,7 +426,7 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
420426
log->push_bold();
421427
log->add_text(" WARNING: ");
422428
log->pop(); // bold
423-
tool_button->set_button_icon(icon);
429+
_set_dock_tab_icon(icon);
424430
} break;
425431
case MSG_TYPE_EDITOR: {
426432
// Distinguish editor messages from messages printed by the project

editor/editor_log.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ class EditorLog : public HBoxContainer {
143143
// Reusable RichTextLabel for BBCode parsing during search
144144
RichTextLabel *bbcode_parser = nullptr;
145145

146-
// Reference to the "Output" button on the toolbar so we can update its icon when warnings or errors are encountered.
147-
Button *tool_button = nullptr;
148-
149146
bool is_loading_state = false; // Used to disable saving requests while loading (some signals from buttons will try to trigger a save, which happens during loading).
150147
Timer *save_state_timer = nullptr;
151148

@@ -169,6 +166,7 @@ class EditorLog : public HBoxContainer {
169166

170167
void _process_message(const String &p_msg, MessageType p_type, bool p_clear);
171168
void _reset_message_counts();
169+
void _set_dock_tab_icon(Ref<Texture2D> p_icon);
172170

173171
void _set_collapse(bool p_collapse);
174172

@@ -184,7 +182,6 @@ class EditorLog : public HBoxContainer {
184182

185183
public:
186184
void add_message(const String &p_msg, MessageType p_type = MSG_TYPE_STD);
187-
void set_tool_button(Button *p_tool_button);
188185
void register_undo_redo(UndoRedo *p_undo_redo);
189186
void deinit();
190187

editor/editor_node.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ void EditorNode::_update_theme(bool p_skip_creation) {
677677
}
678678

679679
editor_main_screen->add_theme_style_override(SceneStringName(panel), theme->get_stylebox(SNAME("Content"), EditorStringName(EditorStyles)));
680-
bottom_panel->add_theme_style_override(SceneStringName(panel), theme->get_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
680+
bottom_panel->_theme_changed();
681681
distraction_free->set_button_icon(theme->get_icon(SNAME("DistractionFree"), EditorStringName(EditorIcons)));
682682
distraction_free->add_theme_style_override(SceneStringName(pressed), theme->get_stylebox(CoreStringName(normal), "FlatMenuButton"));
683683

@@ -8696,12 +8696,12 @@ EditorNode::EditorNode() {
86968696
// Bottom panels.
86978697

86988698
bottom_panel = memnew(EditorBottomPanel);
8699+
bottom_panel->set_theme_type_variation("BottomPanel");
86998700
center_split->add_child(bottom_panel);
87008701
center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
87018702

87028703
log = memnew(EditorLog);
8703-
Button *output_button = bottom_panel->add_item(TTRC("Output"), log, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_output_bottom_panel", TTRC("Toggle Output Bottom Panel"), KeyModifierMask::ALT | Key::O));
8704-
log->set_tool_button(output_button);
8704+
bottom_panel->add_item(TTRC("Output"), log, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_output_bottom_panel", TTRC("Toggle Output Bottom Panel"), KeyModifierMask::ALT | Key::O));
87058705

87068706
center_split->connect(SceneStringName(resized), callable_mp(this, &EditorNode::_vp_resized));
87078707

0 commit comments

Comments
 (0)