From 5c63646e870e6b4dc50219f0de424d521086787b Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Wed, 8 Jan 2025 20:00:20 -0300 Subject: [PATCH] Change print warnings to config ones for popups that need transparency --- main/main.cpp | 2 +- scene/gui/menu_button.cpp | 8 ++++++++ scene/gui/menu_button.h | 4 ++++ scene/gui/option_button.cpp | 8 ++++++++ scene/gui/option_button.h | 4 ++++ scene/gui/popup.cpp | 35 ++++++++++++++++++++++++++--------- scene/gui/popup.h | 4 ++++ scene/gui/popup_menu.cpp | 30 +++++++++++++++++++++++------- scene/gui/popup_menu.h | 4 ++++ 9 files changed, 82 insertions(+), 17 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 4a911af0942b..db05eae16cdc 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2531,7 +2531,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph GLOBAL_DEF_BASIC("internationalization/locale/include_text_server_data", false); OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", true); - OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false); + OS::get_singleton()->_allow_layered = GLOBAL_DEF_RST("display/window/per_pixel_transparency/allowed", false); #ifdef TOOLS_ENABLED if (editor || project_manager) { diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index ae4b45d3eed2..dee54d9b7283 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -204,6 +204,14 @@ void MenuButton::set_disable_shortcuts(bool p_disabled) { disable_shortcuts = p_disabled; } +#ifdef TOOLS_ENABLED +PackedStringArray MenuButton::get_configuration_warnings() const { + PackedStringArray warnings = Button::get_configuration_warnings(); + warnings.append_array(popup->get_configuration_warnings()); + return warnings; +} +#endif + MenuButton::MenuButton(const String &p_text) : Button(p_text) { set_flat(true); diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index 5a74d61091c7..f3ccbcf8d696 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -71,6 +71,10 @@ class MenuButton : public Button { void set_item_count(int p_count); int get_item_count() const; +#ifdef TOOLS_ENABLED + PackedStringArray get_configuration_warnings() const override; +#endif + MenuButton(const String &p_text = String()); ~MenuButton(); }; diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 8540e95fb934..a3e30f541394 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -582,6 +582,14 @@ void OptionButton::set_disable_shortcuts(bool p_disabled) { disable_shortcuts = p_disabled; } +#ifdef TOOLS_ENABLED +PackedStringArray OptionButton::get_configuration_warnings() const { + PackedStringArray warnings = Button::get_configuration_warnings(); + warnings.append_array(popup->get_configuration_warnings()); + return warnings; +} +#endif + OptionButton::OptionButton(const String &p_text) : Button(p_text) { set_toggle_mode(true); diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index 351df9a74977..f33d32fd872f 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -143,6 +143,10 @@ class OptionButton : public Button { void set_disable_shortcuts(bool p_disabled); +#ifdef TOOLS_ENABLED + PackedStringArray get_configuration_warnings() const override; +#endif + OptionButton(const String &p_text = String()); ~OptionButton(); }; diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 4697fb6be989..94d7303ae504 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -30,6 +30,9 @@ #include "popup.h" +#ifdef TOOLS_ENABLED +#include "core/config/project_settings.h" +#endif #include "scene/gui/panel.h" #include "scene/resources/style_box_flat.h" #include "scene/theme/theme_db.h" @@ -221,6 +224,21 @@ Popup::Popup() { Popup::~Popup() { } +#ifdef TOOLS_ENABLED +PackedStringArray PopupPanel::get_configuration_warnings() const { + PackedStringArray warnings = Popup::get_configuration_warnings(); + + if (!DisplayServer::get_singleton()->is_window_transparency_available() && !GLOBAL_GET("display/window/subwindows/embed_subwindows")) { + Ref sb = theme_cache.panel_style; + if (sb.is_valid() && (sb->get_shadow_size() > 0 || sb->get_corner_radius(CORNER_TOP_LEFT) > 0 || sb->get_corner_radius(CORNER_TOP_RIGHT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_LEFT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_RIGHT) > 0)) { + warnings.push_back(RTR("The current theme style has shadows and/or rounded corners for popups, but those won't display correctly if \"display/window/per_pixel_transparency/allowed\" isn't enabled in the Project Settings, nor if it isn't supported.")); + } + } + + return warnings; +} +#endif + void PopupPanel::_input_from_window(const Ref &p_event) { if (p_event.is_valid()) { if (!get_flag(FLAG_POPUP)) { @@ -341,15 +359,6 @@ void PopupPanel::_update_child_rects() const { void PopupPanel::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - if (!Engine::get_singleton()->is_editor_hint() && !DisplayServer::get_singleton()->is_window_transparency_available() && !is_embedded()) { - Ref sb = theme_cache.panel_style; - if (sb.is_valid() && (sb->get_shadow_size() > 0 || sb->get_corner_radius(CORNER_TOP_LEFT) > 0 || sb->get_corner_radius(CORNER_TOP_RIGHT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_LEFT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_RIGHT) > 0)) { - WARN_PRINT_ONCE("The current theme styles PopupPanel to have shadows and/or rounded corners, but those won't display correctly if 'display/window/per_pixel_transparency/allowed' isn't enabled in the Project Settings, nor if it isn't supported."); - } - } - } break; - case NOTIFICATION_THEME_CHANGED: { panel->add_theme_style_override(SceneStringName(panel), theme_cache.panel_style); @@ -358,6 +367,10 @@ void PopupPanel::_notification(int p_what) { } _update_child_rects(); + +#ifdef TOOLS_ENABLED + update_configuration_warnings(); +#endif } break; case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { @@ -410,4 +423,8 @@ PopupPanel::PopupPanel() { panel = memnew(Panel); panel->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); add_child(panel, false, INTERNAL_MODE_FRONT); + +#ifdef TOOLS_ENABLED + ProjectSettings::get_singleton()->connect("settings_changed", callable_mp((Node *)this, &Node::update_configuration_warnings)); +#endif } diff --git a/scene/gui/popup.h b/scene/gui/popup.h index cfebdcb07229..8985f2089a44 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -101,6 +101,10 @@ class PopupPanel : public Popup { virtual Size2 _get_contents_minimum_size() const override; public: +#ifdef TOOLS_ENABLED + PackedStringArray get_configuration_warnings() const override; +#endif + PopupPanel(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 1f3991998a13..5b9dd8655cd9 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1106,13 +1106,6 @@ void PopupMenu::_notification(int p_what) { if (system_menu_id != NativeMenu::INVALID_MENU_ID) { bind_global_menu(); } - - if (!Engine::get_singleton()->is_editor_hint() && !DisplayServer::get_singleton()->is_window_transparency_available() && !is_embedded()) { - Ref sb = theme_cache.panel_style; - if (sb.is_valid() && (sb->get_shadow_size() > 0 || sb->get_corner_radius(CORNER_TOP_LEFT) > 0 || sb->get_corner_radius(CORNER_TOP_RIGHT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_LEFT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_RIGHT) > 0)) { - WARN_PRINT_ONCE("The current theme styles PopupMenu to have shadows and/or rounded corners, but those won't display correctly if 'display/window/per_pixel_transparency/allowed' isn't enabled in the Project Settings, nor if it isn't supported."); - } - } } break; case NOTIFICATION_EXIT_TREE: { @@ -1129,6 +1122,10 @@ void PopupMenu::_notification(int p_what) { _update_shadow_offsets(); } +#ifdef TOOLS_ENABLED + update_configuration_warnings(); +#endif + [[fallthrough]]; } case NOTIFICATION_TRANSLATION_CHANGED: { @@ -2709,6 +2706,21 @@ String PopupMenu::get_tooltip(const Point2 &p_pos) const { return items[over].tooltip; } +#ifdef TOOLS_ENABLED +PackedStringArray PopupMenu::get_configuration_warnings() const { + PackedStringArray warnings = Popup::get_configuration_warnings(); + + if (!DisplayServer::get_singleton()->is_window_transparency_available() && !GLOBAL_GET("display/window/subwindows/embed_subwindows")) { + Ref sb = theme_cache.panel_style; + if (sb.is_valid() && (sb->get_shadow_size() > 0 || sb->get_corner_radius(CORNER_TOP_LEFT) > 0 || sb->get_corner_radius(CORNER_TOP_RIGHT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_LEFT) > 0 || sb->get_corner_radius(CORNER_BOTTOM_RIGHT) > 0)) { + warnings.push_back(RTR("The current theme style has shadows and/or rounded corners for popups, but those won't display correctly if \"display/window/per_pixel_transparency/allowed\" isn't enabled in the Project Settings, nor if it isn't supported.")); + } + } + + return warnings; +} +#endif + void PopupMenu::add_autohide_area(const Rect2 &p_area) { autohide_areas.push_back(p_area); } @@ -3027,6 +3039,10 @@ PopupMenu::PopupMenu() { add_child(minimum_lifetime_timer, false, INTERNAL_MODE_FRONT); property_helper.setup_for_instance(base_property_helper, this); + +#ifdef TOOLS_ENABLED + ProjectSettings::get_singleton()->connect("settings_changed", callable_mp((Node *)this, &Node::update_configuration_warnings)); +#endif } PopupMenu::~PopupMenu() { diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 2a5537e7f975..bed158ba17c8 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -356,6 +356,10 @@ class PopupMenu : public Popup { virtual String get_tooltip(const Point2 &p_pos) const; +#ifdef TOOLS_ENABLED + PackedStringArray get_configuration_warnings() const override; +#endif + void add_autohide_area(const Rect2 &p_area); void clear_autohide_areas();