Browse Source

Add profiler autostart indicator to EditorRunBar

Hendrik Brucker 10 months ago
parent
commit
9f8bbe43ee

+ 2 - 0
editor/debugger/editor_profiler.cpp

@@ -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"
@@ -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) {

+ 2 - 0
editor/debugger/editor_visual_profiler.cpp

@@ -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"
 
@@ -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) {

+ 52 - 1
editor/gui/editor_run_bar.cpp

@@ -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"
@@ -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")));
 
@@ -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();
@@ -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;
 }
@@ -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);

+ 7 - 0
editor/gui/editor_run_bar.h

@@ -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;
@@ -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();
@@ -106,6 +111,8 @@ public:
 	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();

File diff suppressed because it is too large
+ 0 - 0
editor/icons/ProfilerAutostartWarning.svg


+ 8 - 0
editor/themes/editor_theme_manager.cpp

@@ -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.

+ 2 - 0
modules/multiplayer/editor/editor_network_profiler.cpp

@@ -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"
 
@@ -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) {

Some files were not shown because too many files changed in this diff