From 69025254711439913c22d9fd8217e802c0bb0dee Mon Sep 17 00:00:00 2001 From: Salty Panda Date: Mon, 25 Jan 2021 23:16:02 +0100 Subject: [PATCH] Allow for excluding words in recipes filter (#46985) --- src/crafting_gui.cpp | 10 ++++++++++ src/recipe_dictionary.cpp | 3 +++ src/recipe_dictionary.h | 1 + 3 files changed, 14 insertions(+) diff --git a/src/crafting_gui.cpp b/src/crafting_gui.cpp index b16997566dae8..1fd5e6ee8df0f 100644 --- a/src/crafting_gui.cpp +++ b/src/crafting_gui.cpp @@ -769,6 +769,9 @@ const recipe *select_crafting_recipe( int &batch_size ) default: current.clear(); } + } else if( qry_filter_str.size() > 1 && qry_filter_str[0] == '-' ) { + filtered_recipes = filtered_recipes.reduce( qry_filter_str.substr( 1 ), + recipe_subset::search_type::exclude_name, progress_callback ); } else { filtered_recipes = filtered_recipes.reduce( qry_filter_str ); } @@ -956,6 +959,13 @@ const recipe *select_crafting_recipe( int &batch_size ) _( " %s%.*s %s\n" ), example_name, padding, spaces, _( "name of resulting item" ) ); + + std::string example_exclude = _( "clean" ); + padding = max_example_length - utf8_width( example_exclude ); + description += string_format( + _( " -%s%.*s %s\n" ), + example_exclude, padding, spaces, + _( "names to exclude" ) ); } for( const auto &prefix : prefixes ) { diff --git a/src/recipe_dictionary.cpp b/src/recipe_dictionary.cpp index 2d0c096ddf85a..5ee49fc6a024f 100644 --- a/src/recipe_dictionary.cpp +++ b/src/recipe_dictionary.cpp @@ -157,6 +157,9 @@ std::vector recipe_subset::search( case search_type::name: return lcmatch( r->result_name(), txt ); + case search_type::exclude_name: + return !lcmatch( r->result_name(), txt ); + case search_type::skill: return lcmatch( r->required_skills_string( nullptr, true, false ), txt ); diff --git a/src/recipe_dictionary.h b/src/recipe_dictionary.h index e1a5eb026a041..4e9bc83de7d73 100644 --- a/src/recipe_dictionary.h +++ b/src/recipe_dictionary.h @@ -128,6 +128,7 @@ class recipe_subset enum class search_type : int { name, + exclude_name, skill, primary_skill, component,