Skip to content

Commit

Permalink
Refactor monsters shift-v menu (CleverRaven#36722)
Browse files Browse the repository at this point in the history
* Editing game.cpp

* Editing game.cpp 2

* Editing game.cpp 3

* Editing game.cpp 4

* Editing game.cpp 5

* Astyle

* To satisfy Clang-tidy build

* Coloring monster names and some fix

* Some polishing

* Fix npc info

* Another fix

* Fix long 3d vision directions text

* Fixed CleverRaven#24436

Based on commit 2657814 by 8street, originally
merged into mainline by KevinGranade.
  • Loading branch information
tung committed Jun 23, 2020
1 parent ec9c49a commit 02618ec
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 86 deletions.
133 changes: 50 additions & 83 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7483,47 +7483,34 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )

game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list )
{
int iInfoHeight = 14;
const int iInfoHeight = 15;
const int width = 45;
const int offsetX = TERMX - VIEW_OFFSET_X - width; //VIEW_OFFSET_X;
catacurses::window w_monsters = catacurses::newwin( TERMY - iInfoHeight - VIEW_OFFSET_Y * 2,
width - 2, point( offsetX + 1, VIEW_OFFSET_Y + 1 ) );
catacurses::window w_monsters_border = catacurses::newwin( TERMY - iInfoHeight - VIEW_OFFSET_Y * 2,
width, point( offsetX, VIEW_OFFSET_Y ) );
catacurses::window w_monster_info = catacurses::newwin( iInfoHeight - 1, width - 2,
point( offsetX + 1, TERMY - iInfoHeight - VIEW_OFFSET_Y ) );
catacurses::window w_monster_info_border = catacurses::newwin( iInfoHeight, width + 1,
point( offsetX, TERMY - iInfoHeight - VIEW_OFFSET_Y ) );
const int iMaxRows = TERMY - iInfoHeight - VIEW_OFFSET_Y * 2 - 1;

catacurses::window w_monsters = catacurses::newwin( iMaxRows, width - 2, point( offsetX + 1,
VIEW_OFFSET_Y + 1 ) );
catacurses::window w_monsters_border = catacurses::newwin( iMaxRows + 1, width, point( offsetX,
VIEW_OFFSET_Y ) );

catacurses::window w_monster_info = catacurses::newwin( iInfoHeight - 2, width - 2,
point( offsetX + 1, TERMY - iInfoHeight - VIEW_OFFSET_Y + 1 ) );
catacurses::window w_monster_info_border = catacurses::newwin( iInfoHeight, width, point( offsetX,
TERMY - iInfoHeight - VIEW_OFFSET_Y ) );

const int max_gun_range = u.weapon.gun_range( &u );

const tripoint stored_view_offset = u.view_offset;
u.view_offset = tripoint_zero;

int iActive = 0; // monster index that we're looking at
const int iMaxRows = TERMY - iInfoHeight - 2 - VIEW_OFFSET_Y * 2 - 1;
int iStartPos = 0;
cata::optional<tripoint> iLastActivePos;
Creature *cCurMon = nullptr;

for( int j = 0; j < iInfoHeight - 1; j++ ) {
mvwputch( w_monster_info_border, point( 0, j ), c_light_gray, LINE_XOXO );
mvwputch( w_monster_info_border, point( width - 1, j ), c_light_gray, LINE_XOXO );
}

for( int j = 0; j < width - 1; j++ ) {
mvwputch( w_monster_info_border, point( j, iInfoHeight - 1 ), c_light_gray, LINE_OXOX );
}

mvwputch( w_monsters_border, point_zero, BORDER_COLOR, LINE_OXXO ); // |^
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwhline( w_monsters_border, point( 1, 0 ), 0, width );
mvwputch( w_monsters_border, point( width - 1, 0 ), BORDER_COLOR, LINE_OOXX ); // ^|

for( int i = 1; i < getmaxy( w_monsters ) - 1; i++ ) {
mvwputch( w_monsters_border, point( 0, i ), BORDER_COLOR, LINE_XOXO ); // |
mvwputch( w_monsters_border, point( width - 1, i ), BORDER_COLOR, LINE_XOXO ); // |
}
draw_custom_border( w_monsters_border, true, true, true, true, true, true, LINE_XOXO, LINE_XOXO );
draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
true );

