From 834139664027d0eef8a1aabb89bb74c4c6f2d537 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 26 Aug 2023 19:42:17 +0200 Subject: [PATCH] Fixes to filter popup and task palette --- editor/limbo_ai_editor_plugin.cpp | 2 +- editor/task_palette.cpp | 40 ++++++++++++++++++------------- editor/task_palette.h | 4 ++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 66d3030..a7db7fc 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -496,7 +496,7 @@ void LimboAIEditor::_on_tree_task_double_clicked() { } void LimboAIEditor::_on_visibility_changed() { - if (task_tree->is_visible()) { + if (task_tree->is_visible_in_tree()) { Ref sel = task_tree->get_selected(); if (sel.is_valid()) { EditorNode::get_singleton()->edit_resource(sel); diff --git a/editor/task_palette.cpp b/editor/task_palette.cpp index 0b1d799..c94bd40 100644 --- a/editor/task_palette.cpp +++ b/editor/task_palette.cpp @@ -199,19 +199,6 @@ void TaskPalette::_apply_filter(const String &p_text) { } } -void TaskPalette::_show_filter_popup() { - _update_filter_popup(); - - category_list->reset_size(); - category_scroll->set_custom_minimum_size(category_list->get_size() + Size2(8, 8)); - - Rect2i rect = tool_filters->get_screen_rect(); - rect.position.y += rect.size.height; - rect.size.height = 0; - filter_popup->reset_size(); - filter_popup->popup(rect); -} - void TaskPalette::_update_filter_popup() { switch (filter_settings.type_filter) { case FilterSettings::TypeFilter::TYPE_ALL: { @@ -237,12 +224,15 @@ void TaskPalette::_update_filter_popup() { } break; } - for (int i = 0; i < category_list->get_child_count(); i++) { - category_list->get_child(i)->queue_free(); + while (category_list->get_child_count() > 0) { + Node *item = category_list->get_child(0); + category_list->remove_child(item); + item->queue_free(); } for (String &cat : LimboTaskDB::get_categories()) { CheckBox *category_item = memnew(CheckBox); category_item->set_text(cat); + category_item->set_focus_mode(FocusMode::FOCUS_NONE); category_item->set_pressed_no_signal(LOGICAL_XOR( filter_settings.excluded_categories.has(cat), filter_settings.category_filter == FilterSettings::CategoryFilter::CATEGORY_INCLUDE)); @@ -250,9 +240,25 @@ void TaskPalette::_update_filter_popup() { category_list->add_child(category_item); } + category_list->reset_size(); + Size2 size = category_list->get_size() + Size2(8, 8); + size.width = MIN(size.width, 400 * EDSCALE); + size.height = MIN(size.height, 600 * EDSCALE); + category_scroll->set_custom_minimum_size(size); + category_choice->set_visible(filter_settings.category_filter != FilterSettings::CATEGORY_ALL); } +void TaskPalette::_show_filter_popup() { + _update_filter_popup(); + + Rect2i rect = tool_filters->get_screen_rect(); + rect.position.y += rect.size.height; + rect.size.height = 0; + filter_popup->reset_size(); + filter_popup->popup(rect); +} + void TaskPalette::_category_filter_changed() { if (category_all->is_pressed()) { filter_settings.category_filter = FilterSettings::CategoryFilter::CATEGORY_ALL; @@ -305,7 +311,7 @@ void TaskPalette::_filter_data_changed() { call_deferred(SNAME("refresh")); } -void TaskPalette::_draw_category_choice_background() { +void TaskPalette::_draw_filter_popup_background() { category_choice_background->draw(category_choice->get_canvas_item(), Rect2(Point2(), category_choice->get_size())); } @@ -571,7 +577,7 @@ TaskPalette::TaskPalette() { category_filter->add_child(category_exclude); category_choice = memnew(VBoxContainer); - category_choice->connect("draw", callable_mp(this, &TaskPalette::_draw_category_choice_background)); + category_choice->connect("draw", callable_mp(this, &TaskPalette::_draw_filter_popup_background)); vbox->add_child(category_choice); HBoxContainer *selection_controls = memnew(HBoxContainer); diff --git a/editor/task_palette.h b/editor/task_palette.h index a0b9f63..56518d9 100644 --- a/editor/task_palette.h +++ b/editor/task_palette.h @@ -109,14 +109,14 @@ private: void _on_task_button_pressed(const String &p_task); void _on_task_button_rmb(const String &p_task); void _apply_filter(const String &p_text); - void _show_filter_popup(); void _update_filter_popup(); + void _show_filter_popup(); void _type_filter_changed(); void _category_filter_changed(); void _set_all_filter_categories(bool p_selected); void _category_item_toggled(bool p_pressed, const String &p_category); void _filter_data_changed(); - void _draw_category_choice_background(); + void _draw_filter_popup_background(); _FORCE_INLINE_ void _set_category_excluded(const String &p_category, bool p_excluded) { if (p_excluded) {