Mercurial > hg > openttd
changeset 8974:6b1769a870ad draft
(svn r12766) -Add: sorting by road vehicle/train length. Based on a patch by Sir Bob.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 18 Apr 2008 10:58:11 +0000 |
parents | f8dda7737158 |
children | b053ca278abe |
files | src/group_gui.cpp src/lang/english.txt src/vehicle_gui.cpp |
diffstat | 3 files changed, 30 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -523,7 +523,7 @@ 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
--- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -378,6 +378,7 @@ 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
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -72,6 +72,7 @@ static VehicleSortListingTypeFunction VehicleMaxSpeedSorter; static VehicleSortListingTypeFunction VehicleModelSorter; static VehicleSortListingTypeFunction VehicleValueSorter; +static VehicleSortListingTypeFunction VehicleLengthSorter; static VehicleSortListingTypeFunction* const _vehicle_sorter[] = { &VehicleNumberSorter, @@ -84,6 +85,7 @@ &VehicleMaxSpeedSorter, &VehicleModelSorter, &VehicleValueSorter, + &VehicleLengthSorter, }; const StringID _vehicle_sort_listing[] = { @@ -97,6 +99,7 @@ STR_SORT_BY_MAX_SPEED, STR_SORT_BY_MODEL, STR_SORT_BY_VALUE, + STR_SORT_BY_LENGTH, INVALID_STRING_ID }; @@ -698,6 +701,30 @@ 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 @@ 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;