From 318ebb0a4b1d55a7519154320125a1379d9b4e8d Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Thu, 6 Feb 2025 11:44:24 -0600 Subject: [PATCH 1/6] unhardcode auto pickup manager help text and provide the help text three lines to work with --- src/auto_pickup.cpp | 102 ++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index 4d2351c09610c..8563f0f829986 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -326,6 +326,29 @@ void user_interface::show() bool bLeftColumn = true; int iStartPos = 0; Character &player_character = get_player_character(); + bStuffChanged = false; + input_context ctxt( "AUTO_PICKUP" ); + ctxt.register_navigate_ui_list(); + ctxt.register_leftright(); + ctxt.register_action( "CONFIRM" ); + ctxt.register_action( "QUIT" ); + if( tabs.size() > 1 ) { + ctxt.register_action( "NEXT_TAB" ); + } + ctxt.register_action( "ADD_RULE" ); + ctxt.register_action( "REMOVE_RULE" ); + ctxt.register_action( "COPY_RULE" ); + ctxt.register_action( "ENABLE_RULE" ); + ctxt.register_action( "DISABLE_RULE" ); + ctxt.register_action( "MOVE_RULE_UP" ); + ctxt.register_action( "MOVE_RULE_DOWN" ); + ctxt.register_action( "TEST_RULE" ); + ctxt.register_action( "HELP_KEYBINDINGS" ); + ctxt.register_action( "SWITCH_AUTO_PICKUP_OPTION" ); + const bool allow_swapping = tabs.size() == 2; + if( allow_swapping ) { + ctxt.register_action( "SWAP_RULE_GLOBAL_CHAR" ); + } ui.on_redraw( [&]( const ui_adaptor & ) { // Redraw the border @@ -344,41 +367,47 @@ void user_interface::show() wnoutrefresh( w_border ); // Redraw the header - int tmpx = 0; - tmpx += shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "dd" ) ) + 2; - tmpx += shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "emove" ) ) + 2; - tmpx += shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "opy" ) ) + 2; - tmpx += shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "ove" ) ) + 2; - tmpx += shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "nable" ) ) + 2; - tmpx += shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "isable" ) ) + 2; + std::string desc_0 = string_format( "%s %s %s", + ctxt.get_desc( "ADD_RULE", _( "Add" ) ), + ctxt.get_desc( "REMOVE_RULE", _( "Remove" ) ), + ctxt.get_desc( "COPY_RULE", _( "Copy" ) ) ); + std::string desc_1 = string_format( "%s %s", + ctxt.get_desc( "ENABLE_RULE", _( "Enable" ) ), + ctxt.get_desc( "DISABLE_RULE", _( "Disable" ) ) ); + std::string desc_2 = string_format( "%s %s %s", + ctxt.get_desc( "MOVE_RULE_UP", _( "Move up" ) ), + ctxt.get_desc( "MOVE_RULE_DOWN", _( "Move down" ) ), + ctxt.get_desc( "CONFIRM", _( "Edit" ) ) ); if( !player_character.name.empty() ) { - shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "est" ) ); + desc_0 += string_format ( " %s", ctxt.get_desc( "SWAP_RULE_GLOBAL_CHAR", _( "Move" ) ) ); + desc_1 += string_format ( " %s", ctxt.get_desc( "TEST_RULE", _( "Test" ) ) ); + } + if( tabs.size() > 1 ) { + desc_2 += string_format ( " %s", ctxt.get_desc( "NEXT_TAB", _( "Page" ) ) ); } - tmpx = 0; - tmpx += shortcut_print( w_header, point( tmpx, 1 ), c_white, c_light_green, - _( "<+-> Move up/down" ) ) + 2; - tmpx += shortcut_print( w_header, point( tmpx, 1 ), c_white, c_light_green, - _( "-Edit" ) ) + 2; - shortcut_print( w_header, point( tmpx, 1 ), c_white, c_light_green, _( "-Switch Page" ) ); + + fold_and_print( w_header, point( 0, 0 ), 0, c_white, desc_0 ); + fold_and_print( w_header, point( 0, 1 ), 0, c_white, desc_1 ); + fold_and_print( w_header, point( 0, 2 ), 0, c_white, desc_2 ); wattron( w_header, c_light_gray ); - mvwhline( w_header, point( 0, 2 ), LINE_OXOX, 78 ); + mvwhline( w_header, point( 0, 3 ), LINE_OXOX, 78 ); for( int x : { 4, 50, 60 } ) { - mvwaddch( w_header, point( x, 2 ), LINE_OXXX ); - mvwaddch( w_header, point( x, 3 ), LINE_XOXO ); + mvwaddch( w_header, point( x, 3 ), LINE_OXXX ); + mvwaddch( w_header, point( x, 4 ), LINE_XOXO ); } wattroff( w_header, c_light_gray ); - mvwprintz( w_header, point( 1, 3 ), c_white, "#" ); - mvwprintz( w_header, point( 8, 3 ), c_white, _( "Rules" ) ); - mvwprintz( w_header, point( 52, 3 ), c_white, _( "Inc/Exc" ) ); + mvwprintz( w_header, point( 1, 4 ), c_white, "#" ); + mvwprintz( w_header, point( 8, 4 ), c_white, _( "Rules" ) ); + mvwprintz( w_header, point( 52, 4 ), c_white, _( "Inc/Exc" ) ); rule_list &cur_rules = tabs[iTab].new_rules; int locx = 17; for( size_t i = 0; i < tabs.size(); i++ ) { const nc_color color = iTab == i ? hilite( c_white ) : c_white; - locx += shortcut_print( w_header, point( locx, 2 ), c_white, color, tabs[i].title ) + 1; + locx += shortcut_print( w_header, point( locx, 3 ), c_white, color, tabs[i].title ) + 1; } locx = 55; @@ -386,9 +415,8 @@ void user_interface::show() locx += shortcut_print( w_header, point( locx, 1 ), get_option( "AUTO_PICKUP" ) ? c_light_green : c_light_red, c_white, get_option( "AUTO_PICKUP" ) ? _( "True" ) : _( "False" ) ); - locx += shortcut_print( w_header, point( locx, 1 ), c_white, c_light_green, " " ); - locx += shortcut_print( w_header, point( locx, 1 ), c_white, c_light_green, _( "witch" ) ); - shortcut_print( w_header, point( locx, 1 ), c_white, c_light_green, " " ); + std::string desc_3 = string_format( " %s ", ctxt.get_desc( "SWITCH_AUTO_PICKUP_OPTION", _( "Switch" ) ) ); + fold_and_print( w_header, point( locx, 1 ), 0, c_white, desc_3 ); wnoutrefresh( w_header ); @@ -432,32 +460,6 @@ void user_interface::show() wnoutrefresh( w ); } ); - bStuffChanged = false; - input_context ctxt( "AUTO_PICKUP" ); - ctxt.register_navigate_ui_list(); - ctxt.register_leftright(); - ctxt.register_action( "CONFIRM" ); - ctxt.register_action( "QUIT" ); - if( tabs.size() > 1 ) { - ctxt.register_action( "NEXT_TAB" ); - ctxt.register_action( "PREV_TAB" ); - } - ctxt.register_action( "ADD_RULE" ); - ctxt.register_action( "REMOVE_RULE" ); - ctxt.register_action( "COPY_RULE" ); - ctxt.register_action( "ENABLE_RULE" ); - ctxt.register_action( "DISABLE_RULE" ); - ctxt.register_action( "MOVE_RULE_UP" ); - ctxt.register_action( "MOVE_RULE_DOWN" ); - ctxt.register_action( "TEST_RULE" ); - ctxt.register_action( "HELP_KEYBINDINGS" ); - ctxt.register_action( "SWITCH_AUTO_PICKUP_OPTION" ); - - const bool allow_swapping = tabs.size() == 2; - if( allow_swapping ) { - ctxt.register_action( "SWAP_RULE_GLOBAL_CHAR" ); - } - while( true ) { rule_list &cur_rules = tabs[iTab].new_rules; From 246ea220c87e913182b1be2a7572f343cad4b5ac Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Thu, 6 Feb 2025 12:08:55 -0600 Subject: [PATCH 2/6] unhardcode autopickup manager different method --- src/auto_pickup.cpp | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index 8563f0f829986..6c3a101c18682 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -367,28 +367,32 @@ void user_interface::show() wnoutrefresh( w_border ); // Redraw the header - std::string desc_0 = string_format( "%s %s %s", - ctxt.get_desc( "ADD_RULE", _( "Add" ) ), - ctxt.get_desc( "REMOVE_RULE", _( "Remove" ) ), - ctxt.get_desc( "COPY_RULE", _( "Copy" ) ) ); - std::string desc_1 = string_format( "%s %s", - ctxt.get_desc( "ENABLE_RULE", _( "Enable" ) ), - ctxt.get_desc( "DISABLE_RULE", _( "Disable" ) ) ); - std::string desc_2 = string_format( "%s %s %s", - ctxt.get_desc( "MOVE_RULE_UP", _( "Move up" ) ), - ctxt.get_desc( "MOVE_RULE_DOWN", _( "Move down" ) ), - ctxt.get_desc( "CONFIRM", _( "Edit" ) ) ); + std::vector keybinding_tips; + std::vector act_descs; + const auto add_action_desc = [&]( const std::string & act, const std::string & txt ) { + act_descs.emplace_back( ctxt.get_desc( act, txt, input_context::allow_all_keys ) ); + }; + + add_action_desc( "ADD_RULE", pgettext( "autopickup manager", "Add" ) ); + add_action_desc( "REMOVE_RULE", pgettext( "autopickup manager", "Remove" ) ); + add_action_desc( "COPY_RULE", pgettext( "autopickup manager", "Copy" ) ); + add_action_desc( "ENABLE_RULE", pgettext( "autopickup manager", "Enable" ) ); + add_action_desc( "DISABLE_RULE", pgettext( "autopickup manager", "Disable" ) ); + add_action_desc( "MOVE_RULE_UP", pgettext( "autopickup manager", "Move up" ) ); + add_action_desc( "MOVE_RULE_DOWN", pgettext( "autopickup manager", "Move down" ) ); + add_action_desc( "CONFIRM", pgettext( "autopickup manager", "Edit" ) ); + if( tabs.size() > 1 ) { + add_action_desc( "NEXT_TAB", pgettext( "autopickup manager", "Page" ) ); + } if( !player_character.name.empty() ) { - desc_0 += string_format ( " %s", ctxt.get_desc( "SWAP_RULE_GLOBAL_CHAR", _( "Move" ) ) ); - desc_1 += string_format ( " %s", ctxt.get_desc( "TEST_RULE", _( "Test" ) ) ); + add_action_desc( "SWAP_RULE_GLOBAL_CHAR", pgettext( "autopickup manager", "Move" ) ); + add_action_desc( "TEST_RULE", pgettext( "autopickup manager", "Test" ) ); } - if( tabs.size() > 1 ) { - desc_2 += string_format ( " %s", ctxt.get_desc( "NEXT_TAB", _( "Page" ) ) ); + keybinding_tips = foldstring( enumerate_as_string( act_descs, enumeration_conjunction::none ), 50 ); + for( size_t i = 0; i < keybinding_tips.size(); ++i ) { + nc_color dummy = c_white; + print_colored_text( w_header, point( 0, i ), dummy, c_white, keybinding_tips[i] ); } - - fold_and_print( w_header, point( 0, 0 ), 0, c_white, desc_0 ); - fold_and_print( w_header, point( 0, 1 ), 0, c_white, desc_1 ); - fold_and_print( w_header, point( 0, 2 ), 0, c_white, desc_2 ); wattron( w_header, c_light_gray ); mvwhline( w_header, point( 0, 3 ), LINE_OXOX, 78 ); From 66e3aa1365d883cf53fe10f8820e525bfe5501a8 Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Thu, 6 Feb 2025 12:55:26 -0600 Subject: [PATCH 3/6] accept gh bot suggestion I'll take this opportunity to squash in a minor name change Co-Authored-By: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/auto_pickup.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index 6c3a101c18682..e85261312bd39 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -419,8 +419,9 @@ void user_interface::show() locx += shortcut_print( w_header, point( locx, 1 ), get_option( "AUTO_PICKUP" ) ? c_light_green : c_light_red, c_white, get_option( "AUTO_PICKUP" ) ? _( "True" ) : _( "False" ) ); - std::string desc_3 = string_format( " %s ", ctxt.get_desc( "SWITCH_AUTO_PICKUP_OPTION", _( "Switch" ) ) ); - fold_and_print( w_header, point( locx, 1 ), 0, c_white, desc_3 ); + std::string desc = string_format( " %s ", ctxt.get_desc( "SWITCH_AUTO_PICKUP_OPTION", + _( "Switch" ) ) ); + fold_and_print( w_header, point( locx, 1 ), 0, c_white, desc ); wnoutrefresh( w_header ); From c696755852352a8f056e4f72ddf05f71c5fcd6ff Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Thu, 6 Feb 2025 13:14:47 -0600 Subject: [PATCH 4/6] fix autopickup ui alignment issue --- src/auto_pickup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index e85261312bd39..e05b76633236b 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -356,9 +356,9 @@ void user_interface::show() wattron( w, c_light_gray ); // |- - mvwaddch( w_border, point( 0, 3 ), LINE_XXXO ); + mvwaddch( w_border, point( 0, 4 ), LINE_XXXO ); // -| - mvwaddch( w_border, point( 79, 3 ), LINE_XOXX ); + mvwaddch( w_border, point( 79, 4 ), LINE_XOXX ); // _|_ mvwaddch( w_border, point( 5, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX ); mvwaddch( w_border, point( 51, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX ); From 6617fb2807f474068b922598a808ad98cd0aedd9 Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Thu, 6 Feb 2025 16:50:29 -0600 Subject: [PATCH 5/6] trim help text display only "switch" and keybindings help --- src/auto_pickup.cpp | 68 +++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index e05b76633236b..989ec94d45145 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -356,9 +356,9 @@ void user_interface::show() wattron( w, c_light_gray ); // |- - mvwaddch( w_border, point( 0, 4 ), LINE_XXXO ); + mvwaddch( w_border, point( 0, 3 ), LINE_XXXO ); // -| - mvwaddch( w_border, point( 79, 4 ), LINE_XOXX ); + mvwaddch( w_border, point( 79, 3 ), LINE_XOXX ); // _|_ mvwaddch( w_border, point( 5, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX ); mvwaddch( w_border, point( 51, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX ); @@ -367,62 +367,40 @@ void user_interface::show() wnoutrefresh( w_border ); // Redraw the header - std::vector keybinding_tips; - std::vector act_descs; - const auto add_action_desc = [&]( const std::string & act, const std::string & txt ) { - act_descs.emplace_back( ctxt.get_desc( act, txt, input_context::allow_all_keys ) ); - }; - - add_action_desc( "ADD_RULE", pgettext( "autopickup manager", "Add" ) ); - add_action_desc( "REMOVE_RULE", pgettext( "autopickup manager", "Remove" ) ); - add_action_desc( "COPY_RULE", pgettext( "autopickup manager", "Copy" ) ); - add_action_desc( "ENABLE_RULE", pgettext( "autopickup manager", "Enable" ) ); - add_action_desc( "DISABLE_RULE", pgettext( "autopickup manager", "Disable" ) ); - add_action_desc( "MOVE_RULE_UP", pgettext( "autopickup manager", "Move up" ) ); - add_action_desc( "MOVE_RULE_DOWN", pgettext( "autopickup manager", "Move down" ) ); - add_action_desc( "CONFIRM", pgettext( "autopickup manager", "Edit" ) ); - if( tabs.size() > 1 ) { - add_action_desc( "NEXT_TAB", pgettext( "autopickup manager", "Page" ) ); - } - if( !player_character.name.empty() ) { - add_action_desc( "SWAP_RULE_GLOBAL_CHAR", pgettext( "autopickup manager", "Move" ) ); - add_action_desc( "TEST_RULE", pgettext( "autopickup manager", "Test" ) ); - } - keybinding_tips = foldstring( enumerate_as_string( act_descs, enumeration_conjunction::none ), 50 ); - for( size_t i = 0; i < keybinding_tips.size(); ++i ) { - nc_color dummy = c_white; - print_colored_text( w_header, point( 0, i ), dummy, c_white, keybinding_tips[i] ); - } + int locx = 0; + const std::string autopickup_enabled_text = _( "Auto pickup enabled:" ); + mvwprintz( w_header, point( locx, 0 ), c_white, autopickup_enabled_text ); + locx += utf8_width( autopickup_enabled_text ); + locx += shortcut_print( w_header, point( locx + 1, 0 ), + ( get_option( "AUTO_PICKUP" ) ? c_light_green : c_light_red ), c_white, + ( get_option( "AUTO_PICKUP" ) ? _( "True" ) : _( "False" ) ) ); + std::string desc = string_format( " %s ", ctxt.get_desc( "SWITCH_AUTO_PICKUP_OPTION", + _( "Switch" ) ) ); + fold_and_print( w_header, point( locx + 1, 0 ), 0, c_white, desc ); + + std::string desc_2 = string_format( "%s", ctxt.get_desc( "HELP_KEYBINDINGS", _( "Display keybindings" ) ) ); + fold_and_print( w_header, point( 0, 1 ), 0, c_white, desc_2 ); wattron( w_header, c_light_gray ); - mvwhline( w_header, point( 0, 3 ), LINE_OXOX, 78 ); + mvwhline( w_header, point( 0, 2 ), LINE_OXOX, 78 ); for( int x : { 4, 50, 60 } ) { - mvwaddch( w_header, point( x, 3 ), LINE_OXXX ); - mvwaddch( w_header, point( x, 4 ), LINE_XOXO ); + mvwaddch( w_header, point( x, 2 ), LINE_OXXX ); + mvwaddch( w_header, point( x, 3 ), LINE_XOXO ); } wattroff( w_header, c_light_gray ); - mvwprintz( w_header, point( 1, 4 ), c_white, "#" ); - mvwprintz( w_header, point( 8, 4 ), c_white, _( "Rules" ) ); - mvwprintz( w_header, point( 52, 4 ), c_white, _( "Inc/Exc" ) ); + mvwprintz( w_header, point( 1, 3 ), c_white, "#" ); + mvwprintz( w_header, point( 8, 3 ), c_white, _( "Rules" ) ); + mvwprintz( w_header, point( 52, 3 ), c_white, _( "Inc/Exc" ) ); rule_list &cur_rules = tabs[iTab].new_rules; - int locx = 17; + locx = 17; for( size_t i = 0; i < tabs.size(); i++ ) { const nc_color color = iTab == i ? hilite( c_white ) : c_white; - locx += shortcut_print( w_header, point( locx, 3 ), c_white, color, tabs[i].title ) + 1; + locx += shortcut_print( w_header, point( locx, 2 ), c_white, color, tabs[i].title ) + 1; } - locx = 55; - mvwprintz( w_header, point( locx, 0 ), c_white, _( "Auto pickup enabled:" ) ); - locx += shortcut_print( w_header, point( locx, 1 ), - get_option( "AUTO_PICKUP" ) ? c_light_green : c_light_red, c_white, - get_option( "AUTO_PICKUP" ) ? _( "True" ) : _( "False" ) ); - std::string desc = string_format( " %s ", ctxt.get_desc( "SWITCH_AUTO_PICKUP_OPTION", - _( "Switch" ) ) ); - fold_and_print( w_header, point( locx, 1 ), 0, c_white, desc ); - wnoutrefresh( w_header ); // Clear the lines From 1aab90bb6f464997e9a9f953b2d16924bbf9ac9c Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Fri, 7 Feb 2025 00:11:51 -0600 Subject: [PATCH 6/6] trim more extraneous text from autopickup help also accept gh bot suggestion Co-Authored-By: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/auto_pickup.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index 989ec94d45145..8ee5f83ae818a 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -374,11 +374,8 @@ void user_interface::show() locx += shortcut_print( w_header, point( locx + 1, 0 ), ( get_option( "AUTO_PICKUP" ) ? c_light_green : c_light_red ), c_white, ( get_option( "AUTO_PICKUP" ) ? _( "True" ) : _( "False" ) ) ); - std::string desc = string_format( " %s ", ctxt.get_desc( "SWITCH_AUTO_PICKUP_OPTION", - _( "Switch" ) ) ); - fold_and_print( w_header, point( locx + 1, 0 ), 0, c_white, desc ); - - std::string desc_2 = string_format( "%s", ctxt.get_desc( "HELP_KEYBINDINGS", _( "Display keybindings" ) ) ); + std::string desc_2 = string_format( "%s", ctxt.get_desc( "HELP_KEYBINDINGS", + _( "Display keybindings" ) ) ); fold_and_print( w_header, point( 0, 1 ), 0, c_white, desc_2 ); wattron( w_header, c_light_gray );