Skip to content

Commit

Permalink
Don't use arbitrary theme editor icons for scripts with the same name
Browse files Browse the repository at this point in the history
The existing theme editor icon could be unintentionally set for any
global class with matching name (`Group` icon, `Group` class_name etc),
which would only show up in the "Create Dialog" context, but not the
scene tree dock.

This change prevents this behavior, and ensures that the icon can be
actually overidden by explicit icon path in `class_name`, if there's any
custom icon to begin with.

The correct built-in type's icon is fetched for child classes if there
are no custom icons detected throughout base classes as well, so it
isn't left empty for those cases.

(cherry picked from commit c177308)
  • Loading branch information
Andrii Doroshenko (Xrayez) authored and akien-mga committed Jun 26, 2020
1 parent c682410 commit 63523e5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3822,16 +3822,13 @@ Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p
Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_fallback) const {
ERR_FAIL_COND_V_MSG(p_class.empty(), NULL, "Class name cannot be empty.");

if (gui_base->has_icon(p_class, "EditorIcons")) {
return gui_base->get_icon(p_class, "EditorIcons");
}

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()) {
StringName name = EditorNode::get_editor_data().script_class_get_name(script->get_path());
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);
if (icon.is_valid()) {
Expand All @@ -3841,7 +3838,7 @@ Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_f
}

if (icon.is_null()) {
icon = gui_base->get_icon(ScriptServer::get_global_class_base(p_class), "EditorIcons");
icon = gui_base->get_icon(ScriptServer::get_global_class_base(name), "EditorIcons");
}

return icon;
Expand All @@ -3859,8 +3856,13 @@ Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_f
}
}

if (p_fallback.length() && gui_base->has_icon(p_fallback, "EditorIcons"))
if (gui_base->has_icon(p_class, "EditorIcons")) {
return gui_base->get_icon(p_class, "EditorIcons");
}

if (p_fallback.length() && gui_base->has_icon(p_fallback, "EditorIcons")) {
return gui_base->get_icon(p_fallback, "EditorIcons");
}

return NULL;
}
Expand Down

0 comments on commit 63523e5

Please sign in to comment.