mvwprintz( w_monsters_border, point( 2, 0 ), c_light_green, "<Tab> " );
wprintz( w_monsters_border, c_white, _( "Monsters" ) );
Expand Down Expand Up @@ -7597,21 +7584,11 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
}

if( monster_list.empty() ) {
mvwputch( w_monsters_border, point( 0, TERMY - iInfoHeight - 1 - VIEW_OFFSET_Y * 2 ), BORDER_COLOR,
LINE_XOXO ); // |
mvwputch( w_monsters_border, point( width - 1, TERMY - iInfoHeight - 1 - VIEW_OFFSET_Y * 2 ),
BORDER_COLOR, LINE_XOXO ); // |
wrefresh( w_monsters_border );
mvwprintz( w_monsters, point( 2, 10 ), c_white, _( "You don't see any monsters around you!" ) );
mvwprintz( w_monsters, point( 2, iMaxRows / 3 ), c_white,
_( "You don't see any monsters around you!" ) );
} else {
werase( w_monsters );

mvwputch( w_monsters_border, point( 0, TERMY - iInfoHeight - 1 - VIEW_OFFSET_Y * 2 ), BORDER_COLOR,
LINE_XXXO ); // |-
mvwputch( w_monsters_border, point( width - 1, TERMY - iInfoHeight - 1 - VIEW_OFFSET_Y * 2 ),
BORDER_COLOR,
LINE_XOXX ); // -|

const int iNumMonster = monster_list.size();
const int iMenuSize = monster_list.size() + mSortCategory.size();

Expand All @@ -7630,7 +7607,7 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
}
}
// use selected row get the start row
calcStartPos( iStartPos, iSelPos, iMaxRows, iMenuSize );
calcStartPos( iStartPos, iSelPos, iMaxRows - 1, iMenuSize );

// get first visible monster and category
int iCurMon = iStartPos;
Expand All @@ -7640,7 +7617,7 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
--iCurMon;
}

const auto endY = std::min<int>( iMaxRows, iMenuSize );
const auto endY = std::min<int>( iMaxRows - 1, iMenuSize );
for( int y = 0; y < endY; ++y ) {
if( CatSortIter != mSortCategory.cend() ) {
const int iCurPos = iStartPos + y;
Expand All @@ -7663,11 +7640,16 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
bool is_npc = false;
const monster *m = dynamic_cast<monster *>( critter );
const npc *p = dynamic_cast<npc *>( critter );
nc_color name_color = critter->basic_symbol_color();

if( selected ) {
name_color = hilite( name_color );
}

if( m != nullptr ) {
mvwprintz( w_monsters, point( 1, y ), selected ? c_light_green : c_white, m->name() );
trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, m->name() );
} else {
mvwprintz( w_monsters, point( 1, y ), selected ? c_light_green : c_white, critter->disp_name() );
trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, critter->disp_name() );
is_npc = true;
}

Expand All @@ -7681,8 +7663,7 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
sSafemode = _( "<A>dd to safemode Blacklist" );
}

mvwhline( w_monsters, point( 0, getmaxy( w_monsters ) - 2 ), 0, width - 1 );
shortcut_print( w_monsters, point( 1, getmaxy( w_monsters ) - 2 ),
shortcut_print( w_monsters, point( 2, getmaxy( w_monsters ) - 1 ),
c_white, c_light_green, sSafemode );
}

Expand All @@ -7695,7 +7676,7 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
std::tie( sText, color ) =
::get_hp_bar( critter->get_hp(), critter->get_hp_max(), false );
}
mvwprintz( w_monsters, point( 22, y ), color, sText );
mvwprintz( w_monsters, point( width - 25, y ), color, sText );

if( m != nullptr ) {
const auto att = m->get_attitude();
Expand All @@ -7705,13 +7686,18 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
sText = npc_attitude_name( p->get_attitude() );
color = p->symbol_color();
}
mvwprintz( w_monsters, point( 28, y ), color, sText );
mvwprintz( w_monsters, point( width - 19, y ), color, sText );

const int mon_dist = rl_dist( u.pos(), critter->pos() );
const int numd = mon_dist > 999 ? 4 :
mon_dist > 99 ? 3 :
mon_dist > 9 ? 2 : 1;

