Merge pull request #60536 from timothyqiu/class-name-icon-3.x

[3.x] Fix custom class icon when it inherits from a script
This commit is contained in:
Rémi Verschelde 2022-04-27 08:06:02 +02:00 committed by GitHub
commit ac24644464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4070,25 +4070,29 @@ Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_f
ERR_FAIL_COND_V_MSG(p_class.empty(), nullptr, "Class name cannot be empty.");
if (ScriptServer::is_global_class(p_class)) {
Ref<ImageTexture> icon;
Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(p_class);
StringName name = p_class;
String class_name = p_class;
Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(class_name);
while (script.is_valid()) {
name = EditorNode::get_editor_data().script_class_get_name(script->get_path());
String current_icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name);
icon = _load_custom_class_icon(current_icon_path);
while (true) {
String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(class_name);
Ref<Texture> icon = _load_custom_class_icon(icon_path);
if (icon.is_valid()) {
return icon;
return icon; // Current global class has icon.
}
script = script->get_base_script();
}
if (icon.is_null()) {
icon = gui_base->get_icon(ScriptServer::get_global_class_base(name), "EditorIcons");
// Find next global class along the inheritance chain.
do {
Ref<Script> base_script = script->get_base_script();
if (base_script.is_null()) {
// We've reached a native class, use its icon.
String base_type;
script->get_language()->get_global_class_name(script->get_path(), &base_type);
return gui_base->get_icon(base_type, "EditorIcons");
}
script = base_script;
class_name = EditorNode::get_editor_data().script_class_get_name(script->get_path());
} while (class_name.empty());
}
return icon;
}
const Map<String, Vector<EditorData::CustomType>> &p_map = EditorNode::get_editor_data().get_custom_types();