diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 344cb87aa6f..9797a2e9f50 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -54,12 +54,7 @@ void CreateDialog::popup_create(bool p_dontclear) { TreeItem *ti = recent->create_item(root); ti->set_text(0, l); - if (has_icon(l, "EditorIcons")) { - - ti->set_icon(0, get_icon(l, "EditorIcons")); - } else { - ti->set_icon(0, get_icon("Object", "EditorIcons")); - } + ti->set_icon(0, _get_editor_icon(l)); } } @@ -122,6 +117,29 @@ void CreateDialog::_sbox_input(const Ref &p_ie) { } } +Ref CreateDialog::_get_editor_icon(const String &p_type) const { + + if (has_icon(p_type, "EditorIcons")) { + return get_icon(p_type, "EditorIcons"); + } + + const Map > &p_map = EditorNode::get_editor_data().get_custom_types(); + for (const Map >::Element *E = p_map.front(); E; E = E->next()) { + const Vector &ct = E->value(); + for (int i = 0; i < ct.size(); ++i) { + if (ct[i].name == p_type) { + if (ct[i].icon.is_valid()) { + return ct[i].icon; + } else { + return get_icon("Object", "EditorIcons"); + } + } + } + } + + return get_icon("Object", "EditorIcons"); +} + void CreateDialog::add_type(const String &p_type, HashMap &p_types, TreeItem *p_root, TreeItem **to_select) { if (p_types.has(p_type)) @@ -457,13 +475,7 @@ void CreateDialog::_update_favorite_list() { TreeItem *ti = favorites->create_item(root); String l = favorite_list[i]; ti->set_text(0, l); - - if (has_icon(l, "EditorIcons")) { - - ti->set_icon(0, get_icon(l, "EditorIcons")); - } else { - ti->set_icon(0, get_icon("Object", "EditorIcons")); - } + ti->set_icon(0, _get_editor_icon(l)); } } diff --git a/editor/create_dialog.h b/editor/create_dialog.h index 31f106ea227..a523539ba05 100644 --- a/editor/create_dialog.h +++ b/editor/create_dialog.h @@ -74,6 +74,8 @@ class CreateDialog : public ConfirmationDialog { void _confirmed(); void _text_changed(const String &p_newtext); + Ref _get_editor_icon(const String &p_type) const; + void add_type(const String &p_type, HashMap &p_types, TreeItem *p_root, TreeItem **to_select); Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);