Skip to content

Commit

Permalink
Block bound inventory keys from auto assignment (#40288)
Browse files Browse the repository at this point in the history
  • Loading branch information
eJ0opb authored May 8, 2020
1 parent b62aa82 commit 19a6844
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ class input_context
*/
std::vector<std::string> filter_strings_by_phrase( const std::vector<std::string> &strings,
const std::string &phrase ) const;
public:
std::vector<std::string> get_registered_actions_copy() const {
return registered_actions;
}
};

/**
Expand Down
10 changes: 10 additions & 0 deletions src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "colony.h"
#include "flat_set.h"
#include "point.h"
#include "inventory_ui.h" // auto inventory blocking

static const std::string flag_LEAK_ALWAYS( "LEAK_ALWAYS" );
static const std::string flag_LEAK_DAM( "LEAK_DAM" );
Expand Down Expand Up @@ -1036,11 +1037,20 @@ void inventory::assign_empty_invlet( item &it, const Character &p, const bool fo
}
}
if( cur_inv.count() < inv_chars.size() ) {
// XXX YUCK I don't know how else to get the keybindings
// FIXME: Find a better way to get bound keys
avatar &u = g->u;
inventory_selector selector( u );

for( const auto &inv_char : inv_chars ) {
if( assigned_invlet.count( inv_char ) ) {
// don't overwrite assigned keys
continue;
}
if( !selector.action_bound_to_key( inv_char ).empty() ) {
// don't auto-assign bound keys
continue;
}
if( !cur_inv[inv_char] ) {
it.invlet = inv_char;
return;
Expand Down
12 changes: 12 additions & 0 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,18 @@ const navigation_mode_data &inventory_selector::get_navigation_data( navigation_
return mode_data.at( m );
}

std::string inventory_selector::action_bound_to_key( char key ) const
{
for( const std::string &action_descriptor : ctxt.get_registered_actions_copy() ) {
for( char bound_key : ctxt.keys_bound_to( action_descriptor ) ) {
if( key == bound_key ) {
return action_descriptor;
}
}
}
return std::string();
}

item_location inventory_pick_selector::execute()
{
shared_ptr_fast<ui_adaptor> ui = create_or_get_ui_adaptor();
Expand Down
3 changes: 3 additions & 0 deletions src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ class inventory_selector

bool is_empty = true;
bool display_stats = true;

public:
std::string action_bound_to_key( char key ) const;
};

inventory_selector::stat display_stat( const std::string &caption, int cur_value, int max_value,
Expand Down

0 comments on commit 19a6844

Please sign in to comment.