Skip to content

Commit

Permalink
Add the ability to mark items as favorite from the multidrop menu (#2035
Browse files Browse the repository at this point in the history
)

* add V1 without maintaining selection

* add maintaining selection support

* add handling on favorite items merge

* clean code

* clean code

* clean code

* clean code

* clean code
  • Loading branch information
leoCottret authored Oct 30, 2022
1 parent 3ef04fd commit 3293a6a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,12 +1498,24 @@ drop_locations game_menus::inv::multidrop( player &p )
inv_s.set_title( _( "Multidrop" ) );
inv_s.set_hint( _( "To drop x items, type a number before selecting." ) );

if( inv_s.empty() ) {
popup( std::string( _( "You have nothing to drop." ) ), PF_GET_KEY );
return drop_locations();
}
while( true ) {
p.inv.restack( p );
inv_s.clear_items();
inv_s.add_character_items( p );

return inv_s.execute();
if( inv_s.empty() ) {
popup( std::string( _( "You have nothing to drop." ) ), PF_GET_KEY );
return drop_locations();
}

drop_locations result = inv_s.execute();
// an item has been favorited, reopen the UI
if( inv_s.keep_open ) {
continue;
} else {
return result;
}
}
}

iuse_locations game_menus::inv::multiwash( Character &ch, int water, int cleanser, bool do_soft,
Expand Down
30 changes: 29 additions & 1 deletion src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,32 @@ void inventory_drop_selector::process_selected( int &count,
drop_locations inventory_drop_selector::execute()
{
shared_ptr_fast<ui_adaptor> ui = create_or_get_ui_adaptor();
this->keep_open = false;

// if we favorited an item, we exited this function and entered it again
// the selected items are in "dropping", so we fetch and display them in the UI
std::vector<std::pair<inventory_entry *, int>> selected_entries;
const auto always_yes = []( const inventory_entry & ) {
return true;
};

for( const std::pair<const item *const, int> &drop_pair : dropping ) {
for( auto &col : get_all_columns() ) {
for( const auto &entry : col->get_entries( always_yes ) ) {
if( entry->any_item().get_item() == drop_pair.first ) {
selected_entries.push_back( std::pair<inventory_entry *, int>( entry, drop_pair.second ) );
}
}
}
}

// empty the dropping variable, in case of 2 stacks of items being merged on unfavorite/favorite
dropping.clear();
for( auto selected_entry : selected_entries ) {
set_chosen_count( *selected_entry.first, selected_entry.second );
}

// main multidrop selection loop
int count = 0;
while( true ) {
ui_manager::redraw();
Expand Down Expand Up @@ -2248,7 +2273,10 @@ drop_locations inventory_drop_selector::execute()
} else if( input.action == "INVENTORY_FILTER" ) {
set_filter();
} else if( input.action == "TOGGLE_FAVORITE" ) {
// TODO: implement favoriting in multi selection menus while maintaining selection
// change the item favorited state
get_active_column().on_input( input );
this->keep_open = true;
return drop_locations();
} else {
on_input( input );
count = 0;
Expand Down

0 comments on commit 3293a6a

Please sign in to comment.