mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Move localized number formatting methods to TranslationServer
Co-Authored-By: Pāvels Nadtočajevs <7645683+bruvzg@users.noreply.github.com>
This commit is contained in:
parent
6fd949a6dc
commit
72d437c030
27 changed files with 348 additions and 394 deletions
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "editor_performance_profiler.h"
|
||||
|
||||
#include "core/string/translation_server.h"
|
||||
#include "editor/editor_string_names.h"
|
||||
#include "editor/inspector/editor_property_name_processor.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
|
|
@ -45,29 +46,6 @@ EditorPerformanceProfiler::Monitor::Monitor(const String &p_name, const String &
|
|||
base = p_base;
|
||||
}
|
||||
|
||||
void EditorPerformanceProfiler::Monitor::update_value(float p_value) {
|
||||
ERR_FAIL_NULL(item);
|
||||
String label = EditorPerformanceProfiler::_create_label(p_value, type);
|
||||
String tooltip = label;
|
||||
switch (type) {
|
||||
case Performance::MONITOR_TYPE_MEMORY: {
|
||||
tooltip = label;
|
||||
} break;
|
||||
case Performance::MONITOR_TYPE_TIME: {
|
||||
tooltip = label;
|
||||
} break;
|
||||
default: {
|
||||
tooltip += " " + item->get_text(0);
|
||||
} break;
|
||||
}
|
||||
item->set_text(1, label);
|
||||
item->set_tooltip_text(1, tooltip);
|
||||
|
||||
if (p_value > max) {
|
||||
max = p_value;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPerformanceProfiler::Monitor::reset() {
|
||||
history.clear();
|
||||
max = 0.0f;
|
||||
|
|
@ -77,26 +55,53 @@ void EditorPerformanceProfiler::Monitor::reset() {
|
|||
}
|
||||
}
|
||||
|
||||
String EditorPerformanceProfiler::_create_label(float p_value, Performance::MonitorType p_type) {
|
||||
String EditorPerformanceProfiler::_format_label(float p_value, Performance::MonitorType p_type) const {
|
||||
const String &lang = _get_locale();
|
||||
const TranslationServer *ts = TranslationServer::get_singleton();
|
||||
|
||||
switch (p_type) {
|
||||
case Performance::MONITOR_TYPE_QUANTITY: {
|
||||
return TS->format_number(itos(p_value));
|
||||
return ts->format_number(itos(p_value), lang);
|
||||
}
|
||||
case Performance::MONITOR_TYPE_MEMORY: {
|
||||
return String::humanize_size(p_value);
|
||||
}
|
||||
case Performance::MONITOR_TYPE_TIME: {
|
||||
return TS->format_number(rtos(p_value * 1000).pad_decimals(2)) + " " + TTR("ms");
|
||||
return ts->format_number(rtos(p_value * 1000).pad_decimals(2), lang) + " " + TTR("ms");
|
||||
}
|
||||
case Performance::MONITOR_TYPE_PERCENTAGE: {
|
||||
return TS->format_number(rtos(p_value * 100).pad_decimals(2)) + "%";
|
||||
return ts->format_number(rtos(p_value * 100).pad_decimals(2), lang) + "%";
|
||||
}
|
||||
default: {
|
||||
return TS->format_number(rtos(p_value));
|
||||
return ts->format_number(rtos(p_value), lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPerformanceProfiler::_update_monitor_value(Monitor *p_monitor, float p_value) {
|
||||
TreeItem *item = p_monitor->item;
|
||||
ERR_FAIL_NULL(item);
|
||||
|
||||
const String label = EditorPerformanceProfiler::_format_label(p_value, p_monitor->type);
|
||||
item->set_text(1, label);
|
||||
|
||||
String tooltip;
|
||||
switch (p_monitor->type) {
|
||||
case Performance::MONITOR_TYPE_MEMORY:
|
||||
case Performance::MONITOR_TYPE_TIME: {
|
||||
item->set_tooltip_text(1, label);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
item->set_tooltip_text(1, label + " " + item->get_text(0));
|
||||
} break;
|
||||
}
|
||||
|
||||
if (p_value > p_monitor->max) {
|
||||
p_monitor->max = p_value;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPerformanceProfiler::_monitor_select() {
|
||||
monitor_draw->queue_redraw();
|
||||
}
|
||||
|
|
@ -159,12 +164,12 @@ void EditorPerformanceProfiler::_monitor_draw() {
|
|||
Color horizontal_line_color;
|
||||
horizontal_line_color.set_hsv(draw_color.get_h(), draw_color.get_s() * 0.5f, draw_color.get_v() * 0.5f, 0.3f);
|
||||
monitor_draw->draw_line(rect.position, rect.position + Vector2(rect.size.width, 0), horizontal_line_color, Math::round(EDSCALE));
|
||||
monitor_draw->draw_string(graph_font, rect.position + Vector2(0, graph_font->get_ascent(font_size)), _create_label(current.max, current.type), HORIZONTAL_ALIGNMENT_LEFT, rect.size.width, font_size, horizontal_line_color);
|
||||
monitor_draw->draw_string(graph_font, rect.position + Vector2(0, graph_font->get_ascent(font_size)), _format_label(current.max, current.type), HORIZONTAL_ALIGNMENT_LEFT, rect.size.width, font_size, horizontal_line_color);
|
||||
|
||||
for (int j = 0; j < line_count; j++) {
|
||||
Vector2 y_offset = Vector2(0, rect.size.height * (1.0f - float(j) / float(line_count)));
|
||||
monitor_draw->draw_line(rect.position + y_offset, rect.position + Vector2(rect.size.width, 0) + y_offset, horizontal_line_color, Math::round(EDSCALE));
|
||||
monitor_draw->draw_string(graph_font, rect.position - Vector2(0, graph_font->get_descent(font_size)) + y_offset, _create_label(current.max * float(j) / float(line_count), current.type), HORIZONTAL_ALIGNMENT_LEFT, rect.size.width, font_size, horizontal_line_color);
|
||||
monitor_draw->draw_string(graph_font, rect.position - Vector2(0, graph_font->get_descent(font_size)) + y_offset, _format_label(current.max * float(j) / float(line_count), current.type), HORIZONTAL_ALIGNMENT_LEFT, rect.size.width, font_size, horizontal_line_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +194,7 @@ void EditorPerformanceProfiler::_monitor_draw() {
|
|||
line_color.set_hsv(draw_color.get_h(), draw_color.get_s() * 0.8f, draw_color.get_v(), 0.5f);
|
||||
monitor_draw->draw_line(rect.position + Point2(from, 0), rect.position + Point2(from, rect.size.y), line_color, Math::round(EDSCALE));
|
||||
|
||||
String label = _create_label(e->get(), current.type);
|
||||
String label = _format_label(e->get(), current.type);
|
||||
Size2 size = graph_font->get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size);
|
||||
Vector2 text_top_left_position = Vector2(from, h2) - (size + Vector2(MARKER_MARGIN, MARKER_MARGIN));
|
||||
if (text_top_left_position.x < 0) {
|
||||
|
|
@ -225,7 +230,7 @@ void EditorPerformanceProfiler::_build_monitor_tree() {
|
|||
item->set_checked(0, monitor_checked.has(E.key));
|
||||
E.value.item = item;
|
||||
if (!E.value.history.is_empty()) {
|
||||
E.value.update_value(E.value.history.front()->get());
|
||||
_update_monitor_value(&E.value, E.value.history.front()->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -366,7 +371,7 @@ void EditorPerformanceProfiler::add_profile_frame(const Vector<float> &p_values)
|
|||
value = p_values[E.value.frame_index];
|
||||
}
|
||||
E.value.history.push_front(value);
|
||||
E.value.update_value(value);
|
||||
_update_monitor_value(&E.value, value);
|
||||
}
|
||||
marker_frame++;
|
||||
monitor_draw->queue_redraw();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ private:
|
|||
|
||||
Monitor() {}
|
||||
Monitor(const String &p_name, const String &p_base, int p_frame_index, Performance::MonitorType p_type, TreeItem *p_item);
|
||||
void update_value(float p_value);
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
|
@ -69,7 +68,8 @@ private:
|
|||
const int POINT_SEPARATION = 5;
|
||||
const int MARKER_MARGIN = 2;
|
||||
|
||||
static String _create_label(float p_value, Performance::MonitorType p_type);
|
||||
String _format_label(float p_value, Performance::MonitorType p_type) const;
|
||||
void _update_monitor_value(Monitor *p_monitor, float p_value);
|
||||
void _monitor_select();
|
||||
void _monitor_draw();
|
||||
void _build_monitor_tree();
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "editor_profiler.h"
|
||||
|
||||
#include "core/io/image.h"
|
||||
#include "core/string/translation_server.h"
|
||||
#include "editor/editor_string_names.h"
|
||||
#include "editor/run/editor_run_bar.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
|
|
@ -116,29 +117,31 @@ void EditorProfiler::clear() {
|
|||
emit_signal(SNAME("enable_profiling"), activate->is_pressed());
|
||||
}
|
||||
|
||||
static String _get_percent_txt(float p_value, float p_total) {
|
||||
if (p_total == 0) {
|
||||
p_total = 0.00001;
|
||||
}
|
||||
|
||||
return TS->format_number(String::num((p_value / p_total) * 100, 1)) + TS->percent_sign();
|
||||
}
|
||||
|
||||
String EditorProfiler::_get_time_as_text(const Metric &m, float p_time, int p_calls) {
|
||||
const int dmode = display_mode->get_selected();
|
||||
const String &lang = _get_locale();
|
||||
const TranslationServer *ts = TranslationServer::get_singleton();
|
||||
|
||||
if (dmode == DISPLAY_FRAME_TIME) {
|
||||
return TS->format_number(rtos(p_time * 1000).pad_decimals(2)) + " " + TTR("ms");
|
||||
} else if (dmode == DISPLAY_AVERAGE_TIME) {
|
||||
if (p_calls == 0) {
|
||||
return TS->format_number("0.00") + " " + TTR("ms");
|
||||
} else {
|
||||
return TS->format_number(rtos((p_time / p_calls) * 1000).pad_decimals(2)) + " " + TTR("ms");
|
||||
}
|
||||
} else if (dmode == DISPLAY_FRAME_PERCENT) {
|
||||
return _get_percent_txt(p_time, m.frame_time);
|
||||
} else if (dmode == DISPLAY_PHYSICS_FRAME_PERCENT) {
|
||||
return _get_percent_txt(p_time, m.physics_frame_time);
|
||||
switch (display_mode->get_selected()) {
|
||||
case DISPLAY_FRAME_TIME: {
|
||||
return ts->format_number(rtos(p_time * 1000).pad_decimals(2), lang) + " " + TTR("ms");
|
||||
} break;
|
||||
|
||||
case DISPLAY_AVERAGE_TIME: {
|
||||
if (p_calls == 0) {
|
||||
return ts->format_number("0.00", lang) + " " + TTR("ms");
|
||||
}
|
||||
return ts->format_number(rtos((p_time / p_calls) * 1000).pad_decimals(2), lang) + " " + TTR("ms");
|
||||
} break;
|
||||
|
||||
case DISPLAY_FRAME_PERCENT: {
|
||||
float total = m.frame_time == 0 ? 0.00001 : m.frame_time;
|
||||
return ts->format_number(String::num((p_time / total) * 100, 1), lang) + ts->get_percent_sign(lang);
|
||||
} break;
|
||||
|
||||
case DISPLAY_PHYSICS_FRAME_PERCENT: {
|
||||
float total = m.physics_frame_time == 0 ? 0.00001 : m.physics_frame_time;
|
||||
return ts->format_number(String::num((p_time / total) * 100, 1), lang) + ts->get_percent_sign(lang);
|
||||
} break;
|
||||
}
|
||||
|
||||
return "err";
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "editor_visual_profiler.h"
|
||||
|
||||
#include "core/io/image.h"
|
||||
#include "core/string/translation_server.h"
|
||||
#include "editor/editor_string_names.h"
|
||||
#include "editor/run/editor_run_bar.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
|
|
@ -123,12 +124,14 @@ void EditorVisualProfiler::clear() {
|
|||
}
|
||||
|
||||
String EditorVisualProfiler::_get_time_as_text(float p_time) {
|
||||
const String &lang = _get_locale();
|
||||
|
||||
int dmode = display_mode->get_selected();
|
||||
|
||||
if (dmode == DISPLAY_FRAME_TIME) {
|
||||
return TS->format_number(String::num(p_time, 2)) + " " + TTR("ms");
|
||||
return TranslationServer::get_singleton()->format_number(String::num(p_time, 2), lang) + " " + TTR("ms");
|
||||
} else if (dmode == DISPLAY_FRAME_PERCENT) {
|
||||
return TS->format_number(String::num(p_time * 100 / graph_limit, 2)) + " " + TS->percent_sign();
|
||||
return TranslationServer::get_singleton()->format_number(String::num(p_time * 100 / graph_limit, 2), lang) + " " + TranslationServer::get_singleton()->get_percent_sign(lang);
|
||||
}
|
||||
|
||||
return "err";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue