From 5317029012248cf7e59f59d54bbb7ff8bf16055c Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Sat, 27 Jul 2024 15:05:33 -0400 Subject: [PATCH] GH-603 Permit selecting abstract types for variable definitions --- .../property_type_button_property.cpp | 1 + src/editor/select_type_dialog.cpp | 20 +++++++++++++------ src/editor/select_type_dialog.h | 5 +++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/editor/inspector/property_type_button_property.cpp b/src/editor/inspector/property_type_button_property.cpp index 83fbb089..0bb1b291 100644 --- a/src/editor/inspector/property_type_button_property.cpp +++ b/src/editor/inspector/property_type_button_property.cpp @@ -93,6 +93,7 @@ void OrchestratorEditorPropertyVariableClassification::_notification(int p_what) _dialog->set_popup_title("Select variable type"); _dialog->set_data_suffix("variable_type"); _dialog->set_base_type(_base_type); + _dialog->set_allow_abstract_types(true); add_child(_dialog); _dialog->connect("selected", callable_mp(this, &OrchestratorEditorPropertyVariableClassification::_search_selected)); diff --git a/src/editor/select_type_dialog.cpp b/src/editor/select_type_dialog.cpp index 0fa242e2..2bde4536 100644 --- a/src/editor/select_type_dialog.cpp +++ b/src/editor/select_type_dialog.cpp @@ -261,15 +261,23 @@ Vector> OrchestratorSelectTypeSe item->icon = SceneUtils::get_class_icon(clazz_name); item->parent = parent; - if (!ClassDB::can_instantiate(clazz_name)) + if (!_allow_abstract_types) { - item->selectable = false; - item->disabled = true; + if (!ClassDB::can_instantiate(clazz_name)) + { + item->selectable = false; + item->disabled = true; + } + else if (Engine::get_singleton()->get_singleton_list().has(clazz_name)) + { + item->selectable = false; + item->disabled = true; + } } - else if (Engine::get_singleton()->get_singleton_list().has(clazz_name)) + else { - item->selectable = false; - item->disabled = true; + item->selectable = true; + item->disabled = false; } if (ScriptServer::is_global_class(clazz_name)) diff --git a/src/editor/select_type_dialog.h b/src/editor/select_type_dialog.h index 5b787db4..013e31b0 100644 --- a/src/editor/select_type_dialog.h +++ b/src/editor/select_type_dialog.h @@ -45,6 +45,7 @@ class OrchestratorSelectTypeSearchDialog : public OrchestratorEditorSearchDialog HashSet _exclusions; //! Set of types to be excluded Vector _variant_type_names; //! All valid variant type names bool _is_base_type_node{ false }; //! Specifies if base type is a Node + bool _allow_abstract_types{ false }; //! Allow selecting abstract types String _base_type; //! The base type String _fallback_icon{ "Object" }; //! The fallback icon String _preferred_search_result_type; //! The preferred search result type @@ -101,6 +102,10 @@ class OrchestratorSelectTypeSearchDialog : public OrchestratorEditorSearchDialog /// @param p_data_suffix the data file suffix void set_data_suffix(const String& p_data_suffix) { _data_suffix = p_data_suffix; } + /// Sets whether abstract types should be selectable + /// @param p_allow_abstract_types true to allow selecting abstract types + void set_allow_abstract_types(bool p_allow_abstract_types) { _allow_abstract_types = p_allow_abstract_types; } + /// Sets the dialog's title /// @param p_title the title to be used void set_popup_title(const String& p_title) { _title = p_title; }