From a79a050e5263e275016487d87ad56d47c3c8b366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jianxiang=20Wang=20=28=E7=8E=8B=E5=81=A5=E7=BF=94=29?= Date: Sat, 11 Apr 2020 13:44:04 +0800 Subject: [PATCH] Migrate computer UI and construction menu to ui_adaptor (#39448) * Migrate computer_session to ui_adaptor * Migrate construction menu to ui_adaptor --- src/computer_session.cpp | 52 ++-- src/computer_session.h | 6 +- src/construction.cpp | 547 ++++++++++++++++++++------------------- src/game.cpp | 2 - 4 files changed, 320 insertions(+), 287 deletions(-) diff --git a/src/computer_session.cpp b/src/computer_session.cpp index 81d5492372502..842a4df75832c 100644 --- a/src/computer_session.cpp +++ b/src/computer_session.cpp @@ -70,10 +70,10 @@ static const std::string flag_CONSOLE( "CONSOLE" ); static catacurses::window init_window() { - const int width = std::min( FULL_SCREEN_WIDTH, TERMX ); - const int height = std::min( FULL_SCREEN_HEIGHT, TERMY ); - const int x = ( TERMX - width ) / 2; - const int y = ( TERMY - height ) / 2; + const int width = FULL_SCREEN_WIDTH; + const int height = FULL_SCREEN_HEIGHT; + const int x = std::max( 0, ( TERMX - width ) / 2 ); + const int y = std::max( 0, ( TERMY - height ) / 2 ); return catacurses::newwin( height, width, point( x, y ) ); } @@ -85,6 +85,20 @@ computer_session::computer_session( computer &comp ) : comp( comp ), void computer_session::use() { + ui_adaptor ui; + ui.on_screen_resize( [this]( ui_adaptor & ui ) { + const int width = getmaxx( win ); + const int height = getmaxy( win ); + const int x = std::max( 0, ( TERMX - width ) / 2 ); + const int y = std::max( 0, ( TERMY - height ) / 2 ); + win = catacurses::newwin( height, width, point( x, y ) ); + ui.position_from_window( win ); + } ); + ui.mark_resize(); + ui.on_redraw( [this]( const ui_adaptor & ) { + refresh(); + } ); + // Login print_line( _( "Logging into %s…" ), comp.name ); if( comp.security > 0 ) { @@ -140,6 +154,7 @@ void computer_session::use() computer_menu.addentry( i, true, MENU_AUTOASSIGN, comp.options[i].name ); } + ui_manager::redraw(); computer_menu.query(); if( computer_menu.ret < 0 || static_cast( computer_menu.ret ) >= comp.options.size() ) { break; @@ -640,7 +655,7 @@ void computer_session::action_amigara_log() print_gibberish_line(); print_newline(); print_error( _( "FILE CORRUPTED, PRESS ANY KEY…" ) ); - inp_mngr.wait_for_any_key(); + query_any(); reset_terminal(); } @@ -663,12 +678,12 @@ void computer_session::action_complete_disable_external_power() print_error( _( "--ACCESS GRANTED--" ) ); print_error( _( "Mission Complete!" ) ); miss->step_complete( 1 ); - inp_mngr.wait_for_any_key(); + query_any(); return; } } print_error( _( "ACCESS DENIED" ) ); - inp_mngr.wait_for_any_key(); + query_any(); } void computer_session::action_repeater_mod() @@ -682,7 +697,7 @@ void computer_session::action_repeater_mod() print_error( _( "Repeater mod installed…" ) ); print_error( _( "Mission Complete!" ) ); g->u.use_amount( "radio_repeater_mod", 1 ); - inp_mngr.wait_for_any_key(); + query_any(); comp.options.clear(); activate_failure( COMPFAIL_SHUTDOWN ); break; @@ -690,7 +705,7 @@ void computer_session::action_repeater_mod() } } else { print_error( _( "You do not have a repeater mod to install…" ) ); - inp_mngr.wait_for_any_key(); + query_any(); } } @@ -711,7 +726,7 @@ void computer_session::action_download_software() } else { print_error( _( "USB drive required!" ) ); } - inp_mngr.wait_for_any_key(); + query_any(); } void computer_session::action_blood_anal() @@ -1338,7 +1353,7 @@ void computer_session::failure_destroy_blood() } } } - inp_mngr.wait_for_any_key(); + query_any(); } void computer_session::failure_destroy_data() @@ -1361,7 +1376,7 @@ void computer_session::failure_destroy_data() } } } - inp_mngr.wait_for_any_key(); + query_any(); } void computer_session::action_emerg_ref_center() @@ -1417,6 +1432,12 @@ template bool computer_session::query_any( const std::string &text, Args &&... args ) { print_indented_line( 0, width, text, std::forward( args )... ); + return query_any(); +} + +bool computer_session::query_any() +{ + ui_manager::redraw(); inp_mngr.wait_for_any_key(); return true; } @@ -1443,10 +1464,8 @@ computer_session::ynq computer_session::query_ynq( const std::string &text, Args ctxt.describe_key_and_name( "NO", allow_key ), ctxt.describe_key_and_name( "QUIT", allow_key ) ); - // FIXME: temporarily disable redrawing of lower UIs before this UI is migrated to `ui_adaptor` - ui_adaptor ui( ui_adaptor::disable_uis_below {} ); - do { + ui_manager::redraw(); const std::string action = ctxt.handle_input(); if( allow_key( ctxt.get_raw_input() ) ) { if( action == "YES" ) { @@ -1495,7 +1514,6 @@ void computer_session::print_indented_line( const int indent, const int text_wid it < folded.end(); ++it ) { lines.emplace_back( indent, *it ); } - refresh(); } template @@ -1543,7 +1561,6 @@ void computer_session::print_gibberish_line() void computer_session::reset_terminal() { lines.clear(); - refresh(); } void computer_session::print_newline() @@ -1556,5 +1573,4 @@ void computer_session::print_newline() lines.erase( lines.begin(), lines.end() - ( uheight - 1 ) ); } lines.emplace_back(); - refresh(); } diff --git a/src/computer_session.h b/src/computer_session.h index 2843a97061e76..a12eac97e3c7f 100644 --- a/src/computer_session.h +++ b/src/computer_session.h @@ -22,8 +22,8 @@ class computer_session private: computer ∁ - // Output window. This class assumes win's dimensions do not change. - const catacurses::window win; + // Output window. This class assumes win's size does not change. + catacurses::window win; const int left; const int top; const int width; @@ -75,6 +75,8 @@ class computer_session // Simply wait for any key, returns True template bool query_any( const std::string &text, Args &&... args ); + // Wait for any key without new output + bool query_any(); void action_amigara_log(); void action_amigara_start(); diff --git a/src/construction.cpp b/src/construction.cpp index a203c2e858d68..956c5e40067cb 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -283,26 +283,19 @@ construction_id construction_menu( const bool blueprint ) return construction_id( -1 ); } - int w_height = TERMY; - if( static_cast( available.size() ) + 2 < w_height ) { - w_height = available.size() + 2; - } - if( w_height < FULL_SCREEN_HEIGHT ) { - w_height = FULL_SCREEN_HEIGHT; - } - - const int w_width = std::max( FULL_SCREEN_WIDTH, TERMX * 2 / 3 ); - const int w_y0 = ( TERMY > w_height ) ? ( TERMY - w_height ) / 2 : 0; - const int w_x0 = ( TERMX > w_width ) ? ( TERMX - w_width ) / 2 : 0; - catacurses::window w_con = catacurses::newwin( w_height, w_width, point( w_x0, w_y0 ) ); + int w_height = 0; + int w_width = 0; + catacurses::window w_con; - const int w_list_width = static_cast( .375 * w_width ); - const int w_list_height = w_height - 4; + int w_list_width = 0; + int w_list_height = 0; const int w_list_x0 = 1; - catacurses::window w_list = catacurses::newwin( w_list_height, w_list_width, - point( w_x0 + w_list_x0, w_y0 + 3 ) ); + catacurses::window w_list; - draw_grid( w_con, w_list_width + w_list_x0 ); + std::vector notes; + int pos_x = 0; + int available_window_width = 0; + int available_buffer_height = 0; construction_id ret( -1 ); @@ -321,11 +314,6 @@ construction_id construction_menu( const bool blueprint ) std::vector construct_buffer_breakpoints; int total_project_breakpoints = 0; int current_construct_breakpoint = 0; - bool previous_hide_unconstructable = false; - //track the cursor to determine when to refresh the list of construction recipes - int previous_tabindex = -1; - int previous_select = -1; - const inventory &total_inv = g->u.crafting_inventory(); input_context ctxt( "CONSTRUCTION" ); @@ -345,10 +333,276 @@ construction_id construction_menu( const bool blueprint ) const std::vector &construct_cat = construction_categories::get_all(); const int tabcount = static_cast( construction_category::count() ); - // FIXME: temporarily disable redrawing of lower UIs before this UI is migrated to `ui_adaptor` - ui_adaptor ui( ui_adaptor::disable_uis_below {} ); - std::string filter; + + const nc_color color_stage = c_white; + ui_adaptor ui; + + const auto recalc_buffer = [&]() { + //leave room for top and bottom UI text + available_buffer_height = w_height - 3 - 3 - static_cast( notes.size() ); + + if( !constructs.empty() ) { + if( select >= static_cast( constructs.size() ) ) { + select = 0; + } + std::string current_desc = constructs[select]; + + //construct the project list buffer + + // Print stages and their requirement. + std::vector options = constructions_by_desc( current_desc ); + + construct_buffers.clear(); + current_construct_breakpoint = 0; + construct_buffer_breakpoints.clear(); + full_construct_buffer.clear(); + int stage_counter = 0; + for( std::vector::iterator it = options.begin(); + it != options.end(); ++it ) { + stage_counter++; + construction *current_con = *it; + if( hide_unconstructable && !can_construct( *current_con ) ) { + continue; + } + // Update the cached availability of components and tools in the requirement object + current_con->requirements->can_make_with_inventory( total_inv, is_crafting_component ); + + std::vector current_buffer; + + const auto add_folded = [&]( const std::vector &folded ) { + current_buffer.insert( current_buffer.end(), folded.begin(), folded.end() ); + }; + const auto add_line = [&]( const std::string & line ) { + add_folded( foldstring( line, available_window_width ) ); + }; + + // display final product name only if more than one step. + // Assume single stage constructions should be clear + // in their title what their result is. + if( !current_con->post_terrain.empty() && options.size() > 1 ) { + //also print out stage number when multiple stages are available + std::string current_line = string_format( _( "Stage/Variant #%d: " ), stage_counter ); + + // print name of the result of each stage + std::string result_string; + if( current_con->post_is_furniture ) { + result_string = furn_str_id( current_con->post_terrain ).obj().name(); + } else { + result_string = ter_str_id( current_con->post_terrain ).obj().name(); + } + current_line += colorize( result_string, color_title ); + add_line( current_line ); + + // display description of the result for multi-stages + current_line = _( "Result: " ); + if( current_con->post_is_furniture ) { + current_line += colorize( + furn_str_id( current_con->post_terrain ).obj().description, + color_data + ); + } else { + current_line += colorize( + ter_str_id( current_con->post_terrain ).obj().description, + color_data + ); + } + add_line( current_line ); + + // display description of the result for single stages + } else if( !current_con->post_terrain.empty() ) { + std::string current_line = _( "Result: " ); + if( current_con->post_is_furniture ) { + current_line += colorize( + furn_str_id( current_con->post_terrain ).obj().description, + color_data + ); + } else { + current_line += colorize( + ter_str_id( current_con->post_terrain ).obj().description, + color_data + ); + } + add_line( current_line ); + } + + // display required skill and difficulty + if( current_con->required_skills.empty() ) { + add_line( _( "N/A" ) ); + } else { + std::string current_line = _( "Required skills: " ) + enumerate_as_string( + current_con->required_skills.begin(), current_con->required_skills.end(), + []( const std::pair &skill ) { + nc_color col; + int s_lvl = g->u.get_skill_level( skill.first ); + if( s_lvl < skill.second ) { + col = c_red; + } else if( s_lvl < skill.second * 1.25 ) { + col = c_light_blue; + } else { + col = c_green; + } + + return colorize( string_format( "%s (%d)", skill.first.obj().name(), skill.second ), col ); + }, enumeration_conjunction::none ); + add_line( current_line ); + } + + // TODO: Textify pre_flags to provide a bit more information. + // Example: First step of dig pit could say something about + // requiring diggable ground. + if( !current_con->pre_terrain.empty() ) { + std::string require_string; + if( current_con->pre_is_furniture ) { + require_string = furn_str_id( current_con->pre_terrain )->name(); + } else { + require_string = ter_str_id( current_con->pre_terrain )->name(); + } + nc_color pre_color = has_pre_terrain( *current_con ) ? c_green : c_red; + add_line( _( "Requires: " ) + colorize( require_string, pre_color ) ); + } + if( !current_con->pre_note.empty() ) { + add_line( _( "Annotation: " ) + colorize( _( current_con->pre_note ), color_data ) ); + } + // get pre-folded versions of the rest of the construction project to be displayed later + + // get time needed + add_folded( current_con->get_folded_time_string( available_window_width ) ); + + add_folded( current_con->requirements->get_folded_tools_list( available_window_width, color_stage, + total_inv ) ); + + add_folded( current_con->requirements->get_folded_components_list( available_window_width, + color_stage, total_inv, is_crafting_component ) ); + + construct_buffers.push_back( current_buffer ); + } + + //determine where the printing starts for each project, so it can be scrolled to those points + size_t current_buffer_location = 0; + for( size_t i = 0; i < construct_buffers.size(); i++ ) { + construct_buffer_breakpoints.push_back( static_cast( current_buffer_location ) ); + full_construct_buffer.insert( full_construct_buffer.end(), construct_buffers[i].begin(), + construct_buffers[i].end() ); + + //handle text too large for one screen + if( construct_buffers[i].size() > static_cast( available_buffer_height ) ) { + construct_buffer_breakpoints.push_back( static_cast( current_buffer_location + + static_cast( available_buffer_height ) ) ); + } + current_buffer_location += construct_buffers[i].size(); + if( i < construct_buffers.size() - 1 ) { + full_construct_buffer.push_back( std::string() ); + current_buffer_location++; + } + } + total_project_breakpoints = static_cast( construct_buffer_breakpoints.size() ); + } + }; + + ui.on_screen_resize( [&]( ui_adaptor & ui ) { + w_height = TERMY; + if( static_cast( available.size() ) + 2 < w_height ) { + w_height = available.size() + 2; + } + if( w_height < FULL_SCREEN_HEIGHT ) { + w_height = FULL_SCREEN_HEIGHT; + } + + w_width = std::max( FULL_SCREEN_WIDTH, TERMX * 2 / 3 ); + const int w_y0 = ( TERMY > w_height ) ? ( TERMY - w_height ) / 2 : 0; + const int w_x0 = ( TERMX > w_width ) ? ( TERMX - w_width ) / 2 : 0; + w_con = catacurses::newwin( w_height, w_width, point( w_x0, w_y0 ) ); + + w_list_width = static_cast( .375 * w_width ); + w_list_height = w_height - 4; + w_list = catacurses::newwin( w_list_height, w_list_width, + point( w_x0 + w_list_x0, w_y0 + 3 ) ); + + pos_x = w_list_width + w_list_x0 + 2; + available_window_width = w_width - pos_x - 1; + + recalc_buffer(); + + ui.position_from_window( w_con ); + } ); + ui.mark_resize(); + + ui.on_redraw( [&]( const ui_adaptor & ) { + draw_grid( w_con, w_list_width + w_list_x0 ); + + // Erase existing tab selection & list of constructions + mvwhline( w_con, point_south_east, ' ', w_list_width ); + werase( w_list ); + // Print new tab listing + // NOLINTNEXTLINE(cata-use-named-point-constants) + mvwprintz( w_con, point( 1, 1 ), c_yellow, "<< %s >>", _( construct_cat[tabindex].name ) ); + // Determine where in the master list to start printing + calcStartPos( offset, select, w_list_height, constructs.size() ); + // Print the constructions between offset and max (or how many will fit) + for( size_t i = 0; static_cast( i ) < w_list_height && + ( i + offset ) < constructs.size(); i++ ) { + int current = i + offset; + std::string con_name = constructs[current]; + bool highlight = ( current == select ); + + trim_and_print( w_list, point( 0, i ), w_list_width, + construction_color( con_name, highlight ), _( con_name ) ); + } + + // Clear out lines for tools & materials + for( int i = 1; i < w_height - 1; i++ ) { + mvwhline( w_con, point( pos_x, i ), ' ', available_window_width ); + } + + // print the hotkeys regardless of if there are constructions + for( size_t i = 0; i < notes.size(); ++i ) { + trim_and_print( w_con, point( pos_x, + w_height - 1 - static_cast( notes.size() ) + static_cast( i ) ), + available_window_width, c_white, notes[i] ); + } + + if( !constructs.empty() ) { + if( select >= static_cast( constructs.size() ) ) { + select = 0; + } + std::string current_desc = constructs[select]; + // Print construction name + trim_and_print( w_con, point( pos_x, 1 ), available_window_width, c_white, _( current_desc ) ); + + if( current_construct_breakpoint > 0 ) { + // Print previous stage indicator if breakpoint is past the beginning + trim_and_print( w_con, point( pos_x, 2 ), available_window_width, c_white, + _( "Press %s to show previous stage(s)." ), + ctxt.get_desc( "PAGE_UP" ) ); + } + if( static_cast( construct_buffer_breakpoints[current_construct_breakpoint] + + available_buffer_height ) < full_construct_buffer.size() ) { + // Print next stage indicator if more breakpoints are remaining after screen height + trim_and_print( w_con, point( pos_x, w_height - 2 - static_cast( notes.size() ) ), + available_window_width, + c_white, _( "Press %s to show next stage(s)." ), + ctxt.get_desc( "PAGE_DOWN" ) ); + } + // Leave room for above/below indicators + int ypos = 3; + nc_color stored_color = color_stage; + for( size_t i = static_cast( construct_buffer_breakpoints[current_construct_breakpoint] ); + i < full_construct_buffer.size(); i++ ) { + //the value of 3 is from leaving room at the top of window + if( ypos > available_buffer_height + 3 ) { + break; + } + print_colored_text( w_con, point( w_list_width + w_list_x0 + 2, ypos++ ), stored_color, color_stage, + full_construct_buffer[i] ); + } + } + + draw_scrollbar( w_con, select, w_list_height, constructs.size(), point( 0, 3 ) ); + wrefresh( w_con ); + wrefresh( w_list ); + } ); + do { if( update_cat ) { update_cat = false; @@ -366,7 +620,6 @@ construction_id construction_menu( const bool blueprint ) constructs = available; } else if( category_id == "FILTER" ) { constructs.clear(); - previous_select = -1; std::copy_if( available.begin(), available.end(), std::back_inserter( constructs ), [&]( const std::string & a ) { @@ -385,35 +638,11 @@ construction_id construction_menu( const bool blueprint ) } } isnew = false; - // Erase existing tab selection & list of constructions - mvwhline( w_con, point_south_east, ' ', w_list_width ); - werase( w_list ); - // Print new tab listing - // NOLINTNEXTLINE(cata-use-named-point-constants) - mvwprintz( w_con, point( 1, 1 ), c_yellow, "<< %s >>", _( construct_cat[tabindex].name ) ); - // Determine where in the master list to start printing - calcStartPos( offset, select, w_list_height, constructs.size() ); - // Print the constructions between offset and max (or how many will fit) - for( size_t i = 0; static_cast( i ) < w_list_height && - ( i + offset ) < constructs.size(); i++ ) { - int current = i + offset; - std::string con_name = constructs[current]; - bool highlight = ( current == select ); - - trim_and_print( w_list, point( 0, i ), w_list_width, - construction_color( con_name, highlight ), _( con_name ) ); - } if( update_info ) { update_info = false; - // Clear out lines for tools & materials - const int pos_x = w_list_width + w_list_x0 + 2; - const int available_window_width = w_width - pos_x - 1; - for( int i = 1; i < w_height - 1; i++ ) { - mvwhline( w_con, point( pos_x, i ), ' ', available_window_width ); - } - std::vector notes; + notes.clear(); if( tabindex == tabcount - 1 && !filter.empty() ) { notes.push_back( string_format( _( "Press [%s] to clear filter" ), ctxt.get_desc( "RESET_FILTER" ) ) ); @@ -430,214 +659,10 @@ construction_id construction_menu( const bool blueprint ) "to view and edit keybindings." ), ctxt.get_desc( "HELP_KEYBINDINGS" ) ) ); - //leave room for top and bottom UI text - const int available_buffer_height = w_height - 3 - 3 - static_cast( notes.size() ); - - // print the hotkeys regardless of if there are constructions - for( size_t i = 0; i < notes.size(); ++i ) { - trim_and_print( w_con, point( pos_x, - w_height - 1 - static_cast( notes.size() ) + static_cast( i ) ), - available_window_width, c_white, notes[i] ); - } - - if( !constructs.empty() ) { - nc_color color_stage = c_white; - if( select >= static_cast( constructs.size() ) ) { - select = 0; - } - std::string current_desc = constructs[select]; - // Print construction name - trim_and_print( w_con, point( pos_x, 1 ), available_window_width, c_white, _( current_desc ) ); - - //only reconstruct the project list when moving away from the current item, or when changing the display mode - if( previous_select != select || previous_tabindex != tabindex || - previous_hide_unconstructable != hide_unconstructable ) { - previous_select = select; - previous_tabindex = tabindex; - previous_hide_unconstructable = hide_unconstructable; - - //construct the project list buffer - - // Print stages and their requirement. - std::vector options = constructions_by_desc( current_desc ); - - construct_buffers.clear(); - current_construct_breakpoint = 0; - construct_buffer_breakpoints.clear(); - full_construct_buffer.clear(); - int stage_counter = 0; - for( std::vector::iterator it = options.begin(); - it != options.end(); ++it ) { - stage_counter++; - construction *current_con = *it; - if( hide_unconstructable && !can_construct( *current_con ) ) { - continue; - } - // Update the cached availability of components and tools in the requirement object - current_con->requirements->can_make_with_inventory( total_inv, is_crafting_component ); - - std::vector current_buffer; - - const auto add_folded = [&]( const std::vector &folded ) { - current_buffer.insert( current_buffer.end(), folded.begin(), folded.end() ); - }; - const auto add_line = [&]( const std::string & line ) { - add_folded( foldstring( line, available_window_width ) ); - }; - - // display final product name only if more than one step. - // Assume single stage constructions should be clear - // in their title what their result is. - if( !current_con->post_terrain.empty() && options.size() > 1 ) { - //also print out stage number when multiple stages are available - std::string current_line = string_format( _( "Stage/Variant #%d: " ), stage_counter ); - - // print name of the result of each stage - std::string result_string; - if( current_con->post_is_furniture ) { - result_string = furn_str_id( current_con->post_terrain ).obj().name(); - } else { - result_string = ter_str_id( current_con->post_terrain ).obj().name(); - } - current_line += colorize( result_string, color_title ); - add_line( current_line ); - - // display description of the result for multi-stages - current_line = _( "Result: " ); - if( current_con->post_is_furniture ) { - current_line += colorize( - furn_str_id( current_con->post_terrain ).obj().description, - color_data - ); - } else { - current_line += colorize( - ter_str_id( current_con->post_terrain ).obj().description, - color_data - ); - } - add_line( current_line ); - - // display description of the result for single stages - } else if( !current_con->post_terrain.empty() ) { - std::string current_line = _( "Result: " ); - if( current_con->post_is_furniture ) { - current_line += colorize( - furn_str_id( current_con->post_terrain ).obj().description, - color_data - ); - } else { - current_line += colorize( - ter_str_id( current_con->post_terrain ).obj().description, - color_data - ); - } - add_line( current_line ); - } - - // display required skill and difficulty - if( current_con->required_skills.empty() ) { - add_line( _( "N/A" ) ); - } else { - std::string current_line = _( "Required skills: " ) + enumerate_as_string( - current_con->required_skills.begin(), current_con->required_skills.end(), - []( const std::pair &skill ) { - nc_color col; - int s_lvl = g->u.get_skill_level( skill.first ); - if( s_lvl < skill.second ) { - col = c_red; - } else if( s_lvl < skill.second * 1.25 ) { - col = c_light_blue; - } else { - col = c_green; - } - - return colorize( string_format( "%s (%d)", skill.first.obj().name(), skill.second ), col ); - }, enumeration_conjunction::none ); - add_line( current_line ); - } - - // TODO: Textify pre_flags to provide a bit more information. - // Example: First step of dig pit could say something about - // requiring diggable ground. - if( !current_con->pre_terrain.empty() ) { - std::string require_string; - if( current_con->pre_is_furniture ) { - require_string = furn_str_id( current_con->pre_terrain )->name(); - } else { - require_string = ter_str_id( current_con->pre_terrain )->name(); - } - nc_color pre_color = has_pre_terrain( *current_con ) ? c_green : c_red; - add_line( _( "Requires: " ) + colorize( require_string, pre_color ) ); - } - if( !current_con->pre_note.empty() ) { - add_line( _( "Annotation: " ) + colorize( _( current_con->pre_note ), color_data ) ); - } - // get pre-folded versions of the rest of the construction project to be displayed later - - // get time needed - add_folded( current_con->get_folded_time_string( available_window_width ) ); - - add_folded( current_con->requirements->get_folded_tools_list( available_window_width, color_stage, - total_inv ) ); - - add_folded( current_con->requirements->get_folded_components_list( available_window_width, - color_stage, total_inv, is_crafting_component ) ); - - construct_buffers.push_back( current_buffer ); - } - - //determine where the printing starts for each project, so it can be scrolled to those points - size_t current_buffer_location = 0; - for( size_t i = 0; i < construct_buffers.size(); i++ ) { - construct_buffer_breakpoints.push_back( static_cast( current_buffer_location ) ); - full_construct_buffer.insert( full_construct_buffer.end(), construct_buffers[i].begin(), - construct_buffers[i].end() ); - - //handle text too large for one screen - if( construct_buffers[i].size() > static_cast( available_buffer_height ) ) { - construct_buffer_breakpoints.push_back( static_cast( current_buffer_location + - static_cast( available_buffer_height ) ) ); - } - current_buffer_location += construct_buffers[i].size(); - if( i < construct_buffers.size() - 1 ) { - full_construct_buffer.push_back( std::string() ); - current_buffer_location++; - } - } - total_project_breakpoints = static_cast( construct_buffer_breakpoints.size() ); - } - if( current_construct_breakpoint > 0 ) { - // Print previous stage indicator if breakpoint is past the beginning - trim_and_print( w_con, point( pos_x, 2 ), available_window_width, c_white, - _( "Press %s to show previous stage(s)." ), - ctxt.get_desc( "PAGE_UP" ) ); - } - if( static_cast( construct_buffer_breakpoints[current_construct_breakpoint] + - available_buffer_height ) < full_construct_buffer.size() ) { - // Print next stage indicator if more breakpoints are remaining after screen height - trim_and_print( w_con, point( pos_x, w_height - 2 - static_cast( notes.size() ) ), - available_window_width, - c_white, _( "Press %s to show next stage(s)." ), - ctxt.get_desc( "PAGE_DOWN" ) ); - } - // Leave room for above/below indicators - int ypos = 3; - nc_color stored_color = color_stage; - for( size_t i = static_cast( construct_buffer_breakpoints[current_construct_breakpoint] ); - i < full_construct_buffer.size(); i++ ) { - //the value of 3 is from leaving room at the top of window - if( ypos > available_buffer_height + 3 ) { - break; - } - print_colored_text( w_con, point( w_list_width + w_list_x0 + 2, ypos++ ), stored_color, color_stage, - full_construct_buffer[i] ); - } - } + recalc_buffer(); } // Finished updating - draw_scrollbar( w_con, select, w_list_height, constructs.size(), point( 0, 3 ) ); - wrefresh( w_con ); - wrefresh( w_list ); + ui_manager::redraw(); const std::string action = ctxt.handle_input(); if( action == "FILTER" ) { @@ -689,7 +714,6 @@ construction_id construction_menu( const bool blueprint ) update_cat = true; tabindex = ( tabindex + 1 ) % tabcount; } else if( action == "PAGE_UP" ) { - update_info = true; if( current_construct_breakpoint > 0 ) { current_construct_breakpoint--; } @@ -697,7 +721,6 @@ construction_id construction_menu( const bool blueprint ) current_construct_breakpoint = 0; } } else if( action == "PAGE_DOWN" ) { - update_info = true; if( current_construct_breakpoint < total_project_breakpoints - 1 ) { current_construct_breakpoint++; } @@ -706,8 +729,6 @@ construction_id construction_menu( const bool blueprint ) } } else if( action == "QUIT" ) { exit = true; - } else if( action == "HELP_KEYBINDINGS" ) { - draw_grid( w_con, w_list_width + w_list_x0 ); } else if( action == "TOGGLE_UNAVAILABLE_CONSTRUCTIONS" ) { update_info = true; update_cat = true; @@ -730,7 +751,6 @@ construction_id construction_menu( const bool blueprint ) exit = true; } else { popup( _( "You can't build that!" ) ); - draw_grid( w_con, w_list_width + w_list_x0 ); update_info = true; } } else { @@ -749,9 +769,6 @@ construction_id construction_menu( const bool blueprint ) uistate.construction_tab = int_id( tabindex ).id(); - w_list = catacurses::window(); - w_con = catacurses::window(); - g->refresh_all(); return ret; } diff --git a/src/game.cpp b/src/game.cpp index 7a594da43ca3c..1e81191f13b6b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4618,8 +4618,6 @@ void game::use_computer( const tripoint &p ) } computer_session( *used ).use(); - - refresh_all(); } template