Skip to content

Commit

Permalink
GH-595 Improve initial rendering of variable type selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jul 29, 2024
1 parent d4f89d8 commit 235cc78
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/editor/inspector/property_type_button_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

void OrchestratorEditorPropertyVariableClassification::_property_selected()
{
_dialog->popup_create(true, true, get_edited_object()->get(get_edited_property()), get_edited_property());
_dialog->popup_create(true, false, get_edited_object()->get(get_edited_property()), get_edited_property());
}

void OrchestratorEditorPropertyVariableClassification::_search_selected()
Expand Down Expand Up @@ -82,7 +82,7 @@ void OrchestratorEditorPropertyVariableClassification::_update_property()

void OrchestratorEditorPropertyVariableClassification::edit()
{
_dialog->popup_create(true, true, get_edited_object()->get(get_edited_property()), get_edited_property());
_dialog->popup_create(true, false, get_edited_object()->get(get_edited_property()), get_edited_property());
}

void OrchestratorEditorPropertyVariableClassification::setup(const String& p_base_type, const String& p_selected_type)
Expand Down
7 changes: 7 additions & 0 deletions src/editor/search/search_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ void OrchestratorEditorSearchDialog::_set_search_item_collapse_state(TreeItem* p
}
else if (p_item->get_parent())
{
if (_search_box->get_text().is_empty() && _should_collapse_on_empty_search())
{
p_item->set_collapsed(true);
return;
}

bool should_collapse = _get_search_item_collapse_suggestion(p_item);

Ref<EditorSettings> settings = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_settings();
Expand Down Expand Up @@ -452,6 +458,7 @@ void OrchestratorEditorSearchDialog::_update_search()

if (_search_box->get_text().is_empty())
{
_favorite->set_pressed_no_signal(false);
_search_options->scroll_to_item(_search_options->get_root());
_search_options->deselect_all();
}
Expand Down
5 changes: 4 additions & 1 deletion src/editor/search/search_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class OrchestratorEditorSearchDialog : public ConfirmationDialog
/// @param p_focus whether to focus to the search box
virtual void _update_search_box(bool p_clear, bool p_replace, const String& p_text, bool p_focus);

/// Whether the dialog should collapse nodes on empty search terms
/// @returns whether to collapse non-root tree nodes when search box is empty, defaults to false.
virtual bool _should_collapse_on_empty_search() const { return false; }

/// Sets the search item's collapse state
/// @param p_item the tree item
virtual void _set_search_item_collapse_state(TreeItem* p_item);
Expand Down Expand Up @@ -210,7 +214,6 @@ class OrchestratorEditorSearchDialog : public ConfirmationDialog
void _select_item(TreeItem* p_item, bool p_center_on_item);

public:

/// Opens the dialog
/// @param p_dont_clear whether the dialog should clear the search field
/// @param p_replace_mode whether the dialog should replace the current type
Expand Down
31 changes: 29 additions & 2 deletions src/editor/select_type_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ bool OrchestratorSelectTypeSearchDialog::_is_preferred(const String& p_type) con
return OrchestratorEditorSearchDialog::_is_preferred(p_type);
}

bool OrchestratorSelectTypeSearchDialog::_should_collapse_on_empty_search() const
{
return _filters->get_selected_id() == FT_ALL_TYPES;
}

bool OrchestratorSelectTypeSearchDialog::_get_search_item_collapse_suggestion(TreeItem* p_item) const
{
if (p_item->get_parent())
Expand All @@ -99,6 +104,28 @@ Vector<Ref<OrchestratorEditorSearchDialog::SearchItem>> OrchestratorSelectTypeSe
root->set_meta("can_instantiate", false);
items.push_back(root);

Ref<SearchItem> global_enums(memnew(SearchItem));
global_enums->path = "Types/Global_Enums";
global_enums->name = "Global Enums";
global_enums->text = "Global Enums";
global_enums->selectable = false;
global_enums->collapsed = false;
global_enums->icon = SceneUtils::get_editor_icon("Enum");
global_enums->set_meta("can_instantiate", false);
global_enums->parent = root;
items.push_back(global_enums);

Ref<SearchItem> global_bitfields(memnew(SearchItem));
global_bitfields->path = "Types/Global_Bitfields";
global_bitfields->name = "Global Bitfields";
global_bitfields->text = "Global Bitfields";
global_bitfields->selectable = false;
global_bitfields->collapsed = false;
global_bitfields->icon = SceneUtils::get_editor_icon("Enum");
global_bitfields->set_meta("can_instantiate", false);
global_bitfields->parent = root;
items.push_back(global_bitfields);

// Basic Types
for (int i = 0; i < Variant::VARIANT_MAX; i++)
{
Expand Down Expand Up @@ -167,12 +194,12 @@ Vector<Ref<OrchestratorEditorSearchDialog::SearchItem>> OrchestratorSelectTypeSe
const EnumInfo& ei = ExtensionDB::get_global_enum(enum_name);

Ref<SearchItem> item(memnew(SearchItem));
item->path = vformat("Types/%s", enum_name);
item->path = vformat("Types/%s/%s", ei.is_bitfield ? "Global_Bitfields" : "Global_Enums", enum_name);
item->name = vformat("%s:%s", ei.is_bitfield ? "bitfield" : "enum", enum_name);
item->text = enum_name;
item->icon = SceneUtils::get_editor_icon("Enum");
item->selectable = true;
item->parent = root;
item->parent = ei.is_bitfield ? global_bitfields : global_enums;
items.push_back(item);
}

Expand Down
1 change: 1 addition & 0 deletions src/editor/select_type_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class OrchestratorSelectTypeSearchDialog : public OrchestratorEditorSearchDialog
protected:
//~ Begin OrchestratorEditorSearchDialog Interface
bool _is_preferred(const String& p_type) const override;
bool _should_collapse_on_empty_search() const override;
bool _get_search_item_collapse_suggestion(TreeItem* p_item) const override;
void _update_help(const Ref<SearchItem>& p_item) override;
Vector<Ref<SearchItem>> _get_search_items() override;
Expand Down

0 comments on commit 235cc78

Please sign in to comment.