diff --git a/editor/animation/animation_bezier_editor.cpp b/editor/animation/animation_bezier_editor.cpp index 8e7f8300f64..497a98bba2d 100644 --- a/editor/animation/animation_bezier_editor.cpp +++ b/editor/animation/animation_bezier_editor.cpp @@ -412,7 +412,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { if (node) { int ofs = 0; - Ref icon = EditorNode::get_singleton()->get_object_icon(node, "Node"); + Ref icon = EditorNode::get_singleton()->get_object_icon(node); text = node->get_name(); ofs += h_separation; diff --git a/editor/animation/animation_blend_tree_editor_plugin.cpp b/editor/animation/animation_blend_tree_editor_plugin.cpp index 0280cf922c6..c2940b3f248 100644 --- a/editor/animation/animation_blend_tree_editor_plugin.cpp +++ b/editor/animation/animation_blend_tree_editor_plugin.cpp @@ -858,7 +858,7 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref &ano if (base->has_node(accum)) { Node *node = base->get_node(accum); - ti->set_icon(0, EditorNode::get_singleton()->get_object_icon(node, "Node")); + ti->set_icon(0, EditorNode::get_singleton()->get_object_icon(node)); } } else { diff --git a/editor/animation/animation_track_editor.cpp b/editor/animation/animation_track_editor.cpp index 9878dba30f5..fde08fc7901 100644 --- a/editor/animation/animation_track_editor.cpp +++ b/editor/animation/animation_track_editor.cpp @@ -2177,7 +2177,7 @@ void AnimationTrackEdit::_notification(int p_what) { } text_color.a *= 0.7; } else if (node) { - Ref icon = EditorNode::get_singleton()->get_object_icon(node, "Node"); + Ref icon = EditorNode::get_singleton()->get_object_icon(node); const Vector2 icon_size = Vector2(1, 1) * get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)); icon_rect = Rect2(Point2(ofs, (get_size().height - check->get_height()) / 2).round(), icon->get_size()); @@ -5110,7 +5110,7 @@ void AnimationTrackEditor::_update_tracks() { if (root) { Node *n = root->get_node_or_null(base_path); if (n) { - icon = EditorNode::get_singleton()->get_object_icon(n, "Node"); + icon = EditorNode::get_singleton()->get_object_icon(n); name = n->get_name(); tooltip = String(root->get_path_to(n)); } diff --git a/editor/debugger/editor_debugger_tree.cpp b/editor/debugger/editor_debugger_tree.cpp index d842dc82e28..fe16c07abda 100644 --- a/editor/debugger/editor_debugger_tree.cpp +++ b/editor/debugger/editor_debugger_tree.cpp @@ -258,7 +258,7 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int } else { item->set_tooltip_text(0, node.name + "\n" + TTR("Instance:") + " " + node.scene_file_path + "\n" + TTR("Type:") + " " + node.type_name); } - Ref icon = EditorNode::get_singleton()->get_class_icon(node.type_name, ""); + Ref icon = EditorNode::get_singleton()->get_class_icon(node.type_name); if (icon.is_valid()) { item->set_icon(0, icon); } diff --git a/editor/doc/editor_help.cpp b/editor/doc/editor_help.cpp index b86c5154fc4..3956fd45ee5 100644 --- a/editor/doc/editor_help.cpp +++ b/editor/doc/editor_help.cpp @@ -974,7 +974,7 @@ void EditorHelp::_update_doc() { _push_title_font(); class_desc->add_text(TTR("Class:") + " "); - _add_type_icon(edited_class, theme_cache.doc_title_font_size, "Object"); + _add_type_icon(edited_class, theme_cache.doc_title_font_size, ""); class_desc->add_text(nbsp); class_desc->push_color(theme_cache.headline_color); diff --git a/editor/docks/inspector_dock.cpp b/editor/docks/inspector_dock.cpp index 2e5185b8e76..c358187f5bd 100644 --- a/editor/docks/inspector_dock.cpp +++ b/editor/docks/inspector_dock.cpp @@ -337,7 +337,7 @@ void InspectorDock::_prepare_history() { already.insert(id); - Ref icon = EditorNode::get_singleton()->get_object_icon(obj, "Object"); + Ref icon = EditorNode::get_singleton()->get_object_icon(obj); String text; if (obj->has_method("_get_editor_name")) { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 83f1a25c7d6..3307de3c258 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5266,7 +5266,7 @@ void EditorNode::_pick_main_scene_custom_action(const String &p_custom_action_na } } -Ref EditorNode::_get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback, bool p_fallback_script_to_theme) { +Ref EditorNode::_get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback, bool p_fallback_script_to_theme, bool p_skip_fallback_virtual) { ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty."); EditorData &ed = EditorNode::get_editor_data(); @@ -5289,8 +5289,9 @@ Ref EditorNode::_get_class_or_script_icon(const String &p_class, cons base_type = scr->get_instance_base_type(); } } - if (theme.is_valid() && theme->has_icon(base_type, EditorStringName(EditorIcons))) { - return theme->get_icon(base_type, EditorStringName(EditorIcons)); + if (theme.is_valid()) { + bool instantiable = !ClassDB::is_virtual(p_class) && ClassDB::can_instantiate(p_class); + return _get_class_or_script_icon(base_type, "", "", false, p_skip_fallback_virtual || instantiable); } } } @@ -5324,11 +5325,20 @@ Ref EditorNode::_get_class_or_script_icon(const String &p_class, cons // If the fallback is empty or wasn't found, use the default fallback. if (ClassDB::class_exists(p_class)) { - bool instantiable = !ClassDB::is_virtual(p_class) && ClassDB::can_instantiate(p_class); - if (ClassDB::is_parent_class(p_class, SNAME("Node"))) { - return theme->get_icon(instantiable ? "Node" : "NodeDisabled", EditorStringName(EditorIcons)); - } else { - return theme->get_icon(instantiable ? "Object" : "ObjectDisabled", EditorStringName(EditorIcons)); + if (!p_skip_fallback_virtual) { + bool instantiable = !ClassDB::is_virtual(p_class) && ClassDB::can_instantiate(p_class); + if (!instantiable) { + if (ClassDB::is_parent_class(p_class, SNAME("Node"))) { + return theme->get_icon("NodeDisabled", EditorStringName(EditorIcons)); + } else { + return theme->get_icon("ObjectDisabled", EditorStringName(EditorIcons)); + } + } + } + StringName parent = ClassDB::get_parent_class_nocheck(p_class); + if (parent) { + // Skip virtual class if `p_skip_fallback_virtual` is true or `p_class` is instantiable. + return _get_class_or_script_icon(parent, "", "", false, true); } } } diff --git a/editor/editor_node.h b/editor/editor_node.h index c0b7f4b2289..35a89c13c46 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -696,7 +696,7 @@ private: void _feature_profile_changed(); bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class); - Ref _get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback = "Object", bool p_fallback_script_to_theme = false); + Ref _get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback = "", bool p_fallback_script_to_theme = false, bool p_skip_fallback_virtual = false); Ref _get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const; void _pick_main_scene_custom_action(const String &p_custom_action_name); @@ -938,7 +938,7 @@ public: Ref