1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #109203 from IphStich/fix_dialog_inherits_abstract

Fix inheriting from abstract classes dialog
This commit is contained in:
Thaddeus Crews
2025-08-07 10:40:34 -05:00
3 changed files with 12 additions and 3 deletions

View File

@@ -76,6 +76,10 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const St
} }
} }
void CreateDialog::for_inherit() {
allow_abstract_scripts = true;
}
void CreateDialog::_fill_type_list() { void CreateDialog::_fill_type_list() {
List<StringName> complete_type_list; List<StringName> complete_type_list;
ClassDB::get_class_list(&complete_type_list); ClassDB::get_class_list(&complete_type_list);
@@ -222,7 +226,7 @@ bool CreateDialog::_should_hide_type(const StringName &p_type) const {
// Abstract scripts cannot be instantiated. // Abstract scripts cannot be instantiated.
String path = ScriptServer::get_global_class_path(p_type); String path = ScriptServer::get_global_class_path(p_type);
Ref<Script> scr = ResourceLoader::load(path, "Script"); Ref<Script> scr = ResourceLoader::load(path, "Script");
return scr.is_null() || scr->is_abstract(); return scr.is_null() || (!allow_abstract_scripts && scr->is_abstract());
} }
return false; return false;
@@ -363,7 +367,9 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN
type_name = p_type; type_name = p_type;
text = p_type; text = p_type;
is_abstract = ScriptServer::is_global_class_abstract(p_type); if (!allow_abstract_scripts) {
is_abstract = ScriptServer::is_global_class_abstract(p_type);
}
String tooltip = TTR("Script path: %s"); String tooltip = TTR("Script path: %s");
bool is_tool = ScriptServer::is_global_class_tool(p_type); bool is_tool = ScriptServer::is_global_class_tool(p_type);
@@ -392,7 +398,7 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN
r_item->set_metadata(0, meta); r_item->set_metadata(0, meta);
bool can_instantiate = (p_type_category == TypeCategory::CPP_TYPE && ClassDB::can_instantiate(p_type)) || bool can_instantiate = (p_type_category == TypeCategory::CPP_TYPE && ClassDB::can_instantiate(p_type)) ||
(p_type_category == TypeCategory::OTHER_TYPE && !is_abstract); (p_type_category == TypeCategory::OTHER_TYPE && !(!allow_abstract_scripts && is_abstract));
bool instantiable = can_instantiate && !(ClassDB::class_exists(p_type) && ClassDB::is_virtual(p_type)); bool instantiable = can_instantiate && !(ClassDB::class_exists(p_type) && ClassDB::is_virtual(p_type));
r_item->set_meta(SNAME("__instantiable"), instantiable); r_item->set_meta(SNAME("__instantiable"), instantiable);

View File

@@ -56,6 +56,7 @@ class CreateDialog : public ConfirmationDialog {
String base_type; String base_type;
bool is_base_type_node = false; bool is_base_type_node = false;
bool allow_abstract_scripts = false;
String icon_fallback; String icon_fallback;
String preferred_search_result_type; String preferred_search_result_type;
@@ -125,6 +126,7 @@ public:
void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; } void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_current_type = "", const String &p_current_name = ""); void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_current_type = "", const String &p_current_name = "");
void for_inherit();
CreateDialog(); CreateDialog();
}; };

View File

@@ -994,6 +994,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
select_class = memnew(CreateDialog); select_class = memnew(CreateDialog);
select_class->connect("create", callable_mp(this, &ScriptCreateDialog::_create)); select_class->connect("create", callable_mp(this, &ScriptCreateDialog::_create));
select_class->for_inherit();
add_child(select_class); add_child(select_class);
file_browse = memnew(EditorFileDialog); file_browse = memnew(EditorFileDialog);