diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2022-04-27 08:05:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-27 08:05:38 +0200 |
commit | 676f9d39ed40db4d34ee7a3e3da581fa050900a5 (patch) | |
tree | d39c7f262a6b096284f51188321d9100c8b0f9a5 | |
parent | 6e67dc0881f803376a5c53444120db215e98a838 (diff) | |
parent | 8960b990ec01bf3da0255aaef0bf614e26dbb229 (diff) |
Merge pull request #60535 from timothyqiu/class-name-icon
Fix custom class icon when it inherits from a script
-rw-r--r-- | editor/editor_node.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 2da871582a..db6bf4f816 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4096,22 +4096,28 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p ERR_FAIL_COND_V_MSG(p_class.is_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; - - 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); + String class_name = p_class; + Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(class_name); + + 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_theme_icon(ScriptServer::get_global_class_base(name), SNAME("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_theme_icon(base_type, "EditorIcons"); + } + script = base_script; + class_name = EditorNode::get_editor_data().script_class_get_name(script->get_path()); + } while (class_name.is_empty()); } } |