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

Allow using hotkeys to select spells in other categories #74281

Merged
merged 4 commits into from
Jun 4, 2024
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
2 changes: 1 addition & 1 deletion src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2848,7 +2848,7 @@ int known_magic::select_spell( Character &guy )
}
reflesh_favorite( &spell_menu, known_spells );

spell_menu.query();
spell_menu.query( true, -1, true );

casting_ignore = static_cast<spellcasting_callback *>( spell_menu.callback )->casting_ignore;

Expand Down
35 changes: 21 additions & 14 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ uilist::handle_mouse_result_t uilist::handle_mouse( const input_context &ctxt,
* Handle input and update display
*
*/
void uilist::query( bool loop, int timeout )
void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys )
{
#if defined(__ANDROID__)
bool auto_pos = w_x_setup.fun == nullptr && w_y_setup.fun == nullptr &&
Expand Down Expand Up @@ -1140,19 +1140,26 @@ void uilist::query( bool loop, int timeout )
}
filterlist();
} else if( iter != keymap.end() ) {
const auto it = std::find( fentries.begin(), fentries.end(), iter->second );
if( it != fentries.end() ) {
const bool enabled = entries[*it].enabled;
if( enabled || allow_disabled || hilight_disabled ) {
// Change the selection to display correctly when this function
// is called again.
fselected = std::distance( fentries.begin(), it );
selected = *it;
if( enabled || allow_disabled ) {
ret = entries[selected].retval;
}
if( callback != nullptr ) {
callback->select( this );
if( allow_unfiltered_hotkeys ) {
const bool enabled = entries[iter->second].enabled;
if( enabled || allow_disabled ) {
ret = entries[iter->second].retval;
}
} else {
const auto it = std::find( fentries.begin(), fentries.end(), iter->second );
if( it != fentries.end() ) {
const bool enabled = entries[*it].enabled;
if( enabled || allow_disabled || hilight_disabled ) {
// Change the selection to display correctly when this function
// is called again.
fselected = std::distance( fentries.begin(), it );
selected = *it;
if( enabled || allow_disabled ) {
ret = entries[selected].retval;
}
if( callback != nullptr ) {
callback->select( this );
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class uilist // NOLINT(cata-xy)
void reposition( ui_adaptor &ui );
void show( ui_adaptor &ui );
bool scrollby( int scrollby );
void query( bool loop = true, int timeout = -1 );
void query( bool loop = true, int timeout = -1, bool allow_unfiltered_hotkeys = false );
void filterlist();
// In add_entry/add_entry_desc/add_entry_col, int k only support letters
// (a-z, A-Z) and digits (0-9), MENU_AUTOASSIGN, and 0 or ' ' (disable
Expand Down
Loading