Skip to content

Commit 72a1b5a

Browse files
committed
Merge pull request #108607 from beicause/icon-parent-class-by-default
Fall back to parent class icon by default for GDExtension
2 parents 35928c5 + ce2fae7 commit 72a1b5a

19 files changed

+41
-31
lines changed

editor/animation/animation_bezier_editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
412412
if (node) {
413413
int ofs = 0;
414414

415-
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node, "Node");
415+
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node);
416416

417417
text = node->get_name();
418418
ofs += h_separation;

editor/animation/animation_blend_tree_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano
858858

859859
if (base->has_node(accum)) {
860860
Node *node = base->get_node(accum);
861-
ti->set_icon(0, EditorNode::get_singleton()->get_object_icon(node, "Node"));
861+
ti->set_icon(0, EditorNode::get_singleton()->get_object_icon(node));
862862
}
863863

864864
} else {

editor/animation/animation_track_editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ void AnimationTrackEdit::_notification(int p_what) {
21772177
}
21782178
text_color.a *= 0.7;
21792179
} else if (node) {
2180-
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node, "Node");
2180+
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node);
21812181
const Vector2 icon_size = Vector2(1, 1) * get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
21822182

21832183
icon_rect = Rect2(Point2(ofs, (get_size().height - check->get_height()) / 2).round(), icon->get_size());
@@ -5110,7 +5110,7 @@ void AnimationTrackEditor::_update_tracks() {
51105110
if (root) {
51115111
Node *n = root->get_node_or_null(base_path);
51125112
if (n) {
5113-
icon = EditorNode::get_singleton()->get_object_icon(n, "Node");
5113+
icon = EditorNode::get_singleton()->get_object_icon(n);
51145114
name = n->get_name();
51155115
tooltip = String(root->get_path_to(n));
51165116
}

editor/debugger/editor_debugger_tree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
258258
} else {
259259
item->set_tooltip_text(0, node.name + "\n" + TTR("Instance:") + " " + node.scene_file_path + "\n" + TTR("Type:") + " " + node.type_name);
260260
}
261-
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(node.type_name, "");
261+
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(node.type_name);
262262
if (icon.is_valid()) {
263263
item->set_icon(0, icon);
264264
}

editor/doc/editor_help.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ void EditorHelp::_update_doc() {
974974
_push_title_font();
975975

976976
class_desc->add_text(TTR("Class:") + " ");
977-
_add_type_icon(edited_class, theme_cache.doc_title_font_size, "Object");
977+
_add_type_icon(edited_class, theme_cache.doc_title_font_size, "");
978978
class_desc->add_text(nbsp);
979979

980980
class_desc->push_color(theme_cache.headline_color);

editor/docks/inspector_dock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void InspectorDock::_prepare_history() {
337337

338338
already.insert(id);
339339

340-
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj, "Object");
340+
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj);
341341

342342
String text;
343343
if (obj->has_method("_get_editor_name")) {

editor/editor_node.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5266,7 +5266,7 @@ void EditorNode::_pick_main_scene_custom_action(const String &p_custom_action_na
52665266
}
52675267
}
52685268

5269-
Ref<Texture2D> 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) {
5269+
Ref<Texture2D> 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) {
52705270
ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty.");
52715271
EditorData &ed = EditorNode::get_editor_data();
52725272

@@ -5289,8 +5289,9 @@ Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, cons
52895289
base_type = scr->get_instance_base_type();
52905290
}
52915291
}
5292-
if (theme.is_valid() && theme->has_icon(base_type, EditorStringName(EditorIcons))) {
5293-
return theme->get_icon(base_type, EditorStringName(EditorIcons));
5292+
if (theme.is_valid()) {
5293+
bool instantiable = !ClassDB::is_virtual(p_class) && ClassDB::can_instantiate(p_class);
5294+
return _get_class_or_script_icon(base_type, "", "", false, p_skip_fallback_virtual || instantiable);
52945295
}
52955296
}
52965297
}
@@ -5324,11 +5325,20 @@ Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, cons
53245325

53255326
// If the fallback is empty or wasn't found, use the default fallback.
53265327
if (ClassDB::class_exists(p_class)) {
5327-
bool instantiable = !ClassDB::is_virtual(p_class) && ClassDB::can_instantiate(p_class);
5328-
if (ClassDB::is_parent_class(p_class, SNAME("Node"))) {
5329-
return theme->get_icon(instantiable ? "Node" : "NodeDisabled", EditorStringName(EditorIcons));
5330-
} else {
5331-
return theme->get_icon(instantiable ? "Object" : "ObjectDisabled", EditorStringName(EditorIcons));
5328+
if (!p_skip_fallback_virtual) {
5329+
bool instantiable = !ClassDB::is_virtual(p_class) && ClassDB::can_instantiate(p_class);
5330+
if (!instantiable) {
5331+
if (ClassDB::is_parent_class(p_class, SNAME("Node"))) {
5332+
return theme->get_icon("NodeDisabled", EditorStringName(EditorIcons));
5333+
} else {
5334+
return theme->get_icon("ObjectDisabled", EditorStringName(EditorIcons));
5335+
}
5336+
}
5337+
}
5338+
StringName parent = ClassDB::get_parent_class_nocheck(p_class);
5339+
if (parent) {
5340+
// Skip virtual class if `p_skip_fallback_virtual` is true or `p_class` is instantiable.
5341+
return _get_class_or_script_icon(parent, "", "", false, true);
53325342
}
53335343
}
53345344
}

editor/editor_node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ class EditorNode : public Node {
696696
void _feature_profile_changed();
697697
bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
698698

699-
Ref<Texture2D> _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);
699+
Ref<Texture2D> _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);
700700
Ref<Texture2D> _get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
701701

702702
void _pick_main_scene_custom_action(const String &p_custom_action_name);
@@ -938,7 +938,7 @@ class EditorNode : public Node {
938938

939939
Ref<Script> get_object_custom_type_base(const Object *p_object) const;
940940
StringName get_object_custom_type_name(const Object *p_object) const;
941-
Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
941+
Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "");
942942
Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "");
943943

944944
bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);

editor/inspector/editor_inspector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ void EditorInspectorCategory::_update_icon() {
18861886
if (scr.is_valid()) {
18871887
StringName script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path());
18881888
if (script_name == StringName()) {
1889-
icon = EditorNode::get_singleton()->get_object_icon(scr.ptr(), "Object");
1889+
icon = EditorNode::get_singleton()->get_object_icon(scr.ptr());
18901890
} else {
18911891
icon = EditorNode::get_singleton()->get_class_icon(script_name);
18921892
}

editor/inspector/editor_properties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3082,7 +3082,7 @@ void EditorPropertyNodePath::update_property() {
30823082
}
30833083

30843084
assign->set_text(target_node->get_name());
3085-
assign->set_button_icon(EditorNode::get_singleton()->get_object_icon(target_node, "Node"));
3085+
assign->set_button_icon(EditorNode::get_singleton()->get_object_icon(target_node));
30863086
}
30873087

30883088
void EditorPropertyNodePath::setup(const Vector<StringName> &p_valid_types, bool p_use_path_from_scene_root, bool p_editing_node) {

0 commit comments

Comments
 (0)