From 882f307fe966d1961d72c979b99550aa70e635a3 Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Tue, 5 May 2020 21:48:44 -0500 Subject: [PATCH 1/4] Initial commit Compact aim window pt2 for numbers display, adapt existing code from old branch --- src/output.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/output.h | 3 +++ src/ranged.cpp | 57 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 118 insertions(+), 7 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 5b420ca550299..123b7e56337c4 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -1822,6 +1822,71 @@ std::string get_labeled_bar( const double val, const int width, const std::strin return get_labeled_bar( val, width, label, ratings.begin(), ratings.end() ); } +/** + * Inserts a table into a window, with data right-aligned. + * @param pad Reduce table width by padding left side. + * @param line Line to insert table. + * @param columns Number of columns. Can be 1. + * @param nc_color &FG Default color of table text. + * @param divider To insert a character separating table entries. Can be blank. + * @param r_align true for right aligned, false for left aligned. + * @param data Text data to fill. + * Make sure each entry of the data vector fits into one cell, including divider if any. + */ +void insert_table( const catacurses::window &w, int pad, int line, int columns, + const nc_color &FG, const std::string ÷r, bool r_align, + const std::vector &data ) +{ + const int width = getmaxx( w ); + const int rows = getmaxy( w ); + const int col_width = ( ( width - pad ) / columns );// + utf8_width( divider ) ; + int indent = 1; // 1 for right window border + if( r_align ) { + indent = ( col_width * columns ) + 1; + } + int div = columns - 1; + int offset = 0; + +#if defined(__ANDROID__) + input_context ctxt( "INSERT_TABLE" ); +#endif + wattron( w, FG ); + for( int i = 0; i < rows * columns; i++ ) { + if( i + offset * columns >= static_cast( data.size() ) ) { + break; + } + int y = line + ( i / columns ); + if( r_align ) { + indent -= col_width; + } + if( div != 0 ) { + if( r_align ) { + right_print( w, y, indent - utf8_width( divider ), FG, divider ); + } else { + fold_and_print_from( w, point( indent + col_width - utf8_width( divider ), y ), + utf8_width( divider ), 0, FG, divider ); + } + div--; + } else { + div = columns - 1; + } + + if( r_align ) { + right_print( w, y, indent, c_white, data[i + offset * columns] ); + if( indent == 1 ) { + indent = ( col_width * columns ) + 1; + } + } else { + fold_and_print_from( w, point( indent, y ), col_width, 0, c_white, data[i + offset * columns] ); + indent += col_width; + if( indent == ( col_width * columns ) + 1 ) { + indent = 1; + } + } + } + wattroff( w, FG ); +} + scrollingcombattext::cSCT::cSCT( const point &p_pos, const direction p_oDir, const std::string &p_sText, const game_message_type p_gmt, const std::string &p_sText2, const game_message_type p_gmt2, diff --git a/src/output.h b/src/output.h index 49690e134313a..1734b04bfe006 100644 --- a/src/output.h +++ b/src/output.h @@ -323,6 +323,9 @@ void center_print( const catacurses::window &w, int y, const nc_color &FG, const std::string &text ); int right_print( const catacurses::window &w, int line, int right_indent, const nc_color &FG, const std::string &text ); +void insert_table( const catacurses::window &w, int pad, int line, int columns, + const nc_color &FG, const std::string ÷r, bool r_align, + const std::vector &data ); void scrollable_text( const catacurses::window &w, const std::string &title, const std::string &text ); void scrollable_text( const std::function &init_window, diff --git a/src/ranged.cpp b/src/ranged.cpp index 9dc74876bda2a..6dfa1323a588a 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -1235,6 +1235,10 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type != "numbers" ) { window_width -= bars_pad; } + + std::string label_m = _( "Moves" ); + std::vector t_aims( 4 ), t_confidence( 16 ); + int aim_iter = 0, conf_iter = 0; nc_color col = c_dark_gray; @@ -1267,6 +1271,19 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in } line_number++; } + if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type == "numbers" ) { + std::string symbols = _( "Great - Normal" + " - Graze - Moves" ); + fold_and_print( w, point( 1, line_number++ ), window_width + bars_pad, + c_dark_gray, symbols ); + int len = utf8_width( symbols ) - 96; // 96 to subtract color codes + if( len > window_width + bars_pad ) { + line_number++; + } + for( int i = 0; i < window_width; i++ ) { + mvwprintw( w, point( i + 1, line_number ), "-" ); + } + } const auto front_or = [&]( const std::string & s, const char fallback ) { const auto keys = ctxt.keys_bound_to( s ); @@ -1295,11 +1312,16 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in } auto hotkey = front_or( type.action.empty() ? "FIRE" : type.action, ' ' ); - if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type != "numbers" ) { - print_colored_text( w, point( 1, line_number ), col, col, string_format( _( "%s %s:" ), label, - aim_l ) ); - right_print( w, line_number++, 1, c_light_blue, _( "Moves" ) ); - right_print( w, line_number, 1, c_light_blue, string_format( "%d", moves_to_fire ) ); + if( ( panel_type == "compact" || panel_type == "labels-narrow" ) ) { + if( display_type == "numbers" ) { + t_aims[aim_iter] = string_format( "%s:", label ); + t_confidence[( aim_iter * 4 ) + 3] = string_format( "%d", moves_to_fire ); + } else { + print_colored_text( w, point( 1, line_number ), col, col, string_format( _( "%s %s:" ), label, + aim_l ) ); + right_print( w, line_number++, 1, c_light_blue, _( "Moves" ) ); + right_print( w, line_number, 1, c_light_blue, string_format( "%d", moves_to_fire ) ); + } } else { print_colored_text( w, point( 1, line_number++ ), col, col, string_format( _( "[%s] %s %s: Moves to fire: " @@ -1310,6 +1332,19 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in double confidence = confidence_estimate( range, target_size, current_dispersion ); if( display_type == "numbers" ) { + if( panel_type == "compact" || panel_type == "labels-narrow" ) { + int last_chance = 0; + for( const confidence_rating &cr : confidence_config ) { + int chance = std::min( 100, 100.0 * ( cr.aim_level ) * confidence ) - last_chance; + last_chance += chance; + t_confidence[conf_iter] = string_format( "%3d%%", cr.color, chance ); + conf_iter++; + if( conf_iter == ( aim_iter * 4 ) + 3 ) { + conf_iter++; + } + } + aim_iter++; + } else } int last_chance = 0; std::string confidence_s = enumerate_as_string( confidence_config.begin(), confidence_config.end(), [&]( const confidence_rating & config ) { @@ -1337,6 +1372,15 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in } } + // Draw tables for compact Numbers display + if( ( panel_type == "compact" || panel_type == "labels-narrow" ) + && display_type == "numbers" ) { + const std::string divider = "|"; + int left_pad = 10, columns = 4; + insert_table( w, left_pad, ++line_number, columns, c_light_gray, divider, true, t_confidence ); + insert_table( w, 0, line_number, 1, c_light_gray, "", false, t_aims ); + line_number = line_number + 4; // 4 to account for the tables + } return line_number; } @@ -2033,10 +2077,9 @@ target_handler::trajectory target_ui::run( player &pc, ExitCode *exit_code ) void target_ui::init_window_and_input( player &pc ) { - // TODO: make 'narrow' layout work for 'numbers' display type std::string display_type = get_option( "ACCURACY_DISPLAY" ); std::string panel_type = panel_manager::get_manager().get_current_layout_id(); - narrow = ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type != "numbers"; + narrow = ( panel_type == "compact" || panel_type == "labels-narrow" ); int top = 0; int width; From b72c2382c751514eb80a250d7d8091e9c396eed6 Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Tue, 5 May 2020 22:10:49 -0500 Subject: [PATCH 2/4] Fix my curly braces --- src/ranged.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ranged.cpp b/src/ranged.cpp index 6dfa1323a588a..20f57586f7dae 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -1344,7 +1344,7 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in } } aim_iter++; - } else } + } else { int last_chance = 0; std::string confidence_s = enumerate_as_string( confidence_config.begin(), confidence_config.end(), [&]( const confidence_rating & config ) { @@ -1356,6 +1356,7 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in }, enumeration_conjunction::none ); line_number += fold_and_print_from( w, point( 1, line_number ), window_width, 0, c_dark_gray, confidence_s ); + } } else { std::vector> confidence_ratings; std::transform( confidence_config.begin(), confidence_config.end(), From e633595fa8b2946d95762ae255ce9efc0a6b2a8f Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Wed, 6 May 2020 21:35:24 -0500 Subject: [PATCH 3/4] astyle --- src/ranged.cpp | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ranged.cpp b/src/ranged.cpp index 20f57586f7dae..1c2cc57d1d1ed 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -1235,7 +1235,7 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type != "numbers" ) { window_width -= bars_pad; } - + std::string label_m = _( "Moves" ); std::vector t_aims( 4 ), t_confidence( 16 ); int aim_iter = 0, conf_iter = 0; @@ -1271,7 +1271,7 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in } line_number++; } - if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type == "numbers" ) { + if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type == "numbers" ) { std::string symbols = _( "Great - Normal" " - Graze - Moves" ); fold_and_print( w, point( 1, line_number++ ), window_width + bars_pad, @@ -1282,8 +1282,8 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in } for( int i = 0; i < window_width; i++ ) { mvwprintw( w, point( i + 1, line_number ), "-" ); - } - } + } + } const auto front_or = [&]( const std::string & s, const char fallback ) { const auto keys = ctxt.keys_bound_to( s ); @@ -1313,15 +1313,15 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in auto hotkey = front_or( type.action.empty() ? "FIRE" : type.action, ' ' ); if( ( panel_type == "compact" || panel_type == "labels-narrow" ) ) { - if( display_type == "numbers" ) { + if( display_type == "numbers" ) { t_aims[aim_iter] = string_format( "%s:", label ); t_confidence[( aim_iter * 4 ) + 3] = string_format( "%d", moves_to_fire ); - } else { - print_colored_text( w, point( 1, line_number ), col, col, string_format( _( "%s %s:" ), label, - aim_l ) ); - right_print( w, line_number++, 1, c_light_blue, _( "Moves" ) ); - right_print( w, line_number, 1, c_light_blue, string_format( "%d", moves_to_fire ) ); - } + } else { + print_colored_text( w, point( 1, line_number ), col, col, string_format( _( "%s %s:" ), label, + aim_l ) ); + right_print( w, line_number++, 1, c_light_blue, _( "Moves" ) ); + right_print( w, line_number, 1, c_light_blue, string_format( "%d", moves_to_fire ) ); + } } else { print_colored_text( w, point( 1, line_number++ ), col, col, string_format( _( "[%s] %s %s: Moves to fire: " @@ -1332,7 +1332,7 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in double confidence = confidence_estimate( range, target_size, current_dispersion ); if( display_type == "numbers" ) { - if( panel_type == "compact" || panel_type == "labels-narrow" ) { + if( panel_type == "compact" || panel_type == "labels-narrow" ) { int last_chance = 0; for( const confidence_rating &cr : confidence_config ) { int chance = std::min( 100, 100.0 * ( cr.aim_level ) * confidence ) - last_chance; @@ -1344,19 +1344,19 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in } } aim_iter++; - } else { - int last_chance = 0; - std::string confidence_s = enumerate_as_string( confidence_config.begin(), confidence_config.end(), - [&]( const confidence_rating & config ) { - // TODO: Consider not printing 0 chances, but only if you can print something (at least miss 100% or so) - int chance = std::min( 100, 100.0 * ( config.aim_level * confidence ) ) - last_chance; - last_chance += chance; - return string_format( "%s: %3d%%", pgettext( "aim_confidence", - config.label.c_str() ), config.color, chance ); - }, enumeration_conjunction::none ); - line_number += fold_and_print_from( w, point( 1, line_number ), window_width, 0, - c_dark_gray, confidence_s ); - } + } else { + int last_chance = 0; + std::string confidence_s = enumerate_as_string( confidence_config.begin(), confidence_config.end(), + [&]( const confidence_rating & config ) { + // TODO: Consider not printing 0 chances, but only if you can print something (at least miss 100% or so) + int chance = std::min( 100, 100.0 * ( config.aim_level * confidence ) ) - last_chance; + last_chance += chance; + return string_format( "%s: %3d%%", pgettext( "aim_confidence", + config.label.c_str() ), config.color, chance ); + }, enumeration_conjunction::none ); + line_number += fold_and_print_from( w, point( 1, line_number ), window_width, 0, + c_dark_gray, confidence_s ); + } } else { std::vector> confidence_ratings; std::transform( confidence_config.begin(), confidence_config.end(), From 9545ca335cd91b474efc16cc8aa2c14a2829eb43 Mon Sep 17 00:00:00 2001 From: Kilvoctu Date: Thu, 7 May 2020 23:33:10 -0500 Subject: [PATCH 4/4] cleanup remove leftover comment and center colors legend for english --- src/output.cpp | 2 +- src/ranged.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 123b7e56337c4..0e1434be74e62 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -1839,7 +1839,7 @@ void insert_table( const catacurses::window &w, int pad, int line, int columns, { const int width = getmaxx( w ); const int rows = getmaxy( w ); - const int col_width = ( ( width - pad ) / columns );// + utf8_width( divider ) ; + const int col_width = ( ( width - pad ) / columns ); int indent = 1; // 1 for right window border if( r_align ) { indent = ( col_width * columns ) + 1; diff --git a/src/ranged.cpp b/src/ranged.cpp index 1c2cc57d1d1ed..97a290a1011ad 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -1272,7 +1272,7 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in line_number++; } if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type == "numbers" ) { - std::string symbols = _( "Great - Normal" + std::string symbols = _( " Great - Normal" " - Graze - Moves" ); fold_and_print( w, point( 1, line_number++ ), window_width + bars_pad, c_dark_gray, symbols );