Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builtin icons as a fallback option and as a way to use the editor's icons #100298

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading