Skip to content

Commit 7aa331a

Browse files
committed
Merge pull request #109203 from IphStich/fix_dialog_inherits_abstract
Fix inheriting from abstract classes dialog
2 parents b438d21 + 8835ac2 commit 7aa331a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

editor/gui/create_dialog.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const St
7676
}
7777
}
7878

79+
void CreateDialog::for_inherit() {
80+
allow_abstract_scripts = true;
81+
}
82+
7983
void CreateDialog::_fill_type_list() {
8084
List<StringName> complete_type_list;
8185
ClassDB::get_class_list(&complete_type_list);
@@ -222,7 +226,7 @@ bool CreateDialog::_should_hide_type(const StringName &p_type) const {
222226
// Abstract scripts cannot be instantiated.
223227
String path = ScriptServer::get_global_class_path(p_type);
224228
Ref<Script> scr = ResourceLoader::load(path, "Script");
225-
return scr.is_null() || scr->is_abstract();
229+
return scr.is_null() || (!allow_abstract_scripts && scr->is_abstract());
226230
}
227231

228232
return false;
@@ -363,7 +367,9 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN
363367
type_name = p_type;
364368
text = p_type;
365369

366-
is_abstract = ScriptServer::is_global_class_abstract(p_type);
370+
if (!allow_abstract_scripts) {
371+
is_abstract = ScriptServer::is_global_class_abstract(p_type);
372+
}
367373

368374
String tooltip = TTR("Script path: %s");
369375
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
392398
r_item->set_metadata(0, meta);
393399

394400
bool can_instantiate = (p_type_category == TypeCategory::CPP_TYPE && ClassDB::can_instantiate(p_type)) ||
395-
(p_type_category == TypeCategory::OTHER_TYPE && !is_abstract);
401+
(p_type_category == TypeCategory::OTHER_TYPE && !(!allow_abstract_scripts && is_abstract));
396402
bool instantiable = can_instantiate && !(ClassDB::class_exists(p_type) && ClassDB::is_virtual(p_type));
397403

398404
r_item->set_meta(SNAME("__instantiable"), instantiable);

editor/gui/create_dialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class CreateDialog : public ConfirmationDialog {
5656

5757
String base_type;
5858
bool is_base_type_node = false;
59+
bool allow_abstract_scripts = false;
5960
String icon_fallback;
6061
String preferred_search_result_type;
6162

@@ -125,6 +126,7 @@ class CreateDialog : public ConfirmationDialog {
125126
void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
126127

127128
void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_current_type = "", const String &p_current_name = "");
129+
void for_inherit();
128130

129131
CreateDialog();
130132
};

editor/script/script_create_dialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
994994

995995
select_class = memnew(CreateDialog);
996996
select_class->connect("create", callable_mp(this, &ScriptCreateDialog::_create));
997+
select_class->for_inherit();
997998
add_child(select_class);
998999

9991000
file_browse = memnew(EditorFileDialog);

0 commit comments

Comments
 (0)