267 |
267 |
268 sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
268 sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
269 sl->flags &= ~SL_RESORT; |
269 sl->flags &= ~SL_RESORT; |
270 } |
270 } |
271 |
271 |
|
272 static uint32 _cargo_filter = UINT32_MAX; |
|
273 |
272 static void PlayerStationsWndProc(Window *w, WindowEvent *e) |
274 static void PlayerStationsWndProc(Window *w, WindowEvent *e) |
273 { |
275 { |
274 static const uint16 CARGO_ALL_SELECTED = 0x1FFF; |
|
275 |
|
276 const PlayerID owner = (PlayerID)w->window_number; |
276 const PlayerID owner = (PlayerID)w->window_number; |
277 static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK; |
277 static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK; |
278 static uint16 cargo_filter = CARGO_ALL_SELECTED; |
|
279 static Listing station_sort = {0, 0}; |
278 static Listing station_sort = {0, 0}; |
|
279 static bool include_empty = true; |
280 |
280 |
281 plstations_d *sl = &WP(w, plstations_d); |
281 plstations_d *sl = &WP(w, plstations_d); |
282 |
282 |
283 switch (e->event) { |
283 switch (e->event) { |
284 case WE_CREATE: /* set up resort timer */ |
284 case WE_CREATE: /* set up resort timer */ |
|
285 if (_cargo_filter == UINT32_MAX) _cargo_filter = _cargo_mask; |
|
286 |
285 for (uint i = 0; i < 5; i++) { |
287 for (uint i = 0; i < 5; i++) { |
286 if (HASBIT(facilities, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN); |
288 if (HASBIT(facilities, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN); |
287 } |
289 } |
288 for (CargoID i = 0; i < NUM_CARGO; i++) { |
|
289 if (HASBIT(cargo_filter, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_CARGOSTART); |
|
290 } |
|
291 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK)); |
290 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK)); |
292 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, cargo_filter == CARGO_ALL_SELECTED); |
291 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty); |
293 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING, HASBIT(cargo_filter, STATIONLIST_WIDGET_NOCARGOWAITING - NUM_CARGO)); |
292 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING, include_empty); |
294 |
293 |
295 sl->sort_list = NULL; |
294 sl->sort_list = NULL; |
296 sl->flags = SL_REBUILD; |
295 sl->flags = SL_REBUILD; |
297 sl->sort_type = station_sort.criteria; |
296 sl->sort_type = station_sort.criteria; |
298 if (station_sort.order) sl->flags |= SL_ORDER; |
297 if (station_sort.order) sl->flags |= SL_ORDER; |
299 sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
298 sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
300 break; |
299 break; |
301 |
300 |
302 case WE_PAINT: { |
301 case WE_PAINT: { |
303 BuildStationsList(sl, owner, facilities, cargo_filter); |
302 BuildStationsList(sl, owner, facilities, _cargo_filter, include_empty); |
304 SortStationsList(sl); |
303 SortStationsList(sl); |
305 |
304 |
306 SetVScrollCount(w, sl->list_length); |
305 SetVScrollCount(w, sl->list_length); |
307 |
306 |
308 /* draw widgets, with player's name in the caption */ |
307 /* draw widgets, with player's name in the caption */ |
446 case STATIONLIST_WIDGET_SORTCRITERIA: |
452 case STATIONLIST_WIDGET_SORTCRITERIA: |
447 case STATIONLIST_WIDGET_SORTDROPBTN: /* select sorting criteria dropdown menu */ |
453 case STATIONLIST_WIDGET_SORTDROPBTN: /* select sorting criteria dropdown menu */ |
448 ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, STATIONLIST_WIDGET_SORTDROPBTN, 0, 0); |
454 ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, STATIONLIST_WIDGET_SORTDROPBTN, 0, 0); |
449 break; |
455 break; |
450 |
456 |
|
457 case STATIONLIST_WIDGET_NOCARGOWAITING: |
|
458 if (_ctrl_pressed) { |
|
459 include_empty = !include_empty; |
|
460 ToggleWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING); |
|
461 } else { |
|
462 for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) { |
|
463 RaiseWindowWidget(w, i); |
|
464 } |
|
465 |
|
466 _cargo_filter = 0; |
|
467 include_empty = true; |
|
468 |
|
469 LowerWindowWidget(w, STATIONLIST_WIDGET_NOCARGOWAITING); |
|
470 } |
|
471 sl->flags |= SL_REBUILD; |
|
472 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty); |
|
473 SetWindowDirty(w); |
|
474 break; |
|
475 |
451 default: |
476 default: |
452 if (e->we.click.widget >= STATIONLIST_WIDGET_CARGOSTART && e->we.click.widget <= STATIONLIST_WIDGET_NOCARGOWAITING) { //change cargo_filter |
477 if (e->we.click.widget >= STATIONLIST_WIDGET_CARGOSTART) { //change cargo_filter |
|
478 /* Determine the selected cargo type */ |
|
479 CargoID c; |
|
480 int i = 0; |
|
481 for (c = 0; c < NUM_CARGO; c++) { |
|
482 if (!GetCargo(c)->IsValid()) continue; |
|
483 if (e->we.click.widget - STATIONLIST_WIDGET_CARGOSTART == i) break; |
|
484 i++; |
|
485 } |
|
486 |
453 if (_ctrl_pressed) { |
487 if (_ctrl_pressed) { |
454 TOGGLEBIT(cargo_filter, e->we.click.widget - STATIONLIST_WIDGET_CARGOSTART); |
488 TOGGLEBIT(_cargo_filter, c); |
455 ToggleWidgetLoweredState(w, e->we.click.widget); |
489 ToggleWidgetLoweredState(w, e->we.click.widget); |
456 } else { |
490 } else { |
457 for (uint i = 0; cargo_filter != 0; i++, cargo_filter >>= 1) { |
491 for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) { |
458 if (HASBIT(cargo_filter, 0)) RaiseWindowWidget(w, i + STATIONLIST_WIDGET_CARGOSTART); |
492 RaiseWindowWidget(w, i); |
459 } |
493 } |
460 SETBIT(cargo_filter, e->we.click.widget - STATIONLIST_WIDGET_CARGOSTART); |
494 RaiseWindowWidget(w, STATIONLIST_WIDGET_NOCARGOWAITING); |
|
495 |
|
496 _cargo_filter = 0; |
|
497 include_empty = false; |
|
498 |
|
499 SETBIT(_cargo_filter, c); |
461 LowerWindowWidget(w, e->we.click.widget); |
500 LowerWindowWidget(w, e->we.click.widget); |
462 } |
501 } |
463 sl->flags |= SL_REBUILD; |
502 sl->flags |= SL_REBUILD; |
464 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, cargo_filter == CARGO_ALL_SELECTED); |
503 SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty); |
465 SetWindowDirty(w); |
504 SetWindowDirty(w); |
466 } |
505 } |
467 break; |
506 break; |
468 } |
507 } |
469 break; |
508 break; |
511 { WWT_TEXTBTN, RESIZE_NONE, 14, 28, 41, 14, 24, STR_BUS, STR_USE_CTRL_TO_SELECT_MORE}, |
550 { WWT_TEXTBTN, RESIZE_NONE, 14, 28, 41, 14, 24, STR_BUS, STR_USE_CTRL_TO_SELECT_MORE}, |
512 { WWT_TEXTBTN, RESIZE_NONE, 14, 42, 55, 14, 24, STR_PLANE, STR_USE_CTRL_TO_SELECT_MORE}, |
551 { WWT_TEXTBTN, RESIZE_NONE, 14, 42, 55, 14, 24, STR_PLANE, STR_USE_CTRL_TO_SELECT_MORE}, |
513 { WWT_TEXTBTN, RESIZE_NONE, 14, 56, 69, 14, 24, STR_SHIP, STR_USE_CTRL_TO_SELECT_MORE}, |
552 { WWT_TEXTBTN, RESIZE_NONE, 14, 56, 69, 14, 24, STR_SHIP, STR_USE_CTRL_TO_SELECT_MORE}, |
514 //Index 11 |
553 //Index 11 |
515 { WWT_PANEL, RESIZE_NONE, 14, 83, 88, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
554 { WWT_PANEL, RESIZE_NONE, 14, 83, 88, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
516 { WWT_PANEL, RESIZE_NONE, 14, 89, 102, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
555 { WWT_PANEL, RESIZE_NONE, 14, 89, 102, 14, 24, 0x0, STR_NO_WAITING_CARGO}, |
517 { WWT_PANEL, RESIZE_NONE, 14, 103, 116, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
556 { WWT_PANEL, RESIZE_RIGHT, 14, 117, 357, 14, 24, 0x0, STR_NULL}, |
518 { WWT_PANEL, RESIZE_NONE, 14, 117, 130, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
557 |
519 { WWT_PANEL, RESIZE_NONE, 14, 131, 144, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
558 //14 |
520 { WWT_PANEL, RESIZE_NONE, 14, 145, 158, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
521 { WWT_PANEL, RESIZE_NONE, 14, 159, 172, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
522 { WWT_PANEL, RESIZE_NONE, 14, 173, 186, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
523 { WWT_PANEL, RESIZE_NONE, 14, 187, 200, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
524 { WWT_PANEL, RESIZE_NONE, 14, 201, 214, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
525 { WWT_PANEL, RESIZE_NONE, 14, 215, 228, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
526 { WWT_PANEL, RESIZE_NONE, 14, 229, 242, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
527 { WWT_PANEL, RESIZE_NONE, 14, 243, 256, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE}, |
|
528 { WWT_PANEL, RESIZE_NONE, 14, 257, 270, 14, 24, 0x0, STR_NO_WAITING_CARGO}, |
|
529 { WWT_PANEL, RESIZE_RIGHT, 14, 285, 357, 14, 24, 0x0, STR_NULL}, |
|
530 |
|
531 //26 |
|
532 { WWT_PANEL, RESIZE_NONE, 14, 70, 83, 14, 24, 0x0, STR_SELECT_ALL_FACILITIES}, |
559 { WWT_PANEL, RESIZE_NONE, 14, 70, 83, 14, 24, 0x0, STR_SELECT_ALL_FACILITIES}, |
533 { WWT_PANEL, RESIZE_NONE, 14, 271, 284, 14, 24, 0x0, STR_SELECT_ALL_TYPES}, |
560 { WWT_PANEL, RESIZE_NONE, 14, 103, 116, 14, 24, 0x0, STR_SELECT_ALL_TYPES}, |
534 |
561 |
535 //28 |
562 //16 |
536 { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 80, 25, 36, STR_SORT_BY, STR_SORT_ORDER_TIP}, |
563 { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 80, 25, 36, STR_SORT_BY, STR_SORT_ORDER_TIP}, |
537 { WWT_PANEL, RESIZE_NONE, 14, 81, 232, 25, 36, 0x0, STR_SORT_CRITERIA_TIP}, |
564 { WWT_PANEL, RESIZE_NONE, 14, 81, 232, 25, 36, 0x0, STR_SORT_CRITERIA_TIP}, |
538 { WWT_TEXTBTN, RESIZE_NONE, 14, 233, 243, 25, 36, STR_0225, STR_SORT_CRITERIA_TIP}, |
565 { WWT_TEXTBTN, RESIZE_NONE, 14, 233, 243, 25, 36, STR_0225, STR_SORT_CRITERIA_TIP}, |
539 { WWT_PANEL, RESIZE_RIGHT, 14, 244, 357, 25, 36, 0x0, STR_NULL}, |
566 { WWT_PANEL, RESIZE_RIGHT, 14, 244, 357, 25, 36, 0x0, STR_NULL}, |
540 { WIDGETS_END}, |
567 { WIDGETS_END}, |
558 |
585 |
559 w->caption_color = (byte)w->window_number; |
586 w->caption_color = (byte)w->window_number; |
560 w->vscroll.cap = 12; |
587 w->vscroll.cap = 12; |
561 w->resize.step_height = 10; |
588 w->resize.step_height = 10; |
562 w->resize.height = w->height - 10 * 7; // minimum if 5 in the list |
589 w->resize.height = w->height - 10 * 7; // minimum if 5 in the list |
|
590 |
|
591 /* Add cargo filter buttons */ |
|
592 uint num_active = 0; |
|
593 for (CargoID c = 0; c < NUM_CARGO; c++) { |
|
594 if (GetCargo(c)->IsValid()) num_active++; |
|
595 } |
|
596 |
|
597 w->widget_count += num_active; |
|
598 w->widget = ReallocT(w->widget, w->widget_count + 1); |
|
599 w->widget[w->widget_count].type = WWT_LAST; |
|
600 |
|
601 uint i = 0; |
|
602 for (CargoID c = 0; c < NUM_CARGO; c++) { |
|
603 if (!GetCargo(c)->IsValid()) continue; |
|
604 |
|
605 Widget *wi = &w->widget[STATIONLIST_WIDGET_CARGOSTART + i]; |
|
606 wi->type = WWT_PANEL; |
|
607 wi->display_flags = RESIZE_NONE; |
|
608 wi->color = 14; |
|
609 wi->left = 89 + i * 14; |
|
610 wi->right = wi->left + 13; |
|
611 wi->top = 14; |
|
612 wi->bottom = 24; |
|
613 wi->data = 0; |
|
614 wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE; |
|
615 |
|
616 if (HASBIT(_cargo_filter, c)) LowerWindowWidget(w, STATIONLIST_WIDGET_CARGOSTART + i); |
|
617 i++; |
|
618 } |
|
619 |
|
620 w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].left += num_active * 14; |
|
621 w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].right += num_active * 14; |
|
622 w->widget[STATIONLIST_WIDGET_CARGOALL].left += num_active * 14; |
|
623 w->widget[STATIONLIST_WIDGET_CARGOALL].right += num_active * 14; |
|
624 w->widget[13].left += num_active * 14; |
|
625 |
|
626 if (num_active > 15) { |
|
627 /* Resize and fix the minimum width, if necessary */ |
|
628 ResizeWindow(w, (num_active - 15) * 14, 0); |
|
629 w->resize.width = w->width; |
|
630 } |
563 } |
631 } |
564 |
632 |
565 static const Widget _station_view_expanded_widgets[] = { |
633 static const Widget _station_view_expanded_widgets[] = { |
566 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
634 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
567 { WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
635 { WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, |