Răsfoiți Sursa

Don't grab theme icons for scripts

(cherry picked from commit 51f92d1100759f97b08aaa8f9b7da71e462e561e)
kobewi 2 ani în urmă
părinte
comite
a5b59b596f
3 a modificat fișierele cu 13 adăugiri și 12 ștergeri
  1. 0 9
      editor/editor_data.cpp
  2. 12 2
      editor/editor_node.cpp
  3. 1 1
      editor/editor_node.h

+ 0 - 9
editor/editor_data.cpp

@@ -1154,15 +1154,6 @@ Ref<Texture2D> EditorData::get_script_icon(const Ref<Script> &p_script) {
 		return 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.
 	// If no icon found, cache it as null.
 	_script_icon_cache[p_script] = Ref<Texture>();
 	_script_icon_cache[p_script] = Ref<Texture>();
 	return nullptr;
 	return nullptr;

+ 12 - 2
editor/editor_node.cpp

@@ -4239,7 +4239,7 @@ void EditorNode::_pick_main_scene_custom_action(const String &p_custom_action_na
 	}
 	}
 }
 }
 
 
-Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, const Ref<Script> &p_script, const String &p_fallback) {
+Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, const Ref<Script> &p_script, const String &p_fallback, bool p_fallback_script_to_theme) {
 	ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty.");
 	ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty.");
 	EditorData &ed = EditorNode::get_editor_data();
 	EditorData &ed = EditorNode::get_editor_data();
 
 
@@ -4249,6 +4249,16 @@ Ref<Texture2D> EditorNode::_get_class_or_script_icon(const String &p_class, cons
 		if (script_icon.is_valid()) {
 		if (script_icon.is_valid()) {
 			return script_icon;
 			return script_icon;
 		}
 		}
+
+		if (p_fallback_script_to_theme) {
+			// Look for the base type in the editor theme.
+			// This is only relevant for built-in classes.
+			String base_type;
+			p_script->get_language()->get_global_class_name(p_script->get_path(), &base_type);
+			if (gui_base && gui_base->has_theme_icon(base_type, SNAME("EditorIcons"))) {
+				return gui_base->get_theme_icon(base_type, SNAME("EditorIcons"));
+			}
+		}
 	}
 	}
 
 
 	// Script was not valid or didn't yield any useful values, try the class name
 	// Script was not valid or didn't yield any useful values, try the class name
@@ -4301,7 +4311,7 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
 		scr = EditorNode::get_editor_data().script_class_load_script(p_class);
 		scr = EditorNode::get_editor_data().script_class_load_script(p_class);
 	}
 	}
 
 
-	return _get_class_or_script_icon(p_class, scr, p_fallback);
+	return _get_class_or_script_icon(p_class, scr, p_fallback, true);
 }
 }
 
 
 bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringName &p_class) {
 bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringName &p_class) {

+ 1 - 1
editor/editor_node.h

@@ -687,7 +687,7 @@ private:
 	void _feature_profile_changed();
 	void _feature_profile_changed();
 	bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
 	bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
 
 
-	Ref<Texture2D> _get_class_or_script_icon(const String &p_class, const Ref<Script> &p_script, const String &p_fallback = "Object");
+	Ref<Texture2D> _get_class_or_script_icon(const String &p_class, const Ref<Script> &p_script, const String &p_fallback = "Object", bool p_fallback_script_to_theme = false);
 
 
 	void _pick_main_scene_custom_action(const String &p_custom_action_name);
 	void _pick_main_scene_custom_action(const String &p_custom_action_name);