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 overmap_ui.cpp to ui_adaptor #40095

Merged
merged 13 commits into from
May 3, 2020
8 changes: 6 additions & 2 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ class query_destination_callback : public uilist_callback
void draw_squares( const uilist *menu );
public:
query_destination_callback( advanced_inventory &adv_inv ) : _adv_inv( adv_inv ) {}
void select( int /*entnum*/, uilist *menu ) override {
void refresh( uilist *menu ) override {
draw_squares( menu );
}
};
Expand All @@ -1583,8 +1583,11 @@ void query_destination_callback::draw_squares( const uilist *menu )
{
assert( menu->entries.size() >= 9 );
int ofs = -25 - 4;
int sel = _adv_inv.screen_relative_location(
int sel = 0;
if( menu->selected >= 0 && static_cast<size_t>( menu->selected ) < menu->entries.size() ) {
sel = _adv_inv.screen_relative_location(
static_cast <aim_location>( menu->selected + 1 ) );
}
for( int i = 1; i < 10; i++ ) {
aim_location loc = _adv_inv.screen_relative_location( static_cast <aim_location>( i ) );
std::string key = _adv_inv.get_location_key( loc );
Expand All @@ -1601,6 +1604,7 @@ void query_destination_callback::draw_squares( const uilist *menu )
wprintz( menu->window, kcolor, "%s", key );
wprintz( menu->window, bcolor, "%c", bracket[1] );
}
wrefresh( menu->window );
}

bool advanced_inventory::query_destination( aim_location &def )
Expand Down
5 changes: 0 additions & 5 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,6 @@ void editmap::edit_itm()
pgettext( "item manipulation debug menu entry for adding an item on a tile", "Add item" ) );
ilmenu.setup();
ilmenu.filterlist();
ilmenu.refresh();
}
} while( ilmenu.ret != UILIST_CANCEL );
}
Expand Down Expand Up @@ -1576,7 +1575,6 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu )

gmenu.border_color = c_light_gray;
gmenu.hilight_color = c_black_white;
gmenu.redraw();
gmenu.show();

uilist gpmenu;
Expand Down Expand Up @@ -1758,11 +1756,9 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu )
if( gpmenu.ret_act == "LEFT" ) {
gmenu.scrollby( -1 );
gmenu.show();
gmenu.refresh();
} else if( gpmenu.ret_act == "RIGHT" ) {
gmenu.scrollby( 1 );
gmenu.show();
gmenu.refresh();
}
}
showpreview = gpmenu.ret == UILIST_TIMEOUT ? !showpreview : true;
Expand All @@ -1774,7 +1770,6 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu )
}
gmenu.border_color = c_magenta;
gmenu.hilight_color = h_white;
gmenu.redraw();
hilights["mapgentgt"].points.clear();
cleartmpmap( tmpmap );
}
Expand Down
2 changes: 0 additions & 2 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,6 @@ class game
catacurses::window w_pixel_minimap;
//only a pointer, can refer to w_messages_short or w_messages_long

catacurses::window w_blackspace;

// View offset based on the driving speed (if any)
// that has been added to u.view_offset,
// Don't write to this directly, always use set_driving_view_offset
Expand Down
14 changes: 10 additions & 4 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ class spellcasting_callback : public uilist_callback
return false;
}

void select( int entnum, uilist *menu ) override {
void refresh( uilist *menu ) override {
mvwputch( menu->window, point( menu->w_width - menu->pad_right, 0 ), c_magenta, LINE_OXXX );
mvwputch( menu->window, point( menu->w_width - menu->pad_right, menu->w_height - 1 ), c_magenta,
LINE_XXOX );
Expand All @@ -1532,7 +1532,10 @@ class spellcasting_callback : public uilist_callback
const std::string assign_letter = _( "Assign Hotkey [=]" );
mvwprintz( menu->window, point( menu->w_width - assign_letter.length() - 1, 0 ), c_yellow,
assign_letter );
draw_spell_info( *known_spells[entnum], menu );
if( menu->selected >= 0 && static_cast<size_t>( menu->selected ) < known_spells.size() ) {
draw_spell_info( *known_spells[menu->selected], menu );
}
wrefresh( menu->window );
}
};

Expand Down Expand Up @@ -1957,14 +1960,17 @@ static void draw_spellbook_info( const spell_type &sp, uilist *menu )
}
}

void spellbook_callback::select( int entnum, uilist *menu )
void spellbook_callback::refresh( uilist *menu )
{
mvwputch( menu->window, point( menu->pad_left, 0 ), c_magenta, LINE_OXXX );
mvwputch( menu->window, point( menu->pad_left, menu->w_height - 1 ), c_magenta, LINE_XXOX );
for( int i = 1; i < menu->w_height - 1; i++ ) {
mvwputch( menu->window, point( menu->pad_left, i ), c_magenta, LINE_XOXO );
}
draw_spellbook_info( spells[entnum], menu );
if( menu->selected >= 0 && static_cast<size_t>( menu->selected ) < spells.size() ) {
draw_spellbook_info( spells[menu->selected], menu );
}
wrefresh( menu->window );
}

void fake_spell::load( const JsonObject &jo )
Expand Down
2 changes: 1 addition & 1 deletion src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class spellbook_callback : public uilist_callback
std::vector<spell_type> spells;
public:
void add_spell( const spell_id &sp );
void select( int entnum, uilist *menu ) override;
void refresh( uilist *menu ) override;
};

