diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/group_gui.cpp | 2 | ||||
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 29 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/group_gui.cpp b/src/group_gui.cpp index efa8c1af1..967b66f9f 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -523,7 +523,7 @@ static void GroupWndProc(Window *w, WindowEvent *e) break; case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu - ShowDropDownMenu(w, _vehicle_sort_listing, gv->l.sort_type, GRP_WIDGET_SORT_BY_DROPDOWN, 0, 0); + ShowDropDownMenu(w, _vehicle_sort_listing, gv->l.sort_type, GRP_WIDGET_SORT_BY_DROPDOWN, 0, (gv->vehicle_type == VEH_TRAIN || gv->vehicle_type == VEH_ROAD) ? 0 : (1 << 10)); return; case GRP_WIDGET_ALL_VEHICLES: // All vehicles button diff --git a/src/lang/english.txt b/src/lang/english.txt index 35f576601..e298044a0 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -378,6 +378,7 @@ STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE :Total capacity STR_SORT_BY_MAX_SPEED :Maximum speed STR_SORT_BY_MODEL :Model STR_SORT_BY_VALUE :Value +STR_SORT_BY_LENGTH :Length STR_SORT_BY_FACILITY :Station type STR_SORT_BY_WAITING :Waiting cargo value STR_SORT_BY_RATING_MAX :Cargo rating diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 47480910d..41c5c840f 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -72,6 +72,7 @@ static VehicleSortListingTypeFunction VehicleReliabilitySorter; static VehicleSortListingTypeFunction VehicleMaxSpeedSorter; static VehicleSortListingTypeFunction VehicleModelSorter; static VehicleSortListingTypeFunction VehicleValueSorter; +static VehicleSortListingTypeFunction VehicleLengthSorter; static VehicleSortListingTypeFunction* const _vehicle_sorter[] = { &VehicleNumberSorter, @@ -84,6 +85,7 @@ static VehicleSortListingTypeFunction* const _vehicle_sorter[] = { &VehicleMaxSpeedSorter, &VehicleModelSorter, &VehicleValueSorter, + &VehicleLengthSorter, }; const StringID _vehicle_sort_listing[] = { @@ -97,6 +99,7 @@ const StringID _vehicle_sort_listing[] = { STR_SORT_BY_MAX_SPEED, STR_SORT_BY_MODEL, STR_SORT_BY_VALUE, + STR_SORT_BY_LENGTH, INVALID_STRING_ID }; @@ -698,6 +701,30 @@ static int CDECL VehicleValueSorter(const void *a, const void *b) return (_internal_sort_order & 1) ? -r : r; } +static int CDECL VehicleLengthSorter(const void *a, const void *b) +{ + const Vehicle *va = *(const Vehicle**)a; + const Vehicle *vb = *(const Vehicle**)b; + int r = 0; + + switch (va->type) { + case VEH_TRAIN: + r = va->u.rail.cached_total_length - vb->u.rail.cached_total_length; + break; + + case VEH_ROAD: + for (const Vehicle *u = va; u != NULL; u = u->Next()) r += u->u.road.cached_veh_length; + for (const Vehicle *u = vb; u != NULL; u = u->Next()) r -= u->u.road.cached_veh_length; + break; + + default: NOT_REACHED(); + } + + VEHICLEUNITNUMBERSORTER(r, va, vb); + + return (_internal_sort_order & 1) ? -r : r; +} + void InitializeGUI() { memset(&_sorting, 0, sizeof(_sorting)); @@ -1061,7 +1088,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) SetWindowDirty(w); break; case VLW_WIDGET_SORT_BY_PULLDOWN:/* Select sorting criteria dropdown menu */ - ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, 0); + ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, (vl->vehicle_type == VEH_TRAIN || vl->vehicle_type == VEH_ROAD) ? 0 : (1 << 10)); return; case VLW_WIDGET_LIST: { /* Matrix to show vehicles */ uint32 id_v = (e->we.click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / w->resize.step_height; |