Skip to content

Commit

Permalink
Add profiler autostart indicator to EditorRunBar
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometror committed Dec 16, 2024
1 parent b9437c3 commit 9f8bbe4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions editor/debugger/editor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/os/os.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_run_bar.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/check_box.h"
Expand Down Expand Up @@ -430,6 +431,7 @@ void EditorProfiler::_internal_profiles_pressed() {

void EditorProfiler::_autostart_toggled(bool p_toggled_on) {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_profiler", p_toggled_on);
EditorRunBar::get_singleton()->update_profiler_autostart_indicator();
}

void EditorProfiler::_notification(int p_what) {
Expand Down
2 changes: 2 additions & 0 deletions editor/debugger/editor_visual_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/os/os.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_run_bar.h"
#include "editor/themes/editor_scale.h"
#include "scene/resources/image_texture.h"

Expand Down Expand Up @@ -436,6 +437,7 @@ void EditorVisualProfiler::_clear_pressed() {

void EditorVisualProfiler::_autostart_toggled(bool p_toggled_on) {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_visual_profiler", p_toggled_on);
EditorRunBar::get_singleton()->update_profiler_autostart_indicator();
}

void EditorVisualProfiler::_notification(int p_what) {
Expand Down
53 changes: 52 additions & 1 deletion editor/gui/editor_run_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@

#include "core/config/project_settings.h"
#include "editor/debugger/editor_debugger_node.h"
#include "editor/debugger/script_editor_debugger.h"
#include "editor/editor_command_palette.h"
#include "editor/editor_node.h"
#include "editor/editor_run_native.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_bottom_panel.h"
#include "editor/gui/editor_quick_open_dialog.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
Expand All @@ -52,6 +54,7 @@ void EditorRunBar::_notification(int p_what) {

case NOTIFICATION_THEME_CHANGED: {
_update_play_buttons();
profiler_autostart_indicator->set_button_icon(get_editor_theme_icon(SNAME("ProfilerAutostartWarning")));
pause_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));
stop_button->set_button_icon(get_editor_theme_icon(SNAME("Stop")));

Expand Down Expand Up @@ -261,6 +264,20 @@ void EditorRunBar::_run_native(const Ref<EditorExportPreset> &p_preset) {
}
}

void EditorRunBar::_profiler_autostart_indicator_pressed() {
// Switch to the first profiler tab in the bottom panel.
EditorNode::get_singleton()->get_bottom_panel()->make_item_visible(EditorDebuggerNode::get_singleton(), true);

if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false)) {
EditorDebuggerNode::get_singleton()->get_current_debugger()->switch_to_debugger(2);
} else if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false)) {
EditorDebuggerNode::get_singleton()->get_current_debugger()->switch_to_debugger(3);
} else {
// Switch to the network profiler tab.
EditorDebuggerNode::get_singleton()->get_current_debugger()->switch_to_debugger(7);
}
}

void EditorRunBar::play_main_scene(bool p_from_native) {
if (p_from_native) {
run_native->resume_run_native();
Expand Down Expand Up @@ -352,6 +369,28 @@ bool EditorRunBar::is_movie_maker_enabled() const {
return write_movie_button->is_pressed();
}

void EditorRunBar::update_profiler_autostart_indicator() {
bool profiler_active = EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false);
bool visual_profiler_active = EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false);
bool network_profiler_active = EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false);
bool any_profiler_active = profiler_active | visual_profiler_active | network_profiler_active;
profiler_autostart_indicator->set_visible(any_profiler_active);
if (any_profiler_active) {
String tooltip = TTR("Autostart is enabled for the following profilers, which can have a performance impact:");
if (profiler_active) {
tooltip += "\n- " + TTR("Profiler");
}
if (visual_profiler_active) {
tooltip += "\n- " + TTR("Visual Profiler");
}
if (network_profiler_active) {
tooltip += "\n- " + TTR("Network Profiler");
}
tooltip += "\n\n" + TTR("Click to open the first profiler for which autostart is enabled.");
profiler_autostart_indicator->set_tooltip_text(tooltip);
}
}

