Skip to content

Commit

Permalink
Merge pull request #71307 from BrettDong/remove-legacy-display-fn
Browse files Browse the repository at this point in the history
Remove unused legacy functions in display namespace
  • Loading branch information
akrieger authored Jan 28, 2024
2 parents d8490ae + 60e489a commit 47cebfe
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 318 deletions.
305 changes: 0 additions & 305 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,49 +122,6 @@ std::string display::get_temp( const Character &u )
return temp;
}

std::string display::get_moon_graphic()
{
//moon phase display
static std::vector<std::string> vMoonPhase = { "( )", "( ))", "( | )", "(( )" };

const int iPhase = static_cast<int>( get_moon_phase( calendar::turn ) );
std::string sPhase = vMoonPhase[iPhase % 4];

if( iPhase > 0 ) {
sPhase.insert( 5 - ( ( iPhase > 4 ) ? iPhase % 4 : 0 ), "</color>" );
sPhase.insert( 5 - ( ( iPhase < 4 ) ? iPhase + 1 : 5 ),
"<color_" + string_from_color( i_black ) + ">" );
}
return sPhase;
}

std::string display::get_moon()
{
const int iPhase = static_cast<int>( get_moon_phase( calendar::turn ) );
switch( iPhase ) {
case 0:
return _( "New moon" );
case 1:
return _( "Waxing crescent" );
case 2:
return _( "Half moon" );
case 3:
return _( "Waxing gibbous" );
case 4:
return _( "Full moon" );
case 5:
return _( "Waning gibbous" );
case 6:
return _( "Half moon" );
case 7:
return _( "Waning crescent" );
case 8:
return _( "Dark moon" );
default:
return "";
}
}

std::string display::time_approx( const time_point &turn )
{
const int iHour = hour_of_day<int>( turn );
Expand Down Expand Up @@ -328,90 +285,6 @@ static std::pair<bodypart_id, bodypart_id> temp_delta( const Character &u )
return std::make_pair( current_bp_extreme, conv_bp_extreme );
}

static int define_temp_level( const units::temperature lvl )
{
if( lvl > BODYTEMP_SCORCHING ) {
return 7;
} else if( lvl > BODYTEMP_VERY_HOT ) {
return 6;
} else if( lvl > BODYTEMP_HOT ) {
return 5;
} else if( lvl > BODYTEMP_COLD ) {
return 4;
} else if( lvl > BODYTEMP_VERY_COLD ) {
return 3;
} else if( lvl > BODYTEMP_FREEZING ) {
return 2;
}
return 1;
}

std::string display::temp_delta_string( const Character &u )
{
std::string temp_message;
std::pair<bodypart_id, bodypart_id> temp_pair = temp_delta( u );
// Assign zones for comparisons
const int cur_zone = define_temp_level( u.get_part_temp_cur( temp_pair.first ) );
const int conv_zone = define_temp_level( u.get_part_temp_conv( temp_pair.second ) );

// delta will be positive if temp_cur is rising
const int delta = conv_zone - cur_zone;
// Decide if temp_cur is rising or falling
if( delta > 2 ) {
temp_message = _( " (Rising!!)" );
} else if( delta == 2 ) {
temp_message = _( " (Rising!)" );
} else if( delta == 1 ) {
temp_message = _( " (Rising)" );
} else if( delta == 0 ) {
temp_message.clear();
} else if( delta == -1 ) {
temp_message = _( " (Falling)" );
} else if( delta == -2 ) {
temp_message = _( " (Falling!)" );
} else {
temp_message = _( " (Falling!!)" );
}
return temp_message;
}

std::pair<std::string, nc_color> display::temp_delta_arrows( const Character &u )
{
std::string temp_message;
nc_color temp_color = c_white;
std::pair<bodypart_id, bodypart_id> temp_pair = temp_delta( u );
// Assign zones for comparisons
const int cur_zone = define_temp_level( u.get_part_temp_cur( temp_pair.first ) );
const int conv_zone = define_temp_level( u.get_part_temp_conv( temp_pair.second ) );

// delta will be positive if temp_cur is rising
const int delta = conv_zone - cur_zone;
// Decide if temp_cur is rising or falling
if( delta > 2 ) {
temp_message = " ↑↑↑";
temp_color = c_red;
} else if( delta == 2 ) {
temp_message = " ↑↑";
temp_color = c_light_red;
} else if( delta == 1 ) {
temp_message = "";
temp_color = c_yellow;
} else if( delta == 0 ) {
temp_message = "-";
temp_color = c_green;
} else if( delta == -1 ) {
temp_message = "";
temp_color = c_light_blue;
} else if( delta == -2 ) {
temp_message = " ↓↓";
temp_color = c_cyan;
} else {
temp_message = " ↓↓↓";
temp_color = c_blue;
}
return std::make_pair( temp_message, temp_color );
}

