From 9fae65404a223a86816685b0b4036a57b8f976b7 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Fri, 31 Mar 2023 21:17:59 +0200 Subject: [PATCH] Streamline class icon resolution in the editor --- editor/editor_data.cpp | 55 ++++++++++++- editor/editor_data.h | 6 ++ editor/editor_help.cpp | 18 ++-- editor/editor_help.h | 2 +- editor/editor_inspector.cpp | 42 +++------- editor/editor_node.cpp | 155 +++++++++++++---------------------- editor/editor_node.h | 6 +- editor/editor_quick_open.cpp | 5 +- 8 files changed, 137 insertions(+), 152 deletions(-) diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 3059ce445c2..d2af7879d27 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -32,9 +32,11 @@ #include "core/config/project_settings.h" #include "core/io/file_access.h" +#include "core/io/image_loader.h" #include "core/io/resource_loader.h" #include "editor/editor_node.h" #include "editor/editor_plugin.h" +#include "editor/editor_scale.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/script_editor_plugin.h" #include "scene/resources/packed_scene.h" @@ -457,10 +459,10 @@ void EditorData::add_custom_type(const String &p_type, const String &p_inherits, ct.name = p_type; ct.icon = p_icon; ct.script = p_script; + if (!custom_types.has(p_inherits)) { custom_types[p_inherits] = Vector(); } - custom_types[p_inherits].push_back(ct); } @@ -1028,8 +1030,57 @@ void EditorData::script_class_load_icon_paths() { } } +Ref EditorData::_load_script_icon(const String &p_path) const { + if (p_path.length()) { + Ref img = memnew(Image); + Error err = ImageLoader::load_image(p_path, img); + if (err == OK) { + img->resize(16 * EDSCALE, 16 * EDSCALE, Image::INTERPOLATE_LANCZOS); + return ImageTexture::create_from_image(img); + } + } + return nullptr; +} + +Ref EditorData::get_script_icon(const Ref