summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-11-09 18:10:35 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-11-09 18:10:35 +0100
commitc2246a5a6fe1da1815245a54342ef96da9515263 (patch)
treeb59b887298d497c04366e2c3261249fdd90ed08b
parent02e52da77479f0ef76d18eae734d371045cc42f7 (diff)
parentedcad2ea88f35b2a3b9b30a8a56cdf5e3a0009ec (diff)
downloadredot-engine-c2246a5a6fe1da1815245a54342ef96da9515263.tar.gz
Merge pull request #84668 from YuriSizov/gui-dont-warn-when-popup-subs-are-nameless
Allow auto-generated node names in `PopupMenu::add_submenu_item`
-rw-r--r--core/string/ustring.cpp7
-rw-r--r--core/string/ustring.h2
-rw-r--r--scene/gui/popup_menu.cpp6
3 files changed, 12 insertions, 3 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 9be7c04158..60e2d539f8 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4699,11 +4699,16 @@ String String::property_name_encode() const {
static const char32_t invalid_node_name_characters[] = { '.', ':', '@', '/', '\"', UNIQUE_NODE_PREFIX[0], 0 };
-String String::get_invalid_node_name_characters() {
+String String::get_invalid_node_name_characters(bool p_allow_internal) {
// Do not use this function for critical validation.
String r;
const char32_t *c = invalid_node_name_characters;
while (*c) {
+ if (p_allow_internal && *c == '@') {
+ c++;
+ continue;
+ }
+
if (c != invalid_node_name_characters) {
r += " ";
}
diff --git a/core/string/ustring.h b/core/string/ustring.h
index f45392eee1..897b06fc6d 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -437,7 +437,7 @@ public:
String property_name_encode() const;
// node functions
- static String get_invalid_node_name_characters();
+ static String get_invalid_node_name_characters(bool p_allow_internal = false);
String validate_node_name() const;
String validate_identifier() const;
String validate_filename() const;
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 0cda27ec24..d6b8dd0202 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -1487,7 +1487,11 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons
}
void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) {
- ERR_FAIL_COND_MSG(p_submenu.validate_node_name() != p_submenu, "Invalid node name for submenu, the following characters are not allowed:\n" + String::get_invalid_node_name_characters());
+ String submenu_name_safe = p_submenu.replace("@", "_"); // Allow special characters for auto-generated names.
+ if (submenu_name_safe.validate_node_name() != submenu_name_safe) {
+ ERR_FAIL_MSG(vformat("Invalid node name '%s' for a submenu, the following characters are not allowed:\n%s", p_submenu, String::get_invalid_node_name_characters(true)));
+ }
+
Item item;
item.text = p_label;
item.xl_text = atr(p_label);