From 2cfdb27c81967236b7d41a1c740c0c7b366315a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Fam=C3=A0?= Date: Tue, 9 Jan 2024 00:22:22 +0100 Subject: [PATCH] Fix missing icons for custom resources in EditorResourcePicker The icons of custom resources created with `class_name` and annotated with `@icon` or GDExtensionen resources that have an icon specified in the .gdextension file are not appearing in the `EditorResourcePicker`. The problem is that the `EditorResourcePicker` retrieves the editor theme icon for the resource type and defaults to the `Object` icon if the type wasn't found. This will apply both to `class_name` and GDExtension resources. This solution addresses the issue by replacing the usage of `Control::get_editor_theme_icon` with `EditorNode::get_class_icon` to ensure the correct icon is retrieved for the resource. Additionally, this fix removes the `custom_resources` lookup above that call, as these resources, added through `EditorPlugin::add_custom_type`, were not being included in the allowed types within `_add_allowed_type` in the `EditorResoucePicker`. Currently, these particular custom resources are never displayed in the picker. The related issue is logged here: #75245. Fixes #86072. --- editor/editor_resource_picker.cpp | 34 ++++++++----------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 011cb2662190..977e65d78ca4 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -487,38 +487,16 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) { HashSet allowed_types; _get_allowed_types(false, &allowed_types); - Vector custom_resources; - if (EditorNode::get_editor_data().get_custom_types().has("Resource")) { - custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"]; - } - for (const StringName &E : allowed_types) { const String &t = E; - bool is_custom_resource = false; - Ref icon; - if (!custom_resources.is_empty()) { - for (int j = 0; j < custom_resources.size(); j++) { - if (custom_resources[j].name == t) { - is_custom_resource = true; - if (custom_resources[j].icon.is_valid()) { - icon = custom_resources[j].icon; - } - break; - } - } - } - - if (!is_custom_resource && !ClassDB::can_instantiate(t)) { + if (!ClassDB::can_instantiate(t)) { continue; } inheritors_array.push_back(t); - if (!icon.is_valid()) { - icon = get_editor_theme_icon(has_theme_icon(t, EditorStringName(EditorIcons)) ? t : String("Object")); - } - + Ref icon = EditorNode::get_singleton()->get_class_icon(t, "Object"); int id = TYPE_BASE_ID + idx; edit_menu->add_icon_item(icon, vformat(TTR("New %s"), t), id); @@ -804,7 +782,12 @@ void EditorResourcePicker::_notification(int p_what) { [[fallthrough]]; } case NOTIFICATION_THEME_CHANGED: { - assign_button->add_theme_constant_override("icon_max_width", get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor))); + const int icon_width = get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)); + assign_button->add_theme_constant_override("icon_max_width", icon_width); + if (edit_menu) { + edit_menu->add_theme_constant_override("icon_max_width", icon_width); + } + edit_button->set_icon(get_theme_icon(SNAME("select_arrow"), SNAME("Tree"))); } break; @@ -940,6 +923,7 @@ void EditorResourcePicker::_ensure_resource_menu() { return; } edit_menu = memnew(PopupMenu); + edit_menu->add_theme_constant_override("icon_max_width", get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor))); add_child(edit_menu); edit_menu->connect("id_pressed", callable_mp(this, &EditorResourcePicker::_edit_menu_cbk)); edit_menu->connect("popup_hide", callable_mp((BaseButton *)edit_button, &BaseButton::set_pressed).bind(false));