diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-09-17 12:42:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-17 12:42:08 +0200 |
commit | 3e66cd9b6862ffd6991dba7c7cad5a175b8db320 (patch) | |
tree | adb53ee5b6417536d5dd3f1e8532733a1d9852d4 | |
parent | c24ca2c7a8b5471e9175f8ec1a84fd69a24bbbcf (diff) | |
parent | 672a6c968032df9aa3eda7cd779621dda439ce53 (diff) |
Merge pull request #10998 from MillionOstrich/custom-types-fix-icons
Fix icons for custom types in the recent & favorites lists in the create dialog
-rw-r--r-- | editor/create_dialog.cpp | 38 | ||||
-rw-r--r-- | editor/create_dialog.h | 2 |
2 files changed, 27 insertions, 13 deletions
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 344cb87aa6..9797a2e9f5 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<InputEvent> &p_ie) { } } +Ref<Texture> CreateDialog::_get_editor_icon(const String &p_type) const { + + if (has_icon(p_type, "EditorIcons")) { + return get_icon(p_type, "EditorIcons"); + } + + const Map<String, Vector<EditorData::CustomType> > &p_map = EditorNode::get_editor_data().get_custom_types(); + for (const Map<String, Vector<EditorData::CustomType> >::Element *E = p_map.front(); E; E = E->next()) { + const Vector<EditorData::CustomType> &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<String, TreeItem *> &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 31f106ea22..a523539ba0 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<Texture> _get_editor_icon(const String &p_type) const; + void add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select); Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |