203 case VEH_ROAD: this->sorting = &_sorting.roadveh; break; |
203 case VEH_ROAD: this->sorting = &_sorting.roadveh; break; |
204 case VEH_SHIP: this->sorting = &_sorting.ship; break; |
204 case VEH_SHIP: this->sorting = &_sorting.ship; break; |
205 case VEH_AIRCRAFT: this->sorting = &_sorting.aircraft; break; |
205 case VEH_AIRCRAFT: this->sorting = &_sorting.aircraft; break; |
206 } |
206 } |
207 |
207 |
208 this->vehicles.sort_type = this->sorting->criteria; |
208 this->vehicles.SetListing(*this->sorting); |
209 this->vehicles.flags = VL_REBUILD | (this->sorting->order ? VL_DESC : VL_NONE); |
209 this->vehicles.ForceRebuild(); |
210 this->vehicles.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer |
210 this->vehicles.NeedResort(); |
211 |
211 |
212 this->groups.ForceRebuild(); |
212 this->groups.ForceRebuild(); |
213 this->groups.NeedResort(); |
213 this->groups.NeedResort(); |
214 |
214 |
215 this->group_sel = ALL_GROUP; |
215 this->group_sel = ALL_GROUP; |
258 this->FindWindowPlacementAndResize(desc); |
258 this->FindWindowPlacementAndResize(desc); |
259 } |
259 } |
260 |
260 |
261 ~VehicleGroupWindow() |
261 ~VehicleGroupWindow() |
262 { |
262 { |
|
263 *this->sorting = this->vehicles.GetListing(); |
263 } |
264 } |
264 |
265 |
265 virtual void OnInvalidateData(int data) |
266 virtual void OnInvalidateData(int data) |
266 { |
267 { |
267 this->vehicles.flags |= (data == 0 ? VL_REBUILD : VL_RESORT); |
|
268 |
|
269 if (data == 0) { |
268 if (data == 0) { |
|
269 this->vehicles.ForceRebuild(); |
270 this->groups.ForceRebuild(); |
270 this->groups.ForceRebuild(); |
271 } else { |
271 } else { |
|
272 this->vehicles.ForceResort(); |
272 this->groups.ForceResort(); |
273 this->groups.ForceResort(); |
273 } |
274 } |
274 |
275 |
275 if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || IsValidGroupID(this->group_sel))) { |
276 if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || IsValidGroupID(this->group_sel))) { |
276 this->group_sel = ALL_GROUP; |
277 this->group_sel = ALL_GROUP; |
432 /* draw the number of vehicles of the group */ |
433 /* draw the number of vehicles of the group */ |
433 SetDParam(0, g->num_vehicle); |
434 SetDParam(0, g->num_vehicle); |
434 DrawStringRightAligned(187, y1 + 1, STR_GROUP_TINY_NUM, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK); |
435 DrawStringRightAligned(187, y1 + 1, STR_GROUP_TINY_NUM, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK); |
435 } |
436 } |
436 |
437 |
437 this->DrawSortButtonState(GRP_WIDGET_SORT_BY_ORDER, this->vehicles.flags & VL_DESC ? SBS_DOWN : SBS_UP); |
438 this->DrawSortButtonState(GRP_WIDGET_SORT_BY_ORDER, this->vehicles.IsDescSortOrder() ? SBS_DOWN : SBS_UP); |
438 |
439 |
439 int list_width = this->widget[GRP_WIDGET_LIST_VEHICLE].right - this->widget[GRP_WIDGET_LIST_VEHICLE].left - 20; |
440 int list_width = this->widget[GRP_WIDGET_LIST_VEHICLE].right - this->widget[GRP_WIDGET_LIST_VEHICLE].left - 20; |
440 |
441 |
441 /* Draw Matrix Vehicle according to the vehicle list built before */ |
442 /* Draw Matrix Vehicle according to the vehicle list built before */ |
442 max = min(this->vscroll2.pos + this->vscroll2.cap, this->vehicles.Length()); |
443 max = min(this->vscroll2.pos + this->vscroll2.cap, this->vehicles.Length()); |
470 { |
471 { |
471 if (widget != GRP_WIDGET_SORT_BY_DROPDOWN && widget != GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN) HideDropDownMenu(this); |
472 if (widget != GRP_WIDGET_SORT_BY_DROPDOWN && widget != GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN) HideDropDownMenu(this); |
472 |
473 |
473 switch(widget) { |
474 switch(widget) { |
474 case GRP_WIDGET_SORT_BY_ORDER: // Flip sorting method ascending/descending |
475 case GRP_WIDGET_SORT_BY_ORDER: // Flip sorting method ascending/descending |
475 this->vehicles.flags ^= VL_DESC; |
476 this->vehicles.ToggleSortOrder(); |
476 this->vehicles.flags |= VL_RESORT; |
|
477 |
|
478 this->sorting->order = !!(this->vehicles.flags & VL_DESC); |
|
479 this->SetDirty(); |
477 this->SetDirty(); |
480 break; |
478 break; |
481 |
479 |
482 case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu |
480 case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu |
483 ShowDropDownMenu(this, _vehicle_sort_listing, this->vehicles.sort_type, GRP_WIDGET_SORT_BY_DROPDOWN, 0, (this->vehicle_type == VEH_TRAIN || this->vehicle_type == VEH_ROAD) ? 0 : (1 << 10)); |
481 ShowDropDownMenu(this, _vehicle_sort_listing, this->vehicles.SortType(), GRP_WIDGET_SORT_BY_DROPDOWN, 0, (this->vehicle_type == VEH_TRAIN || this->vehicle_type == VEH_ROAD) ? 0 : (1 << 10)); |
484 return; |
482 return; |
485 |
483 |
486 case GRP_WIDGET_ALL_VEHICLES: // All vehicles button |
484 case GRP_WIDGET_ALL_VEHICLES: // All vehicles button |
487 if (!IsAllGroupID(this->group_sel)) { |
485 if (!IsAllGroupID(this->group_sel)) { |
488 this->group_sel = ALL_GROUP; |
486 this->group_sel = ALL_GROUP; |
489 this->vehicles.flags |= VL_REBUILD; |
487 this->vehicles.ForceRebuild(); |
490 this->SetDirty(); |
488 this->SetDirty(); |
491 } |
489 } |
492 break; |
490 break; |
493 |
491 |
494 case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles button |
492 case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles button |
495 if (!IsDefaultGroupID(this->group_sel)) { |
493 if (!IsDefaultGroupID(this->group_sel)) { |
496 this->group_sel = DEFAULT_GROUP; |
494 this->group_sel = DEFAULT_GROUP; |
497 this->vehicles.flags |= VL_REBUILD; |
495 this->vehicles.ForceRebuild(); |
498 this->SetDirty(); |
496 this->SetDirty(); |
499 } |
497 } |
500 break; |
498 break; |
501 |
499 |
502 case GRP_WIDGET_LIST_GROUP: { // Matrix Group |
500 case GRP_WIDGET_LIST_GROUP: { // Matrix Group |
667 |
665 |
668 virtual void OnDropdownSelect(int widget, int index) |
666 virtual void OnDropdownSelect(int widget, int index) |
669 { |
667 { |
670 switch (widget) { |
668 switch (widget) { |
671 case GRP_WIDGET_SORT_BY_DROPDOWN: |
669 case GRP_WIDGET_SORT_BY_DROPDOWN: |
672 if (this->vehicles.sort_type != index) { |
670 this->vehicles.SetSortType(index); |
673 this->vehicles.flags |= VL_RESORT; |
|
674 this->vehicles.sort_type = index; |
|
675 this->sorting->criteria = this->vehicles.sort_type; |
|
676 } |
|
677 break; |
671 break; |
678 |
672 |
679 case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: |
673 case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: |
680 assert(this->vehicles.Length() != 0); |
674 assert(this->vehicles.Length() != 0); |
681 |
675 |
713 } |
707 } |
714 |
708 |
715 virtual void OnTick() |
709 virtual void OnTick() |
716 { |
710 { |
717 if (_pause_game != 0) return; |
711 if (_pause_game != 0) return; |
718 if (--this->vehicles.resort_timer == 0) { |
712 if (this->groups.NeedResort() || this->vehicles.NeedResort()) { |
719 this->vehicles.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
|
720 this->vehicles.flags |= VL_RESORT; |
|
721 this->SetDirty(); |
|
722 } |
|
723 if (this->groups.NeedResort()) { |
|
724 this->SetDirty(); |
713 this->SetDirty(); |
725 } |
714 } |
726 } |
715 } |
727 |
716 |
728 virtual void OnPlaceObjectAbort() |
717 virtual void OnPlaceObjectAbort() |