Update WindowDialog title when translation changes

This commit is contained in:
Michael Alexsander Silva Dias 2019-08-04 13:42:46 -03:00
parent 45be9c67ef
commit 06a890f7a3
1 changed files with 25 additions and 14 deletions

View File

@ -219,6 +219,14 @@ void WindowDialog::_notification(int p_what) {
close_button->set_begin(Point2(-get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog"))); close_button->set_begin(Point2(-get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog")));
} break; } break;
case NOTIFICATION_TRANSLATION_CHANGED: {
String new_title = tr(title);
if (title != new_title) {
title = new_title;
update();
}
} break;
case NOTIFICATION_MOUSE_EXIT: { case NOTIFICATION_MOUSE_EXIT: {
// Reset the mouse cursor when leaving the resizable window border. // Reset the mouse cursor when leaving the resizable window border.
if (resizable && !drag_type) { if (resizable && !drag_type) {
@ -226,11 +234,13 @@ void WindowDialog::_notification(int p_what) {
set_default_cursor_shape(CURSOR_ARROW); set_default_cursor_shape(CURSOR_ARROW);
} }
} break; } break;
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
case NOTIFICATION_POST_POPUP: { case NOTIFICATION_POST_POPUP: {
if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton())
EditorNode::get_singleton()->dim_editor(true); EditorNode::get_singleton()->dim_editor(true);
} break; } break;
case NOTIFICATION_POPUP_HIDE: { case NOTIFICATION_POPUP_HIDE: {
if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton())
EditorNode::get_singleton()->dim_editor(false); EditorNode::get_singleton()->dim_editor(false);
@ -272,8 +282,11 @@ int WindowDialog::_drag_hit_test(const Point2 &pos) const {
void WindowDialog::set_title(const String &p_title) { void WindowDialog::set_title(const String &p_title) {
title = tr(p_title); String new_title = tr(p_title);
update(); if (title != new_title) {
title = new_title;
update();
}
} }
String WindowDialog::get_title() const { String WindowDialog::get_title() const {
@ -296,8 +309,8 @@ Size2 WindowDialog::get_minimum_size() const {
const int padding = button_width / 2; const int padding = button_width / 2;
const int button_area = button_width + padding; const int button_area = button_width + padding;
// as the title gets centered, title_width + close_button_width is not enough. // As the title gets centered, title_width + close_button_width is not enough.
// we want a width w, such that w / 2 - title_width / 2 >= button_area, i.e. // We want a width w, such that w / 2 - title_width / 2 >= button_area, i.e.
// w >= 2 * button_area + title_width // w >= 2 * button_area + title_width
return Size2(2 * button_area + title_width, 1); return Size2(2 * button_area + title_width, 1);
@ -324,7 +337,6 @@ void WindowDialog::_bind_methods() {
WindowDialog::WindowDialog() { WindowDialog::WindowDialog() {
//title="Hello!";
drag_type = DRAG_NONE; drag_type = DRAG_NONE;
resizable = false; resizable = false;
close_button = memnew(TextureButton); close_button = memnew(TextureButton);
@ -340,7 +352,6 @@ WindowDialog::~WindowDialog() {
void PopupDialog::_notification(int p_what) { void PopupDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) { if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item(); RID ci = get_canvas_item();
get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size())); get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size()));
} }
@ -362,15 +373,15 @@ void AcceptDialog::_post_popup() {
void AcceptDialog::_notification(int p_what) { void AcceptDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_MODAL_CLOSE) { switch (p_what) {
case NOTIFICATION_MODAL_CLOSE: {
cancel_pressed();
} break;
cancel_pressed(); case NOTIFICATION_READY:
} else if (p_what == NOTIFICATION_READY) { case NOTIFICATION_RESIZED: {
_update_child_rects();
_update_child_rects(); } break;
} else if (p_what == NOTIFICATION_RESIZED) {
_update_child_rects();
} }
} }