Skip to content

Commit

Permalink
Dynamic compact aim window pt.1 (#37715)
Browse files Browse the repository at this point in the history
* dynamic aim window

Make aim window dynamically shrink in size whenever sidebar is set to compact

* fix astyle regressions

* use right_print

Right align text using right_print instead of janky solution

* Set up to split project into two parts

Add conditionals to exclude Numbers indicator style, to work on later. Also fix minor bugs.

* Right align "moves to fire" text and remove hotkeys display

* fix translation markers

fix translation markers and clean up some code

* text handling

Minor refactor of aim strings, change "moves to fire" to "moves", detect length of "symbols" line and wrap if necessary

* revise text wrapping

* commit suggestions

* use correct types

* Fix conflicts

Fix conflicts by adapting code into new existing code

* astyle

* trim includes

remove the unnecessary includes that I accidentally added during fixing conflicts
  • Loading branch information
Kilvoctu authored Apr 27, 2020
1 parent d1c39eb commit 5926e6e
Showing 1 changed file with 79 additions and 19 deletions.
98 changes: 79 additions & 19 deletions src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "optional.h"
#include "options.h"
#include "output.h"
#include "panels.h"
#include "player.h"
#include "player_activity.h"
#include "point.h"
Expand Down Expand Up @@ -836,6 +837,7 @@ static int draw_targeting_window( const catacurses::window &w_target, const std:
// Draw the "title" of the window.
mvwprintz( w_target, point( 2, 0 ), c_white, "< " );
std::string title;
std::string panel_type = panel_manager::get_manager().get_current_layout_id();

switch( mode ) {
case TARGET_MODE_FIRE:
Expand Down Expand Up @@ -877,8 +879,20 @@ static int draw_targeting_window( const catacurses::window &w_target, const std:

// The -1 is the -2 from above, but adjusted since this is a total, not an index.
int lines_used = getmaxy( w_target ) - 1 - text_y;
mvwprintz( w_target, point( 1, text_y++ ), c_white,
_( "Move cursor to target with directional keys" ) );

if( panel_type == "compact" || panel_type == "labels-narrow" ) {
std::string display_type = get_option<std::string>( "ACCURACY_DISPLAY" );
if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type != "numbers" ) {
int text_y = getmaxy( w_target ) - 1;
int lines_used = getmaxy( w_target ) - 1 - text_y;
const std::string aimhelp = _( "< [?] show help >" );
mvwprintz( w_target, point( 1, text_y ), c_white, aimhelp );
return lines_used;
}
} else {
mvwprintz( w_target, point( 1, text_y++ ), c_white,
_( "Move cursor to target with directional keys" ) );
}

const auto front_or = [&]( const std::string & s, const char fallback ) {
const auto keys = ctxt.keys_bound_to( s );
Expand Down Expand Up @@ -1047,8 +1061,13 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in
const dispersion_sources &dispersion, const std::vector<confidence_rating> &confidence_config,
double range, double target_size, int recoil = 0 )
{
const int window_width = getmaxx( w ) - 2; // Window width minus borders.
int window_width = getmaxx( w ) - 2; // Window width minus borders.
std::string display_type = get_option<std::string>( "ACCURACY_DISPLAY" );
std::string panel_type = panel_manager::get_manager().get_current_layout_id();
const int bars_pad = 3; // Padding for "bars" to fit moves_to_fire value.
if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type != "numbers" ) {
window_width -= bars_pad;
}

nc_color col = c_dark_gray;

Expand All @@ -1061,12 +1080,25 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in

if( display_type != "numbers" ) {
std::string symbols;
int column_number = 1;
if( !( panel_type == "compact" || panel_type == "labels-narrow" ) ) {
std::string label = _( "Symbols:" );
mvwprintw( w, point( column_number, line_number ), label );
column_number += utf8_width( label ) + 1; // 1 for whitespace after 'Symbols:'
}
for( const confidence_rating &cr : confidence_config ) {
symbols += string_format( " <color_%s>%s</color> = %s", cr.color, cr.symbol,
pgettext( "aim_confidence", cr.label.c_str() ) );
std::string label = pgettext( "aim_confidence", cr.label.c_str() );
std::string symbols = string_format( "<color_%s>%s</color> = %s", cr.color, cr.symbol,
label );
int line_len = utf8_width( label ) + 5; // 5 for '# = ' and whitespace at end
if( ( window_width + bars_pad - column_number ) < line_len ) {
column_number = 1;
line_number++;
}
print_colored_text( w, point( column_number, line_number ), col, col, symbols );
column_number += line_len;
}
print_colored_text( w, point( 1, line_number++ ), col, col, string_format(
_( "Symbols:%s" ), symbols ) );
line_number++;
}

const auto front_or = [&]( const std::string & s, const char fallback ) {
Expand All @@ -1077,7 +1109,8 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in
for( const aim_type &type : aim_types ) {
dispersion_sources current_dispersion = dispersion;
int threshold = MAX_RECOIL;
std::string label = _( "Current Aim" );
std::string label = _( "Current" );
std::string aim_l = _( "Aim" );
if( type.has_threshold ) {
label = type.name;
threshold = type.threshold;
Expand All @@ -1095,9 +1128,17 @@ static int print_ranged_chance( const player &p, const catacurses::window &w, in
}

auto hotkey = front_or( type.action.empty() ? "FIRE" : type.action, ' ' );
print_colored_text( w, point( 1, line_number++ ), col, col,
string_format( _( "<color_white>[%s]</color> %s: Moves to fire: <color_light_blue>%d</color>" ),
hotkey, label, moves_to_fire ) );
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 ) );
} else {
print_colored_text( w, point( 1, line_number++ ), col, col,
string_format( _( "<color_white>[%s]</color> %s %s: Moves to fire: "
"<color_light_blue>%d</color>" ),
hotkey, label, aim_l, moves_to_fire ) );
}

double confidence = confidence_estimate( range, target_size, current_dispersion );

Expand Down Expand Up @@ -1259,17 +1300,17 @@ std::vector<aim_type> Character::get_aim_types( const item &gun ) const
thresholds_it = std::adjacent_find( thresholds.begin(), thresholds.end() );
}
thresholds_it = thresholds.begin();
aim_types.push_back( aim_type { _( "Regular Aim" ), "AIMED_SHOT", _( "[%c] to aim and fire." ),
aim_types.push_back( aim_type { _( "Regular" ), "AIMED_SHOT", _( "[%c] to aim and fire." ),
true, *thresholds_it } );
thresholds_it++;
if( thresholds_it != thresholds.end() ) {
aim_types.push_back( aim_type { _( "Careful Aim" ), "CAREFUL_SHOT",
aim_types.push_back( aim_type { _( "Careful" ), "CAREFUL_SHOT",
_( "[%c] to take careful aim and fire." ), true,
*thresholds_it } );
thresholds_it++;
}
if( thresholds_it != thresholds.end() ) {
aim_types.push_back( aim_type { _( "Precise Aim" ), "PRECISE_SHOT",
aim_types.push_back( aim_type { _( "Precise" ), "PRECISE_SHOT",
_( "[%c] to take precise aim and fire." ), true,
*thresholds_it } );
}
Expand Down Expand Up @@ -1351,6 +1392,7 @@ std::vector<tripoint> target_handler::target_ui( player &pc, target_mode mode,
// TODO: this should return a reference to a static vector which is cleared on each call.
static const std::vector<tripoint> empty_result{};
std::vector<tripoint> ret;
std::string panel_type = panel_manager::get_manager().get_current_layout_id();

int sight_dispersion = 0;
if( relevant ) {
Expand Down Expand Up @@ -1384,6 +1426,11 @@ std::vector<tripoint> target_handler::target_ui( player &pc, target_mode mode,
// Cover up more low-value ui elements if we're tight on space.
height = 25;
}
// Call accuracy display type to exclude "Numbers" style
std::string display_type = get_option<std::string>( "ACCURACY_DISPLAY" );
if( ( panel_type == "compact" || panel_type == "labels-narrow" ) && display_type != "numbers" ) {
width = 34;
}
catacurses::window w_target = catacurses::newwin( height, width, point( TERMX - width, top ) );

input_context ctxt( "TARGET" );
Expand Down Expand Up @@ -1531,12 +1578,25 @@ std::vector<tripoint> target_handler::target_ui( player &pc, target_mode mode,
g->draw_line( dst, center, ret_this_zlevel );

// Print to target window
mvwprintw( w_target, point( 1, line_number++ ), _( "Range: %d/%d Elevation: %d Targets: %d" ),
rl_dist( src, dst ), range, relative_elevation, t.size() );

if( ( panel_type == "compact" || panel_type == "labels-narrow" )
&& display_type != "numbers" ) {
mvwprintw( w_target, point( 1, line_number++ ), _( "Range: %d/%d Elevation: %d" ),
rl_dist( src, dst ), range, relative_elevation );
mvwprintw( w_target, point( 1, line_number++ ), _( "Targets: %d" ), t.size() );
} else {
mvwprintw( w_target, point( 1, line_number++ ), _( "Range: %d Elevation: %d "
"Targets: %d" ), range, relative_elevation, t.size() );
}
} else {
mvwprintw( w_target, point( 1, line_number++ ), _( "Range: %d Elevation: %d Targets: %d" ), range,
relative_elevation, t.size() );
if( ( panel_type == "compact" || panel_type == "labels-narrow" )
&& display_type != "numbers" ) {
mvwprintw( w_target, point( 1, line_number++ ), _( "Range: %d/%d Elevation: %d" ),
rl_dist( src, dst ), range, relative_elevation );
mvwprintw( w_target, point( 1, line_number++ ), _( "Targets: %d" ), t.size() );
} else {
mvwprintw( w_target, point( 1, line_number++ ), _( "Range: %d Elevation: %d "
"Targets: %d" ), range, relative_elevation, t.size() );
}
}

// Skip blank lines if we're short on space.
Expand Down

0 comments on commit 5926e6e

Please sign in to comment.