diff options
Diffstat (limited to 'scene/gui/dialogs.cpp')
-rw-r--r-- | scene/gui/dialogs.cpp | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 5654219a3e..4f59f4a36a 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -31,8 +31,8 @@ #include "dialogs.h" #include "core/os/keyboard.h" -#include "core/print_string.h" -#include "core/translation.h" +#include "core/string/print_string.h" +#include "core/string/translation.h" #include "line_edit.h" #ifdef TOOLS_ENABLED @@ -51,15 +51,15 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) { } void AcceptDialog::_parent_focused() { - _cancel_pressed(); + if (!is_exclusive()) { + _cancel_pressed(); + } } void AcceptDialog::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { if (is_visible()) { - get_ok()->grab_focus(); _update_child_rects(); parent_visible = get_parent_visible_window(); @@ -98,20 +98,18 @@ void AcceptDialog::_notification(int p_what) { } void AcceptDialog::_text_entered(const String &p_text) { - _ok_pressed(); } void AcceptDialog::_ok_pressed() { - - if (hide_on_ok) + if (hide_on_ok) { set_visible(false); + } ok_pressed(); emit_signal("confirmed"); } void AcceptDialog::_cancel_pressed() { - Window *parent_window = parent_visible; if (parent_visible) { parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); @@ -130,11 +128,10 @@ void AcceptDialog::_cancel_pressed() { } String AcceptDialog::get_text() const { - return label->get_text(); } -void AcceptDialog::set_text(String p_text) { +void AcceptDialog::set_text(String p_text) { label->set_text(p_text); child_controls_changed(); if (is_visible()) { @@ -143,33 +140,30 @@ void AcceptDialog::set_text(String p_text) { } void AcceptDialog::set_hide_on_ok(bool p_hide) { - hide_on_ok = p_hide; } -bool AcceptDialog::get_hide_on_ok() const { +bool AcceptDialog::get_hide_on_ok() const { return hide_on_ok; } void AcceptDialog::set_autowrap(bool p_autowrap) { - label->set_autowrap(p_autowrap); } -bool AcceptDialog::has_autowrap() { +bool AcceptDialog::has_autowrap() { return label->has_autowrap(); } void AcceptDialog::register_text_enter(Node *p_line_edit) { - ERR_FAIL_NULL(p_line_edit); LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit); - if (line_edit) + if (line_edit) { line_edit->connect("text_entered", callable_mp(this, &AcceptDialog::_text_entered)); + } } void AcceptDialog::_update_child_rects() { - Size2 label_size = label->get_minimum_size(); if (label->get_text().empty()) { label_size.height = 0; @@ -183,11 +177,13 @@ void AcceptDialog::_update_child_rects() { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; + } - if (c == hbc || c == label || c == bg || c->is_set_as_toplevel()) + if (c == hbc || c == label || c == bg || c->is_set_as_top_level()) { continue; + } c->set_position(cpos); c->set_size(csize); @@ -204,17 +200,18 @@ void AcceptDialog::_update_child_rects() { } Size2 AcceptDialog::_get_contents_minimum_size() const { - int margin = hbc->get_theme_constant("margin", "Dialogs"); Size2 minsize = label->get_combined_minimum_size(); for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; + } - if (c == hbc || c == label || c->is_set_as_toplevel()) + if (c == hbc || c == label || c->is_set_as_top_level()) { continue; + } Size2 cminsize = c->get_combined_minimum_size(); minsize.x = MAX(cminsize.x, minsize.x); @@ -233,20 +230,17 @@ Size2 AcceptDialog::_get_contents_minimum_size() const { } void AcceptDialog::_custom_action(const String &p_action) { - emit_signal("custom_action", p_action); custom_action(p_action); } Button *AcceptDialog::add_button(const String &p_text, bool p_right, const String &p_action) { - Button *button = memnew(Button); button->set_text(p_text); if (p_right) { hbc->add_child(button); hbc->add_spacer(); } else { - hbc->add_child(button); hbc->move_child(button, 0); hbc->add_spacer(true); @@ -260,17 +254,16 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin } Button *AcceptDialog::add_cancel(const String &p_cancel) { - String c = p_cancel; - if (p_cancel == "") + if (p_cancel == "") { c = RTR("Cancel"); - Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c); + } + Button *b = swap_cancel_ok ? add_button(c, true) : add_button(c); b->connect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed)); return b; } void AcceptDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_ok"), &AcceptDialog::get_ok); ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label); ClassDB::bind_method(D_METHOD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok); @@ -293,19 +286,19 @@ void AcceptDialog::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dialog_autowrap"), "set_autowrap", "has_autowrap"); } -bool AcceptDialog::swap_ok_cancel = false; -void AcceptDialog::set_swap_ok_cancel(bool p_swap) { - - swap_ok_cancel = p_swap; +bool AcceptDialog::swap_cancel_ok = false; +void AcceptDialog::set_swap_cancel_ok(bool p_swap) { + swap_cancel_ok = p_swap; } AcceptDialog::AcceptDialog() { - parent_visible = nullptr; set_wrap_controls(true); set_visible(false); set_transient(true); + set_exclusive(true); + set_clamp_to_embedder(true); bg = memnew(Panel); add_child(bg); @@ -344,17 +337,14 @@ AcceptDialog::~AcceptDialog() { // ConfirmationDialog void ConfirmationDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_cancel"), &ConfirmationDialog::get_cancel); } Button *ConfirmationDialog::get_cancel() { - return cancel; } ConfirmationDialog::ConfirmationDialog() { - set_title(RTR("Please Confirm...")); #ifdef TOOLS_ENABLED set_min_size(Size2(200, 70) * EDSCALE); |