# road_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: road_gui.cpp 15723 2009-03-15 15:12:06Z rubidium $ */
    00002
    00005 #include "stdafx.h"
    00006 #include "openttd.h"
    00007 #include "gui.h"
    00008 #include "window_gui.h"
    00009 #include "station_gui.h"
    00010 #include "terraform_gui.h"
    00011 #include "viewport_func.h"
    00012 #include "gfx_func.h"
    00013 #include "command_func.h"
    00014 #include "road_type.h"
    00015 #include "road_cmd.h"
    00016 #include "road_map.h"
    00017 #include "station_func.h"
    00018 #include "functions.h"
    00019 #include "window_func.h"
    00020 #include "vehicle_func.h"
    00021 #include "sound_func.h"
    00022 #include "company_func.h"
    00023 #include "tunnelbridge.h"
    00024 #include "tilehighlight_func.h"
    00025 #include "company_base.h"
    00026 #include "settings_type.h"
    00027
    00028 #include "table/sprites.h"
    00029 #include "table/strings.h"
    00030
    00031 static void ShowRVStationPicker(Window *parent, RoadStopType rs);
    00032 static void ShowRoadDepotPicker(Window *parent);
    00033
    00034 static bool _remove_button_clicked;
    00035 static bool _one_way_button_clicked;
    00036
    00041 enum RoadFlags {
    00042   RF_NONE             = 0x00,
    00043   RF_START_HALFROAD_Y = 0x01,    // The start tile in Y-dir should have only a half road
    00044   RF_END_HALFROAD_Y   = 0x02,    // The end tile in Y-dir should have only a half road
    00045   RF_DIR_Y            = 0x04,    // The direction is Y-dir
    00046   RF_DIR_X            = RF_NONE, // Dummy; Dir X is set when RF_DIR_Y is not set
    00047   RF_START_HALFROAD_X = 0x08,    // The start tile in X-dir should have only a half road
    00048   RF_END_HALFROAD_X   = 0x10,    // The end tile in X-dir should have only a half road
    00049 };
    00050 DECLARE_ENUM_AS_BIT_SET(RoadFlags);
    00051
    00052 static RoadFlags _place_road_flag;
    00053
    00054 static RoadType _cur_roadtype;
    00055
    00056 static DiagDirection _road_depot_orientation;
    00057 static DiagDirection _road_station_picker_orientation;
    00058
    00059 void CcPlaySound1D(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00060 {
    00061   if (success) SndPlayTileFx(SND_1F_SPLAT, tile);
    00062 }
    00063
    00072 static void PlaceRoad_X_Dir(TileIndex tile)
    00073 {
    00074   _place_road_flag = RF_DIR_X;
    00075   if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
    00076   VpStartPlaceSizing(tile, VPM_FIX_Y, DDSP_PLACE_ROAD_X_DIR);
    00077 }
    00078
    00087 static void PlaceRoad_Y_Dir(TileIndex tile)
    00088 {
    00089   _place_road_flag = RF_DIR_Y;
    00090   if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
    00091   VpStartPlaceSizing(tile, VPM_FIX_X, DDSP_PLACE_ROAD_Y_DIR);
    00092 }
    00093
    00102 static void PlaceRoad_AutoRoad(TileIndex tile)
    00103 {
    00104   _place_road_flag = RF_NONE;
    00105   if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
    00106   if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
    00107   VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_PLACE_AUTOROAD);
    00108 }
    00109
    00110 static void PlaceRoad_Bridge(TileIndex tile)
    00111 {
    00112   VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
    00113 }
    00114
    00115
    00116 void CcBuildRoadTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00117 {
    00118   if (success) {
    00119     SndPlayTileFx(SND_20_SPLAT_2, tile);
    00120     if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00121   } else {
    00122     SetRedErrorSquare(_build_tunnel_endtile);
    00123   }
    00124 }
    00125
    00127 struct RoadTypeInfo {
    00128   StringID err_build_road;
    00129   StringID err_remove_road;
    00130   StringID err_depot;
    00131   StringID err_build_station[2];
    00132   StringID err_remove_station[2];
    00133
    00134   StringID picker_title[2];
    00135   StringID picker_tooltip[2];
    00136
    00137   SpriteID cursor_nesw;
    00138   SpriteID cursor_nwse;
    00139   SpriteID cursor_autoroad;
    00140 };
    00141
    00143 static const RoadTypeInfo _road_type_infos[] = {
    00144   {
    00145     STR_1804_CAN_T_BUILD_ROAD_HERE,
    00146     STR_1805_CAN_T_REMOVE_ROAD_FROM,
    00147     STR_1807_CAN_T_BUILD_ROAD_VEHICLE,
    00148     { STR_1808_CAN_T_BUILD_BUS_STATION,        STR_1809_CAN_T_BUILD_TRUCK_STATION },
    00149     { STR_CAN_T_REMOVE_BUS_STATION,            STR_CAN_T_REMOVE_TRUCK_STATION     },
    00150     { STR_3042_BUS_STATION_ORIENTATION,        STR_3043_TRUCK_STATION_ORIENT      },
    00151     { STR_3051_SELECT_BUS_STATION_ORIENTATION, STR_3052_SELECT_TRUCK_LOADING_BAY  },
    00152
    00153     SPR_CURSOR_ROAD_NESW,
    00154     SPR_CURSOR_ROAD_NWSE,
    00155     SPR_CURSOR_AUTOROAD,
    00156   },
    00157   {
    00158     STR_CAN_T_BUILD_TRAMWAY_HERE,
    00159     STR_CAN_T_REMOVE_TRAMWAY_FROM,
    00160     STR_CAN_T_BUILD_TRAM_VEHICLE,
    00161     { STR_CAN_T_BUILD_PASSENGER_TRAM_STATION,        STR_CAN_T_BUILD_CARGO_TRAM_STATION        },
    00162     { STR_CAN_T_REMOVE_PASSENGER_TRAM_STATION,       STR_CAN_T_REMOVE_CARGO_TRAM_STATION       },
    00163     { STR_PASSENGER_TRAM_STATION_ORIENTATION,        STR_CARGO_TRAM_STATION_ORIENT             },
    00164     { STR_SELECT_PASSENGER_TRAM_STATION_ORIENTATION, STR_SELECT_CARGO_TRAM_STATION_ORIENTATION },
    00165
    00166     SPR_CURSOR_TRAMWAY_NESW,
    00167     SPR_CURSOR_TRAMWAY_NWSE,
    00168     SPR_CURSOR_AUTOTRAM,
    00169   },
    00170 };
    00171
    00172 static void PlaceRoad_Tunnel(TileIndex tile)
    00173 {
    00174   DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE), CcBuildRoadTunnel);
    00175 }
    00176
    00177 static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
    00178 {
    00179   tile += TileOffsByDiagDir(direction);
    00180   /* if there is a roadpiece just outside of the station entrance, build a connecting route */
    00181   if (IsNormalRoadTile(tile)) {
    00182     if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
    00183       DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, CMD_BUILD_ROAD);
    00184     }
    00185   }
    00186 }
    00187
    00188 void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00189 {
    00190   if (success) {
    00191     DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
    00192     SndPlayTileFx(SND_1F_SPLAT, tile);
    00193     if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00194     BuildRoadOutsideStation(tile, dir);
    00195     /* For a drive-through road stop build connecting road for other entrance */
    00196     if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
    00197   }
    00198 }
    00199
    00200 static void PlaceRoad_Depot(TileIndex tile)
    00201 {
    00202   DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CMD_BUILD_ROAD_DEPOT | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot), CcRoadDepot);
    00203 }
    00204
    00205 static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
    00206 {
    00207   uint32 p1 = _road_station_picker_orientation;
    00208   SB(p2, 16, 16, INVALID_STATION); // no station to join
    00209
    00210   if (p1 >= DIAGDIR_END) {
    00211     SetBit(p2, 1); // It's a drive-through stop
    00212     p1 -= DIAGDIR_END; // Adjust picker result to actual direction
    00213   }
    00214   CommandContainer cmdcont = { tile, p1, p2, cmd, CcRoadDepot, "" };
    00215   ShowSelectStationIfNeeded(cmdcont, 1, 1);
    00216 }
    00217
    00218 static void PlaceRoad_BusStation(TileIndex tile)
    00219 {
    00220   if (_remove_button_clicked) {
    00221     DoCommandP(tile, 0, ROADSTOP_BUS, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]), CcPlaySound1D);
    00222   } else {
    00223     PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_BUS, CMD_BUILD_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_BUS]));
    00224   }
    00225 }
    00226
    00227 static void PlaceRoad_TruckStation(TileIndex tile)
    00228 {
    00229   if (_remove_button_clicked) {
    00230     DoCommandP(tile, 0, ROADSTOP_TRUCK, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]), CcPlaySound1D);
    00231   } else {
    00232     PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_TRUCK, CMD_BUILD_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_TRUCK]));
    00233   }
    00234 }
    00235
    00237 enum RoadToolbarWidgets {
    00238   RTW_CLOSEBOX = 0,
    00239   RTW_CAPTION,
    00240   RTW_STICKY,
    00241   RTW_ROAD_X,
    00242   RTW_ROAD_Y,
    00243   RTW_AUTOROAD,
    00244   RTW_DEMOLISH,
    00245   RTW_DEPOT,
    00246   RTW_BUS_STATION,
    00247   RTW_TRUCK_STATION,
    00248   RTW_ONE_WAY,
    00249   RTW_BUILD_BRIDGE,
    00250   RTW_BUILD_TUNNEL,
    00251   RTW_REMOVE,
    00252 };
    00253
    00254 typedef void OnButtonClick(Window *w);
    00255
    00256
    00260 static void ToggleRoadButton_Remove(Window *w)
    00261 {
    00262   w->ToggleWidgetLoweredState(RTW_REMOVE);
    00263   w->InvalidateWidget(RTW_REMOVE);
    00264   _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
    00265   SetSelectionRed(_remove_button_clicked);
    00266 }
    00267
    00272 static bool RoadToolbar_CtrlChanged(Window *w)
    00273 {
    00274   if (w->IsWidgetDisabled(RTW_REMOVE)) return false;
    00275
    00276   /* allow ctrl to switch remove mode only for these widgets */
    00277   for (uint i = RTW_ROAD_X; i <= RTW_AUTOROAD; i++) {
    00278     if (w->IsWidgetLowered(i)) {
    00279       ToggleRoadButton_Remove(w);
    00280       return true;
    00281     }
    00282   }
    00283
    00284   return false;
    00285 }
    00286
    00287
    00294 static void BuildRoadClick_X_Dir(Window *w)
    00295 {
    00296   HandlePlacePushButton(w, RTW_ROAD_X, _road_type_infos[_cur_roadtype].cursor_nwse, VHM_RECT, PlaceRoad_X_Dir);
    00297 }
    00298
    00305 static void BuildRoadClick_Y_Dir(Window *w)
    00306 {
    00307   HandlePlacePushButton(w, RTW_ROAD_Y, _road_type_infos[_cur_roadtype].cursor_nesw, VHM_RECT, PlaceRoad_Y_Dir);
    00308 }
    00309
    00316 static void BuildRoadClick_AutoRoad(Window *w)
    00317 {
    00318   HandlePlacePushButton(w, RTW_AUTOROAD, _road_type_infos[_cur_roadtype].cursor_autoroad, VHM_RECT, PlaceRoad_AutoRoad);
    00319 }
    00320
    00321 static void BuildRoadClick_Demolish(Window *w)
    00322 {
    00323   HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceProc_DemolishArea);
    00324 }
    00325
    00326 static void BuildRoadClick_Depot(Window *w)
    00327 {
    00328   if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
    00329   if (HandlePlacePushButton(w, RTW_DEPOT, SPR_CURSOR_ROAD_DEPOT, VHM_RECT, PlaceRoad_Depot)) ShowRoadDepotPicker(w);
    00330 }
    00331
    00332 static void BuildRoadClick_BusStation(Window *w)
    00333 {
    00334   if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
    00335   if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, VHM_RECT, PlaceRoad_BusStation)) ShowRVStationPicker(w, ROADSTOP_BUS);
    00336 }
    00337
    00338 static void BuildRoadClick_TruckStation(Window *w)
    00339 {
    00340   if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
    00341   if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, VHM_RECT, PlaceRoad_TruckStation)) ShowRVStationPicker(w, ROADSTOP_TRUCK);
    00342 }
    00343
    00350 static void BuildRoadClick_OneWay(Window *w)
    00351 {
    00352   if (w->IsWidgetDisabled(RTW_ONE_WAY)) return;
    00353   w->SetDirty();
    00354   w->ToggleWidgetLoweredState(RTW_ONE_WAY);
    00355   SetSelectionRed(false);
    00356 }
    00357
    00358 static void BuildRoadClick_Bridge(Window *w)
    00359 {
    00360   HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, VHM_RECT, PlaceRoad_Bridge);
    00361 }
    00362
    00363 static void BuildRoadClick_Tunnel(Window *w)
    00364 {
    00365   HandlePlacePushButton(w, RTW_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, VHM_SPECIAL, PlaceRoad_Tunnel);
    00366 }
    00367
    00368 static void BuildRoadClick_Remove(Window *w)
    00369 {
    00370   if (w->IsWidgetDisabled(RTW_REMOVE)) return;
    00371
    00372   DeleteWindowById(WC_SELECT_STATION, 0);
    00373   ToggleRoadButton_Remove(w);
    00374   SndPlayFx(SND_15_BEEP);
    00375 }
    00376
    00378 static OnButtonClick * const _build_road_button_proc[] = {
    00379   BuildRoadClick_X_Dir,
    00380   BuildRoadClick_Y_Dir,
    00381   BuildRoadClick_AutoRoad,
    00382   BuildRoadClick_Demolish,
    00383   BuildRoadClick_Depot,
    00384   BuildRoadClick_BusStation,
    00385   BuildRoadClick_TruckStation,
    00386   BuildRoadClick_OneWay,
    00387   BuildRoadClick_Bridge,
    00388   BuildRoadClick_Tunnel,
    00389   BuildRoadClick_Remove
    00390 };
    00391
    00393 static const uint16 _road_keycodes[] = {
    00394   '1',
    00395   '2',
    00396   '3',
    00397   '4',
    00398   '5',
    00399   '6',
    00400   '7',
    00401   '8',
    00402   'B',
    00403   'T',
    00404   'R',
    00405 };
    00406
    00407 struct BuildRoadToolbarWindow : Window {
    00408   BuildRoadToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
    00409   {
    00410     this->SetWidgetsDisabledState(true,
    00411       RTW_REMOVE,
    00412       RTW_ONE_WAY,
    00413       WIDGET_LIST_END);
    00414
    00415     this->FindWindowPlacementAndResize(desc);
    00416     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
    00417   }
    00418
    00419   ~BuildRoadToolbarWindow()
    00420   {
    00421     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
    00422   }
    00423
    00429   void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
    00430   {
    00431     /* The remove and the one way button state is driven
    00432      * by the other buttons so they don't act on themselfs.
    00433      * Both are only valid if they are able to apply as options. */
    00434     switch (clicked_widget) {
    00435       case RTW_REMOVE:
    00436         this->RaiseWidget(RTW_ONE_WAY);
    00437         this->InvalidateWidget(RTW_ONE_WAY);
    00438         break;
    00439
    00440       case RTW_ONE_WAY:
    00441         this->RaiseWidget(RTW_REMOVE);
    00442         this->InvalidateWidget(RTW_REMOVE);
    00443         break;
    00444
    00445       case RTW_BUS_STATION:
    00446       case RTW_TRUCK_STATION:
    00447         this->DisableWidget(RTW_ONE_WAY);
    00448         this->SetWidgetDisabledState(RTW_REMOVE, !this->IsWidgetLowered(clicked_widget));
    00449         break;
    00450
    00451       case RTW_ROAD_X:
    00452       case RTW_ROAD_Y:
    00453       case RTW_AUTOROAD:
    00454         this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
    00455           RTW_REMOVE,
    00456           RTW_ONE_WAY,
    00457           WIDGET_LIST_END);
    00458         break;
    00459
    00460       default:
    00461         /* When any other buttons than road/station, raise and
    00462          * disable the removal button */
    00463         this->SetWidgetsDisabledState(true,
    00464           RTW_REMOVE,
    00465           RTW_ONE_WAY,
    00466           WIDGET_LIST_END);
    00467         this->SetWidgetsLoweredState (false,
    00468           RTW_REMOVE,
    00469           RTW_ONE_WAY,
    00470           WIDGET_LIST_END);
    00471         break;
    00472     }
    00473   }
    00474
    00475   virtual void OnPaint()
    00476   {
    00477     this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
    00478       RTW_DEPOT,
    00479       RTW_BUS_STATION,
    00480       RTW_TRUCK_STATION,
    00481       WIDGET_LIST_END);
    00482     this->DrawWidgets();
    00483   }
    00484
    00485   virtual void OnClick(Point pt, int widget)
    00486   {
    00487     if (widget >= RTW_ROAD_X) {
    00488       _remove_button_clicked = false;
    00489       _one_way_button_clicked = false;
    00490       _build_road_button_proc[widget - RTW_ROAD_X](this);
    00491     }
    00492     this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget);
    00493     if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
    00494   }
    00495
    00496   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00497   {
    00498     EventState state = ES_NOT_HANDLED;
    00499     for (uint i = 0; i != lengthof(_road_keycodes); i++) {
    00500       if (keycode == _road_keycodes[i]) {
    00501         _remove_button_clicked = false;
    00502         _one_way_button_clicked = false;
    00503         _build_road_button_proc[i](this);
    00504         this->UpdateOptionWidgetStatus((RoadToolbarWidgets)(i + RTW_ROAD_X));
    00505         if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
    00506         state = ES_HANDLED;
    00507         break;
    00508       }
    00509     }
    00510     MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
    00511     return state;
    00512   }
    00513
    00514   virtual void OnPlaceObject(Point pt, TileIndex tile)
    00515   {
    00516     _remove_button_clicked = this->IsWidgetLowered(RTW_REMOVE);
    00517     _one_way_button_clicked = this->IsWidgetLowered(RTW_ONE_WAY);
    00518     _place_proc(tile);
    00519   }
    00520
    00521   virtual void OnPlaceObjectAbort()
    00522   {
    00523     this->RaiseButtons();
    00524     this->SetWidgetsDisabledState(true,
    00525       RTW_REMOVE,
    00526       RTW_ONE_WAY,
    00527       WIDGET_LIST_END);
    00528     this->InvalidateWidget(RTW_REMOVE);
    00529     this->InvalidateWidget(RTW_ONE_WAY);
    00530
    00531     DeleteWindowById(WC_BUS_STATION, 0);
    00532     DeleteWindowById(WC_TRUCK_STATION, 0);
    00533     DeleteWindowById(WC_BUILD_DEPOT, 0);
    00534     DeleteWindowById(WC_SELECT_STATION, 0);
    00535     DeleteWindowById(WC_BUILD_BRIDGE, 0);
    00536   }
    00537
    00538   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
    00539   {
    00540     /* Here we update the end tile flags
    00541      * of the road placement actions.
    00542      * At first we reset the end halfroad
    00543      * bits and if needed we set them again. */
    00544     switch (select_proc) {
    00545       case DDSP_PLACE_ROAD_X_DIR:
    00546         _place_road_flag &= ~RF_END_HALFROAD_X;
    00547         if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
    00548         break;
    00549
    00550       case DDSP_PLACE_ROAD_Y_DIR:
    00551         _place_road_flag &= ~RF_END_HALFROAD_Y;
    00552         if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
    00553         break;
    00554
    00555       case DDSP_PLACE_AUTOROAD:
    00556         _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
    00557         if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
    00558         if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
    00559
    00560         /* For autoroad we need to update the
    00561          * direction of the road */
    00562         if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
    00563             ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
    00564             (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
    00565           /* Set dir = X */
    00566           _place_road_flag &= ~RF_DIR_Y;
    00567         } else {
    00568           /* Set dir = Y */
    00569           _place_road_flag |= RF_DIR_Y;
    00570         }
    00571
    00572         break;
    00573
    00574       default:
    00575         break;
    00576     }
    00577
    00578     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
    00579   }
    00580
    00581   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
    00582   {
    00583     if (pt.x != -1) {
    00584       switch (select_proc) {
    00585         default: NOT_REACHED();
    00586         case DDSP_BUILD_BRIDGE:
    00587           if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00588           ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
    00589           break;
    00590
    00591         case DDSP_DEMOLISH_AREA:
    00592           GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
    00593           break;
    00594
    00595         case DDSP_PLACE_ROAD_X_DIR:
    00596         case DDSP_PLACE_ROAD_Y_DIR:
    00597         case DDSP_PLACE_AUTOROAD:
    00598           /* Flag description:
    00599            * Use the first three bits (0x07) if dir == Y
    00600            * else use the last 2 bits (X dir has
    00601            * not the 3rd bit set) */
    00602           _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
    00603
    00604           DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
    00605             (_ctrl_pressed || _remove_button_clicked) ?
    00606             CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
    00607             CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
    00608           break;
    00609       }
    00610     }
    00611   }
    00612
    00613   virtual void OnPlacePresize(Point pt, TileIndex tile)
    00614   {
    00615     DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL);
    00616     VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
    00617   }
    00618
    00619   virtual EventState OnCTRLStateChange()
    00620   {
    00621     if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
    00622     return ES_NOT_HANDLED;
    00623   }
    00624 };
    00625
    00627 static const Widget _build_road_widgets[] = {
    00628 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    10,     0,    13, STR_00C5,                   STR_018B_CLOSE_WINDOW},             // RTW_CLOSEBOX
    00629 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,    11,   250,     0,    13, STR_1802_ROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS},   // RTW_CAPTION
    00630 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,   251,   262,     0,    13, 0x0,                        STR_STICKY_BUTTON},                 // RTW_STICKY
    00631
    00632 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    21,    14,    35, SPR_IMG_ROAD_X_DIR,         STR_180B_BUILD_ROAD_SECTION},       // RTW_ROAD_X
    00633 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    22,    43,    14,    35, SPR_IMG_ROAD_Y_DIR,         STR_180B_BUILD_ROAD_SECTION},       // RTW_ROAD_Y
    00634 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    44,    65,    14,    35, SPR_IMG_AUTOROAD,           STR_BUILD_AUTOROAD_TIP},            // RTW_AUTOROAD
    00635 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    66,    87,    14,    35, SPR_IMG_DYNAMITE,           STR_018D_DEMOLISH_BUILDINGS_ETC},   // RTW_DEMOLISH
    00636 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    88,   109,    14,    35, SPR_IMG_ROAD_DEPOT,         STR_180C_BUILD_ROAD_VEHICLE_DEPOT}, // RTW_DEPOT
    00637 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   110,   131,    14,    35, SPR_IMG_BUS_STATION,        STR_180D_BUILD_BUS_STATION},        // RTW_BUS_STATION
    00638 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   132,   153,    14,    35, SPR_IMG_TRUCK_BAY,          STR_180E_BUILD_TRUCK_LOADING_BAY},  // RTW_TRUCK_STATION
    00639 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   154,   175,    14,    35, SPR_IMG_ROAD_ONE_WAY,       STR_TOGGLE_ONE_WAY_ROAD},           // RTW_ONE_WAY
    00640 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   176,   218,    14,    35, SPR_IMG_BRIDGE,             STR_180F_BUILD_ROAD_BRIDGE},        // RTW_BUILD_BRIDGE
    00641 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   219,   240,    14,    35, SPR_IMG_ROAD_TUNNEL,        STR_1810_BUILD_ROAD_TUNNEL},        // RTW_BUILD_TUNNEL
    00642 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   241,   262,    14,    35, SPR_IMG_REMOVE,             STR_1811_TOGGLE_BUILD_REMOVE_FOR},  // RTW_REMOVE
    00643
    00644 {   WIDGETS_END},
    00645 };
    00646
    00647 static const WindowDesc _build_road_desc(
    00648   WDP_ALIGN_TBR, 22, 263, 36, 263, 36,
    00649   WC_BUILD_TOOLBAR, WC_NONE,
    00650   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_CONSTRUCTION,
    00651   _build_road_widgets
    00652 );
    00653
    00655 static const Widget _build_tramway_widgets[] = {
    00656 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},                // RTW_CLOSEBOX
    00657 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,    11,   228,     0,    13, STR_WHITE_TRAMWAY_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS},      // RTW_CAPTION
    00658 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,   229,   240,     0,    13, 0x0,                            STR_STICKY_BUTTON},                    // RTW_STICKY
    00659
    00660 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    21,    14,    35, SPR_IMG_TRAMWAY_X_DIR,          STR_BUILD_TRAMWAY_SECTION},            // RTW_ROAD_X
    00661 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    22,    43,    14,    35, SPR_IMG_TRAMWAY_Y_DIR,          STR_BUILD_TRAMWAY_SECTION},            // RTW_ROAD_Y
    00662 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    44,    65,    14,    35, SPR_IMG_AUTOTRAM,               STR_BUILD_AUTOTRAM_TIP},               // RTW_AUTOROAD
    00663 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    66,    87,    14,    35, SPR_IMG_DYNAMITE,               STR_018D_DEMOLISH_BUILDINGS_ETC},      // RTW_DEMOLISH
    00664 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    88,   109,    14,    35, SPR_IMG_ROAD_DEPOT,             STR_BUILD_TRAM_VEHICLE_DEPOT},         // RTW_DEPOT
    00665 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   110,   131,    14,    35, SPR_IMG_BUS_STATION,            STR_BUILD_PASSENGER_TRAM_STATION},     // RTW_BUS_STATION
    00666 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   132,   153,    14,    35, SPR_IMG_TRUCK_BAY,              STR_BUILD_CARGO_TRAM_STATION},         // RTW_TRUCK_STATION
    00667 {      WWT_EMPTY,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,     0,     0,     0, 0x0,                            STR_NULL},                             // RTW_ONE_WAY
    00668 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   154,   196,    14,    35, SPR_IMG_BRIDGE,                 STR_BUILD_TRAMWAY_BRIDGE},             // RTW_BUILD_BRIDGE
    00669 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   197,   218,    14,    35, SPR_IMG_ROAD_TUNNEL,            STR_BUILD_TRAMWAY_TUNNEL},             // RTW_BUILD_TUNNEL
    00670 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   219,   240,    14,    35, SPR_IMG_REMOVE,                 STR_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS}, // RTW_REMOVE
    00671
    00672 {   WIDGETS_END},
    00673 };
    00674
    00675 static const WindowDesc _build_tramway_desc(
    00676   WDP_ALIGN_TBR, 22, 241, 36, 241, 36,
    00677   WC_BUILD_TOOLBAR, WC_NONE,
    00678   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_CONSTRUCTION,
    00679   _build_tramway_widgets
    00680 );
    00681
    00682 void ShowBuildRoadToolbar(RoadType roadtype)
    00683 {
    00684   if (!IsValidCompanyID(_local_company)) return;
    00685   _cur_roadtype = roadtype;
    00686
    00687   DeleteWindowByClass(WC_BUILD_TOOLBAR);
    00688   AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
    00689 }
    00690
    00692 static const Widget _build_road_scen_widgets[] = {
    00693 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    10,     0,    13, STR_00C5,                   STR_018B_CLOSE_WINDOW},            // RTW_CLOSEBOX
    00694 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,    11,   184,     0,    13, STR_1802_ROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS},  // RTW_CAPTION
    00695 {  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,   185,   196,     0,    13, 0x0,                        STR_STICKY_BUTTON},                // RTW_STICKY
    00696
    00697 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    21,    14,    35, SPR_IMG_ROAD_X_DIR,         STR_180B_BUILD_ROAD_SECTION},      // RTW_ROAD_X
    00698 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    22,    43,    14,    35, SPR_IMG_ROAD_Y_DIR,         STR_180B_BUILD_ROAD_SECTION},      // RTW_ROAD_Y
    00699 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    44,    65,    14,    35, SPR_IMG_AUTOROAD,           STR_BUILD_AUTOROAD_TIP},           // RTW_AUTOROAD
    00700 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    66,    87,    14,    35, SPR_IMG_DYNAMITE,           STR_018D_DEMOLISH_BUILDINGS_ETC},  // RTW_DEMOLISH
    00701 {      WWT_EMPTY,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,     0,     0,     0, 0x0,                        STR_NULL},                         // RTW_DEPOT
    00702 {      WWT_EMPTY,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,     0,     0,     0, 0x0,                        STR_NULL},                         // RTW_BUS_STATION
    00703 {      WWT_EMPTY,   RESIZE_NONE,  COLOUR_DARK_GREEN,     0,     0,     0,     0, 0x0,                        STR_NULL},                         // RTW_TRUCK_STATION
    00704 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,    88,   109,    14,    35, SPR_IMG_ROAD_ONE_WAY,       STR_TOGGLE_ONE_WAY_ROAD},          // RTW_ONE_WAY
    00705 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   110,   152,    14,    35, SPR_IMG_BRIDGE,             STR_180F_BUILD_ROAD_BRIDGE},       // RTW_BUILD_BRIDGE
    00706 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   153,   174,    14,    35, SPR_IMG_ROAD_TUNNEL,        STR_1810_BUILD_ROAD_TUNNEL},       // RTW_BUILD_TUNNEL
    00707 {     WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   175,   196,    14,    35, SPR_IMG_REMOVE,             STR_1811_TOGGLE_BUILD_REMOVE_FOR}, // RTW_REMOVE
    00708 {   WIDGETS_END},
    00709 };
    00710
    00711 static const WindowDesc _build_road_scen_desc(
    00712   WDP_AUTO, WDP_AUTO, 197, 36, 197, 36,
    00713   WC_SCEN_BUILD_TOOLBAR, WC_NONE,
    00714   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_CONSTRUCTION,
    00715   _build_road_scen_widgets
    00716 );
    00717
    00718 void ShowBuildRoadScenToolbar()
    00719 {
    00720   _cur_roadtype = ROADTYPE_ROAD;
    00721   AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, 0);
    00722 }
    00723
    00724 struct BuildRoadDepotWindow : public PickerWindowBase {
    00725 private:
    00727   enum BuildRoadDepotWidgets {
    00728     BRDW_CLOSEBOX = 0,
    00729     BRDW_CAPTION,
    00730     BRDW_BACKGROUND,
    00731     BRDW_DEPOT_NE,
    00732     BRDW_DEPOT_SE,
    00733     BRDW_DEPOT_SW,
    00734     BRDW_DEPOT_NW,
    00735   };
    00736
    00737 public:
    00738   BuildRoadDepotWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
    00739   {
    00740     this->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00741     if ( _cur_roadtype == ROADTYPE_TRAM) {
    00742       this->widget[BRDW_CAPTION].data = STR_TRAM_DEPOT_ORIENTATION;
    00743       for (int i = BRDW_DEPOT_NE; i <= BRDW_DEPOT_NW; i++) this->widget[i].tooltips = STR_SELECT_TRAM_VEHICLE_DEPOT;
    00744     }
    00745     this->FindWindowPlacementAndResize(desc);
    00746   }
    00747
    00748   virtual void OnPaint()
    00749   {
    00750     this->DrawWidgets();
    00751
    00752     DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype);
    00753     DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype);
    00754     DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype);
    00755     DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype);
    00756   }
    00757
    00758   virtual void OnClick(Point pt, int widget)
    00759   {
    00760     switch (widget) {
    00761       case BRDW_DEPOT_NW:
    00762       case BRDW_DEPOT_NE:
    00763       case BRDW_DEPOT_SW:
    00764       case BRDW_DEPOT_SE:
    00765         this->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00766         _road_depot_orientation = (DiagDirection)(widget - BRDW_DEPOT_NE);
    00767         this->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00768         SndPlayFx(SND_15_BEEP);
    00769         this->SetDirty();
    00770         break;
    00771
    00772       default:
    00773         break;
    00774     }
    00775   }
    00776 };
    00777
    00779 static const Widget _build_road_depot_widgets[] = {
    00780 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,    0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},              // BRDW_CLOSEBOX
    00781 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,   11,   139,     0,    13, STR_1806_ROAD_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS},    // BRDW_CAPTION
    00782 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_DARK_GREEN,    0,   139,    14,   121, 0x0,                             STR_NULL},                           // BRDW_BACKGROUND
    00783 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,         71,   136,    17,    66, 0x0,                             STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_NE
    00784 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,         71,   136,    69,   118, 0x0,                             STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_SE
    00785 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,          3,    68,    69,   118, 0x0,                             STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_SW
    00786 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,          3,    68,    17,    66, 0x0,                             STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_NW
    00787 {   WIDGETS_END},
    00788 };
    00789
    00790 static const WindowDesc _build_road_depot_desc(
    00791   WDP_AUTO, WDP_AUTO, 140, 122, 140, 122,
    00792   WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
    00793   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_CONSTRUCTION,
    00794   _build_road_depot_widgets
    00795 );
    00796
    00797 static void ShowRoadDepotPicker(Window *parent)
    00798 {
    00799   new BuildRoadDepotWindow(&_build_road_depot_desc, parent);
    00800 }
    00801
    00802 struct BuildRoadStationWindow : public PickerWindowBase {
    00803 private:
    00805   enum BuildRoadStationWidgets {
    00806     BRSW_CLOSEBOX = 0,
    00807     BRSW_CAPTION,
    00808     BRSW_BACKGROUND,
    00809     BRSW_STATION_NE,
    00810     BRSW_STATION_SE,
    00811     BRSW_STATION_SW,
    00812     BRSW_STATION_NW,
    00813     BRSW_STATION_X,
    00814     BRSW_STATION_Y,
    00815     BRSW_LT_OFF,
    00816     BRSW_LT_ON,
    00817     BRSW_INFO,
    00818   };
    00819
    00820 public:
    00821   BuildRoadStationWindow(const WindowDesc *desc, Window *parent, RoadStopType rs) : PickerWindowBase(desc, parent)
    00822   {
    00823     /* Trams don't have non-drivethrough stations */
    00824     if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) {
    00825       _road_station_picker_orientation = DIAGDIR_END;
    00826     }
    00827     this->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM,
    00828       BRSW_STATION_NE,
    00829       BRSW_STATION_SE,
    00830       BRSW_STATION_SW,
    00831       BRSW_STATION_NW,
    00832       WIDGET_LIST_END);
    00833
    00834     this->window_class = (rs == ROADSTOP_BUS) ? WC_BUS_STATION : WC_TRUCK_STATION;
    00835     this->widget[BRSW_CAPTION].data = _road_type_infos[_cur_roadtype].picker_title[rs];
    00836     for (uint i = BRSW_STATION_NE; i < BRSW_LT_OFF; i++) this->widget[i].tooltips = _road_type_infos[_cur_roadtype].picker_tooltip[rs];
    00837
    00838     this->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00839     this->LowerWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00840     this->FindWindowPlacementAndResize(desc);
    00841   }
    00842
    00843   virtual ~BuildRoadStationWindow()
    00844   {
    00845     DeleteWindowById(WC_SELECT_STATION, 0);
    00846   }
    00847
    00848   virtual void OnPaint()
    00849   {
    00850     this->DrawWidgets();
    00851
    00852     if (_settings_client.gui.station_show_coverage) {
    00853       int rad = _settings_game.station.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED;
    00854       SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
    00855     } else {
    00856       SetTileSelectSize(1, 1);
    00857     }
    00858
    00859     StationType st = (this->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
    00860
    00861     StationPickerDrawSprite(103, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 0);
    00862     StationPickerDrawSprite(103, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 1);
    00863     StationPickerDrawSprite( 35, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 2);
    00864     StationPickerDrawSprite( 35, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 3);
    00865
    00866     StationPickerDrawSprite(171, 35, st, INVALID_RAILTYPE, _cur_roadtype, 4);
    00867     StationPickerDrawSprite(171, 85, st, INVALID_RAILTYPE, _cur_roadtype, 5);
    00868
    00869     int text_end = DrawStationCoverageAreaText(2, 146,
    00870       (this->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
    00871       3, false);
    00872     text_end = DrawStationCoverageAreaText(2, text_end + 4,
    00873       (this->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
    00874       3, true) + 4;
    00875     if (text_end > this->widget[BRSW_BACKGROUND].bottom) {
    00876       this->SetDirty();
    00877       ResizeWindowForWidget(this, BRSW_BACKGROUND, 0, text_end - this->widget[BRSW_BACKGROUND].bottom);
    00878       this->SetDirty();
    00879     }
    00880   }
    00881
    00882   virtual void OnClick(Point pt, int widget)
    00883   {
    00884     switch (widget) {
    00885       case BRSW_STATION_NE:
    00886       case BRSW_STATION_SE:
    00887       case BRSW_STATION_SW:
    00888       case BRSW_STATION_NW:
    00889       case BRSW_STATION_X:
    00890       case BRSW_STATION_Y:
    00891         this->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00892         _road_station_picker_orientation = (DiagDirection)(widget - BRSW_STATION_NE);
    00893         this->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00894         SndPlayFx(SND_15_BEEP);
    00895         this->SetDirty();
    00896         DeleteWindowById(WC_SELECT_STATION, 0);
    00897         break;
    00898
    00899       case BRSW_LT_OFF:
    00900       case BRSW_LT_ON:
    00901         this->RaiseWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00902         _settings_client.gui.station_show_coverage = (widget != BRSW_LT_OFF);
    00903         this->LowerWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00904         SndPlayFx(SND_15_BEEP);
    00905         this->SetDirty();
    00906         break;
    00907
    00908       default:
    00909         break;
    00910     }
    00911   }
    00912
    00913   virtual void OnTick()
    00914   {
    00915     CheckRedrawStationCoverage(this);
    00916   }
    00917 };
    00918
    00920 static const Widget _rv_station_picker_widgets[] = {
    00921 {   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0,    10,     0,    13, STR_00C5,                         STR_018B_CLOSE_WINDOW},             // BRSW_CLOSEBOX
    00922 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,  11,   206,     0,    13, STR_NULL,                         STR_018C_WINDOW_TITLE_DRAG_THIS},   // BRSW_CAPTION
    00923 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0,   206,    14,   176, 0x0,                              STR_NULL},                          // BRSW_BACKGROUND
    00924
    00925 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,        71,   136,    17,    66, 0x0,                              STR_NULL},                          // BRSW_STATION_NE
    00926 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,        71,   136,    69,   118, 0x0,                              STR_NULL},                          // BRSW_STATION_SE
    00927 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,         3,    68,    69,   118, 0x0,                              STR_NULL},                          // BRSW_STATION_SW
    00928 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,         3,    68,    17,    66, 0x0,                              STR_NULL},                          // BRSW_STATION_NW
    00929 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,       139,   204,    17,    66, 0x0,                              STR_NULL},                          // BRSW_STATION_X
    00930 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,       139,   204,    69,   118, 0x0,                              STR_NULL},                          // BRSW_STATION_Y
    00931
    00932 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,        10,    69,   133,   144, STR_02DB_OFF,                     STR_3065_DON_T_HIGHLIGHT_COVERAGE}, // BRSW_LT_OFF
    00933 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_GREY,        70,   129,   133,   144, STR_02DA_ON,                      STR_3064_HIGHLIGHT_COVERAGE_AREA},  // BRSW_LT_ON
    00934 {      WWT_LABEL,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0,   139,   120,   133, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL},                          // BRSW_INFO
    00935 {   WIDGETS_END},
    00936 };
    00937
    00938 static const WindowDesc _rv_station_picker_desc(
    00939   WDP_AUTO, WDP_AUTO, 207, 177, 207, 177,
    00940   WC_BUS_STATION, WC_BUILD_TOOLBAR,
    00941   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_CONSTRUCTION,
    00942   _rv_station_picker_widgets
    00943 );
    00944
    00945 static void ShowRVStationPicker(Window *parent, RoadStopType rs)
    00946 {
    00947   new BuildRoadStationWindow(&_rv_station_picker_desc, parent, rs);
    00948 }
    00949
    00950 void InitializeRoadGui()
    00951 {
    00952   _road_depot_orientation = DIAGDIR_NW;
    00953   _road_station_picker_orientation = DIAGDIR_NW;
    00954 }