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:
commit
ac24644464
1 changed files with 18 additions and 14 deletions
|
@ -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.");
|
ERR_FAIL_COND_V_MSG(p_class.empty(), nullptr, "Class name cannot be empty.");
|
||||||
|
|
||||||
if (ScriptServer::is_global_class(p_class)) {
|
if (ScriptServer::is_global_class(p_class)) {
|
||||||
Ref<ImageTexture> icon;
|
String class_name = p_class;
|
||||||
Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(p_class);
|
Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(class_name);
|
||||||
StringName name = p_class;
|
|
||||||
|
|
||||||
while (script.is_valid()) {
|
while (true) {
|
||||||
name = EditorNode::get_editor_data().script_class_get_name(script->get_path());
|
String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(class_name);
|
||||||
String current_icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name);
|
Ref<Texture> icon = _load_custom_class_icon(icon_path);
|
||||||
icon = _load_custom_class_icon(current_icon_path);
|
|
||||||
if (icon.is_valid()) {
|
if (icon.is_valid()) {
|
||||||
return icon;
|
return icon; // Current global class has icon.
|
||||||
}
|
}
|
||||||
script = script->get_base_script();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (icon.is_null()) {
|
// Find next global class along the inheritance chain.
|
||||||
icon = gui_base->get_icon(ScriptServer::get_global_class_base(name), "EditorIcons");
|
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();
|
const Map<String, Vector<EditorData::CustomType>> &p_map = EditorNode::get_editor_data().get_custom_types();
|
||||||
|
|
Loading…
Reference in a new issue