From 02618ece084293d8aea625638bc8db039a070f5d Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Mon, 22 Jun 2020 22:57:41 +1000 Subject: [PATCH] Refactor monsters shift-v menu (#36722) * 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 #24436 Based on commit 2657814db424ef84955a896531de1cc2c4dbf3bd by 8street, originally merged into mainline by KevinGranade. --- src/game.cpp | 133 ++++++++++++++++++------------------------------ src/monster.cpp | 4 +- src/npc.cpp | 3 +- 3 files changed, 54 insertions(+), 86 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 9fd9469ee2c82..9fbbf2fcb5df1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7483,17 +7483,20 @@ game::vmenu_ret game::list_items( const std::vector &item_list ) game::vmenu_ret game::list_monsters( const std::vector &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 ); @@ -7501,29 +7504,13 @@ game::vmenu_ret game::list_monsters( const std::vector &monster_list 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 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, " " ); wprintz( w_monsters_border, c_white, _( "Monsters" ) ); @@ -7597,21 +7584,11 @@ game::vmenu_ret game::list_monsters( const std::vector &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(); @@ -7630,7 +7607,7 @@ game::vmenu_ret game::list_monsters( const std::vector &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; @@ -7640,7 +7617,7 @@ game::vmenu_ret game::list_monsters( const std::vector &monster_list --iCurMon; } - const auto endY = std::min( iMaxRows, iMenuSize ); + const auto endY = std::min( iMaxRows - 1, iMenuSize ); for( int y = 0; y < endY; ++y ) { if( CatSortIter != mSortCategory.cend() ) { const int iCurPos = iStartPos + y; @@ -7663,11 +7640,16 @@ game::vmenu_ret game::list_monsters( const std::vector &monster_list bool is_npc = false; const monster *m = dynamic_cast( critter ); const npc *p = dynamic_cast( 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; } @@ -7681,8 +7663,7 @@ game::vmenu_ret game::list_monsters( const std::vector &monster_list sSafemode = _( "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 ); } @@ -7695,7 +7676,7 @@ game::vmenu_ret game::list_monsters( const std::vector &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(); @@ -7705,13 +7686,18 @@ game::vmenu_ret game::list_monsters( const std::vector &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, @@ -7721,19 +7707,22 @@ game::vmenu_ret game::list_monsters( const std::vector &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 @@ -7744,30 +7733,8 @@ game::vmenu_ret game::list_monsters( const std::vector &monster_list draw_scrollbar( w_monsters_border, iActive, iMaxRows, static_cast( 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 ); diff --git a/src/monster.cpp b/src/monster.cpp index d3c4599f9410e..5236e93a54f6f 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -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 ); diff --git a/src/npc.cpp b/src/npc.cpp index bdad2311d7af6..1124481a5721e 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -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!" ) );