From e73d4b095904ced37a03c8a437d111fa69d7bf60 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 28 Aug 2023 11:39:56 +0200 Subject: [PATCH] TaskPalette: Remember filter settings in a project config. Also, fixes ConfigFile usage without Ref. --- editor/limbo_ai_editor_plugin.cpp | 16 +++++---- editor/task_palette.cpp | 59 +++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index a7db7fc..0e33d31 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -736,18 +736,20 @@ void LimboAIEditor::_update_banners() { void LimboAIEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - ConfigFile conf; + Ref cf; + cf.instantiate(); String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg"); - if (conf.load(conf_path) == OK) { - hsc->set_split_offset(conf.get_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset())); + if (cf->load(conf_path) == OK) { + hsc->set_split_offset(cf->get_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset())); } } break; case NOTIFICATION_EXIT_TREE: { - ConfigFile conf; + Ref cf; + cf.instantiate(); String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg"); - conf.load(conf_path); - conf.set_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset()); - conf.save(conf_path); + cf->load(conf_path); + cf->set_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset()); + cf->save(conf_path); } break; case NOTIFICATION_THEME_CHANGED: { new_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("New"), SNAME("EditorIcons"))); diff --git a/editor/task_palette.cpp b/editor/task_palette.cpp index 084312e..df92812 100644 --- a/editor/task_palette.cpp +++ b/editor/task_palette.cpp @@ -330,10 +330,11 @@ void TaskPalette::refresh() { HashSet collapsed_sections; if (sections->get_child_count() == 0) { // Restore collapsed state from config. - ConfigFile conf; + Ref cf; + cf.instantiate(); String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg"); - if (conf.load(conf_path) == OK) { - Variant value = conf.get_value("bt_editor", "collapsed_sections", Array()); + if (cf->load(conf_path) == OK) { + Variant value = cf->get_value("task_palette", "collapsed_sections", Array()); if (value.is_array()) { Array arr = value; for (int i = 0; i < arr.size(); i++) { @@ -416,10 +417,39 @@ void TaskPalette::refresh() { void TaskPalette::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_EXIT_TREE: { - if (sections->get_child_count() == 0) { - return; + case NOTIFICATION_ENTER_TREE: { + Ref cf; + cf.instantiate(); + String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg"); + if (cf->load(conf_path) == OK) { + Variant value = cf->get_value("task_palette", "type_filter", FilterSettings::TypeFilter(0)); + if (value.is_num()) { + filter_settings.type_filter = (FilterSettings::TypeFilter)(int)value; + } + + value = cf->get_value("task_palette", "category_filter", FilterSettings::CategoryFilter(0)); + if (value.is_num()) { + filter_settings.category_filter = (FilterSettings::CategoryFilter)(int)value; + } + + value = cf->get_value("task_palette", "excluded_categories", Array()); + if (value.is_array()) { + Array arr = value; + for (int i = 0; i < arr.size(); i++) { + if (arr[i].get_type() == Variant::STRING) { + filter_settings.excluded_categories.insert(arr[i]); + } + } + } } + _update_filter_button(); + } break; + case NOTIFICATION_EXIT_TREE: { + Ref cf; + cf.instantiate(); + String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg"); + cf->load(conf_path); + Array collapsed_sections; for (int i = 0; i < sections->get_child_count(); i++) { TaskPaletteSection *sec = Object::cast_to(sections->get_child(i)); @@ -427,11 +457,18 @@ void TaskPalette::_notification(int p_what) { collapsed_sections.push_back(sec->get_category_name()); } } - ConfigFile conf; - String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg"); - conf.load(conf_path); - conf.set_value("bt_editor", "collapsed_sections", collapsed_sections); - conf.save(conf_path); + cf->set_value("task_palette", "collapsed_sections", collapsed_sections); + + cf->set_value("task_palette", "type_filter", filter_settings.type_filter); + cf->set_value("task_palette", "category_filter", filter_settings.category_filter); + + Array excluded_categories; + for (const String &cat : filter_settings.excluded_categories) { + excluded_categories.append(cat); + } + cf->set_value("task_palette", "excluded_categories", excluded_categories); + + cf->save(conf_path); } break; case NOTIFICATION_THEME_CHANGED: { tool_filters->set_icon(get_theme_icon(SNAME("AnimationFilter"), SNAME("EditorIcons")));