Skip to content

Commit

Permalink
GH-603 Permit selecting abstract types for variable definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jul 27, 2024
1 parent 1b1c22c commit 5317029
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/editor/inspector/property_type_button_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
20 changes: 14 additions & 6 deletions src/editor/select_type_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,23 @@ Vector<Ref<OrchestratorEditorSearchDialog::SearchItem>> 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))
Expand Down
5 changes: 5 additions & 0 deletions src/editor/select_type_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class OrchestratorSelectTypeSearchDialog : public OrchestratorEditorSearchDialog
HashSet<StringName> _exclusions; //! Set of types to be excluded
Vector<String> _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
Expand Down Expand Up @@ -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; }
Expand Down

0 comments on commit 5317029

Please sign in to comment.