Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate remaining menus to ui_adaptor and clean up redundant drawing code #41112

Merged
merged 13 commits into from
Jun 6, 2020
46 changes: 22 additions & 24 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,6 @@ action_id handle_action_menu()
smenu.query();
const int selection = smenu.ret;

g->draw();

if( selection < 0 || selection == NUM_ACTIONS ) {
return ACTION_NULL;
} else if( selection == 2 * NUM_ACTIONS ) {
Expand Down Expand Up @@ -1006,8 +1004,6 @@ action_id handle_main_menu()
smenu.query();
int selection = smenu.ret;

g->draw();

if( selection < 0 || selection >= NUM_ACTIONS ) {
return ACTION_NULL;
} else {
Expand Down Expand Up @@ -1076,31 +1072,33 @@ cata::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool ( const tripoint & )> &allowed,
const bool allow_vertical )
{
// Highlight nearby terrain according to the highlight function
if( allowed != nullptr ) {
cata::optional<tripoint> single;
bool highlighted = false;
std::vector<tripoint> valid;
if( allowed ) {
for( const tripoint &pos : g->m.points_in_radius( g->u.pos(), 1 ) ) {
if( allowed( pos ) ) {
if( !highlighted ) {
single = pos;
highlighted = true;
} else {
single = cata::nullopt;
}
valid.emplace_back( pos );
}
}
}

const bool auto_select = get_option<bool>( "AUTOSELECT_SINGLE_VALID_TARGET" );
if( valid.empty() && auto_select ) {
add_msg( failure_message );
return cata::nullopt;
} else if( valid.size() == 1 && auto_select ) {
return valid.back();
}

shared_ptr_fast<game::draw_callback_t> hilite_cb;
if( !valid.empty() ) {
hilite_cb = make_shared_fast<game::draw_callback_t>( [&]() {
for( const tripoint &pos : valid ) {
g->m.drawsq( g->w_terrain, g->u, pos,
true, true, g->u.pos() + g->u.view_offset );
}
}
if( highlighted ) {
wrefresh( g->w_terrain );
} else if( get_option<bool>( "AUTOSELECT_SINGLE_VALID_TARGET" ) ) {
add_msg( failure_message );
return cata::nullopt;
}
if( get_option<bool>( "AUTOSELECT_SINGLE_VALID_TARGET" ) && single ) {
return single;
}
} );
g->add_draw_callback( hilite_cb );
}

return choose_adjacent( message, allow_vertical );
}
10 changes: 1 addition & 9 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ void aim_activity_actor::do_turn( player_activity &act, Character &who )
}

g->temp_exit_fullscreen();
g->m.draw( g->w_terrain, you.pos() );
target_handler::trajectory trajectory = target_handler::mode_fire( you, *this );
g->reenter_fullscreen();

Expand Down Expand Up @@ -180,11 +179,6 @@ void aim_activity_actor::finish( player_activity &act, Character &who )
return;
}

// Recenter our view
g->draw_ter();
wrefresh( g->w_terrain );
g->draw_panels();

// Fire!
item *weapon = get_weapon();
gun_mode gun = weapon->gun_current_mode();
Expand Down Expand Up @@ -264,7 +258,7 @@ void aim_activity_actor::restore_view()
g->u.view_offset = initial_view_offset;
if( changed_z ) {
g->m.invalidate_map_cache( g->u.view_offset.z );
g->refresh_all();
g->invalidate_main_ui_adaptor();
}
}

Expand Down Expand Up @@ -310,7 +304,6 @@ bool aim_activity_actor::load_RAS_weapon()
reload_time += ( sta_percent < 25 ) ? ( ( 25 - sta_percent ) * 2 ) : 0;

you.moves -= reload_time;
g->refresh_all();
return true;
}

Expand All @@ -335,7 +328,6 @@ void aim_activity_actor::unload_RAS_weapon()
if( first_turn ) {
you.moves = moves_before_unload;
}
g->refresh_all();
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,6 @@ void activity_handlers::vehicle_finish( player_activity *act, player *p )
} else {
if( vp ) {
g->m.invalidate_map_cache( g->get_levz() );
g->refresh_all();
// TODO: Z (and also where the activity is queued)
// Or not, because the vehicle coordinates are dropped anyway
if( !resume_for_multi_activities( *p ) ) {
Expand Down Expand Up @@ -2620,7 +2619,6 @@ void activity_handlers::repair_item_finish( player_activity *act, player *p )

// target selection and validation.
while( act->targets.size() < 2 ) {
g->draw();
item_location item_loc = game_menus::inv::repair( *p, actor, &main_tool );

if( item_loc == item_location::nowhere ) {
Expand Down Expand Up @@ -2673,7 +2671,6 @@ void activity_handlers::repair_item_finish( player_activity *act, player *p )
act->values.resize( 1 );
}
do {
g->draw();
repeat = repeat_menu( title, repeat );

if( repeat == REPEAT_CANCEL ) {
Expand Down Expand Up @@ -2950,7 +2947,6 @@ void activity_handlers::travel_do_turn( player_activity *act, player *p )
p->omt_path.pop_back();
if( p->omt_path.empty() ) {
p->add_msg_if_player( m_info, _( "You have reached your destination." ) );
g->draw();
act->set_to_null();
return;
}
Expand All @@ -2977,7 +2973,6 @@ void activity_handlers::travel_do_turn( player_activity *act, player *p )
} else {
p->add_msg_if_player( m_info, _( "You have reached your destination." ) );
}
g->draw();
act->set_to_null();
}

Expand Down
13 changes: 1 addition & 12 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ advanced_inventory::~advanced_inventory()
}
// Only refresh if we exited manually, otherwise we're going to be right back
if( exit ) {
werase( head );
werase( minimap );
werase( mm_border );
werase( panes[left].window );
werase( panes[right].window );
g->refresh_all();
g->u.check_item_encumbrance_flag();
}
}
Expand Down Expand Up @@ -1681,12 +1675,7 @@ bool advanced_inventory::query_destination( aim_location &def )
}
// Selected keyed to uilist.entries, which starts at 0.
menu.selected = save_state->last_popup_dest - AIM_SOUTHWEST;
// generate and show window.
menu.show();
// query, but don't loop
while( menu.ret == UILIST_WAIT_INPUT ) {
menu.query( false );
}
menu.query();
if( menu.ret >= AIM_SOUTHWEST && menu.ret <= AIM_NORTHEAST ) {
assert( squares[menu.ret].canputitems() );
def = static_cast<aim_location>( menu.ret );
Expand Down
Loading