Skip to content

Commit

Permalink
Merge pull request #35576 from jbytheway/sort_vehicle_spawn_list
Browse files Browse the repository at this point in the history
Sort list of vehciles in debug menu vehicle spawn list
  • Loading branch information
ZhilkinSerg authored Nov 18, 2019
2 parents dd3d5cc + af2f244 commit 14a8951
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,24 +1146,28 @@ void debug()
dbg( D_ERROR ) << "game:load: There's already vehicle here";
debugmsg( "There's already vehicle here" );
} else {
std::vector<vproto_id> veh_strings;
// Vector of name, id so that we can sort by name
std::vector<std::pair<std::string, vproto_id>> veh_strings;
for( auto &elem : vehicle_prototype::get_all() ) {
if( elem == vproto_id( "custom" ) ) {
continue;
}
veh_strings.emplace_back( elem->name, elem );
}
std::sort( veh_strings.begin(), veh_strings.end() );
uilist veh_menu;
veh_menu.text = _( "Choose vehicle to spawn" );
int menu_ind = 0;
for( auto &elem : vehicle_prototype::get_all() ) {
if( elem != vproto_id( "custom" ) ) {
const vehicle_prototype &proto = elem.obj();
veh_strings.push_back( elem );
//~ Menu entry in vehicle wish menu: 1st string: displayed name, 2nd string: internal name of vehicle
veh_menu.addentry( menu_ind, true, MENU_AUTOASSIGN, _( "%1$s (%2$s)" ), _( proto.name ),
elem.c_str() );
++menu_ind;
}
for( auto &elem : veh_strings ) {
//~ Menu entry in vehicle wish menu: 1st string: displayed name, 2nd string: internal name of vehicle
veh_menu.addentry( menu_ind, true, MENU_AUTOASSIGN, _( "%1$s (%2$s)" ),
_( elem.first ), elem.second.c_str() );
++menu_ind;
}
veh_menu.query();
if( veh_menu.ret >= 0 && veh_menu.ret < static_cast<int>( veh_strings.size() ) ) {
//Didn't cancel
const vproto_id &selected_opt = veh_strings[veh_menu.ret];
const vproto_id &selected_opt = veh_strings[veh_menu.ret].second;
tripoint dest = u.pos(); // TODO: Allow picking this when add_vehicle has 3d argument
vehicle *veh = m.add_vehicle( selected_opt, dest.xy(), -90, 100, 0 );
if( veh != nullptr ) {
Expand Down

0 comments on commit 14a8951

Please sign in to comment.