HBoxContainer *EditorRunBar::get_buttons_container() {
return main_hbox;
}
Expand All @@ -364,8 +403,20 @@ void EditorRunBar::_bind_methods() {
EditorRunBar::EditorRunBar() {
singleton = this;

outer_hbox = memnew(HBoxContainer);
add_child(outer_hbox);

// Use a button for the indicator since it comes with a background panel and pixel perfect centering of an icon.
profiler_autostart_indicator = memnew(Button);
profiler_autostart_indicator->set_icon_alignment(HORIZONTAL_ALIGNMENT_CENTER);
profiler_autostart_indicator->set_focus_mode(FOCUS_NONE);
profiler_autostart_indicator->set_theme_type_variation("ProfilerAutostartIndicator");
profiler_autostart_indicator->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_profiler_autostart_indicator_pressed));
outer_hbox->add_child(profiler_autostart_indicator);
update_profiler_autostart_indicator();

main_panel = memnew(PanelContainer);
add_child(main_panel);
outer_hbox->add_child(main_panel);

main_hbox = memnew(HBoxContainer);
main_panel->add_child(main_hbox);
Expand Down
7 changes: 7 additions & 0 deletions editor/gui/editor_run_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class EditorRunBar : public MarginContainer {

PanelContainer *main_panel = nullptr;
HBoxContainer *main_hbox = nullptr;
HBoxContainer *outer_hbox = nullptr;

Button *profiler_autostart_indicator = nullptr;

Button *play_button = nullptr;
Button *pause_button = nullptr;
Expand Down Expand Up @@ -83,6 +86,8 @@ class EditorRunBar : public MarginContainer {
void _run_scene(const String &p_scene_path = "");
void _run_native(const Ref<EditorExportPreset> &p_preset);

void _profiler_autostart_indicator_pressed();

protected:
void _notification(int p_what);
static void _bind_methods();
Expand All @@ -106,6 +111,8 @@ class EditorRunBar : public MarginContainer {
void set_movie_maker_enabled(bool p_enabled);
bool is_movie_maker_enabled() const;

void update_profiler_autostart_indicator();

Button *get_pause_button() { return pause_button; }

HBoxContainer *get_buttons_container();
Expand Down
1 change: 1 addition & 0 deletions editor/icons/ProfilerAutostartWarning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions editor/themes/editor_theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,14 @@ void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &p_theme
p_theme->set_color("movie_writer_icon_pressed", EditorStringName(EditorStyles), Color(0, 0, 0, 0.84));
p_theme->set_color("movie_writer_icon_hover", EditorStringName(EditorStyles), Color(1, 1, 1, 0.9));
p_theme->set_color("movie_writer_icon_hover_pressed", EditorStringName(EditorStyles), Color(0, 0, 0, 0.84));

// Profiler autostart indicator panel.
Ref<StyleBoxFlat> style_profiler_autostart = style_launch_pad->duplicate();
style_profiler_autostart->set_bg_color(Color(1, 0.867, 0.396));
p_theme->set_type_variation("ProfilerAutostartIndicator", "Button");
p_theme->set_stylebox(CoreStringName(normal), "ProfilerAutostartIndicator", style_profiler_autostart);
p_theme->set_stylebox(SceneStringName(pressed), "ProfilerAutostartIndicator", style_profiler_autostart);
p_theme->set_stylebox("hover", "ProfilerAutostartIndicator", style_profiler_autostart);
}

// Standard GUI variations.
Expand Down
2 changes: 2 additions & 0 deletions modules/multiplayer/editor/editor_network_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "core/os/os.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_run_bar.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/check_box.h"

Expand Down Expand Up @@ -227,6 +228,7 @@ void EditorNetworkProfiler::_clear_pressed() {

void EditorNetworkProfiler::_autostart_toggled(bool p_toggled_on) {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_network_profiler", p_toggled_on);
EditorRunBar::get_singleton()->update_profiler_autostart_indicator();
}

void EditorNetworkProfiler::_replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button) {
Expand Down

0 comments on commit 9f8bbe4

Please sign in to comment.