std::pair<std::string, nc_color> display::temp_text_color( const Character &u,
const bodypart_str_id &bp )
{
Expand Down Expand Up @@ -543,24 +416,6 @@ std::pair<std::string, nc_color> display::power_balance_text_color( const avatar
return std::make_pair( s_pwr, c_pwr );
}

std::pair<std::string, nc_color> display::mana_text_color( const Character &you )
{
nc_color c_mana = c_red;
std::string s_mana;
if( you.magic->max_mana( you ) <= 0 ) {
s_mana = "--";
c_mana = c_light_gray;
} else {
if( you.magic->available_mana() >= you.magic->max_mana( you ) / 2 ) {
c_mana = c_light_blue;
} else if( you.magic->available_mana() >= you.magic->max_mana( you ) / 3 ) {
c_mana = c_yellow;
}
s_mana = std::to_string( you.magic->available_mana() );
}
return std::make_pair( s_mana, c_mana );
}

std::pair<std::string, nc_color> display::safe_mode_text_color( const bool classic_mode )
{
// "classic" mode used by draw_limb2 and draw_health_classic are "SAFE" or (empty)
Expand Down Expand Up @@ -1607,166 +1462,6 @@ std::string display::colorized_bodygraph_text( const Character &u, const std::st
return ret;
}

// Print monster info to the given window
void display::print_mon_info( const avatar &u, const catacurses::window &w, int hor_padding,
bool compact )
{
const monster_visible_info &mon_visible = u.get_mon_visible();
const auto &unique_types = mon_visible.unique_types;
const auto &unique_mons = mon_visible.unique_mons;
const auto &dangerous = mon_visible.dangerous;

const int width = getmaxx( w ) - 2 * hor_padding;
const int maxheight = getmaxy( w ) - 1;

const int startrow = 0;

// Print the direction headings
// Reminder:
// 7 0 1 unique_types uses these indices;
// 6 8 2 0-7 are provide by direction_from()
// 5 4 3 8 is used for local monsters (for when we explain them below)

const std::array<std::string, 8> dir_labels = {{
_( "North:" ), _( "NE:" ), _( "East:" ), _( "SE:" ),
_( "South:" ), _( "SW:" ), _( "West:" ), _( "NW:" )
}
};
std::array<int, 8> widths;
for( int i = 0; i < 8; i++ ) {
widths[i] = utf8_width( dir_labels[i] );
}
std::array<int, 8> xcoords;
const std::array<int, 8> ycoords = {{ 0, 0, 1, 2, 2, 2, 1, 0 }};
xcoords[0] = xcoords[4] = width / 3;
xcoords[1] = xcoords[3] = xcoords[2] = ( width / 3 ) * 2;
xcoords[5] = xcoords[6] = xcoords[7] = 0;
//for the alignment of the 1,2,3 rows on the right edge (East - NE)
xcoords[2] -= widths[2] - widths[1];
for( int i = 0; i < 8; i++ ) {
nc_color c = unique_types[i].empty() && unique_mons[i].empty() ? c_dark_gray
: ( dangerous[i] ? c_light_red : c_light_gray );
mvwprintz( w, point( xcoords[i] + hor_padding, ycoords[i] + startrow ), c, dir_labels[i] );
}

// Print the symbols of all monsters in all directions.
for( int i = 0; i < 8; i++ ) {
point pr( xcoords[i] + widths[i] + 1, ycoords[i] + startrow );

// The list of symbols needs a space on each end.
int symroom = ( width / 3 ) - widths[i] - 2;
const int typeshere_npc = unique_types[i].size();
const int typeshere_mon = unique_mons[i].size();
const int typeshere = typeshere_mon + typeshere_npc;
for( int j = 0; j < typeshere && j < symroom; j++ ) {
nc_color c;
std::string sym;
if( symroom < typeshere && j == symroom - 1 ) {
// We've run out of room!
c = c_white;
sym = "+";
} else if( j < typeshere_npc ) {
switch( unique_types[i][j]->get_attitude() ) {
case NPCATT_KILL:
c = c_red;
break;
case NPCATT_FOLLOW:
c = c_light_green;
break;
default:
c = c_pink;
break;
}
sym = "@";
} else {
const mtype &mt = *unique_mons[i][j - typeshere_npc].first;
c = mt.color;
sym = mt.sym;
}
mvwprintz( w, pr, c, sym );

pr.x++;
}
}

// Now we print their full names!
struct nearest_loc_and_cnt {
int nearest_loc;
int cnt;
};
std::map<const mtype *, nearest_loc_and_cnt> all_mons;
for( int loc = 0; loc < 9; loc++ ) {
for( const std::pair<const mtype *, int> &mon : unique_mons[loc] ) {
const auto mon_it = all_mons.find( mon.first );
if( mon_it == all_mons.end() ) {
all_mons.emplace( mon.first, nearest_loc_and_cnt{ loc, mon.second } );
} else {
// 8 being the nearest location (local monsters)
mon_it->second.nearest_loc = std::max( mon_it->second.nearest_loc, loc );
mon_it->second.cnt += mon.second;
}
}
}
std::array<std::vector<std::pair<const mtype *, int>>, 9> mons_at;
for( const std::pair<const mtype *const, nearest_loc_and_cnt> &mon : all_mons ) {
mons_at[mon.second.nearest_loc].emplace_back( mon.first, mon.second.cnt );
}

// Rows 0-2 are for labels.
// Start monster names on row 3
point pr( hor_padding, 3 + startrow );
// In non-compact mode, leave a blank line
if( !compact ) {
pr.y++;
}

// Print monster names, starting with those at location 8 (nearby).
for( int j = 8; j >= 0 && pr.y < maxheight; j-- ) {
// Separate names by some number of spaces (more for local monsters).
int namesep = j == 8 ? 2 : 1;
for( const std::pair<const mtype *, int> &mon : mons_at[j] ) {
const mtype *const type = mon.first;
const int count = mon.second;
if( pr.y >= maxheight ) {
// no space to print to anyway
break;
}

const mtype &mt = *type;
std::string name = mt.nname( count );
// Some languages don't have plural forms, but we want to always
// omit 1.
if( count != 1 ) {
name = string_format( pgettext( "monster count and name", "%1$d %2$s" ),
count, name );
}

// Move to the next row if necessary. (The +2 is for the "Z ").
if( pr.x + 2 + utf8_width( name ) >= width ) {
pr.y++;
pr.x = hor_padding;
}

if( pr.y < maxheight ) { // Don't print if we've overflowed
mvwprintz( w, pr, mt.color, mt.sym );
pr.x += 2; // symbol and space
nc_color danger = c_dark_gray;
if( mt.difficulty >= 30 ) {
danger = c_red;
} else if( mt.difficulty >= 16 ) {
danger = c_light_red;
} else if( mt.difficulty >= 8 ) {
danger = c_white;
} else if( mt.agro > 0 ) {
danger = c_light_gray;
}
mvwprintz( w, pr, danger, name );
pr.x += utf8_width( name ) + namesep;
}
}
}
}

std::pair<std::string, nc_color> display::weather_text_color( const Character &u )
{
if( u.pos().z < 0 ) {
Expand Down
13 changes: 0 additions & 13 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ struct disp_bodygraph_cache {
namespace display
{
// Functions returning plain strings
// Current moon phase, ex. "Full moon", "Waxing crescent"
std::string get_moon();
// Current moon phase as ascii-art, ex. "( )", "( ))"
std::string get_moon_graphic();
// Current date, in terms of day within season, ex. "Summer, day 17"
std::string date_string();
// Approximate time of day on the given turn, ex. "Early morning", "Around dusk"
Expand All @@ -100,8 +96,6 @@ std::string sundial_time_text_color( const Character &u, int width );

// Temperature at character location, if they have a thermometer
std::string get_temp( const Character &u );
// Change in character body temperature, ex. "(Rising)", "(Falling!!)"
std::string temp_delta_string( const Character &u );

// Text descriptor for given activity level, ex. "Light", "Brisk", "Extreme"
std::string activity_level_str( float level );
Expand Down Expand Up @@ -132,8 +126,6 @@ std::pair<std::string, nc_color> health_text_color( const Character &u );
std::pair<std::string, nc_color> fatigue_text_color( const Character &u );
std::pair<std::string, nc_color> pain_text_color( const Creature &c );
std::pair<std::string, nc_color> pain_text_color( const Character &u );
// Change in character body temperature, as colorized arrows
std::pair<std::string, nc_color> temp_delta_arrows( const Character &u );
// Character morale, as a color-coded ascii emoticon face
std::pair<std::string, nc_color> morale_face_color( const avatar &u );
// Helpers for morale_face_color
Expand All @@ -150,7 +142,6 @@ std::pair<std::string, nc_color> temp_text_color( const Character &u,
const bodypart_str_id &bp = bodypart_str_id::NULL_ID() );
std::pair<std::string, nc_color> power_text_color( const Character &u );
std::pair<std::string, nc_color> power_balance_text_color( const avatar &u );
std::pair<std::string, nc_color> mana_text_color( const Character &you );

std::pair<std::string, nc_color> safe_mode_text_color( bool classic_mode );
std::pair<std::string, nc_color> wind_text_color( const Character &u );
Expand Down Expand Up @@ -198,10 +189,6 @@ std::string weight_string( const Character &u );
// Functions returning colorized string
// gets the string that describes your health
std::string health_string( const Character &u );

// Prints a list of nearby monsters
void print_mon_info( const avatar &u, const catacurses::window &, int hor_padding = 0,
bool compact = false );
} // namespace display

#endif // CATA_SRC_DISPLAY_H

0 comments on commit 47cebfe

Please sign in to comment.