From f1787ab50d3773f4bfd81445a521352a8b22ed9b Mon Sep 17 00:00:00 2001 From: b3brodie Date: Sun, 2 Jun 2024 23:01:13 -0700 Subject: [PATCH 1/4] Allow using magic hotkeys when in other category --- src/magic.cpp | 2 +- src/ui.cpp | 33 ++++++++++++++++++++------------- src/ui.h | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/magic.cpp b/src/magic.cpp index f727e3e07bf94..4fb346794472d 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -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( spell_menu.callback )->casting_ignore; diff --git a/src/ui.cpp b/src/ui.cpp index b901cde3aefd7..cdfc2035d3f8a 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -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 && @@ -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 ( allow_unfiltered_hotkeys ) { + const bool enabled = entries[iter->second].enabled; + if (enabled || allow_disabled) { + ret = entries[iter->second].retval; } - if( callback != nullptr ) { - callback->select( this ); + } 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 ); + } } } } diff --git a/src/ui.h b/src/ui.h index ee77bdf282599..d05f2ae487b6e 100644 --- a/src/ui.h +++ b/src/ui.h @@ -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 From d2092f19ded981e6ab02f9732dd42decb0ec07b6 Mon Sep 17 00:00:00 2001 From: b3brodie Date: Mon, 3 Jun 2024 00:04:15 -0700 Subject: [PATCH 2/4] astyle unstyled style --- src/magic.cpp | 2 +- src/ui.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/magic.cpp b/src/magic.cpp index 4fb346794472d..1d571de084c49 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -2848,7 +2848,7 @@ int known_magic::select_spell( Character &guy ) } reflesh_favorite( &spell_menu, known_spells ); - spell_menu.query(true, -1, true); + spell_menu.query( true, -1, true ); casting_ignore = static_cast( spell_menu.callback )->casting_ignore; diff --git a/src/ui.cpp b/src/ui.cpp index cdfc2035d3f8a..8b51c5e708c57 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1140,11 +1140,11 @@ void uilist::query( bool loop, int timeout, bool allow_unfiltered_hotkeys ) } filterlist(); } else if( iter != keymap.end() ) { - if ( allow_unfiltered_hotkeys ) { - const bool enabled = entries[iter->second].enabled; - if (enabled || allow_disabled) { - ret = entries[iter->second].retval; - } + 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() ) { From 3bf29007019af8f01856bfae16c5917377bf96ac Mon Sep 17 00:00:00 2001 From: b3brodie Date: Mon, 3 Jun 2024 11:51:56 -0700 Subject: [PATCH 3/4] Rerun tests Part 1 --- doc/MAGIC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/MAGIC.md b/doc/MAGIC.md index 546d938fa343d..8b4e3d387db4c 100644 --- a/doc/MAGIC.md +++ b/doc/MAGIC.md @@ -964,5 +964,5 @@ Character status value | Description { "value": "ARMOR_HEAT", "multiply": 0.4 } // increases damage taken from fire by 40% { "value": "ARMOR_CUT", "add": 2 } // increases incoming cut damage by 2 { "value": "ARMOR_BIO", "multiply": -1.4 } // subtracts 100 percent of incoming biological damage, heals for the remaining 40% - { "value": "ARMOR_ACID", "multiply": 1.4 } // increases incoming acid damage by 140% + { "value": "ARMOR_ACID", "multiply": 1.4 } // increases incoming acid damage by 140% ``` From b4ab4a0ddbec9ceb3df3a241cd550e6f3065fae1 Mon Sep 17 00:00:00 2001 From: b3brodie Date: Mon, 3 Jun 2024 11:52:19 -0700 Subject: [PATCH 4/4] Rerun Tests Part 2 --- doc/MAGIC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/MAGIC.md b/doc/MAGIC.md index 8b4e3d387db4c..546d938fa343d 100644 --- a/doc/MAGIC.md +++ b/doc/MAGIC.md @@ -964,5 +964,5 @@ Character status value | Description { "value": "ARMOR_HEAT", "multiply": 0.4 } // increases damage taken from fire by 40% { "value": "ARMOR_CUT", "add": 2 } // increases incoming cut damage by 2 { "value": "ARMOR_BIO", "multiply": -1.4 } // subtracts 100 percent of incoming biological damage, heals for the remaining 40% - { "value": "ARMOR_ACID", "multiply": 1.4 } // increases incoming acid damage by 140% + { "value": "ARMOR_ACID", "multiply": 1.4 } // increases incoming acid damage by 140% ```