Skip to content

Commit

Permalink
Overhaul look around panels (CleverRaven#39793)
Browse files Browse the repository at this point in the history
(cherry picked from commit 16aba7e)
  • Loading branch information
Matthew Taylor authored and tung committed Jun 26, 2020
1 parent 0e9aff6 commit 2120e63
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 91 deletions.
106 changes: 65 additions & 41 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5739,70 +5739,77 @@ void game::print_visibility_info( const catacurses::window &w_look, int column,
break;
}

mvwprintw( w_look, point( line, column ), visibility_message );
mvwprintz( w_look, point( line, column ), c_light_gray, visibility_message );
line += 2;
}

void game::print_terrain_info( const tripoint &lp, const catacurses::window &w_look,
const std::string &area_name, int column,
int &line )
const std::string &area_name, int column, int &line )
{
const int max_width = getmaxx( w_look ) - column - 1;
int lines;

// Print OMT type and terrain type on first line.
std::string tile = m.tername( lp );
tile = "(" + area_name + ") " + tile;
trim_and_print( w_look, point( column, line ), max_width, c_white, area_name );
trim_and_print( w_look, point( column + utf8_width( area_name ) + 1, line ), max_width,
c_light_gray, tile );

// Furniture on second line if any.
if( m.has_furn( lp ) ) {
tile += "; " + m.furnname( lp );
mvwprintz( w_look, point( column, ++line ), c_light_blue, m.furnname( lp ) );
}

// Cover percentage from terrain and furniture next.
fold_and_print( w_look, point( column, ++line ), max_width, c_light_gray, _( "Cover: %d%%" ),
m.coverage( lp ) );
// Terrain and furniture flags next. These can be several lines for some combinations of
// furnitures and terrains.
std::vector<std::string> lines = foldstring( m.features( lp ), max_width );
int numlines = lines.size();
for( int i = 0; i < numlines; i++ ) {
mvwprintz( w_look, point( column, ++line ), c_light_gray, lines[i] );
}

// Move cost from terrain and furntiure and vehicle parts.
// Vehicle part information is printed in a different function.
if( m.impassable( lp ) ) {
lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
_( "%s; Impassable" ),
tile );
mvwprintz( w_look, point( column, ++line ), c_light_red, _( "Impassable" ) );
} else {
lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
_( "%s; Movement cost %d" ),
tile, m.move_cost( lp ) * 50 );

const auto ll = get_light_level( std::max( 1.0,
LIGHT_AMBIENT_LIT - m.ambient_light_at( lp ) + 1.0 ) );
mvwprintw( w_look, point( column, ++lines ), _( "Lighting: " ) );
wprintz( w_look, ll.second, ll.first );
mvwprintz( w_look, point( column, ++line ), c_light_gray, _( "Move cost: %d" ),
m.move_cost( lp ) * 50 );
}

// Next print the string on any SIGN flagged furniture if any.
std::string signage = m.get_signage( lp );
if( !signage.empty() ) {
trim_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
// NOLINTNEXTLINE(cata-text-style): the question mark does not end a sentence
u.has_trait( trait_ILLITERATE ) ? _( "Sign: ???" ) : _( "Sign: %s" ), signage );
std::string sign_string = u.has_trait( trait_ILLITERATE ) ? "???" : signage;
mvwprintz( w_look, point( column, ++line ), c_light_gray, _( "Sign: %s" ), sign_string );
}

// Print light level on the selected tile.
std::pair<std::string, nc_color> ll = get_light_level( std::max( 1.0,
LIGHT_AMBIENT_LIT - m.ambient_light_at( lp ) + 1.0 ) );
mvwprintz( w_look, point( column, ++line ), c_light_gray, _( "Lighting: " ) );
mvwprintz( w_look, point( column + utf8_width( _( "Lighting: " ) ), line ), ll.second, ll.first );