mvwprintz( w_monsters, point( width - ( 6 + numw ), y ),
( selected ? c_light_green : c_light_gray ),
"%*d %s",
numw, rl_dist( u.pos(), critter->pos() ),
direction_name_short( direction_from( u.pos(), critter->pos() ) ) );
trim_and_print( w_monsters, point( width - ( 8 + numd ), y ), 6 + numd,
selected ? c_light_green : c_light_gray,
"%*d %s",
numd, mon_dist,
direction_name_short( direction_from( u.pos(), critter->pos() ) ) );
}

mvwprintz( w_monsters_border, point( ( width / 2 ) - numw - 2, 0 ), c_light_green, " %*d", numw,
Expand All @@ -7721,19 +7707,22 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
cCurMon = monster_list[iActive];

werase( w_monster_info );
cCurMon->print_info( w_monster_info, 1, 11, 1 );
cCurMon->print_info( w_monster_info, 1, iInfoHeight - 3, 1 );

draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
true );

if( bVMonsterLookFire ) {
mvwprintz( w_monsters, point( 1, getmaxy( w_monsters ) - 3 ), c_light_green,
ctxt.press_x( "look" ) );
wprintz( w_monsters, c_light_gray, " %s", _( "to look around" ) );
mvwprintw( w_monster_info_border, point_east, "< " );
wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "look" ) );
wprintz( w_monster_info_border, c_light_gray, " %s", _( "to look around" ) );

if( rl_dist( u.pos(), cCurMon->pos() ) <= max_gun_range ) {
wprintz( w_monsters, c_light_gray, "%s", " " );
mvwprintz( w_monsters, point( 24, getmaxy( w_monsters ) - 3 ), c_light_green,
ctxt.press_x( "fire" ) );
wprintz( w_monsters, c_light_gray, " %s", _( "to shoot" ) );
wprintw( w_monster_info_border, " " );
wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "fire" ) );
wprintz( w_monster_info_border, c_light_gray, " %s", _( "to shoot" ) );
}
wprintw( w_monster_info_border, " >" );
}

// Only redraw trail/terrain if x/y position changed or if keybinding menu erased it
Expand All @@ -7744,30 +7733,8 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list

draw_scrollbar( w_monsters_border, iActive, iMaxRows, static_cast<int>( monster_list.size() ),
point_south );
wrefresh( w_monsters_border );
}

// repairing the damage caused by refreshing the whole screen for w_terrain
// the previous situation was only refreshing the screen minus sidebar width.
for( int j = 0; j < iInfoHeight - 1; j++ ) {
mvwputch( w_monster_info_border, point( 0, j ), c_light_gray, LINE_XOXO );
mvwputch( w_monster_info_border, point( width - 1, j ), c_light_gray, LINE_XOXO );
}

for( int j = 0; j < width - 1; j++ ) {
mvwputch( w_monster_info_border, point( j, iInfoHeight - 1 ), c_light_gray, LINE_OXOX );
}

for( int i = 1; i < getmaxy( w_monsters ) - 1; i++ ) {
mvwputch( w_monsters_border, point( 0, i ), BORDER_COLOR, LINE_XOXO ); // |
mvwputch( w_monsters_border, point( width - 1, i ), BORDER_COLOR, LINE_XOXO ); // |
}

mvwputch( w_monster_info_border, point( 0, getmaxy( w_monster_info_border ) - 1 ), BORDER_COLOR,
LINE_XXOO ); // |_
mvwputch( w_monster_info_border, point( width - 1, getmaxy( w_monster_info_border ) - 1 ),
BORDER_COLOR, LINE_XOOX ); // _|

wrefresh( w_monsters_border );
wrefresh( w_monster_info_border );
wrefresh( w_monsters );
Expand Down
4 changes: 2 additions & 2 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ int monster::print_info( const catacurses::window &w, int vStart, int vLines, in
{
const int vEnd = vStart + vLines;

mvwprintz( w, point( column, vStart ), c_white, "%s ", name() );

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

Expand Down
3 changes: 2 additions & 1 deletion src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,8 @@ 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: %s" ), name );
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!" ) );
Expand Down

0 comments on commit 02618ec

Please sign in to comment.