Browse Source

Allow class_name scripts to have nested inheritance

George Marques 6 years ago
parent
commit
25f9aee005

+ 1 - 1
core/io/resource_loader.cpp

@@ -946,7 +946,7 @@ void ResourceLoader::add_custom_loaders() {
 	for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
 	for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
 
 
 		StringName class_name = E->get();
 		StringName class_name = E->get();
-		StringName base_class = ScriptServer::get_global_class_base(class_name);
+		StringName base_class = ScriptServer::get_global_class_native_base(class_name);
 
 
 		if (base_class == custom_loader_base_class) {
 		if (base_class == custom_loader_base_class) {
 			String path = ScriptServer::get_global_class_path(class_name);
 			String path = ScriptServer::get_global_class_path(class_name);

+ 1 - 1
core/io/resource_saver.cpp

@@ -249,7 +249,7 @@ void ResourceSaver::add_custom_savers() {
 	for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
 	for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
 
 
 		StringName class_name = E->get();
 		StringName class_name = E->get();
-		StringName base_class = ScriptServer::get_global_class_base(class_name);
+		StringName base_class = ScriptServer::get_global_class_native_base(class_name);
 
 
 		if (base_class == custom_saver_base_class) {
 		if (base_class == custom_saver_base_class) {
 			String path = ScriptServer::get_global_class_path(class_name);
 			String path = ScriptServer::get_global_class_path(class_name);

+ 8 - 0
core/script_language.cpp

@@ -190,6 +190,14 @@ StringName ScriptServer::get_global_class_base(const String &p_class) {
 	ERR_FAIL_COND_V(!global_classes.has(p_class), String());
 	ERR_FAIL_COND_V(!global_classes.has(p_class), String());
 	return global_classes[p_class].base;
 	return global_classes[p_class].base;
 }
 }
+StringName ScriptServer::get_global_class_native_base(const String &p_class) {
+	ERR_FAIL_COND_V(!global_classes.has(p_class), String());
+	String base = global_classes[p_class].base;
+	while (global_classes.has(base)) {
+		base = global_classes[base].base;
+	}
+	return base;
+}
 void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
 void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
 	const StringName *K = NULL;
 	const StringName *K = NULL;
 	List<StringName> classes;
 	List<StringName> classes;

+ 1 - 0
core/script_language.h

@@ -87,6 +87,7 @@ public:
 	static StringName get_global_class_language(const StringName &p_class);
 	static StringName get_global_class_language(const StringName &p_class);
 	static String get_global_class_path(const String &p_class);
 	static String get_global_class_path(const String &p_class);
 	static StringName get_global_class_base(const String &p_class);
 	static StringName get_global_class_base(const String &p_class);
+	static StringName get_global_class_native_base(const String &p_class);
 	static void get_global_class_list(List<StringName> *r_global_classes);
 	static void get_global_class_list(List<StringName> *r_global_classes);
 	static void save_global_classes();
 	static void save_global_classes();
 
 

+ 1 - 1
editor/create_dialog.cpp

@@ -204,7 +204,7 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
 		if (cpp_type) {
 		if (cpp_type) {
 			String cpp_to_select_type = to_select_type;
 			String cpp_to_select_type = to_select_type;
 			if (ScriptServer::is_global_class(to_select_type))
 			if (ScriptServer::is_global_class(to_select_type))
-				cpp_to_select_type = ScriptServer::get_global_class_base(to_select_type);
+				cpp_to_select_type = ScriptServer::get_global_class_native_base(to_select_type);
 			current_item_is_preferred = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(cpp_to_select_type, preferred_search_result_type);
 			current_item_is_preferred = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(cpp_to_select_type, preferred_search_result_type);
 		} else {
 		} else {
 			current_item_is_preferred = ed.script_class_is_parent(p_type, preferred_search_result_type) && !ed.script_class_is_parent(to_select_type, preferred_search_result_type) && search_box->get_text() != to_select_type;
 			current_item_is_preferred = ed.script_class_is_parent(p_type, preferred_search_result_type) && !ed.script_class_is_parent(to_select_type, preferred_search_result_type) && search_box->get_text() != to_select_type;

+ 1 - 1
editor/editor_data.cpp

@@ -895,7 +895,7 @@ StringName EditorData::script_class_get_base(const String &p_class) const {
 
 
 Object *EditorData::script_class_instance(const String &p_class) {
 Object *EditorData::script_class_instance(const String &p_class) {
 	if (ScriptServer::is_global_class(p_class)) {
 	if (ScriptServer::is_global_class(p_class)) {
-		Object *obj = ClassDB::instance(ScriptServer::get_global_class_base(p_class));
+		Object *obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class));
 		if (obj) {
 		if (obj) {
 			RES script = ResourceLoader::load(ScriptServer::get_global_class_path(p_class));
 			RES script = ResourceLoader::load(ScriptServer::get_global_class_path(p_class));
 			if (script.is_valid())
 			if (script.is_valid())

+ 1 - 1
editor/editor_node.cpp

@@ -3354,7 +3354,7 @@ Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_f
 			icon = ResourceLoader::load(icon_path);
 			icon = ResourceLoader::load(icon_path);
 		}
 		}
 		if (!icon.is_valid()) {
 		if (!icon.is_valid()) {
-			icon = gui_base->get_icon(ScriptServer::get_global_class_base(p_class), "EditorIcons");
+			icon = gui_base->get_icon(ScriptServer::get_global_class_native_base(p_class), "EditorIcons");
 		}
 		}
 		return icon;
 		return icon;
 	}
 	}

+ 1 - 1
editor/editor_properties.cpp

@@ -2190,7 +2190,7 @@ void EditorPropertyResource::_menu_option(int p_which) {
 			Object *obj = NULL;
 			Object *obj = NULL;
 
 
 			if (ScriptServer::is_global_class(intype)) {
 			if (ScriptServer::is_global_class(intype)) {
-				obj = ClassDB::instance(ScriptServer::get_global_class_base(intype));
+				obj = ClassDB::instance(ScriptServer::get_global_class_native_base(intype));
 				if (obj) {
 				if (obj) {
 					Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(intype));
 					Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(intype));
 					if (script.is_valid()) {
 					if (script.is_valid()) {

+ 2 - 2
editor/scene_tree_dock.cpp

@@ -827,7 +827,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 			if (TOOL_CREATE_FAVORITE == p_tool) {
 			if (TOOL_CREATE_FAVORITE == p_tool) {
 				String name = selected_favorite_root.get_slicec(' ', 0);
 				String name = selected_favorite_root.get_slicec(' ', 0);
 				if (ScriptServer::is_global_class(name)) {
 				if (ScriptServer::is_global_class(name)) {
-					new_node = Object::cast_to<Node>(ClassDB::instance(ScriptServer::get_global_class_base(name)));
+					new_node = Object::cast_to<Node>(ClassDB::instance(ScriptServer::get_global_class_native_base(name)));
 					Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(name), "Script");
 					Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(name), "Script");
 					if (new_node && script.is_valid()) {
 					if (new_node && script.is_valid()) {
 						new_node->set_script(script.get_ref_ptr());
 						new_node->set_script(script.get_ref_ptr());
@@ -2294,7 +2294,7 @@ void SceneTreeDock::_update_create_root_dialog() {
 					button->set_text(TTR(l));
 					button->set_text(TTR(l));
 					String name = l.get_slicec(' ', 0);
 					String name = l.get_slicec(' ', 0);
 					if (ScriptServer::is_global_class(name))
 					if (ScriptServer::is_global_class(name))
-						name = ScriptServer::get_global_class_base(name);
+						name = ScriptServer::get_global_class_native_base(name);
 					button->set_icon(EditorNode::get_singleton()->get_class_icon(name));
 					button->set_icon(EditorNode::get_singleton()->get_class_icon(name));
 					button->connect("pressed", this, "_favorite_root_selected", make_binds(l));
 					button->connect("pressed", this, "_favorite_root_selected", make_binds(l));
 				}
 				}