// Print the terrain and any furntiure on the tile below and whether it is walkable.
if( m.has_zlevels() && lp.z > -OVERMAP_DEPTH && !m.has_floor( lp ) ) {
// Print info about stuff below
tripoint below( lp.xy(), lp.z - 1 );
std::string tile_below = m.tername( below );
if( m.has_furn( below ) ) {
tile_below += "; " + m.furnname( below );
tile_below += ", " + m.furnname( below );
}

if( !m.has_floor_or_support( lp ) ) {
fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
_( "Below: %s; No support" ),
tile_below );
fold_and_print( w_look, point( column, ++line ), max_width, c_dark_gray,
_( "Below: %s; No support" ), tile_below );
} else {
fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
_( "Below: %s; Walkable" ),
fold_and_print( w_look, point( column, ++line ), max_width, c_dark_gray, _( "Below: %s; Walkable" ),
tile_below );
}
}

int map_features = fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
m.features( lp ) );
fold_and_print( w_look, point( column, ++lines ), max_width, c_light_gray, _( "Coverage: %d%%" ),
m.coverage( lp ) );
if( line < lines ) {
line = lines + map_features - 1;
}
++line;
}

void game::print_fields_info( const tripoint &lp, const catacurses::window &w_look, int column,
Expand All @@ -5821,6 +5828,11 @@ void game::print_fields_info( const tripoint &lp, const catacurses::window &w_lo
mvwprintz( w_look, point( column, ++line ), cur.color(), cur.name() );
}
}

int size = std::distance( tmpfield.begin(), tmpfield.end() );
if( size > 0 ) {
mvwprintz( w_look, point( column, ++line ), c_white, "\n" );
}
}

void game::print_trap_info( const tripoint &lp, const catacurses::window &w_look, const int column,
Expand All @@ -5840,6 +5852,8 @@ void game::print_trap_info( const tripoint &lp, const catacurses::window &w_look

mvwprintz( w_look, point( column, ++line ), tr.color, tr_name );
}

++line;
}

void game::print_creature_info( const Creature *creature, const catacurses::window &w_look,
Expand All @@ -5855,7 +5869,11 @@ void game::print_vehicle_info( const vehicle *veh, int veh_part, const catacurse
const int column, int &line, const int last_line )
{
if( veh ) {
mvwprintw( w_look, point( column, ++line ), _( "There is a %s there. Parts:" ), veh->name );
// Print the name of the vehicle.
mvwprintz( w_look, point( column, ++line ), c_light_gray, _( "Vehicle: " ) );
mvwprintz( w_look, point( column + utf8_width( _( "Vehicle: " ) ), line ), c_white, "%s",
veh->name );
// Then the list of parts on that tile.
line = veh->print_part_list( w_look, ++line, last_line, getmaxx( w_look ), veh_part );
}
}
Expand Down Expand Up @@ -5903,9 +5921,10 @@ void game::print_items_info( const tripoint &lp, const catacurses::window &w_loo
_( "There's something there, but you can't see what it is." ) );
return;
} else {
std::map<std::string, int> item_names;
std::map<std::string, std::pair<int, nc_color>> item_names;
for( auto &item : m.i_at( lp ) ) {
++item_names[item.tname()];
++item_names[item.tname()].first;
item_names[item.tname()].second = item.color_in_inventory();
}

const int max_width = getmaxx( w_look ) - column - 1;
Expand All @@ -5915,12 +5934,12 @@ void game::print_items_info( const tripoint &lp, const catacurses::window &w_loo
break;
}

if( it.second > 1 ) {
trim_and_print( w_look, point( column, ++line ), max_width, c_white,
if( it.second.first > 1 ) {
trim_and_print( w_look, point( column, ++line ), max_width, it.second.second,
pgettext( "%s is the name of the item. %d is the quantity of that item.", "%s [%d]" ),
it.first.c_str(), it.second );
it.first.c_str(), it.second.first );
} else {
trim_and_print( w_look, point( column, ++line ), max_width, c_white, it.first );
trim_and_print( w_look, point( column, ++line ), max_width, it.second.second, it.first );
}
}
}
Expand Down Expand Up @@ -7705,6 +7724,11 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
::get_hp_bar( critter->get_hp(), critter->get_hp_max(), false );
}
mvwprintz( w_monsters, point( width - 25, y ), color, sText );
const int bar_max_width = 5;
const int bar_width = utf8_width( sText );
for( int i = 0; i < bar_max_width - bar_width; ++i ) {
mvwprintz( w_monsters, point( width - 21 - i, y ), c_white, "." );
}

