Editor: Fix enum detection for unnamed classes

This commit is contained in:
Danil Alexeev 2024-04-10 15:35:48 +03:00
parent 6c57928063
commit fc6c1d6363
No known key found for this signature in database
GPG Key ID: 124453E157DA8DC7

View File

@ -3191,21 +3191,34 @@ String EditorHelpBit::get_property_description(const StringName &p_class_name, c
for (const DocData::PropertyDoc &property : E->value.properties) { for (const DocData::PropertyDoc &property : E->value.properties) {
String description_current = is_native ? DTR(property.description) : property.description; String description_current = is_native ? DTR(property.description) : property.description;
const Vector<String> class_enum = property.enumeration.split("."); String enum_class_name;
const String enum_name = class_enum.size() >= 2 ? class_enum[1] : ""; String enum_name;
if (!enum_name.is_empty()) { if (CoreConstants::is_global_enum(property.enumeration)) {
// Classes can use enums from other classes, so check from which it came. enum_class_name = "@GlobalScope";
const HashMap<String, DocData::ClassDoc>::ConstIterator enum_class = dd->class_list.find(class_enum[0]); enum_name = property.enumeration;
if (enum_class) { } else {
for (DocData::ConstantDoc val : enum_class->value.constants) { const int dot_pos = property.enumeration.rfind(".");
// Don't display `_MAX` enum value descriptions, as these are never exposed in the inspector. if (dot_pos >= 0) {
if (val.enumeration == enum_name && !val.name.ends_with("_MAX")) { enum_class_name = property.enumeration.left(dot_pos);
const String enum_value = EditorPropertyNameProcessor::get_singleton()->process_name(val.name, EditorPropertyNameProcessor::STYLE_CAPITALIZED); enum_name = property.enumeration.substr(dot_pos + 1);
const String enum_prefix = EditorPropertyNameProcessor::get_singleton()->process_name(enum_name, EditorPropertyNameProcessor::STYLE_CAPITALIZED) + " "; }
const String enum_description = is_native ? DTR(val.description) : val.description; }
// Prettify the enum value display, so that "<ENUM NAME>_<VALUE>" becomes "Value". if (!enum_class_name.is_empty() && !enum_name.is_empty()) {
description_current = description_current.trim_prefix("\n") + vformat("\n[b]%s:[/b] %s", enum_value.trim_prefix(enum_prefix), enum_description.is_empty() ? ("[i]" + DTR("No description available.") + "[/i]") : enum_description); // Classes can use enums from other classes, so check from which it came.
const HashMap<String, DocData::ClassDoc>::ConstIterator enum_class = dd->class_list.find(enum_class_name);
if (enum_class) {
const String enum_prefix = EditorPropertyNameProcessor::get_singleton()->process_name(enum_name, EditorPropertyNameProcessor::STYLE_CAPITALIZED) + " ";
for (DocData::ConstantDoc constant : enum_class->value.constants) {
// Don't display `_MAX` enum value descriptions, as these are never exposed in the inspector.
if (constant.enumeration == enum_name && !constant.name.ends_with("_MAX")) {
// Prettify the enum value display, so that "<ENUM_NAME>_<ITEM>" becomes "Item".
const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(constant.name, EditorPropertyNameProcessor::STYLE_CAPITALIZED).trim_prefix(enum_prefix);
String item_descr = (is_native ? DTR(constant.description) : constant.description).strip_edges();
if (item_descr.is_empty()) {
item_descr = ("[i]" + DTR("No description available.") + "[/i]");
}
description_current += vformat("\n[b]%s:[/b] %s", item_name, item_descr);
} }
} }
} }