src/station_gui.cpp
changeset 8493 3ab458f7cff4
parent 8428 f8300c908bd9
child 8501 66d88113ba24
equal deleted inserted replaced
8492:d61f7a733d19 8493:3ab458f7cff4
   288 	switch (e->event) {
   288 	switch (e->event) {
   289 		case WE_CREATE: /* set up resort timer */
   289 		case WE_CREATE: /* set up resort timer */
   290 			if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
   290 			if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
   291 
   291 
   292 			for (uint i = 0; i < 5; i++) {
   292 			for (uint i = 0; i < 5; i++) {
   293 				if (HasBit(facilities, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
   293 				if (HasBit(facilities, i)) w->LowerWidget(i + STATIONLIST_WIDGET_TRAIN);
   294 			}
   294 			}
   295 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   295 			w->SetWidgetLoweredState(STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   296 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   296 			w->SetWidgetLoweredState(STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   297 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING, include_empty);
   297 			w->SetWidgetLoweredState(STATIONLIST_WIDGET_NOCARGOWAITING, include_empty);
   298 
   298 
   299 			sl->sort_list = NULL;
   299 			sl->sort_list = NULL;
   300 			sl->flags = SL_REBUILD;
   300 			sl->flags = SL_REBUILD;
   301 			sl->sort_type = station_sort.criteria;
   301 			sl->sort_type = station_sort.criteria;
   302 			if (station_sort.order) sl->flags |= SL_ORDER;
   302 			if (station_sort.order) sl->flags |= SL_ORDER;
   335 				x += 14;
   335 				x += 14;
   336 				i++;
   336 				i++;
   337 			}
   337 			}
   338 
   338 
   339 			x += 6;
   339 			x += 6;
   340 			cg_ofst = IsWindowWidgetLowered(w, STATIONLIST_WIDGET_NOCARGOWAITING) ? 2 : 1;
   340 			cg_ofst = w->IsWidgetLowered(STATIONLIST_WIDGET_NOCARGOWAITING) ? 2 : 1;
   341 			DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
   341 			DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
   342 			x += 14;
   342 			x += 14;
   343 			cg_ofst = IsWindowWidgetLowered(w, STATIONLIST_WIDGET_CARGOALL) ? 2 : 1;
   343 			cg_ofst = w->IsWidgetLowered(STATIONLIST_WIDGET_CARGOALL) ? 2 : 1;
   344 			DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
   344 			DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
   345 
   345 
   346 			cg_ofst = IsWindowWidgetLowered(w, STATIONLIST_WIDGET_FACILALL) ? 2 : 1;
   346 			cg_ofst = w->IsWidgetLowered(STATIONLIST_WIDGET_FACILALL) ? 2 : 1;
   347 			DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
   347 			DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
   348 
   348 
   349 			if (w->vscroll.count == 0) { // player has no stations
   349 			if (w->vscroll.count == 0) { // player has no stations
   350 				DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
   350 				DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
   351 				return;
   351 				return;
   399 				case STATIONLIST_WIDGET_BUS:
   399 				case STATIONLIST_WIDGET_BUS:
   400 				case STATIONLIST_WIDGET_AIRPLANE:
   400 				case STATIONLIST_WIDGET_AIRPLANE:
   401 				case STATIONLIST_WIDGET_SHIP:
   401 				case STATIONLIST_WIDGET_SHIP:
   402 					if (_ctrl_pressed) {
   402 					if (_ctrl_pressed) {
   403 						ToggleBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   403 						ToggleBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   404 						ToggleWidgetLoweredState(w, e->we.click.widget);
   404 						w->ToggleWidgetLoweredState(e->we.click.widget);
   405 					} else {
   405 					} else {
   406 						for (uint i = 0; facilities != 0; i++, facilities >>= 1) {
   406 						for (uint i = 0; facilities != 0; i++, facilities >>= 1) {
   407 							if (HasBit(facilities, 0)) RaiseWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
   407 							if (HasBit(facilities, 0)) w->RaiseWidget(i + STATIONLIST_WIDGET_TRAIN);
   408 						}
   408 						}
   409 						SetBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   409 						SetBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   410 						LowerWindowWidget(w, e->we.click.widget);
   410 						w->LowerWidget(e->we.click.widget);
   411 					}
   411 					}
   412 					SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   412 					w->SetWidgetLoweredState(STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   413 					sl->flags |= SL_REBUILD;
   413 					sl->flags |= SL_REBUILD;
   414 					SetWindowDirty(w);
   414 					SetWindowDirty(w);
   415 					break;
   415 					break;
   416 
   416 
   417 				case STATIONLIST_WIDGET_FACILALL:
   417 				case STATIONLIST_WIDGET_FACILALL:
   418 					for (uint i = 0; i < 5; i++) {
   418 					for (uint i = 0; i < 5; i++) {
   419 						LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
   419 						w->LowerWidget(i + STATIONLIST_WIDGET_TRAIN);
   420 					}
   420 					}
   421 					LowerWindowWidget(w, STATIONLIST_WIDGET_FACILALL);
   421 					w->LowerWidget(STATIONLIST_WIDGET_FACILALL);
   422 
   422 
   423 					facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
   423 					facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
   424 					sl->flags |= SL_REBUILD;
   424 					sl->flags |= SL_REBUILD;
   425 					SetWindowDirty(w);
   425 					SetWindowDirty(w);
   426 					break;
   426 					break;
   427 
   427 
   428 				case STATIONLIST_WIDGET_CARGOALL: {
   428 				case STATIONLIST_WIDGET_CARGOALL: {
   429 					uint i = 0;
   429 					uint i = 0;
   430 					for (CargoID c = 0; c < NUM_CARGO; c++) {
   430 					for (CargoID c = 0; c < NUM_CARGO; c++) {
   431 						if (!GetCargo(c)->IsValid()) continue;
   431 						if (!GetCargo(c)->IsValid()) continue;
   432 						LowerWindowWidget(w, i + STATIONLIST_WIDGET_CARGOSTART);
   432 						w->LowerWidget(i + STATIONLIST_WIDGET_CARGOSTART);
   433 						i++;
   433 						i++;
   434 					}
   434 					}
   435 					LowerWindowWidget(w, STATIONLIST_WIDGET_NOCARGOWAITING);
   435 					w->LowerWidget(STATIONLIST_WIDGET_NOCARGOWAITING);
   436 					LowerWindowWidget(w, STATIONLIST_WIDGET_CARGOALL);
   436 					w->LowerWidget(STATIONLIST_WIDGET_CARGOALL);
   437 
   437 
   438 					_cargo_filter = _cargo_mask;
   438 					_cargo_filter = _cargo_mask;
   439 					include_empty = true;
   439 					include_empty = true;
   440 					sl->flags |= SL_REBUILD;
   440 					sl->flags |= SL_REBUILD;
   441 					SetWindowDirty(w);
   441 					SetWindowDirty(w);
   445 				case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/
   445 				case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/
   446 					sl->flags ^= SL_ORDER; //DESC-flag
   446 					sl->flags ^= SL_ORDER; //DESC-flag
   447 					station_sort.order = HasBit(sl->flags, 0);
   447 					station_sort.order = HasBit(sl->flags, 0);
   448 					sl->flags |= SL_RESORT;
   448 					sl->flags |= SL_RESORT;
   449 					w->flags4 |= 5 << WF_TIMEOUT_SHL;
   449 					w->flags4 |= 5 << WF_TIMEOUT_SHL;
   450 					LowerWindowWidget(w, STATIONLIST_WIDGET_SORTBY);
   450 					w->LowerWidget(STATIONLIST_WIDGET_SORTBY);
   451 					SetWindowDirty(w);
   451 					SetWindowDirty(w);
   452 					break;
   452 					break;
   453 
   453 
   454 				case STATIONLIST_WIDGET_SORTCRITERIA:
   454 				case STATIONLIST_WIDGET_SORTCRITERIA:
   455 				case STATIONLIST_WIDGET_SORTDROPBTN: /* select sorting criteria dropdown menu */
   455 				case STATIONLIST_WIDGET_SORTDROPBTN: /* select sorting criteria dropdown menu */
   457 					break;
   457 					break;
   458 
   458 
   459 				case STATIONLIST_WIDGET_NOCARGOWAITING:
   459 				case STATIONLIST_WIDGET_NOCARGOWAITING:
   460 					if (_ctrl_pressed) {
   460 					if (_ctrl_pressed) {
   461 						include_empty = !include_empty;
   461 						include_empty = !include_empty;
   462 						ToggleWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING);
   462 						w->ToggleWidgetLoweredState(STATIONLIST_WIDGET_NOCARGOWAITING);
   463 					} else {
   463 					} else {
   464 						for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) {
   464 						for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) {
   465 							RaiseWindowWidget(w, i);
   465 							w->RaiseWidget(i);
   466 						}
   466 						}
   467 
   467 
   468 						_cargo_filter = 0;
   468 						_cargo_filter = 0;
   469 						include_empty = true;
   469 						include_empty = true;
   470 
   470 
   471 						LowerWindowWidget(w, STATIONLIST_WIDGET_NOCARGOWAITING);
   471 						w->LowerWidget(STATIONLIST_WIDGET_NOCARGOWAITING);
   472 					}
   472 					}
   473 					sl->flags |= SL_REBUILD;
   473 					sl->flags |= SL_REBUILD;
   474 					SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   474 					w->SetWidgetLoweredState(STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   475 					SetWindowDirty(w);
   475 					SetWindowDirty(w);
   476 					break;
   476 					break;
   477 
   477 
   478 				default:
   478 				default:
   479 					if (e->we.click.widget >= STATIONLIST_WIDGET_CARGOSTART) { //change cargo_filter
   479 					if (e->we.click.widget >= STATIONLIST_WIDGET_CARGOSTART) { //change cargo_filter
   486 							i++;
   486 							i++;
   487 						}
   487 						}
   488 
   488 
   489 						if (_ctrl_pressed) {
   489 						if (_ctrl_pressed) {
   490 							ToggleBit(_cargo_filter, c);
   490 							ToggleBit(_cargo_filter, c);
   491 							ToggleWidgetLoweredState(w, e->we.click.widget);
   491 							w->ToggleWidgetLoweredState(e->we.click.widget);
   492 						} else {
   492 						} else {
   493 							for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) {
   493 							for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) {
   494 								RaiseWindowWidget(w, i);
   494 								w->RaiseWidget(i);
   495 							}
   495 							}
   496 							RaiseWindowWidget(w, STATIONLIST_WIDGET_NOCARGOWAITING);
   496 							w->RaiseWidget(STATIONLIST_WIDGET_NOCARGOWAITING);
   497 
   497 
   498 							_cargo_filter = 0;
   498 							_cargo_filter = 0;
   499 							include_empty = false;
   499 							include_empty = false;
   500 
   500 
   501 							SetBit(_cargo_filter, c);
   501 							SetBit(_cargo_filter, c);
   502 							LowerWindowWidget(w, e->we.click.widget);
   502 							w->LowerWidget(e->we.click.widget);
   503 						}
   503 						}
   504 						sl->flags |= SL_REBUILD;
   504 						sl->flags |= SL_REBUILD;
   505 						SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   505 						w->SetWidgetLoweredState(STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   506 						SetWindowDirty(w);
   506 						SetWindowDirty(w);
   507 					}
   507 					}
   508 					break;
   508 					break;
   509 			}
   509 			}
   510 			break;
   510 			break;
   527 				SetWindowDirty(w);
   527 				SetWindowDirty(w);
   528 			}
   528 			}
   529 			break;
   529 			break;
   530 
   530 
   531 		case WE_TIMEOUT:
   531 		case WE_TIMEOUT:
   532 			RaiseWindowWidget(w, STATIONLIST_WIDGET_SORTBY);
   532 			w->RaiseWidget(STATIONLIST_WIDGET_SORTBY);
   533 			SetWindowDirty(w);
   533 			SetWindowDirty(w);
   534 			break;
   534 			break;
   535 
   535 
   536 		case WE_RESIZE:
   536 		case WE_RESIZE:
   537 			w->vscroll.cap += e->we.sizing.diff.y / 10;
   537 			w->vscroll.cap += e->we.sizing.diff.y / 10;
   613 		wi->top      = 14;
   613 		wi->top      = 14;
   614 		wi->bottom   = 24;
   614 		wi->bottom   = 24;
   615 		wi->data     = 0;
   615 		wi->data     = 0;
   616 		wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
   616 		wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
   617 
   617 
   618 		if (HasBit(_cargo_filter, c)) LowerWindowWidget(w, STATIONLIST_WIDGET_CARGOSTART + i);
   618 		if (HasBit(_cargo_filter, c)) w->LowerWidget(STATIONLIST_WIDGET_CARGOSTART + i);
   619 		i++;
   619 		i++;
   620 	}
   620 	}
   621 
   621 
   622 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].left += num_active * 14;
   622 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].left += num_active * 14;
   623 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].right += num_active * 14;
   623 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].right += num_active * 14;
   708 			if (st->goods[i].cargo.Source() != station_id) num++;
   708 			if (st->goods[i].cargo.Source() != station_id) num++;
   709 		}
   709 		}
   710 	}
   710 	}
   711 	SetVScrollCount(w, num);
   711 	SetVScrollCount(w, num);
   712 
   712 
   713 	SetWindowWidgetDisabledState(w,  9, st->owner != _local_player);
   713 	w->SetWidgetDisabledState( 9, st->owner != _local_player);
   714 	SetWindowWidgetDisabledState(w, 10, !(st->facilities & FACIL_TRAIN));
   714 	w->SetWidgetDisabledState(10, !(st->facilities & FACIL_TRAIN));
   715 	SetWindowWidgetDisabledState(w, 11, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
   715 	w->SetWidgetDisabledState(11, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
   716 	SetWindowWidgetDisabledState(w, 12, !(st->facilities & FACIL_AIRPORT));
   716 	w->SetWidgetDisabledState(12, !(st->facilities & FACIL_AIRPORT));
   717 	SetWindowWidgetDisabledState(w, 13, !(st->facilities & FACIL_DOCK));
   717 	w->SetWidgetDisabledState(13, !(st->facilities & FACIL_DOCK));
   718 
   718 
   719 	SetDParam(0, st->index);
   719 	SetDParam(0, st->index);
   720 	SetDParam(1, st->facilities);
   720 	SetDParam(1, st->facilities);
   721 	DrawWindowWidgets(w);
   721 	DrawWindowWidgets(w);
   722 
   722