Skip to content

Commit

Permalink
Merge pull request #1 from sylbeth/editor-icon-auto-fallback
Browse files Browse the repository at this point in the history
Add builtin icons as a fallback option and as a way to use the editor's icons
  • Loading branch information
sylbeth authored Dec 12, 2024
2 parents 3877573 + 2a62742 commit 41c5bc5
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 41c5bc5

Please sign in to comment.