Skip to content

Commit

Permalink
add builtin icons as a fallback option and as a way to use the editor…
Browse files Browse the repository at this point in the history
…'s icons

This check makes it so, in case any custom icon finding or opening were to fail, it fallbacks on a builtin icon in the theme with the same name. This way, we can specify an icon that's already in the engine instead of having to provide it. For example, if you wanted your CustomNode icon to be that of a CharacterBody2D, you could specify it as a path with "CharacterBody2D".
  • Loading branch information
sylbeth authored Dec 12, 2024
1 parent 3877573 commit 2a62742
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4846,6 +4846,17 @@ Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, cons
if (theme->has_icon(p_class, EditorStringName(EditorIcons))) {
return theme->get_icon(p_class, EditorStringName(EditorIcons));
}

// If there is a path associated with the node but there was no icon there or it was invalid.
// Then it takes the basename of the file and, if it's the name of an icon in the theme, it uses that instead as a fallback.
// This enables using "Node2D" as a valid path to get the icon without having to copy it and have it inside the project folder.
if (GDExtensionManager::get_singleton()->class_has_icon_path(p_class)) {
String icon_name = GDExtensionManager::get_singleton()
->class_get_icon_path(p_class).get_file().get_basename();
if (theme->has_icon(icon_path, EditorStringName(EditorIcons))) {
return theme->get_icon(icon_path, EditorStringName(EditorIcons));
}
}

if (!p_fallback.is_empty() && theme->has_icon(p_fallback, EditorStringName(EditorIcons))) {
return theme->get_icon(p_fallback, EditorStringName(EditorIcons));
Expand Down

0 comments on commit 2a62742

Please sign in to comment.