From ba8601f557bae4734ea8a0dcb5760ae4dbe04092 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sat, 21 Sep 2019 15:16:15 +0200 Subject: [PATCH] Improve the network profiler UI - Add icons to the up/down bandwidth LineEdits for better visual grepping. - Make bandwidth LineEdit texts more prominent when data is being received/emitted. - Add more spacing between the up and down bandwidth LineEdits. - Initialize the bandwidth texts using `set_bandwidth()` to ensure consistency with the actual bandwidth texts once the profiler is started. - Fix icon colors when switching from a dark theme to a light theme and vice versa. - Add missing `EDSCALE` constants for hiDPI scaling. --- editor/editor_network_profiler.cpp | 35 +++++++++++++++++++++++------- editor/icons/icon_arrow_down.svg | 1 + editor/icons/icon_arrow_up.svg | 1 + 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 editor/icons/icon_arrow_down.svg create mode 100644 editor/icons/icon_arrow_up.svg diff --git a/editor/editor_network_profiler.cpp b/editor/editor_network_profiler.cpp index b90fe96cee8..8482c4e38ab 100644 --- a/editor/editor_network_profiler.cpp +++ b/editor/editor_network_profiler.cpp @@ -43,9 +43,15 @@ void EditorNetworkProfiler::_bind_methods() { void EditorNetworkProfiler::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { activate->set_icon(get_icon("Play", "EditorIcons")); clear_button->set_icon(get_icon("Clear", "EditorIcons")); + incoming_bandwidth_text->set_right_icon(get_icon("ArrowDown", "EditorIcons")); + outgoing_bandwidth_text->set_right_icon(get_icon("ArrowUp", "EditorIcons")); + + // This needs to be done here to set the faded color when the profiler is first opened + incoming_bandwidth_text->add_color_override("font_color_uneditable", get_color("font_color", "Editor") * Color(1, 1, 1, 0.5)); + outgoing_bandwidth_text->add_color_override("font_color_uneditable", get_color("font_color", "Editor") * Color(1, 1, 1, 0.5)); } } @@ -113,6 +119,14 @@ void EditorNetworkProfiler::set_bandwidth(int p_incoming, int p_outgoing) { incoming_bandwidth_text->set_text(vformat(TTR("%s/s"), String::humanize_size(p_incoming))); outgoing_bandwidth_text->set_text(vformat(TTR("%s/s"), String::humanize_size(p_outgoing))); + + // Make labels more prominent when the bandwidth is greater than 0 to attract user attention + incoming_bandwidth_text->add_color_override( + "font_color_uneditable", + get_color("font_color", "Editor") * Color(1, 1, 1, p_incoming > 0 ? 1 : 0.5)); + outgoing_bandwidth_text->add_color_override( + "font_color_uneditable", + get_color("font_color", "Editor") * Color(1, 1, 1, p_outgoing > 0 ? 1 : 0.5)); } bool EditorNetworkProfiler::is_profiling() { @@ -139,27 +153,32 @@ EditorNetworkProfiler::EditorNetworkProfiler() { hb->add_spacer(); Label *lb = memnew(Label); - lb->set_text("Down "); + lb->set_text(TTR("Down")); hb->add_child(lb); incoming_bandwidth_text = memnew(LineEdit); incoming_bandwidth_text->set_editable(false); - incoming_bandwidth_text->set_custom_minimum_size(Size2(100, 0)); + incoming_bandwidth_text->set_custom_minimum_size(Size2(120, 0) * EDSCALE); incoming_bandwidth_text->set_align(LineEdit::Align::ALIGN_RIGHT); - incoming_bandwidth_text->set_text("0.0 B/s"); hb->add_child(incoming_bandwidth_text); + Control *down_up_spacer = memnew(Control); + down_up_spacer->set_custom_minimum_size(Size2(30, 0) * EDSCALE); + hb->add_child(down_up_spacer); + lb = memnew(Label); - lb->set_text("Up "); + lb->set_text(TTR("Up")); hb->add_child(lb); outgoing_bandwidth_text = memnew(LineEdit); outgoing_bandwidth_text->set_editable(false); - outgoing_bandwidth_text->set_custom_minimum_size(Size2(100, 0)); + outgoing_bandwidth_text->set_custom_minimum_size(Size2(120, 0) * EDSCALE); outgoing_bandwidth_text->set_align(LineEdit::Align::ALIGN_RIGHT); - outgoing_bandwidth_text->set_text("0.0 B/s"); hb->add_child(outgoing_bandwidth_text); + // Set initial texts in the incoming/outgoing bandwidth labels + set_bandwidth(0, 0); + counters_display = memnew(Tree); counters_display->set_custom_minimum_size(Size2(300, 0) * EDSCALE); counters_display->set_v_size_flags(SIZE_EXPAND_FILL); @@ -169,7 +188,7 @@ EditorNetworkProfiler::EditorNetworkProfiler() { counters_display->set_column_titles_visible(true); counters_display->set_column_title(0, TTR("Node")); counters_display->set_column_expand(0, true); - counters_display->set_column_min_width(0, 60); + counters_display->set_column_min_width(0, 60 * EDSCALE); counters_display->set_column_title(1, TTR("Incoming RPC")); counters_display->set_column_expand(1, false); counters_display->set_column_min_width(1, 120 * EDSCALE); diff --git a/editor/icons/icon_arrow_down.svg b/editor/icons/icon_arrow_down.svg new file mode 100644 index 00000000000..49a93e6e28b --- /dev/null +++ b/editor/icons/icon_arrow_down.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/editor/icons/icon_arrow_up.svg b/editor/icons/icon_arrow_up.svg new file mode 100644 index 00000000000..9bf19a6a124 --- /dev/null +++ b/editor/icons/icon_arrow_up.svg @@ -0,0 +1 @@ + \ No newline at end of file