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.
This commit is contained in:
parent
84e205b5a1
commit
2cfdb27c81
1 changed files with 9 additions and 25 deletions
|
@ -487,38 +487,16 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) {
|
||||||
HashSet<StringName> allowed_types;
|
HashSet<StringName> allowed_types;
|
||||||
_get_allowed_types(false, &allowed_types);
|
_get_allowed_types(false, &allowed_types);
|
||||||
|
|
||||||
Vector<EditorData::CustomType> 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) {
|
for (const StringName &E : allowed_types) {
|
||||||
const String &t = E;
|
const String &t = E;
|
||||||
|
|
||||||
bool is_custom_resource = false;
|
if (!ClassDB::can_instantiate(t)) {
|
||||||
Ref<Texture2D> 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)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
inheritors_array.push_back(t);
|
inheritors_array.push_back(t);
|
||||||
|
|
||||||
if (!icon.is_valid()) {
|
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(t, "Object");
|
||||||
icon = get_editor_theme_icon(has_theme_icon(t, EditorStringName(EditorIcons)) ? t : String("Object"));
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = TYPE_BASE_ID + idx;
|
int id = TYPE_BASE_ID + idx;
|
||||||
edit_menu->add_icon_item(icon, vformat(TTR("New %s"), t), id);
|
edit_menu->add_icon_item(icon, vformat(TTR("New %s"), t), id);
|
||||||
|
|
||||||
|
@ -804,7 +782,12 @@ void EditorResourcePicker::_notification(int p_what) {
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
}
|
}
|
||||||
case NOTIFICATION_THEME_CHANGED: {
|
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")));
|
edit_button->set_icon(get_theme_icon(SNAME("select_arrow"), SNAME("Tree")));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -940,6 +923,7 @@ void EditorResourcePicker::_ensure_resource_menu() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
edit_menu = memnew(PopupMenu);
|
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);
|
add_child(edit_menu);
|
||||||
edit_menu->connect("id_pressed", callable_mp(this, &EditorResourcePicker::_edit_menu_cbk));
|
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));
|
edit_menu->connect("popup_hide", callable_mp((BaseButton *)edit_button, &BaseButton::set_pressed).bind(false));
|
||||||
|
|
Loading…
Reference in a new issue