Skip to content

Commit

Permalink
Filter items by book skill ( V, e, / ), fixes CleverRaven#47530 (Clev…
Browse files Browse the repository at this point in the history
…erRaven#48275)

* Add a filter to search books by skills they teach

* Hide books not skimmed when filtering items

The player was able to know which skill a book tech without first skim it.

* Fix typographic error

* Check non-skill by ID

name() is i18n-dependent and it may return something other than "nothing" in different languages.

Co-authored-by: Binrui Dong <[email protected]>
  • Loading branch information
2 people authored and KorGgenT committed Jul 4, 2021
1 parent d2b8c5a commit 52ff0f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7099,6 +7099,16 @@ bool item::is_book() const
return !!type->book;
}

std::string item::get_book_skill() const
{
if( is_book() ) {
if( type->book->skill->ident() != skill_id::NULL_ID() ) {
return type->book->skill->name();
}
}
return "";
}

bool item::is_map() const
{
return get_category_shallow().get_id() == item_category_maps;
Expand Down
2 changes: 2 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,8 @@ class item : public visitable
/** Returns true if the item is A: is SOLID and if it B: is of type LIQUID */
bool is_frozen_liquid() const;

/** Returns empty string if the book teach no skill */
std::string get_book_skill() const;
float get_specific_heat_liquid() const;
float get_specific_heat_solid() const;
float get_latent_heat() const;
Expand Down
10 changes: 10 additions & 0 deletions src/item_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <map>
#include <utility>

#include "avatar.h"
#include "cata_utility.h"
#include "game.h"
#include "item.h"
#include "item_category.h"
#include "material.h"
Expand Down Expand Up @@ -68,6 +70,14 @@ std::function<bool( const item & )> basic_item_filter( std::string filter )
const std::string note = i.get_var( "item_note" );
return !note.empty() && lcmatch( note, filter );
};
// by book skill
case 's':
return [filter]( const item & i ) {
if( get_avatar().has_identified( i.typeId() ) ) {
return lcmatch( i.get_book_skill(), filter );
}
return false;
};
// by name
default:
return [filter]( const item & a ) {
Expand Down
5 changes: 3 additions & 2 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,12 @@ void draw_item_filter_rules( const catacurses::window &win, int starty, int heig

starty += fold_and_print( win, point( 1, starty ), len, c_white,
_( "Search [<color_yellow>c</color>]ategory, [<color_yellow>m</color>]aterial, "
"[<color_yellow>q</color>]uality, [<color_yellow>n</color>]otes or "
"[<color_yellow>q</color>]uality, [<color_yellow>n</color>]otes, "
"[<color_yellow>s</color>]skill taught by books or "
"[<color_yellow>d</color>]isassembled components." ) );
fold_and_print( win, point( 1, starty ), len, c_white,
//~ An example of how to filter items based on category or material.
_( "Examples: c:food,m:iron,q:hammering,n:toolshelf,d:pipe" ) );
_( "Examples: c:food,m:iron,q:hammering,n:toolshelf,d:pipe,s:devices" ) );
wnoutrefresh( win );
}

Expand Down

0 comments on commit 52ff0f9

Please sign in to comment.