if( m != nullptr ) {
const auto att = m->get_attitude();
Expand Down
67 changes: 35 additions & 32 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,54 +627,57 @@ static std::pair<std::string, nc_color> hp_description( int cur_hp, int max_hp )
damage_info = _( "It is nearly dead!" );
col = c_red;
}
/*
// This is unused code that allows the player to see the exact amount of monster HP, to be implemented later!
if( true ) ) {
damage_info = string_format( _( "It has %d/%d HP." ), cur_hp, max_hp );
}*/

return std::make_pair( damage_info, col );
}

int monster::print_info( const catacurses::window &w, int vStart, int vLines, int column ) const
{
const int vEnd = vStart + vLines;

mvwprintz( w, point( column, vStart ), basic_symbol_color(), name() );
wprintw( w, " " );
const auto att = get_attitude();
wprintz( w, att.second, att.first );

if( debug_mode ) {
wprintz( w, c_light_gray, _( " Difficulty " ) + to_string( type->difficulty ) );
}

if( sees( g->u ) ) {
mvwprintz( w, point( column, ++vStart ), c_yellow, _( "Aware of your presence!" ) );
}

std::string effects = get_effect_status();
if( !effects.empty() ) {
trim_and_print( w, point( column, ++vStart ), getmaxx( w ) - 2, h_white, effects );
const int max_width = getmaxx( w ) - column - 1;

// Print health bar, monster name, then statuses on the first line.
nc_color color = c_white;
std::string bar_str;
get_HP_Bar( color, bar_str );
mvwprintz( w, point( column, vStart ), color, bar_str );
const int bar_max_width = 5;
const int bar_width = utf8_width( bar_str );
for( int i = 0; i < bar_max_width - bar_width; ++i ) {
mvwprintz( w, point( column + 4 - i, vStart ), c_white, "." );
}
mvwprintz( w, point( column + bar_max_width + 1, vStart ), basic_symbol_color(), name() );
trim_and_print( w, point( column + bar_max_width + utf8_width( " " + name() + " " ), vStart ),
max_width - bar_max_width - utf8_width( " " + name() + " " ), h_white, get_effect_status() );

// Hostility indicator on the second line.
std::pair<std::string, nc_color> att = get_attitude();
mvwprintz( w, point( column, ++vStart ), att.second, att.first );

// Awareness indicator in the third line.
std::string senses_str = sees( g->u ) ? _( "Can see to your current location" ) :
_( "Can't see to your current location" );
mvwprintz( w, point( column, ++vStart ), sees( g->u ) ? c_red : c_green, senses_str );

// Monster description on following lines.
std::vector<std::string> lines = foldstring( type->get_description(), max_width );
int numlines = lines.size();
for( int i = 0; i < numlines && vStart < vEnd; i++ ) {
mvwprintz( w, point( column, ++vStart ), c_light_gray, lines[i] );
}

const auto hp_desc = hp_description( hp, type->hp );
mvwprintz( w, point( column, ++vStart ), hp_desc.second, hp_desc.first );
// Riding indicator on next line after description.
if( has_effect( effect_ridden ) && mounted_player ) {
mvwprintz( w, point( column, ++vStart ), c_white, _( "Rider: %s" ), mounted_player->disp_name() );
}

// Show monster size on the last line
if( size_bonus > 0 ) {
wprintz( w, c_light_gray, _( " It is %s." ), size_names.at( get_size() ) );
}

std::vector<std::string> lines = foldstring( type->get_description(), getmaxx( w ) - 1 - column );
int numlines = lines.size();
for( int i = 0; i < numlines && vStart <= vEnd; i++ ) {
mvwprintz( w, point( column, ++vStart ), c_white, lines[i] );
mvwprintz( w, point( column, ++vStart ), c_light_gray, _( " It is %s." ),
size_names.at( get_size() ) );
}

return vStart;
return ++vStart;
}

std::string monster::extended_description() const
Expand Down
53 changes: 35 additions & 18 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,31 +2196,45 @@ int npc::print_info( const catacurses::window &w, int line, int vLines, int colu
// is a blank line. w is 13 characters tall, and we can't use the last one
// because it's a border as well; so we have lines 6 through 11.
// w is also 48 characters wide - 2 characters for border = 46 characters for us
mvwprintz( w, point( column, line++ ), c_white, _( "NPC: " ) );
wprintz( w, basic_symbol_color(), name );

if( sees( g->u ) ) {
mvwprintz( w, point( column, line++ ), c_yellow, _( "Aware of your presence!" ) );
// Print health bar and NPC name on the first line.
std::pair<std::string, nc_color> bar = get_hp_bar( hp_percentage(), 100 );
mvwprintz( w, point( column, line ), bar.second, bar.first );
const int bar_max_width = 5;
const int bar_width = utf8_width( bar.first );
for( int i = 0; i < bar_max_width - bar_width; ++i ) {
mvwprintz( w, point( column + 4 - i, line ), c_white, "." );
}
trim_and_print( w, point( column + bar.first.length() + 1, line ), iWidth, basic_symbol_color(),
name );

// Hostility indicator in the second line.
Attitude att = attitude_to( g->u );
const std::pair<translation, nc_color> res = Creature::get_attitude_ui_data( att );
mvwprintz( w, point( column, ++line ), res.second, res.first.translated() );

// Awareness indicator on the third line.
std::string senses_str = sees( g->u ) ? _( "Aware of your presence" ) :
_( "Unaware of you" );
mvwprintz( w, point( column, ++line ), sees( g->u ) ? c_yellow : c_green, senses_str );

// Print what item the NPC is holding if any on the fourth line.
if( is_armed() ) {
trim_and_print( w, point( column, line++ ), iWidth, c_red, _( "Wielding a %s" ), weapon.tname() );
mvwprintz( w, point( column, ++line ), c_light_gray, _( "Wielding: " ) );
trim_and_print( w, point( column + utf8_width( _( "Wielding: " ) ), line ), iWidth, c_red,
weapon.tname() );
}

const auto enumerate_print = [ w, last_line, column, iWidth, &line ]( const std::string & str_in,
nc_color color ) {
const std::vector<std::string> folded = foldstring( str_in, iWidth );
for( auto it = folded.begin(); it < folded.end() && line < last_line; ++it, ++line ) {
trim_and_print( w, point( column, line ), iWidth, color, *it );
}
};

// Worn gear list on following lines.
const std::string worn_str = enumerate_as_string( worn.begin(), worn.end(), []( const item & it ) {
return it.tname();
} );
if( !worn_str.empty() ) {
const std::string wearing = _( "Wearing: " ) + worn_str;
enumerate_print( wearing, c_light_blue );
std::vector<std::string> worn_lines = foldstring( _( "Wearing: " ) + worn_str, iWidth );
int worn_numlines = worn_lines.size();
for( int i = 0; i < worn_numlines && line < last_line; i++ ) {
trim_and_print( w, point( column, ++line ), iWidth, c_light_gray, worn_lines[i] );
}
}

// as of now, visibility of mutations is between 0 and 10
Expand All @@ -2238,10 +2252,13 @@ int npc::print_info( const catacurses::window &w, int line, int vLines, int colu
visibility_cap = round( dist * dist / 20.0 / ( per - 1 ) );
}

const auto trait_str = visible_mutations( visibility_cap );
const std::string trait_str = visible_mutations( visibility_cap );
if( !trait_str.empty() ) {
const std::string mutations = _( "Traits: " ) + trait_str;
enumerate_print( mutations, c_green );
std::vector<std::string> trait_lines = foldstring( _( "Traits: " ) + trait_str, iWidth );
int trait_numlines = trait_lines.size();
for( int i = 0; i < trait_numlines && line < last_line; i++ ) {
trim_and_print( w, point( column, ++line ), iWidth, c_light_gray, trait_lines[i] );
}
}

return line;
Expand Down

0 comments on commit 2120e63

Please sign in to comment.