mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
Merge pull request #78670 from KoBeWi/cache_with_full_power
Improve script icon cache
This commit is contained in:
commit
d08ba5f3dc
@ -1114,7 +1114,9 @@ Ref<Texture2D> EditorData::_load_script_icon(const String &p_path) const {
|
||||
|
||||
Ref<Texture2D> EditorData::get_script_icon(const Ref<Script> &p_script) {
|
||||
// Take from the local cache, if available.
|
||||
if (_script_icon_cache.has(p_script) && _script_icon_cache[p_script].is_valid()) {
|
||||
if (_script_icon_cache.has(p_script)) {
|
||||
// Can be an empty value if we can't resolve any icon for this script.
|
||||
// An empty value is still cached to avoid unnecessary attempts at resolving it again.
|
||||
return _script_icon_cache[p_script];
|
||||
}
|
||||
|
||||
@ -1141,6 +1143,27 @@ Ref<Texture2D> EditorData::get_script_icon(const Ref<Script> &p_script) {
|
||||
base_scr = base_scr->get_base_script();
|
||||
}
|
||||
|
||||
// No custom icon was found in the inheritance chain, so check the base
|
||||
// class of the script instead.
|
||||
String base_type;
|
||||
p_script->get_language()->get_global_class_name(p_script->get_path(), &base_type);
|
||||
|
||||
// Check if the base type is an extension-defined type.
|
||||
Ref<Texture2D> ext_icon = extension_class_get_icon(base_type);
|
||||
if (ext_icon.is_valid()) {
|
||||
_script_icon_cache[p_script] = ext_icon;
|
||||
return ext_icon;
|
||||
}
|
||||
|
||||
// Look for the base type in the editor theme.
|
||||
// This is only relevant for built-in classes.
|
||||
const Control *gui_base = EditorNode::get_singleton()->get_gui_base();
|
||||
if (gui_base && gui_base->has_theme_icon(base_type, SNAME("EditorIcons"))) {
|
||||
Ref<Texture2D> theme_icon = gui_base->get_theme_icon(base_type, SNAME("EditorIcons"));
|
||||
_script_icon_cache[p_script] = theme_icon;
|
||||
return theme_icon;
|
||||
}
|
||||
|
||||
// If no icon found, cache it as null.
|
||||
_script_icon_cache[p_script] = Ref<Texture>();
|
||||
return nullptr;
|
||||
|
@ -3408,6 +3408,7 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) {
|
||||
|
||||
void EditorNode::_remove_scene(int index, bool p_change_tab) {
|
||||
// Clear icon cache in case some scripts are no longer needed.
|
||||
// FIXME: Perfectly the cache should never be cleared and only updated on per-script basis, when an icon changes.
|
||||
editor_data.clear_script_icon_cache();
|
||||
|
||||
if (editor_data.get_edited_scene() == index) {
|
||||
@ -4243,23 +4244,6 @@ Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, cons
|
||||
if (script_icon.is_valid()) {
|
||||
return script_icon;
|
||||
}
|
||||
|
||||
// No custom icon was found in the inheritance chain, so check the base
|
||||
// class of the script instead.
|
||||
String base_type;
|
||||
p_script->get_language()->get_global_class_name(p_script->get_path(), &base_type);
|
||||
|
||||
// Check if the base type is an extension-defined type.
|
||||
Ref<Texture2D> ext_icon = ed.extension_class_get_icon(base_type);
|
||||
if (ext_icon.is_valid()) {
|
||||
return ext_icon;
|
||||
}
|
||||
|
||||
// Look for the base type in the editor theme.
|
||||
// This is only relevant for built-in classes.
|
||||
if (gui_base && gui_base->has_theme_icon(base_type, "EditorIcons")) {
|
||||
return gui_base->get_theme_icon(base_type, "EditorIcons");
|
||||
}
|
||||
}
|
||||
|
||||
// Script was not valid or didn't yield any useful values, try the class name
|
||||
|
Loading…
Reference in New Issue
Block a user