Skip to content

Commit

Permalink
Allow for excluding words in recipes filter (#46985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salty-Panda authored Jan 25, 2021
1 parent 83bac48 commit 6902525
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -956,6 +959,13 @@ const recipe *select_crafting_recipe( int &batch_size )
_( " <color_white>%s</color>%.*s %s\n" ),
example_name, padding, spaces,
_( "<color_cyan>name</color> of resulting item" ) );

std::string example_exclude = _( "clean" );
padding = max_example_length - utf8_width( example_exclude );
description += string_format(
_( " <color_yellow>-</color><color_white>%s</color>%.*s %s\n" ),
example_exclude, padding, spaces,
_( "<color_cyan>names</color> to exclude" ) );
}

for( const auto &prefix : prefixes ) {
Expand Down
3 changes: 3 additions & 0 deletions src/recipe_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ std::vector<const recipe *> 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 );

Expand Down
1 change: 1 addition & 0 deletions src/recipe_dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class recipe_subset

enum class search_type : int {
name,
exclude_name,
skill,
primary_skill,
component,
Expand Down

0 comments on commit 6902525

Please sign in to comment.