mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 13:21:10 +01:00
Cache script icons in editor
(cherry picked from commit 3f50dad460dc2239343e0eb9ba8fb63b8fd20b88)
This commit is contained in:
parent
850a84584d
commit
89b5c84fd1
@ -3244,6 +3244,9 @@ 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.
|
||||
script_icon_cache.clear();
|
||||
|
||||
if (editor_data.get_edited_scene() == index) {
|
||||
//Scene to remove is current scene
|
||||
_remove_edited_scene(p_change_tab);
|
||||
@ -3889,7 +3892,7 @@ void EditorNode::_pick_main_scene_custom_action(const String &p_custom_action_na
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) const {
|
||||
Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) {
|
||||
ERR_FAIL_COND_V(!p_object || !gui_base, nullptr);
|
||||
|
||||
Ref<Script> script = p_object->get_script();
|
||||
@ -3897,13 +3900,14 @@ Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p
|
||||
script = p_object;
|
||||
}
|
||||
|
||||
if (script.is_valid()) {
|
||||
if (script.is_valid() && !script_icon_cache.has(script)) {
|
||||
Ref<Script> base_script = script;
|
||||
while (base_script.is_valid()) {
|
||||
StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path());
|
||||
String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name);
|
||||
Ref<ImageTexture> icon = _load_custom_class_icon(icon_path);
|
||||
if (icon.is_valid()) {
|
||||
script_icon_cache[script] = icon;
|
||||
return icon;
|
||||
}
|
||||
|
||||
@ -3913,12 +3917,18 @@ Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p
|
||||
const Vector<EditorData::CustomType> &types = EditorNode::get_editor_data().get_custom_types()[base];
|
||||
for (int i = 0; i < types.size(); ++i) {
|
||||
if (types[i].script == base_script && types[i].icon.is_valid()) {
|
||||
script_icon_cache[script] = types[i].icon;
|
||||
return types[i].icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
base_script = base_script->get_base_script();
|
||||
}
|
||||
|
||||
// If no icon found, cache it as null.
|
||||
script_icon_cache[script] = Ref<Texture>();
|
||||
} else if (script.is_valid() && script_icon_cache.has(script) && script_icon_cache[script].is_valid()) {
|
||||
return script_icon_cache[script];
|
||||
}
|
||||
|
||||
// should probably be deprecated in 4.x
|
||||
|
@ -584,6 +584,7 @@ private:
|
||||
Set<EditorFileDialog *> editor_file_dialogs;
|
||||
|
||||
Map<String, Ref<Texture>> icon_type_cache;
|
||||
Map<Ref<Script>, Ref<Texture>> script_icon_cache;
|
||||
void _build_icon_type_cache();
|
||||
|
||||
bool _initializing_addons;
|
||||
@ -838,7 +839,7 @@ public:
|
||||
Ref<Theme> get_editor_theme() const { return theme; }
|
||||
Ref<Script> get_object_custom_type_base(const Object *p_object) const;
|
||||
StringName get_object_custom_type_name(const Object *p_object) const;
|
||||
Ref<Texture> get_object_icon(const Object *p_object, const String &p_fallback = "Object") const;
|
||||
Ref<Texture> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
|
||||
Ref<Texture> get_class_icon(const String &p_class, const String &p_fallback = "Object") const;
|
||||
|
||||
void show_accept(const String &p_text, const String &p_title);
|
||||
|
Loading…
Reference in New Issue
Block a user