Skip to content

Commit

Permalink
Bodygraph enhancements: view NPC body graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
dseguin committed May 2, 2022
1 parent 022a674 commit 931cbfd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
19 changes: 8 additions & 11 deletions src/bodygraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void bodygraph::check() const
#define BPGRAPH_HEIGHT 24

struct bodygraph_display {
const Character *u;
bodygraph_id id;
input_context ctxt;
weak_ptr_fast<ui_adaptor> ui;
Expand All @@ -195,7 +196,7 @@ struct bodygraph_display {
bodygraph_display() = delete;
bodygraph_display( const bodygraph_display & ) = delete;
bodygraph_display( const bodygraph_display && ) = delete;
explicit bodygraph_display( const bodygraph_id &id );
explicit bodygraph_display( const Character *u, const bodygraph_id &id );

shared_ptr_fast<ui_adaptor> create_or_get_ui_adaptor();
void prepare_partlist();
Expand All @@ -209,7 +210,8 @@ struct bodygraph_display {
void display();
};

bodygraph_display::bodygraph_display( const bodygraph_id &id ) : id( id ), ctxt( "BODYGRAPH" )
bodygraph_display::bodygraph_display( const Character *u, const bodygraph_id &id ) :
u( u ), id( id ), ctxt( "BODYGRAPH" )
{
if( id.is_null() ) {
this->id = bodygraph_full_body;
Expand Down Expand Up @@ -412,11 +414,6 @@ void bodygraph_display::prepare_infolist()
// sbps will either be a group for a body part and we'll need to do averages OR a single sub part
std::set<sub_bodypart_id> sub_parts;

// should maybe be not just the avater I'm not sure how you are getting character passed in
// FIXME: pass Character to display_bodygraph() and then to bodygraph constructor,
// and access with this->id->character_var
const avatar &p = get_avatar();

// this might be null need to test for nullbp as this all continues
if( std::get<1>( partlist[sel_part] ) != nullptr ) {
sub_parts.emplace( std::get<1>( partlist[sel_part] )->id );
Expand All @@ -429,7 +426,7 @@ void bodygraph_display::prepare_infolist()
}
}

p.worn.prepare_bodymap_info( info, bp, sub_parts, p );
u->worn.prepare_bodymap_info( info, bp, sub_parts, *u );

// update info text cache
info_txt.clear();
Expand Down Expand Up @@ -525,7 +522,7 @@ void bodygraph_display::display()
if( !!std::get<2>( partlist[sel_part] ) ) {
bodygraph_id nextgraph = std::get<2>( partlist[sel_part] )->nested_graph;
if( !nextgraph.is_null() ) {
display_bodygraph( nextgraph );
display_bodygraph( *u, nextgraph );
prepare_infolist();
}
}
Expand Down Expand Up @@ -559,8 +556,8 @@ void bodygraph_display::display()
}
}

void display_bodygraph( const bodygraph_id &id )
void display_bodygraph( const Character &u, const bodygraph_id &id )
{
bodygraph_display bgd( id );
bodygraph_display bgd( &u, id );
bgd.display();
}
2 changes: 1 addition & 1 deletion src/bodygraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ struct bodygraph {
void check() const;
};

void display_bodygraph( const bodygraph_id &id = bodygraph_id::NULL_ID() );
void display_bodygraph( const Character &u, const bodygraph_id &id = bodygraph_id::NULL_ID() );

#endif // CATA_SRC_BODYGRAPH_H
10 changes: 10 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5186,6 +5186,7 @@ bool game::npc_menu( npc &who )
swap_pos,
push,
examine_wounds,
examine_status,
use_item,
sort_armor,
attack,
Expand All @@ -5204,6 +5205,7 @@ bool game::npc_menu( npc &who )
!u.is_mounted(), 's', _( "Swap positions" ) );
amenu.addentry( push, obeys && !who.is_mounted(), 'p', _( "Push away" ) );
amenu.addentry( examine_wounds, true, 'w', _( "Examine wounds" ) );
amenu.addentry( examine_status, true, 'e', _( "Examine status" ) );
amenu.addentry( use_item, true, 'i', _( "Use item on" ) );
amenu.addentry( sort_armor, true, 'r', _( "Sort armor" ) );
amenu.addentry( attack, true, 'a', _( "Attack" ) );
Expand Down Expand Up @@ -5251,6 +5253,14 @@ bool game::npc_menu( npc &who )
const bool precise = prof_bonus * 4 + u.per_cur >= 20;
who.body_window( _( "Limbs of: " ) + who.disp_name(), true, precise, 0, 0, 0, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f );
} else if( choice == examine_status ) {
if( debug_mode || ( who.is_npc() && ( who.as_npc()->op_of_u.trust >= 5 ||
who.is_friendly( u ) ) ) ||
who.in_sleep_state() ) {
display_bodygraph( who );
} else {
who.say( SNIPPET.random_from_category( "<no>" ).value_or( translation() ).translated() );
}
} else if( choice == use_item ) {
static const std::string heal_string( "heal" );
const auto will_accept = [&who]( const item & it ) {
Expand Down
2 changes: 1 addition & 1 deletion src/player_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ static bool handle_player_display_action( Character &you, unsigned int &line,
} else if( action == "VIEW_PROFICIENCIES" ) {
show_proficiencies_window( you );
} else if( action == "VIEW_BODYSTAT" ) {
display_bodygraph();
display_bodygraph( you );
} else if( customize_character && action == "SWITCH_GENDER" ) {
uilist cmenu;
cmenu.title = _( "Customize Character" );
Expand Down

0 comments on commit 931cbfd

Please sign in to comment.