inventory_selector::inventory_selector( player &u, item_filter filter )
    : columns()
    , active_column_index( 0 )
    , dropping()
    , ctxt("INVENTORY")
    , w_inv( newwin( TERMY, TERMX, VIEW_OFFSET_Y, VIEW_OFFSET_X ) )
    , navigation( navigation_mode::ITEM )
    , weapon_cat("WEAPON", _("WEAPON HELD"), 0)
    , worn_cat("ITEMS WORN", _("ITEMS WORN"), 0)
    , u(u)
{
    ctxt.register_action("DOWN", _("Next item"));
    ctxt.register_action("UP", _("Previous item"));
    ctxt.register_action("RIGHT", _("Confirm"));
    ctxt.register_action("LEFT", _("Switch inventory/worn"));
    ctxt.register_action("CONFIRM", _("Mark selected item"));
    ctxt.register_action("QUIT", _("Cancel"));
    ctxt.register_action("CATEGORY_SELECTION");
    ctxt.register_action("NEXT_TAB", _("Page down"));
    ctxt.register_action("PREV_TAB", _("Page up"));
    ctxt.register_action("HOME", _("Home"));
    ctxt.register_action("END", _("End"));
    ctxt.register_action("HELP_KEYBINDINGS");
    ctxt.register_action("ANY_INPUT"); // For invlets


    std::unique_ptr<inventory_column> first_column( new inventory_column() );
    std::unique_ptr<inventory_column> second_column( new inventory_column() );

    first_column->add_entries( u.inv.indexed_slice_filter_by( filter ) );

    if( !first_column->empty() ) {
        insert_column( columns.end(), first_column );
    }

    if( u.is_armed() && filter( u.weapon ) ) {
        second_column->add_entry( inventory_entry( &u.weapon, -1, &weapon_cat ) );
    }

    size_t i = 0;
    for( const auto &it : u.worn ) {
        if( filter( it ) ) {
            second_column->add_entry( inventory_entry( &it, player::worn_position_to_index( i ), &worn_cat ) );
        }
        ++i;
    }

    if( !second_column->empty() ) {
        insert_column( columns.end(), second_column );
    }
}
Esempio n. 2
0
inventory_selector::inventory_selector( player &u, const std::string &title, const item_location_filter &filter )
    : u(u)
    , ctxt( "INVENTORY" )
    , title( title )
    , filter( filter )
    , w_inv( newwin( TERMY, TERMX, VIEW_OFFSET_Y, VIEW_OFFSET_X ) )
    , columns()
    , active_column_index( 0 )
    , navigation( navigation_mode::ITEM )
{
    ctxt.register_action("DOWN", _("Next item"));
    ctxt.register_action("UP", _("Previous item"));
    ctxt.register_action("RIGHT", _("Confirm"));
    ctxt.register_action("LEFT", _("Switch inventory/worn"));
    ctxt.register_action("CONFIRM", _("Mark selected item"));
    ctxt.register_action("QUIT", _("Cancel"));
    ctxt.register_action("CATEGORY_SELECTION");
    ctxt.register_action("NEXT_TAB", _("Page down"));
    ctxt.register_action("PREV_TAB", _("Page up"));
    ctxt.register_action("HOME", _("Home"));
    ctxt.register_action("END", _("End"));
    ctxt.register_action("HELP_KEYBINDINGS");
    ctxt.register_action("ANY_INPUT"); // For invlets

    std::unique_ptr<inventory_column> first_column( new inventory_column() );
    std::unique_ptr<inventory_column> second_column( new inventory_column() );

    for( size_t i = 0; i < u.inv.size(); ++i ) {
        const auto &stack = u.inv.const_stack( i );
        const auto location = std::make_shared<item_location>( u, const_cast<item *>( &stack.front() ) );

        if( filter( *location ) ) {
            first_column->add_entry( inventory_entry( location, stack.size() ) );
        }
    }

    if( !first_column->empty() ) {
        insert_column( columns.end(), first_column );
    }

    if( u.is_armed() ) {
        categories.emplace_back( "WEAPON", _( "WEAPON HELD" ), 0 );
        const auto location = std::make_shared<item_location>( u, &u.weapon );
        if( filter( *location ) ) {
            second_column->add_entry( inventory_entry( location, &categories.back(), c_ltblue ) );
        }
    }

    if( !u.worn.empty() ) {
        categories.emplace_back( "ITEMS WORN", _( "ITEMS WORN" ), 0 );
        for( auto &it : u.worn ) {
            const auto location = std::make_shared<item_location>( u, &it );
            if( filter( *location ) ) {
                second_column->add_entry( inventory_entry( location, &categories.back(), c_cyan ) );
            }
        }
    }

    if( !second_column->empty() ) {
        insert_column( columns.end(), second_column );
    }
}