diff options
Diffstat (limited to 'scene/main/window.cpp')
-rw-r--r-- | scene/main/window.cpp | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp index c345c3d179..f5468b29c5 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -829,16 +829,7 @@ void Window::set_visible(bool p_visible) { //update transient exclusive if (transient_parent) { - if (exclusive && visible) { - if (!is_in_edited_scene_root()) { - ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child."); - transient_parent->exclusive_child = this; - } - } else { - if (transient_parent->exclusive_child == this) { - transient_parent->exclusive_child = nullptr; - } - } + _set_transient_exclusive_child(true); } } @@ -878,15 +869,7 @@ void Window::_make_transient() { if (window) { transient_parent = window; window->transient_children.insert(this); - if (is_inside_tree() && is_visible() && exclusive) { - if (transient_parent->exclusive_child == nullptr) { - if (!is_in_edited_scene_root()) { - transient_parent->exclusive_child = this; - } - } else if (transient_parent->exclusive_child != this) { - ERR_PRINT("Making child transient exclusive, but parent has another exclusive child"); - } - } + _set_transient_exclusive_child(); } //see if we can make transient @@ -895,6 +878,22 @@ void Window::_make_transient() { } } +void Window::_set_transient_exclusive_child(bool p_clear_invalid) { + if (exclusive && visible && is_inside_tree()) { + if (!is_in_edited_scene_root()) { + // Transient parent has another exclusive child. + if (transient_parent->exclusive_child && transient_parent->exclusive_child != this) { + ERR_PRINT(vformat("Attempting to make child window exclusive, but the parent window already has another exclusive child. This window: %s, parent window: %s, current exclusive child window: %s", this->get_description(), transient_parent->get_description(), transient_parent->exclusive_child->get_description())); + } + transient_parent->exclusive_child = this; + } + } else if (p_clear_invalid) { + if (transient_parent->exclusive_child == this) { + transient_parent->exclusive_child = nullptr; + } + } +} + void Window::set_transient(bool p_transient) { ERR_MAIN_THREAD_GUARD; if (transient == p_transient) { @@ -936,16 +935,7 @@ void Window::set_exclusive(bool p_exclusive) { } if (transient_parent) { - if (p_exclusive && is_inside_tree() && is_visible()) { - ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child."); - if (!is_in_edited_scene_root()) { - transient_parent->exclusive_child = this; - } - } else { - if (transient_parent->exclusive_child == this) { - transient_parent->exclusive_child = nullptr; - } - } + _set_transient_exclusive_child(true); } } @@ -1999,7 +1989,7 @@ StringName Window::get_theme_type_variation() const { Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<Texture2D>()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2023,7 +2013,7 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<StyleBox>()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2047,7 +2037,7 @@ Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringN Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<Font>()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2071,7 +2061,7 @@ Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_t int Window::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(0); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2095,7 +2085,7 @@ int Window::get_theme_font_size(const StringName &p_name, const StringName &p_th Color Window::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Color()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2119,7 +2109,7 @@ Color Window::get_theme_color(const StringName &p_name, const StringName &p_them int Window::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(0); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2170,7 +2160,7 @@ Ref<Texture2D> Window::get_editor_theme_icon(const StringName &p_name) const { bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2187,7 +2177,7 @@ bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2204,7 +2194,7 @@ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_th bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2221,7 +2211,7 @@ bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2238,7 +2228,7 @@ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_t bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2255,7 +2245,7 @@ bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme bool Window::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { |