Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix consuming menu filter cleared after consuming an item #37538

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ static item_location inv_internal( player &u, const inventory_selector_preset &p

std::pair<size_t, size_t> init_pair;
bool init_selection = false;
std::string init_filter;
bool has_init_filter = false;

const std::vector<activity_id> consuming {
ACT_EAT_MENU,
Expand All @@ -119,6 +121,10 @@ static item_location inv_internal( player &u, const inventory_selector_preset &p
init_pair.second = u.activity.values[1];
init_selection = true;
}
if( u.has_activity( consuming ) && !u.activity.str_values.empty() ) {
init_filter = u.activity.str_values[0];
has_init_filter = true;
}

bool need_refresh = true;
do {
Expand All @@ -128,10 +134,17 @@ static item_location inv_internal( player &u, const inventory_selector_preset &p
inv_s.add_character_items( u );
inv_s.add_nearby_items( radius );

if( init_selection ) {
if( init_selection || has_init_filter ) {
inv_s.update( need_refresh );
inv_s.select_position( init_pair );
init_selection = false;
if( has_init_filter ) {
inv_s.set_filter( init_filter );
has_init_filter = false;
}
// Set position after filter to keep cursor at the right position
if( init_selection ) {
inv_s.select_position( init_pair );
init_selection = false;
}
}

if( inv_s.empty() ) {
Expand All @@ -154,6 +167,8 @@ static item_location inv_internal( player &u, const inventory_selector_preset &p
init_pair = inv_s.get_selection_position();
u.activity.values.push_back( init_pair.first );
u.activity.values.push_back( init_pair.second );
u.activity.str_values.clear();
u.activity.str_values.emplace_back( inv_s.get_filter() );
}

return location;
Expand Down
14 changes: 14 additions & 0 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,20 @@ void inventory_selector::set_filter()
layout_is_valid = false;
}

void inventory_selector::set_filter( const std::string &str )
{
filter = str;
for( const auto elem : columns ) {
elem->set_filter( filter );
}
layout_is_valid = false;
}

std::string inventory_selector::get_filter() const
{
return filter;
}

void inventory_selector::update( bool &need_refresh )
{
if( need_refresh ) {
Expand Down
5 changes: 5 additions & 0 deletions src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ class inventory_selector
/** @return true when there are enabled entries to select. */
bool has_available_choices() const;

/** Apply filter string to all columns */
void set_filter( const std::string &str );
/** Get last filter string set by set_filter or entered by player */
std::string get_filter() const;

// An array of cells for the stat lines. Example: ["Weight (kg)", "10", "/", "20"].
using stat = std::array<std::string, 4>;
using stats = std::array<stat, 2>;
Expand Down