Skip to content

Commit

Permalink
Migrate martial arts info to ui_adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox committed Apr 26, 2020
1 parent 80ace93 commit 6bde81e
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,24 +1475,49 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
buffer += enumerate_as_string( weapons );
}

catacurses::window w = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
point( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0,
TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ) );

std::string text = replace_colors( buffer );
int width = FULL_SCREEN_WIDTH - 4;
int height = FULL_SCREEN_HEIGHT - 2;
const auto vFolded = foldstring( text, width );
int iLines = vFolded.size();
catacurses::window w;

const std::string text = replace_colors( buffer );
int width = 0;
int height = 0;
int iLines = 0;
int selected = 0;

ui_adaptor ui;
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
w = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
point( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0,
TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ) );

width = FULL_SCREEN_WIDTH - 4;
height = FULL_SCREEN_HEIGHT - 2;

const auto vFolded = foldstring( text, width );
iLines = vFolded.size();

if( iLines < height ) {
selected = 0;
} else if( selected >= iLines - height ) {
selected = iLines - height;
}

ui.position_from_window( w );
} );
ui.mark_resize();

input_context ict;
ict.register_action( "UP" );
ict.register_action( "DOWN" );
ict.register_action( "QUIT" );
ict.register_action( "HELP_KEYBINDINGS" );

// FIXME: temporarily disable redrawing of lower UIs before this UI is migrated to `ui_adaptor`
ui_adaptor ui( ui_adaptor::disable_uis_below {} );
ui.on_redraw( [&]( const ui_adaptor & ) {
werase( w );
fold_and_print_from( w, point( 2, 1 ), width, selected, c_light_gray, text );
draw_border( w, BORDER_COLOR, string_format( _( " Style: %s " ), ma.name ) );
draw_scrollbar( w, selected, height, iLines, point_south, BORDER_COLOR, true );
wrefresh( w );
} );

do {
if( selected < 0 ) {
Expand All @@ -1503,12 +1528,7 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
selected = iLines - height;
}

werase( w );
fold_and_print_from( w, point( 2, 1 ), width, selected, c_light_gray, text );
draw_border( w, BORDER_COLOR, string_format( _( " Style: %s " ), ma.name ) );
draw_scrollbar( w, selected, height, iLines, point_south, BORDER_COLOR, true );
wrefresh( w );
catacurses::refresh();
ui_manager::redraw();

std::string action = ict.handle_input();

Expand Down

0 comments on commit 6bde81e

Please sign in to comment.