Skip to content

Commit 6f7f8f4

Browse files
committed
Refactor Bottom Panel to be a TabContainer
1 parent 428a762 commit 6f7f8f4

File tree

10 files changed

+201
-290
lines changed

10 files changed

+201
-290
lines changed

editor/debugger/editor_debugger_node.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,26 +435,38 @@ void EditorDebuggerNode::_update_errors() {
435435
dbg->update_tabs();
436436
});
437437

438+
last_error_count = error_count;
439+
last_warning_count = warning_count;
440+
441+
TabContainer *parent = static_cast<TabContainer *>(get_parent());
442+
if (!parent) {
443+
return;
444+
}
445+
446+
int idx = parent->get_tab_idx_from_control(this);
447+
438448
if (error_count == 0 && warning_count == 0) {
439-
debugger_button->set_text(TTR("Debugger"));
440-
debugger_button->remove_theme_color_override(SceneStringName(font_color));
441-
debugger_button->set_button_icon(Ref<Texture2D>());
449+
set_name(TTR("Debugger"));
450+
parent->set_tab_icon(idx, Ref<Texture2D>());
451+
// TODO: Uncomment once GH-106263 or similar is merged.
452+
// parent->set_font_unselected_color_override(idx, Color(0, 0, 0, 0));
442453
} else {
443-
debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")");
454+
set_name(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")");
444455
if (error_count >= 1 && warning_count >= 1) {
445-
debugger_button->set_button_icon(get_editor_theme_icon(SNAME("ErrorWarning")));
456+
parent->set_tab_icon(idx, get_editor_theme_icon(SNAME("ErrorWarning")));
446457
// Use error color to represent the highest level of severity reported.
447-
debugger_button->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
458+
// TODO: Uncomment once GH-106263 or similar is merged.
459+
// parent->set_font_unselected_color_override(idx, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
448460
} else if (error_count >= 1) {
449-
debugger_button->set_button_icon(get_editor_theme_icon(SNAME("Error")));
450-
debugger_button->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
461+
parent->set_tab_icon(idx, get_editor_theme_icon(SNAME("Error")));
462+
// TODO: Uncomment once GH-106263 or similar is merged.
463+
// parent->set_font_unselected_color_override(idx, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
451464
} else {
452-
debugger_button->set_button_icon(get_editor_theme_icon(SNAME("Warning")));
453-
debugger_button->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
465+
parent->set_tab_icon(idx, get_editor_theme_icon(SNAME("Warning")));
466+
// TODO: Uncomment once GH-106263 or similar is merged.
467+
// parent->set_font_unselected_color_override(idx, get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
454468
}
455469
}
456-
last_error_count = error_count;
457-
last_warning_count = warning_count;
458470
}
459471
}
460472

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/editor_log.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "editor/editor_string_names.h"
4040
#include "editor/themes/editor_scale.h"
4141
#include "scene/gui/separator.h"
42+
#include "scene/gui/tab_container.h"
4243
#include "scene/resources/font.h"
4344

4445
void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type) {
@@ -203,7 +204,7 @@ void EditorLog::_clear_request() {
203204
log->clear();
204205
messages.clear();
205206
_reset_message_counts();
206-
tool_button->set_button_icon(Ref<Texture2D>());
207+
_set_dock_tab_icon(Ref<Texture2D>());
207208
}
208209

209210
void EditorLog::_copy_request() {
@@ -254,8 +255,13 @@ void EditorLog::add_message(const String &p_msg, MessageType p_type) {
254255
}
255256
}
256257

257-
void EditorLog::set_tool_button(Button *p_tool_button) {
258-
tool_button = p_tool_button;
258+
void EditorLog::_set_dock_tab_icon(Ref<Texture2D> p_icon) {
259+
// This is the sole reason to import TabContainer here.
260+
TabContainer *parent = static_cast<TabContainer *>(get_parent());
261+
if (parent) {
262+
int idx = parent->get_tab_idx_from_control(this);
263+
parent->set_tab_icon(idx, p_icon);
264+
}
259265
}
260266

261267
void EditorLog::register_undo_redo(UndoRedo *p_undo_redo) {
@@ -360,7 +366,7 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
360366
log->push_bold();
361367
log->add_text(" ERROR: ");
362368
log->pop(); // bold
363-
tool_button->set_button_icon(icon);
369+
_set_dock_tab_icon(icon);
364370
} break;
365371
case MSG_TYPE_WARNING: {
366372
log->push_color(theme_cache.warning_color);
@@ -369,7 +375,7 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
369375
log->push_bold();
370376
log->add_text(" WARNING: ");
371377
log->pop(); // bold
372-
tool_button->set_button_icon(icon);
378+
_set_dock_tab_icon(icon);
373379
} break;
374380
case MSG_TYPE_EDITOR: {
375381
// 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
@@ -139,9 +139,6 @@ class EditorLog : public HBoxContainer {
139139
Button *show_search_button = nullptr;
140140
LineEdit *search_box = nullptr;
141141

142-
// Reference to the "Output" button on the toolbar so we can update its icon when warnings or errors are encountered.
143-
Button *tool_button = nullptr;
144-
145142
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).
146143
Timer *save_state_timer = nullptr;
147144

@@ -165,6 +162,7 @@ class EditorLog : public HBoxContainer {
165162

166163
void _process_message(const String &p_msg, MessageType p_type, bool p_clear);
167164
void _reset_message_counts();
165+
void _set_dock_tab_icon(Ref<Texture2D> p_icon);
168166

169167
void _set_collapse(bool p_collapse);
170168

@@ -180,7 +178,6 @@ class EditorLog : public HBoxContainer {
180178

181179
public:
182180
void add_message(const String &p_msg, MessageType p_type = MSG_TYPE_STD);
183-
void set_tool_button(Button *p_tool_button);
184181
void register_undo_redo(UndoRedo *p_undo_redo);
185182
void deinit();
186183

editor/editor_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8142,12 +8142,12 @@ EditorNode::EditorNode() {
81428142
// Bottom panels.
81438143

81448144
bottom_panel = memnew(EditorBottomPanel);
8145+
bottom_panel->set_theme_type_variation("BottomPanel");
81458146
center_split->add_child(bottom_panel);
81468147
center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
81478148

81488149
log = memnew(EditorLog);
8149-
Button *output_button = bottom_panel->add_item(TTR("Output"), log, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_output_bottom_panel", TTRC("Toggle Output Bottom Panel"), KeyModifierMask::ALT | Key::O));
8150-
log->set_tool_button(output_button);
8150+
bottom_panel->add_item(TTR("Output"), log, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_output_bottom_panel", TTRC("Toggle Output Bottom Panel"), KeyModifierMask::ALT | Key::O));
81518151

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

0 commit comments

Comments
 (0)