Skip to content

Commit

Permalink
Sort vehicle spawn list (from debug menu)
Browse files Browse the repository at this point in the history
The list of vehicles in the debug menu spawn vehicle list was in an
arbitrary order, making it difficult to see what was going on.
Searching was available, but browsing was difficult.

Instead, sort them by translated name (using naive string sorting).
  • Loading branch information
jbytheway committed Nov 18, 2019
1 parent b653d6b commit af2f244
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 af2f244

Please sign in to comment.