src/road_gui.cpp
changeset 8821 1411d08e26b3
parent 8785 871586967963
child 8822 d40bd6519bae
equal deleted inserted replaced
8820:93ad0db32ea0 8821:1411d08e26b3
   173 }
   173 }
   174 
   174 
   175 static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
   175 static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
   176 {
   176 {
   177 	tile += TileOffsByDiagDir(direction);
   177 	tile += TileOffsByDiagDir(direction);
   178 	// if there is a roadpiece just outside of the station entrance, build a connecting route
   178 	/* if there is a roadpiece just outside of the station entrance, build a connecting route */
   179 	if (IsNormalRoadTile(tile)) {
   179 	if (IsNormalRoadTile(tile)) {
   180 		if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
   180 		if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
   181 			DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
   181 			DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
   182 		}
   182 		}
   183 	}
   183 	}
   407  * Update the remove button lowered state of the road toolbar
   407  * Update the remove button lowered state of the road toolbar
   408  *
   408  *
   409  * @param w The toolbar window
   409  * @param w The toolbar window
   410  * @param clicked_widget The widget which the player clicked just now
   410  * @param clicked_widget The widget which the player clicked just now
   411  */
   411  */
   412 static void UpdateOptionWidgetStatus(Window *w, int clicked_widget)
   412 static void UpdateOptionWidgetStatus(Window *w, RoadToolbarWidgets clicked_widget)
   413 {
   413 {
   414 	/* The remove and the one way button state is driven
   414 	/* The remove and the one way button state is driven
   415 	 * by the other buttons so they don't act on themselfs.
   415 	 * by the other buttons so they don't act on themselfs.
   416 	 * Both are only valid if they are able to apply as options. */
   416 	 * Both are only valid if they are able to apply as options. */
   417 	switch (clicked_widget) {
   417 	switch (clicked_widget) {
   418 		case RTW_REMOVE:
   418 		case RTW_REMOVE:
   419 			w->RaiseWidget(RTW_ONE_WAY);
   419 			w->RaiseWidget(RTW_ONE_WAY);
   420 			w->InvalidateWidget(RTW_ONE_WAY);
   420 			w->InvalidateWidget(RTW_ONE_WAY);
   421 			break;
   421 			break;
       
   422 
   422 		case RTW_ONE_WAY:
   423 		case RTW_ONE_WAY:
   423 			w->RaiseWidget(RTW_REMOVE);
   424 			w->RaiseWidget(RTW_REMOVE);
   424 			w->InvalidateWidget(RTW_REMOVE);
   425 			w->InvalidateWidget(RTW_REMOVE);
   425 			break;
   426 			break;
       
   427 
   426 		case RTW_BUS_STATION:
   428 		case RTW_BUS_STATION:
   427 		case RTW_TRUCK_STATION:
   429 		case RTW_TRUCK_STATION:
   428 			w->DisableWidget(RTW_ONE_WAY);
   430 			w->DisableWidget(RTW_ONE_WAY);
   429 			w->SetWidgetDisabledState(RTW_REMOVE, !w->IsWidgetLowered(clicked_widget));
   431 			w->SetWidgetDisabledState(RTW_REMOVE, !w->IsWidgetLowered(clicked_widget));
   430 			break;
   432 			break;
       
   433 
   431 		case RTW_ROAD_X:
   434 		case RTW_ROAD_X:
   432 		case RTW_ROAD_Y:
   435 		case RTW_ROAD_Y:
   433 		case RTW_AUTOROAD:
   436 		case RTW_AUTOROAD:
   434 			w->SetWidgetsDisabledState(!w->IsWidgetLowered(clicked_widget),
   437 			w->SetWidgetsDisabledState(!w->IsWidgetLowered(clicked_widget),
   435 				RTW_REMOVE,
   438 				RTW_REMOVE,
   436 				RTW_ONE_WAY,
   439 				RTW_ONE_WAY,
   437 				WIDGET_LIST_END);
   440 				WIDGET_LIST_END);
   438 			break;
   441 			break;
       
   442 
   439 		default:
   443 		default:
   440 			/* When any other buttons than road/station, raise and
   444 			/* When any other buttons than road/station, raise and
   441 			 * disable the removal button */
   445 			 * disable the removal button */
   442 			w->SetWidgetsDisabledState(true,
   446 			w->SetWidgetsDisabledState(true,
   443 				RTW_REMOVE,
   447 				RTW_REMOVE,
   452 }
   456 }
   453 
   457 
   454 static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
   458 static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
   455 {
   459 {
   456 	switch (e->event) {
   460 	switch (e->event) {
   457 	case WE_CREATE:
   461 		case WE_CREATE:
   458 		w->SetWidgetsDisabledState(true,
   462 			w->SetWidgetsDisabledState(true,
   459 			RTW_REMOVE,
   463 				RTW_REMOVE,
   460 			RTW_ONE_WAY,
   464 				RTW_ONE_WAY,
   461 			WIDGET_LIST_END);
   465 				WIDGET_LIST_END);
   462 		break;
   466 			break;
   463 
   467 
   464 	case WE_PAINT:
   468 		case WE_PAINT:
   465 		w->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
   469 			w->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
   466 			RTW_DEPOT,
   470 				RTW_DEPOT,
   467 			RTW_BUS_STATION,
   471 				RTW_BUS_STATION,
   468 			RTW_TRUCK_STATION,
   472 				RTW_TRUCK_STATION,
   469 			WIDGET_LIST_END);
   473 				WIDGET_LIST_END);
   470 		DrawWindowWidgets(w);
   474 			DrawWindowWidgets(w);
   471 		break;
   475 			break;
   472 
   476 
   473 	case WE_CLICK:
   477 		case WE_CLICK:
   474 		if (e->we.click.widget >= RTW_ROAD_X) {
   478 			if (e->we.click.widget >= RTW_ROAD_X) {
   475 			_remove_button_clicked = false;
       
   476 			_one_way_button_clicked = false;
       
   477 			_build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w);
       
   478 		}
       
   479 		UpdateOptionWidgetStatus(w, e->we.click.widget);
       
   480 		if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
       
   481 		break;
       
   482 
       
   483 	case WE_KEYPRESS:
       
   484 		for (uint8 i = 0; i != lengthof(_road_keycodes); i++) {
       
   485 			if (e->we.keypress.keycode == _road_keycodes[i]) {
       
   486 				e->we.keypress.cont = false;
       
   487 				_remove_button_clicked = false;
   479 				_remove_button_clicked = false;
   488 				_one_way_button_clicked = false;
   480 				_one_way_button_clicked = false;
   489 				_build_road_button_proc[i](w);
   481 				_build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w);
   490 				UpdateOptionWidgetStatus(w, i + RTW_ROAD_X);
       
   491 				if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
       
   492 				break;
       
   493 			}
   482 			}
   494 		}
   483 			UpdateOptionWidgetStatus(w, (RoadToolbarWidgets)e->we.click.widget);
   495 		MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
   484 			if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
   496 		break;
   485 			break;
   497 
   486 
   498 	case WE_PLACE_OBJ:
   487 		case WE_KEYPRESS:
   499 		_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
   488 			for (uint i = 0; i != lengthof(_road_keycodes); i++) {
   500 		_one_way_button_clicked = w->IsWidgetLowered(RTW_ONE_WAY);
   489 				if (e->we.keypress.keycode == _road_keycodes[i]) {
   501 		_place_proc(e->we.place.tile);
   490 					e->we.keypress.cont = false;
   502 		break;
   491 					_remove_button_clicked = false;
   503 
   492 					_one_way_button_clicked = false;
   504 	case WE_ABORT_PLACE_OBJ:
   493 					_build_road_button_proc[i](w);
   505 		w->RaiseButtons();
   494 					UpdateOptionWidgetStatus(w, (RoadToolbarWidgets)(i + RTW_ROAD_X));
   506 		w->SetWidgetsDisabledState(true,
   495 					if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
   507 			RTW_REMOVE,
   496 					break;
   508 			RTW_ONE_WAY,
       
   509 			WIDGET_LIST_END);
       
   510 		w->InvalidateWidget(RTW_REMOVE);
       
   511 		w->InvalidateWidget(RTW_ONE_WAY);
       
   512 
       
   513 		w = FindWindowById(WC_BUS_STATION, 0);
       
   514 		if (w != NULL) WP(w, def_d).close = true;
       
   515 		w = FindWindowById(WC_TRUCK_STATION, 0);
       
   516 		if (w != NULL) WP(w, def_d).close = true;
       
   517 		w = FindWindowById(WC_BUILD_DEPOT, 0);
       
   518 		if (w != NULL) WP(w, def_d).close = true;
       
   519 		break;
       
   520 
       
   521 	case WE_PLACE_DRAG:
       
   522 		/* Here we update the end tile flags
       
   523 		 * of the road placement actions.
       
   524 		 * At first we reset the end halfroad
       
   525 		 * bits and if needed we set them again. */
       
   526 		switch (e->we.place.select_proc) {
       
   527 			case DDSP_PLACE_ROAD_X_DIR:
       
   528 				_place_road_flag &= ~RF_END_HALFROAD_X;
       
   529 				if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
       
   530 				break;
       
   531 
       
   532 			case DDSP_PLACE_ROAD_Y_DIR:
       
   533 				_place_road_flag &= ~RF_END_HALFROAD_Y;
       
   534 				if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
       
   535 				break;
       
   536 
       
   537 			case DDSP_PLACE_AUTOROAD:
       
   538 				_place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
       
   539 				if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
       
   540 				if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
       
   541 
       
   542 				/* For autoroad we need to update the
       
   543 				 * direction of the road */
       
   544 				if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
       
   545 						( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
       
   546 						  (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
       
   547 					/* Set dir = X */
       
   548 					_place_road_flag &= ~RF_DIR_Y;
       
   549 				} else {
       
   550 					/* Set dir = Y */
       
   551 					_place_road_flag |= RF_DIR_Y;
       
   552 				}
   497 				}
   553 
   498 			}
   554 				break;
   499 			MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
   555 		}
   500 			break;
   556 
   501 
   557 		VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
   502 		case WE_PLACE_OBJ:
   558 		return;
   503 			_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
   559 
   504 			_one_way_button_clicked = w->IsWidgetLowered(RTW_ONE_WAY);
   560 	case WE_PLACE_MOUSEUP:
   505 			_place_proc(e->we.place.tile);
   561 		if (e->we.place.pt.x != -1) {
   506 			break;
   562 			TileIndex start_tile = e->we.place.starttile;
   507 
   563 			TileIndex end_tile = e->we.place.tile;
   508 		case WE_ABORT_PLACE_OBJ:
   564 
   509 			w->RaiseButtons();
       
   510 			w->SetWidgetsDisabledState(true,
       
   511 				RTW_REMOVE,
       
   512 				RTW_ONE_WAY,
       
   513 				WIDGET_LIST_END);
       
   514 			w->InvalidateWidget(RTW_REMOVE);
       
   515 			w->InvalidateWidget(RTW_ONE_WAY);
       
   516 
       
   517 			w = FindWindowById(WC_BUS_STATION, 0);
       
   518 			if (w != NULL) WP(w, def_d).close = true;
       
   519 			w = FindWindowById(WC_TRUCK_STATION, 0);
       
   520 			if (w != NULL) WP(w, def_d).close = true;
       
   521 			w = FindWindowById(WC_BUILD_DEPOT, 0);
       
   522 			if (w != NULL) WP(w, def_d).close = true;
       
   523 			break;
       
   524 
       
   525 		case WE_PLACE_DRAG:
       
   526 			/* Here we update the end tile flags
       
   527 			* of the road placement actions.
       
   528 			* At first we reset the end halfroad
       
   529 			* bits and if needed we set them again. */
   565 			switch (e->we.place.select_proc) {
   530 			switch (e->we.place.select_proc) {
   566 				case DDSP_BUILD_BRIDGE:
   531 				case DDSP_PLACE_ROAD_X_DIR:
   567 					ResetObjectToPlace();
   532 					_place_road_flag &= ~RF_END_HALFROAD_X;
   568 					ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
   533 					if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
   569 					break;
   534 					break;
   570 
   535 
   571 				case DDSP_DEMOLISH_AREA:
   536 				case DDSP_PLACE_ROAD_Y_DIR:
   572 					DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
   537 					_place_road_flag &= ~RF_END_HALFROAD_Y;
       
   538 					if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
   573 					break;
   539 					break;
   574 
   540 
   575 				case DDSP_PLACE_ROAD_X_DIR:
       
   576 				case DDSP_PLACE_ROAD_Y_DIR:
       
   577 				case DDSP_PLACE_AUTOROAD:
   541 				case DDSP_PLACE_AUTOROAD:
   578 					/* Flag description:
   542 					_place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
   579 					 * Use the first three bits (0x07) if dir == Y
   543 					if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
   580 					 * else use the last 2 bits (X dir has
   544 					if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
   581 					 * not the 3rd bit set) */
   545 
   582 					_place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
   546 					/* For autoroad we need to update the
   583 
   547 					* direction of the road */
   584 					DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D,
   548 					if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
   585 						(_ctrl_pressed || _remove_button_clicked) ?
   549 							( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
   586 						CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
   550 							(_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
   587 						CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road));
   551 						/* Set dir = X */
       
   552 						_place_road_flag &= ~RF_DIR_Y;
       
   553 					} else {
       
   554 						/* Set dir = Y */
       
   555 						_place_road_flag |= RF_DIR_Y;
       
   556 					}
       
   557 
       
   558 					break;
       
   559 
       
   560 				default:
   588 					break;
   561 					break;
   589 			}
   562 			}
   590 		}
   563 
   591 		break;
   564 			VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
   592 
   565 			return;
   593 	case WE_PLACE_PRESIZE: {
   566 
   594 		TileIndex tile = e->we.place.tile;
   567 		case WE_PLACE_MOUSEUP:
   595 
   568 			if (e->we.place.pt.x != -1) {
   596 		DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL);
   569 				TileIndex start_tile = e->we.place.starttile;
   597 		VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
   570 				TileIndex end_tile = e->we.place.tile;
   598 		break;
   571 
   599 	}
   572 				switch (e->we.place.select_proc) {
   600 
   573 					case DDSP_BUILD_BRIDGE:
   601 	case WE_DESTROY:
   574 						ResetObjectToPlace();
   602 		if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
   575 						ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
   603 		break;
   576 						break;
   604 
   577 
   605 	case WE_CTRL_CHANGED:
   578 					case DDSP_DEMOLISH_AREA:
   606 		if (RoadToolbar_CtrlChanged(w)) e->we.ctrl.cont = false;
   579 						DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
   607 		break;
   580 						break;
       
   581 
       
   582 					case DDSP_PLACE_ROAD_X_DIR:
       
   583 					case DDSP_PLACE_ROAD_Y_DIR:
       
   584 					case DDSP_PLACE_AUTOROAD:
       
   585 						/* Flag description:
       
   586 						* Use the first three bits (0x07) if dir == Y
       
   587 						* else use the last 2 bits (X dir has
       
   588 						* not the 3rd bit set) */
       
   589 						_place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
       
   590 
       
   591 						DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D,
       
   592 							(_ctrl_pressed || _remove_button_clicked) ?
       
   593 							CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
       
   594 							CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road));
       
   595 						break;
       
   596 				}
       
   597 			}
       
   598 			break;
       
   599 
       
   600 		case WE_PLACE_PRESIZE: {
       
   601 			TileIndex tile = e->we.place.tile;
       
   602 
       
   603 			DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL);
       
   604 			VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
       
   605 		} break;
       
   606 
       
   607 		case WE_DESTROY:
       
   608 			if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
       
   609 			break;
       
   610 
       
   611 		case WE_CTRL_CHANGED:
       
   612 			if (RoadToolbar_CtrlChanged(w)) e->we.ctrl.cont = false;
       
   613 			break;
       
   614 
       
   615 		default:
       
   616 			break;
   608 	}
   617 	}
   609 }
   618 }
   610 
   619 
   611 /** Widget definition of the build road toolbar */
   620 /** Widget definition of the build road toolbar */
   612 static const Widget _build_road_widgets[] = {
   621 static const Widget _build_road_widgets[] = {
   722 };
   731 };
   723 
   732 
   724 static void BuildRoadDepotWndProc(Window *w, WindowEvent *e)
   733 static void BuildRoadDepotWndProc(Window *w, WindowEvent *e)
   725 {
   734 {
   726 	switch (e->event) {
   735 	switch (e->event) {
   727 	case WE_CREATE: w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE); break;
   736 		case WE_CREATE:
   728 
   737 			w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
   729 	case WE_PAINT:
   738 			break;
   730 		DrawWindowWidgets(w);
   739 
   731 
   740 		case WE_PAINT:
   732 		DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype);
   741 			DrawWindowWidgets(w);
   733 		DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype);
   742 
   734 		DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype);
   743 			DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype);
   735 		DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype);
   744 			DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype);
   736 		break;
   745 			DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype);
   737 
   746 			DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype);
   738 	case WE_CLICK:
   747 			break;
   739 		switch (e->we.click.widget) {
   748 
   740 			case BRDW_DEPOT_NW:
   749 		case WE_CLICK:
   741 			case BRDW_DEPOT_NE:
   750 			switch (e->we.click.widget) {
   742 			case BRDW_DEPOT_SW:
   751 				case BRDW_DEPOT_NW:
   743 			case BRDW_DEPOT_SE:
   752 				case BRDW_DEPOT_NE:
   744 				w->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE);
   753 				case BRDW_DEPOT_SW:
   745 				_road_depot_orientation = (DiagDirection)(e->we.click.widget - BRDW_DEPOT_NE);
   754 				case BRDW_DEPOT_SE:
   746 				w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
   755 					w->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE);
   747 				SndPlayFx(SND_15_BEEP);
   756 					_road_depot_orientation = (DiagDirection)(e->we.click.widget - BRDW_DEPOT_NE);
   748 				SetWindowDirty(w);
   757 					w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
   749 				break;
   758 					SndPlayFx(SND_15_BEEP);
   750 		}
   759 					SetWindowDirty(w);
   751 		break;
   760 					break;
   752 
   761 
   753 	case WE_MOUSELOOP:
   762 				default:
   754 		if (WP(w, def_d).close) DeleteWindow(w);
   763 					break;
   755 		break;
   764 			}
   756 
   765 			break;
   757 	case WE_DESTROY:
   766 
   758 		if (!WP(w, def_d).close) ResetObjectToPlace();
   767 		case WE_MOUSELOOP:
   759 		break;
   768 			if (WP(w, def_d).close) DeleteWindow(w);
       
   769 			break;
       
   770 
       
   771 		case WE_DESTROY:
       
   772 			if (!WP(w, def_d).close) ResetObjectToPlace();
       
   773 			break;
       
   774 
       
   775 		default:
       
   776 			break;
   760 	}
   777 	}
   761 }
   778 }
   762 
   779 
   763 /** Widget definition of the build road depot window */
   780 /** Widget definition of the build road depot window */
   764 static const Widget _build_road_depot_widgets[] = {
   781 static const Widget _build_road_depot_widgets[] = {
   822 };
   839 };
   823 
   840 
   824 static void RoadStationPickerWndProc(Window *w, WindowEvent *e)
   841 static void RoadStationPickerWndProc(Window *w, WindowEvent *e)
   825 {
   842 {
   826 	switch (e->event) {
   843 	switch (e->event) {
   827 	case WE_CREATE:
   844 		case WE_CREATE:
   828 		/* Trams don't have non-drivethrough stations */
   845 			/* Trams don't have non-drivethrough stations */
   829 		if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) {
   846 			if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) {
   830 			_road_station_picker_orientation = DIAGDIR_END;
   847 				_road_station_picker_orientation = DIAGDIR_END;
   831 		}
   848 			}
   832 		w->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM,
   849 			w->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM,
   833 			BRSW_STATION_NE,
   850 				BRSW_STATION_NE,
   834 			BRSW_STATION_SE,
   851 				BRSW_STATION_SE,
   835 			BRSW_STATION_SW,
   852 				BRSW_STATION_SW,
   836 			BRSW_STATION_NW,
   853 				BRSW_STATION_NW,
   837 			WIDGET_LIST_END);
   854 				WIDGET_LIST_END);
   838 
   855 
   839 		w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
   856 			w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
   840 		w->LowerWidget(_station_show_coverage + BRSW_LT_OFF);
   857 			w->LowerWidget(_station_show_coverage + BRSW_LT_OFF);
   841 		break;
   858 			break;
   842 
   859 
   843 	case WE_PAINT: {
   860 		case WE_PAINT: {
   844 		if (WP(w, def_d).close) return;
   861 			if (WP(w, def_d).close) return;
   845 
   862 
   846 		DrawWindowWidgets(w);
   863 			DrawWindowWidgets(w);
   847 
   864 
   848 		if (_station_show_coverage) {
   865 			if (_station_show_coverage) {
   849 			int rad = _patches.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED;
   866 				int rad = _patches.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED;
   850 			SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
   867 				SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
   851 		} else {
   868 			} else {
   852 			SetTileSelectSize(1, 1);
   869 				SetTileSelectSize(1, 1);
   853 		}
   870 			}
   854 
   871 
   855 		StationType st = (w->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
   872 			StationType st = (w->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
   856 
   873 
   857 		StationPickerDrawSprite(103, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 0);
   874 			StationPickerDrawSprite(103, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 0);
   858 		StationPickerDrawSprite(103, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 1);
   875 			StationPickerDrawSprite(103, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 1);
   859 		StationPickerDrawSprite( 35, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 2);
   876 			StationPickerDrawSprite( 35, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 2);
   860 		StationPickerDrawSprite( 35, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 3);
   877 			StationPickerDrawSprite( 35, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 3);
   861 
   878 
   862 		StationPickerDrawSprite(171, 35, st, INVALID_RAILTYPE, _cur_roadtype, 4);
   879 			StationPickerDrawSprite(171, 35, st, INVALID_RAILTYPE, _cur_roadtype, 4);
   863 		StationPickerDrawSprite(171, 85, st, INVALID_RAILTYPE, _cur_roadtype, 5);
   880 			StationPickerDrawSprite(171, 85, st, INVALID_RAILTYPE, _cur_roadtype, 5);
   864 
   881 
   865 		int text_end = DrawStationCoverageAreaText(2, 146,
   882 			int text_end = DrawStationCoverageAreaText(2, 146,
   866 			(w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
   883 				(w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
   867 			3) + 4;
   884 				3) + 4;
   868 		if (text_end > w->widget[BRSW_BACKGROUND].bottom) {
   885 			if (text_end > w->widget[BRSW_BACKGROUND].bottom) {
   869 			SetWindowDirty(w);
       
   870 			ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom);
       
   871 			SetWindowDirty(w);
       
   872 		}
       
   873 
       
   874 	} break;
       
   875 
       
   876 	case WE_CLICK: {
       
   877 		switch (e->we.click.widget) {
       
   878 			case BRSW_STATION_NE:
       
   879 			case BRSW_STATION_SE:
       
   880 			case BRSW_STATION_SW:
       
   881 			case BRSW_STATION_NW:
       
   882 			case BRSW_STATION_X:
       
   883 			case BRSW_STATION_Y:
       
   884 				w->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE);
       
   885 				_road_station_picker_orientation = (DiagDirection)(e->we.click.widget - BRSW_STATION_NE);
       
   886 				w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
       
   887 				SndPlayFx(SND_15_BEEP);
       
   888 				SetWindowDirty(w);
   886 				SetWindowDirty(w);
   889 				break;
   887 				ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom);
   890 
       
   891 			case BRSW_LT_OFF:
       
   892 			case BRSW_LT_ON:
       
   893 				w->RaiseWidget(_station_show_coverage + BRSW_LT_OFF);
       
   894 				_station_show_coverage = (e->we.click.widget != BRSW_LT_OFF);
       
   895 				w->LowerWidget(_station_show_coverage + BRSW_LT_OFF);
       
   896 				SndPlayFx(SND_15_BEEP);
       
   897 				SetWindowDirty(w);
   888 				SetWindowDirty(w);
   898 				break;
   889 			}
   899 		}
   890 
   900 	} break;
   891 		} break;
   901 
   892 
   902 	case WE_MOUSELOOP: {
   893 		case WE_CLICK: {
   903 		if (WP(w, def_d).close) {
   894 			switch (e->we.click.widget) {
   904 			DeleteWindow(w);
   895 				case BRSW_STATION_NE:
   905 			return;
   896 				case BRSW_STATION_SE:
   906 		}
   897 				case BRSW_STATION_SW:
   907 
   898 				case BRSW_STATION_NW:
   908 		CheckRedrawStationCoverage(w);
   899 				case BRSW_STATION_X:
   909 	} break;
   900 				case BRSW_STATION_Y:
   910 
   901 					w->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE);
   911 	case WE_DESTROY:
   902 					_road_station_picker_orientation = (DiagDirection)(e->we.click.widget - BRSW_STATION_NE);
   912 		if (!WP(w, def_d).close) ResetObjectToPlace();
   903 					w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
   913 		break;
   904 					SndPlayFx(SND_15_BEEP);
       
   905 					SetWindowDirty(w);
       
   906 					break;
       
   907 
       
   908 				case BRSW_LT_OFF:
       
   909 				case BRSW_LT_ON:
       
   910 					w->RaiseWidget(_station_show_coverage + BRSW_LT_OFF);
       
   911 					_station_show_coverage = (e->we.click.widget != BRSW_LT_OFF);
       
   912 					w->LowerWidget(_station_show_coverage + BRSW_LT_OFF);
       
   913 					SndPlayFx(SND_15_BEEP);
       
   914 					SetWindowDirty(w);
       
   915 					break;
       
   916 
       
   917 				default:
       
   918 					break;
       
   919 			}
       
   920 		} break;
       
   921 
       
   922 		case WE_MOUSELOOP: {
       
   923 			if (WP(w, def_d).close) {
       
   924 				DeleteWindow(w);
       
   925 				return;
       
   926 			}
       
   927 
       
   928 			CheckRedrawStationCoverage(w);
       
   929 		} break;
       
   930 
       
   931 		case WE_DESTROY:
       
   932 			if (!WP(w, def_d).close) ResetObjectToPlace();
       
   933 			break;
       
   934 
       
   935 		default:
       
   936 			break;
   914 	}
   937 	}
   915 }
   938 }
   916 
   939 
   917 /** Widget definition of the build raod station window */
   940 /** Widget definition of the build raod station window */
   918 static const Widget _rv_station_picker_widgets[] = {
   941 static const Widget _rv_station_picker_widgets[] = {