// Utility structure to run area queries over weight map. It uses shortest-path-expanding-tree,
Expand Down
18 changes: 11 additions & 7 deletions src/magic_teleporter_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,23 @@ class teleporter_callback : public uilist_callback
std::map<int, tripoint> index_pairs;
public:
teleporter_callback( std::map<int, tripoint> &ip ) : index_pairs( ip ) {}
void select( int entnum, uilist *menu ) override {
void refresh( uilist *menu ) override {
const int entnum = menu->selected;
const int start_x = menu->w_width - menu->pad_right;
mvwputch( menu->window, point( start_x, 0 ), c_magenta, LINE_OXXX );
mvwputch( menu->window, point( start_x, menu->w_height - 1 ), c_magenta, LINE_XXOX );
for( int i = 1; i < menu->w_height - 1; i++ ) {
mvwputch( menu->window, point( start_x, i ), c_magenta, LINE_XOXO );
}
overmap_ui::draw_overmap_chunk( menu->window, g->u, index_pairs[entnum], point( start_x + 1, 1 ),
29, 21 );
mvwprintz( menu->window, point( start_x + 2, 1 ), c_white,
string_format( _( "Distance: %d (%d, %d)" ),
rl_dist( ms_to_omt_copy( g->m.getabs( g->u.pos() ) ), index_pairs[entnum] ),
index_pairs[entnum].x, index_pairs[entnum].y ) );
if( entnum >= 0 && static_cast<size_t>( entnum ) < index_pairs.size() ) {
overmap_ui::draw_overmap_chunk( menu->window, g->u, index_pairs[entnum], point( start_x + 1, 1 ),
29, 21 );
mvwprintz( menu->window, point( start_x + 2, 1 ), c_white,
string_format( _( "Distance: %d (%d, %d)" ),
rl_dist( ms_to_omt_copy( g->m.getabs( g->u.pos() ) ), index_pairs[entnum] ),
index_pairs[entnum].x, index_pairs[entnum].y ) );
}
wrefresh( menu->window );
}
};

Expand Down
4 changes: 1 addition & 3 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ std::string ma_technique::get_description() const
}

bool ma_style_callback::key( const input_context &ctxt, const input_event &event, int entnum,
uilist *menu )
uilist * )
{
const std::string &action = ctxt.input_to_action( event );
if( action != "SHOW_DESCRIPTION" ) {
Expand Down Expand Up @@ -1540,8 +1540,6 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
selected--;
}
} while( true );

menu->redraw();
}
return true;
}
50 changes: 0 additions & 50 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,56 +1829,6 @@ std::string get_labeled_bar( const double val, const int width, const std::strin
return get_labeled_bar( val, width, label, ratings.begin(), ratings.end() );
}

/**
* Display data in table, each cell contains one entry from the
* data vector. Allows vertical scrolling if the data does not fit.
* Data is displayed using fold_and_print_from, which allows coloring!
* @param columns Number of columns, can be 1. Make sure each entry
* of the data vector fits into one cell.
* @param title The title text, displayed on top.
* @param w The window to draw this in, the whole widow is used.
* @param data Text data to fill.
*/
void display_table( const catacurses::window &w, const std::string &title, int columns,
const std::vector<std::string> &data )
{
const int width = getmaxx( w ) - 2; // -2 for border
const int rows = getmaxy( w ) - 2 - 1; // -2 for border, -1 for title
const int col_width = width / columns;
int offset = 0;

// FIXME: temporarily disable redrawing of lower UIs before this UI is migrated to `ui_adaptor`
ui_adaptor ui( ui_adaptor::disable_uis_below {} );

#if defined(__ANDROID__)
// no bindings, but give it its own input context so stale buttons don't hang around.
input_context ctxt( "DISPLAY_TABLE" );
#endif
for( ;; ) {
werase( w );
draw_border( w, BORDER_COLOR, title, c_white );
for( int i = 0; i < rows * columns; i++ ) {
if( i + offset * columns >= static_cast<int>( data.size() ) ) {
break;
}
const int x = 2 + ( i % columns ) * col_width;
const int y = ( i / columns ) + 2;
fold_and_print_from( w, point( x, y ), col_width, 0, c_white, data[i + offset * columns] );
}
draw_scrollbar( w, offset, rows, ( data.size() + columns - 1 ) / columns, point( 0, 2 ) );
wrefresh( w );
// TODO: use input context
int ch = inp_mngr.get_input_event().get_first_input();
if( ch == KEY_DOWN && ( ( offset + 1 ) * columns ) < static_cast<int>( data.size() ) ) {
offset++;
} else if( ch == KEY_UP && offset > 0 ) {
offset--;
} else if( ch == ' ' || ch == '\n' || ch == KEY_ESCAPE ) {
break;
}
}
}

scrollingcombattext::cSCT::cSCT( const point &p_pos, const direction p_oDir,
const std::string &p_sText, const game_message_type p_gmt,
const std::string &p_sText2, const game_message_type p_gmt2,
Expand Down
2 changes: 0 additions & 2 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ void center_print( const catacurses::window &w, int y, const nc_color &FG,
const std::string &text );
int right_print( const catacurses::window &w, int line, int right_indent,
const nc_color &FG, const std::string &text );
void display_table( const catacurses::window &w, const std::string &title, int columns,
const std::vector<std::string> &data );
void scrollable_text( const catacurses::window &w, const std::string &title,
const std::string &text );
void scrollable_text( const std::function<catacurses::window()> &init_window,
Expand Down
Loading