# road_gui.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "openttd.h"
    00014 #include "gui.h"
    00015 #include "window_gui.h"
    00016 #include "station_gui.h"
    00017 #include "terraform_gui.h"
    00018 #include "viewport_func.h"
    00019 #include "gfx_func.h"
    00020 #include "command_func.h"
    00021 #include "road_type.h"
    00022 #include "road_cmd.h"
    00023 #include "road_map.h"
    00024 #include "station_func.h"
    00025 #include "functions.h"
    00026 #include "window_func.h"
    00027 #include "vehicle_func.h"
    00028 #include "sound_func.h"
    00029 #include "company_func.h"
    00030 #include "tunnelbridge.h"
    00031 #include "tilehighlight_func.h"
    00032 #include "company_base.h"
    00033
    00034 #include "table/sprites.h"
    00035 #include "table/strings.h"
    00036
    00037 static void ShowRVStationPicker(Window *parent, RoadStopType rs);
    00038 static void ShowRoadDepotPicker(Window *parent);
    00039
    00040 static bool _remove_button_clicked;
    00041 static bool _one_way_button_clicked;
    00042
    00047 enum RoadFlags {
    00048   RF_NONE             = 0x00,
    00049   RF_START_HALFROAD_Y = 0x01,    // The start tile in Y-dir should have only a half road
    00050   RF_END_HALFROAD_Y   = 0x02,    // The end tile in Y-dir should have only a half road
    00051   RF_DIR_Y            = 0x04,    // The direction is Y-dir
    00052   RF_DIR_X            = RF_NONE, // Dummy; Dir X is set when RF_DIR_Y is not set
    00053   RF_START_HALFROAD_X = 0x08,    // The start tile in X-dir should have only a half road
    00054   RF_END_HALFROAD_X   = 0x10,    // The end tile in X-dir should have only a half road
    00055 };
    00056 DECLARE_ENUM_AS_BIT_SET(RoadFlags);
    00057
    00058 static RoadFlags _place_road_flag;
    00059
    00060 static RoadType _cur_roadtype;
    00061
    00062 static DiagDirection _road_depot_orientation;
    00063 static DiagDirection _road_station_picker_orientation;
    00064
    00065 void CcPlaySound1D(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00066 {
    00067   if (success) SndPlayTileFx(SND_1F_SPLAT, tile);
    00068 }
    00069
    00078 static void PlaceRoad_X_Dir(TileIndex tile)
    00079 {
    00080   _place_road_flag = RF_DIR_X;
    00081   if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
    00082   VpStartPlaceSizing(tile, VPM_FIX_Y, DDSP_PLACE_ROAD_X_DIR);
    00083 }
    00084
    00093 static void PlaceRoad_Y_Dir(TileIndex tile)
    00094 {
    00095   _place_road_flag = RF_DIR_Y;
    00096   if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
    00097   VpStartPlaceSizing(tile, VPM_FIX_X, DDSP_PLACE_ROAD_Y_DIR);
    00098 }
    00099
    00108 static void PlaceRoad_AutoRoad(TileIndex tile)
    00109 {
    00110   _place_road_flag = RF_NONE;
    00111   if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
    00112   if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
    00113   VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_PLACE_AUTOROAD);
    00114 }
    00115
    00116 static void PlaceRoad_Bridge(TileIndex tile)
    00117 {
    00118   VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
    00119 }
    00120
    00121
    00122 void CcBuildRoadTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00123 {
    00124   if (success) {
    00125     SndPlayTileFx(SND_20_SPLAT_2, tile);
    00126     if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00127   } else {
    00128     SetRedErrorSquare(_build_tunnel_endtile);
    00129   }
    00130 }
    00131
    00133 struct RoadTypeInfo {
    00134   StringID err_build_road;
    00135   StringID err_remove_road;
    00136   StringID err_depot;
    00137   StringID err_build_station[2];
    00138   StringID err_remove_station[2];
    00139
    00140   StringID picker_title[2];
    00141   StringID picker_tooltip[2];
    00142
    00143   SpriteID cursor_nesw;
    00144   SpriteID cursor_nwse;
    00145   SpriteID cursor_autoroad;
    00146 };
    00147
    00149 static const RoadTypeInfo _road_type_infos[] = {
    00150   {
    00151     STR_ERROR_CAN_T_BUILD_ROAD_HERE,
    00152     STR_ERROR_CAN_T_REMOVE_ROAD_FROM,
    00153     STR_ERROR_CAN_T_BUILD_ROAD_DEPOT,
    00154     { STR_ERROR_CAN_T_BUILD_BUS_STATION,         STR_ERROR_CAN_T_BUILD_TRUCK_STATION          },
    00155     { STR_ERROR_CAN_T_REMOVE_BUS_STATION,        STR_ERROR_CAN_T_REMOVE_TRUCK_STATION         },
    00156     { STR_STATION_BUILD_BUS_ORIENTATION,         STR_STATION_BUILD_TRUCK_ORIENTATION          },
    00157     { STR_STATION_BUILD_BUS_ORIENTATION_TOOLTIP, STR_STATION_BUILD_TRUCK_ORIENTATION_TOOLTIP  },
    00158
    00159     SPR_CURSOR_ROAD_NESW,
    00160     SPR_CURSOR_ROAD_NWSE,
    00161     SPR_CURSOR_AUTOROAD,
    00162   },
    00163   {
    00164     STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE,
    00165     STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM,
    00166     STR_ERROR_CAN_T_BUILD_TRAM_DEPOT,
    00167     { STR_ERROR_CAN_T_BUILD_PASSENGER_TRAM_STATION,         STR_ERROR_CAN_T_BUILD_CARGO_TRAM_STATION         },
    00168     { STR_ERROR_CAN_T_REMOVE_PASSENGER_TRAM_STATION,        STR_ERROR_CAN_T_REMOVE_CARGO_TRAM_STATION        },
    00169     { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION,         STR_STATION_BUILD_CARGO_TRAM_ORIENTATION         },
    00170     { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION_TOOLTIP, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION_TOOLTIP },
    00171
    00172     SPR_CURSOR_TRAMWAY_NESW,
    00173     SPR_CURSOR_TRAMWAY_NWSE,
    00174     SPR_CURSOR_AUTOTRAM,
    00175   },
    00176 };
    00177
    00178 static void PlaceRoad_Tunnel(TileIndex tile)
    00179 {
    00180   DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRoadTunnel);
    00181 }
    00182
    00183 static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
    00184 {
    00185   tile += TileOffsByDiagDir(direction);
    00186   /* if there is a roadpiece just outside of the station entrance, build a connecting route */
    00187   if (IsNormalRoadTile(tile)) {
    00188     if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
    00189       DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, CMD_BUILD_ROAD);
    00190     }
    00191   }
    00192 }
    00193
    00194 void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
    00195 {
    00196   if (success) {
    00197     DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
    00198     SndPlayTileFx(SND_1F_SPLAT, tile);
    00199     if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00200     BuildRoadOutsideStation(tile, dir);
    00201     /* For a drive-through road stop build connecting road for other entrance */
    00202     if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
    00203   }
    00204 }
    00205
    00206 static void PlaceRoad_Depot(TileIndex tile)
    00207 {
    00208   DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CMD_BUILD_ROAD_DEPOT | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot), CcRoadDepot);
    00209 }
    00210
    00211 static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
    00212 {
    00213   uint32 p1 = _road_station_picker_orientation;
    00214   SB(p2, 16, 16, INVALID_STATION); // no station to join
    00215
    00216   if (p1 >= DIAGDIR_END) {
    00217     SetBit(p2, 1); // It's a drive-through stop
    00218     p1 -= DIAGDIR_END; // Adjust picker result to actual direction
    00219   }
    00220   CommandContainer cmdcont = { tile, p1, p2, cmd, CcRoadDepot, "" };
    00221   ShowSelectStationIfNeeded(cmdcont, TileArea(tile, 1, 1));
    00222 }
    00223
    00224 static void PlaceRoad_BusStation(TileIndex tile)
    00225 {
    00226   if (_remove_button_clicked) {
    00227     DoCommandP(tile, 0, ROADSTOP_BUS, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]), CcPlaySound1D);
    00228   } else {
    00229     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]));
    00230   }
    00231 }
    00232
    00233 static void PlaceRoad_TruckStation(TileIndex tile)
    00234 {
    00235   if (_remove_button_clicked) {
    00236     DoCommandP(tile, 0, ROADSTOP_TRUCK, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]), CcPlaySound1D);
    00237   } else {
    00238     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]));
    00239   }
    00240 }
    00241
    00243 enum RoadToolbarWidgets {
    00244   RTW_ROAD_X,
    00245   RTW_ROAD_Y,
    00246   RTW_AUTOROAD,
    00247   RTW_DEMOLISH,
    00248   RTW_DEPOT,
    00249   RTW_BUS_STATION,
    00250   RTW_TRUCK_STATION,
    00251   RTW_ONE_WAY,
    00252   RTW_BUILD_BRIDGE,
    00253   RTW_BUILD_TUNNEL,
    00254   RTW_REMOVE,
    00255 };
    00256
    00257 typedef void OnButtonClick(Window *w);
    00258
    00259
    00263 static void ToggleRoadButton_Remove(Window *w)
    00264 {
    00265   w->ToggleWidgetLoweredState(RTW_REMOVE);
    00266   w->SetWidgetDirty(RTW_REMOVE);
    00267   _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
    00268   SetSelectionRed(_remove_button_clicked);
    00269 }
    00270
    00275 static bool RoadToolbar_CtrlChanged(Window *w)
    00276 {
    00277   if (w->IsWidgetDisabled(RTW_REMOVE)) return false;
    00278
    00279   /* allow ctrl to switch remove mode only for these widgets */
    00280   for (uint i = RTW_ROAD_X; i <= RTW_AUTOROAD; i++) {
    00281     if (w->IsWidgetLowered(i)) {
    00282       ToggleRoadButton_Remove(w);
    00283       return true;
    00284     }
    00285   }
    00286
    00287   return false;
    00288 }
    00289
    00290
    00297 static void BuildRoadClick_X_Dir(Window *w)
    00298 {
    00299   HandlePlacePushButton(w, RTW_ROAD_X, _road_type_infos[_cur_roadtype].cursor_nwse, HT_RECT, PlaceRoad_X_Dir);
    00300 }
    00301
    00308 static void BuildRoadClick_Y_Dir(Window *w)
    00309 {
    00310   HandlePlacePushButton(w, RTW_ROAD_Y, _road_type_infos[_cur_roadtype].cursor_nesw, HT_RECT, PlaceRoad_Y_Dir);
    00311 }
    00312
    00319 static void BuildRoadClick_AutoRoad(Window *w)
    00320 {
    00321   HandlePlacePushButton(w, RTW_AUTOROAD, _road_type_infos[_cur_roadtype].cursor_autoroad, HT_RECT, PlaceRoad_AutoRoad);
    00322 }
    00323
    00324 static void BuildRoadClick_Demolish(Window *w)
    00325 {
    00326   HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT, PlaceProc_DemolishArea);
    00327 }
    00328
    00329 static void BuildRoadClick_Depot(Window *w)
    00330 {
    00331   if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
    00332   if (HandlePlacePushButton(w, RTW_DEPOT, SPR_CURSOR_ROAD_DEPOT, HT_RECT, PlaceRoad_Depot)) ShowRoadDepotPicker(w);
    00333 }
    00334
    00335 static void BuildRoadClick_BusStation(Window *w)
    00336 {
    00337   if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
    00338   if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, HT_RECT, PlaceRoad_BusStation)) ShowRVStationPicker(w, ROADSTOP_BUS);
    00339 }
    00340
    00341 static void BuildRoadClick_TruckStation(Window *w)
    00342 {
    00343   if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
    00344   if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, HT_RECT, PlaceRoad_TruckStation)) ShowRVStationPicker(w, ROADSTOP_TRUCK);
    00345 }
    00346
    00353 static void BuildRoadClick_OneWay(Window *w)
    00354 {
    00355   if (w->IsWidgetDisabled(RTW_ONE_WAY)) return;
    00356   w->SetDirty();
    00357   w->ToggleWidgetLoweredState(RTW_ONE_WAY);
    00358   SetSelectionRed(false);
    00359 }
    00360
    00361 static void BuildRoadClick_Bridge(Window *w)
    00362 {
    00363   HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT, PlaceRoad_Bridge);
    00364 }
    00365
    00366 static void BuildRoadClick_Tunnel(Window *w)
    00367 {
    00368   HandlePlacePushButton(w, RTW_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, HT_SPECIAL, PlaceRoad_Tunnel);
    00369 }
    00370
    00371 static void BuildRoadClick_Remove(Window *w)
    00372 {
    00373   if (w->IsWidgetDisabled(RTW_REMOVE)) return;
    00374
    00375   DeleteWindowById(WC_SELECT_STATION, 0);
    00376   ToggleRoadButton_Remove(w);
    00377   SndPlayFx(SND_15_BEEP);
    00378 }
    00379
    00381 static OnButtonClick * const _build_road_button_proc[] = {
    00382   BuildRoadClick_X_Dir,
    00383   BuildRoadClick_Y_Dir,
    00384   BuildRoadClick_AutoRoad,
    00385   BuildRoadClick_Demolish,
    00386   BuildRoadClick_Depot,
    00387   BuildRoadClick_BusStation,
    00388   BuildRoadClick_TruckStation,
    00389   BuildRoadClick_OneWay,
    00390   BuildRoadClick_Bridge,
    00391   BuildRoadClick_Tunnel,
    00392   BuildRoadClick_Remove
    00393 };
    00394
    00396 static const uint16 _road_keycodes[] = {
    00397   '1',
    00398   '2',
    00399   '3',
    00400   '4',
    00401   '5',
    00402   '6',
    00403   '7',
    00404   '8',
    00405   'B',
    00406   'T',
    00407   'R',
    00408 };
    00409
    00410 struct BuildRoadToolbarWindow : Window {
    00411   BuildRoadToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
    00412   {
    00413     this->InitNested(desc, window_number);
    00414     this->SetWidgetsDisabledState(true,
    00415       RTW_REMOVE,
    00416       RTW_ONE_WAY,
    00417       WIDGET_LIST_END);
    00418
    00419     this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
    00420       RTW_DEPOT,
    00421       RTW_BUS_STATION,
    00422       RTW_TRUCK_STATION,
    00423       WIDGET_LIST_END);
    00424
    00425     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
    00426   }
    00427
    00428   ~BuildRoadToolbarWindow()
    00429   {
    00430     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
    00431   }
    00432
    00438   void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
    00439   {
    00440     /* The remove and the one way button state is driven
    00441      * by the other buttons so they don't act on themselfs.
    00442      * Both are only valid if they are able to apply as options. */
    00443     switch (clicked_widget) {
    00444       case RTW_REMOVE:
    00445         this->RaiseWidget(RTW_ONE_WAY);
    00446         this->SetWidgetDirty(RTW_ONE_WAY);
    00447         break;
    00448
    00449       case RTW_ONE_WAY:
    00450         this->RaiseWidget(RTW_REMOVE);
    00451         this->SetWidgetDirty(RTW_REMOVE);
    00452         break;
    00453
    00454       case RTW_BUS_STATION:
    00455       case RTW_TRUCK_STATION:
    00456         this->DisableWidget(RTW_ONE_WAY);
    00457         this->SetWidgetDisabledState(RTW_REMOVE, !this->IsWidgetLowered(clicked_widget));
    00458         break;
    00459
    00460       case RTW_ROAD_X:
    00461       case RTW_ROAD_Y:
    00462       case RTW_AUTOROAD:
    00463         this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
    00464           RTW_REMOVE,
    00465           RTW_ONE_WAY,
    00466           WIDGET_LIST_END);
    00467         break;
    00468
    00469       default:
    00470         /* When any other buttons than road/station, raise and
    00471          * disable the removal button */
    00472         this->SetWidgetsDisabledState(true,
    00473           RTW_REMOVE,
    00474           RTW_ONE_WAY,
    00475           WIDGET_LIST_END);
    00476         this->SetWidgetsLoweredState(false,
    00477           RTW_REMOVE,
    00478           RTW_ONE_WAY,
    00479           WIDGET_LIST_END);
    00480         break;
    00481     }
    00482   }
    00483
    00484   virtual void OnPaint()
    00485   {
    00486     this->DrawWidgets();
    00487   }
    00488
    00489   virtual void OnClick(Point pt, int widget)
    00490   {
    00491     if (widget >= RTW_ROAD_X) {
    00492       _remove_button_clicked = false;
    00493       _one_way_button_clicked = false;
    00494       _build_road_button_proc[widget - RTW_ROAD_X](this);
    00495     }
    00496     this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget);
    00497     if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
    00498   }
    00499
    00500   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00501   {
    00502     EventState state = ES_NOT_HANDLED;
    00503     for (uint i = 0; i != lengthof(_road_keycodes); i++) {
    00504       if (keycode == _road_keycodes[i]) {
    00505         _remove_button_clicked = false;
    00506         _one_way_button_clicked = false;
    00507         _build_road_button_proc[i](this);
    00508         this->UpdateOptionWidgetStatus((RoadToolbarWidgets)(i + RTW_ROAD_X));
    00509         if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
    00510         state = ES_HANDLED;
    00511         break;
    00512       }
    00513     }
    00514     MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
    00515     return state;
    00516   }
    00517
    00518   virtual void OnPlaceObject(Point pt, TileIndex tile)
    00519   {
    00520     _remove_button_clicked = this->IsWidgetLowered(RTW_REMOVE);
    00521     _one_way_button_clicked = this->IsWidgetLowered(RTW_ONE_WAY);
    00522     _place_proc(tile);
    00523   }
    00524
    00525   virtual void OnPlaceObjectAbort()
    00526   {
    00527     this->RaiseButtons();
    00528     this->SetWidgetsDisabledState(true,
    00529       RTW_REMOVE,
    00530       RTW_ONE_WAY,
    00531       WIDGET_LIST_END);
    00532     this->SetWidgetDirty(RTW_REMOVE);
    00533     this->SetWidgetDirty(RTW_ONE_WAY);
    00534
    00535     DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD);
    00536     DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD);
    00537     DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD);
    00538     DeleteWindowById(WC_SELECT_STATION, 0);
    00539     DeleteWindowByClass(WC_BUILD_BRIDGE);
    00540   }
    00541
    00542   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
    00543   {
    00544     /* Here we update the end tile flags
    00545      * of the road placement actions.
    00546      * At first we reset the end halfroad
    00547      * bits and if needed we set them again. */
    00548     switch (select_proc) {
    00549       case DDSP_PLACE_ROAD_X_DIR:
    00550         _place_road_flag &= ~RF_END_HALFROAD_X;
    00551         if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
    00552         break;
    00553
    00554       case DDSP_PLACE_ROAD_Y_DIR:
    00555         _place_road_flag &= ~RF_END_HALFROAD_Y;
    00556         if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
    00557         break;
    00558
    00559       case DDSP_PLACE_AUTOROAD:
    00560         _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
    00561         if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
    00562         if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
    00563
    00564         /* For autoroad we need to update the
    00565          * direction of the road */
    00566         if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
    00567             ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
    00568             (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
    00569           /* Set dir = X */
    00570           _place_road_flag &= ~RF_DIR_Y;
    00571         } else {
    00572           /* Set dir = Y */
    00573           _place_road_flag |= RF_DIR_Y;
    00574         }
    00575
    00576         break;
    00577
    00578       default:
    00579         break;
    00580     }
    00581
    00582     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
    00583   }
    00584
    00585   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
    00586   {
    00587     if (pt.x != -1) {
    00588       switch (select_proc) {
    00589         default: NOT_REACHED();
    00590         case DDSP_BUILD_BRIDGE:
    00591           if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00592           ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
    00593           break;
    00594
    00595         case DDSP_DEMOLISH_AREA:
    00596           GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
    00597           break;
    00598
    00599         case DDSP_PLACE_ROAD_X_DIR:
    00600         case DDSP_PLACE_ROAD_Y_DIR:
    00601         case DDSP_PLACE_AUTOROAD:
    00602           /* Flag description:
    00603            * Use the first three bits (0x07) if dir == Y
    00604            * else use the last 2 bits (X dir has
    00605            * not the 3rd bit set) */
    00606           _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
    00607
    00608           DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
    00609             _remove_button_clicked ?
    00610             CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
    00611             CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
    00612           break;
    00613       }
    00614     }
    00615   }
    00616
    00617   virtual void OnPlacePresize(Point pt, TileIndex tile)
    00618   {
    00619     DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL);
    00620     VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
    00621   }
    00622
    00623   virtual EventState OnCTRLStateChange()
    00624   {
    00625     if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
    00626     return ES_NOT_HANDLED;
    00627   }
    00628 };
    00629
    00630 static const NWidgetPart _nested_build_road_widgets[] = {
    00631   NWidget(NWID_HORIZONTAL),
    00632     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00633     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00634     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00635   EndContainer(),
    00636   NWidget(NWID_HORIZONTAL),
    00637     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_X),
    00638             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00639     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_Y),
    00640             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00641     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_AUTOROAD),
    00642             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
    00643     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEMOLISH),
    00644             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00645     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEPOT),
    00646             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
    00647     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUS_STATION),
    00648             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
    00649     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_TRUCK_STATION),
    00650             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
    00651     NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
    00652     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ONE_WAY),
    00653             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
    00654     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_BRIDGE),
    00655             SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
    00656     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_TUNNEL),
    00657             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
    00658     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_REMOVE),
    00659             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
    00660   EndContainer(),
    00661 };
    00662
    00663 static const WindowDesc _build_road_desc(
    00664   WDP_ALIGN_TOOLBAR, 0, 0,
    00665   WC_BUILD_TOOLBAR, WC_NONE,
    00666   WDF_CONSTRUCTION,
    00667   _nested_build_road_widgets, lengthof(_nested_build_road_widgets)
    00668 );
    00669
    00670 static const NWidgetPart _nested_build_tramway_widgets[] = {
    00671   NWidget(NWID_HORIZONTAL),
    00672     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00673     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_TRAM_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00674     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00675   EndContainer(),
    00676   NWidget(NWID_HORIZONTAL),
    00677     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_X),
    00678             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
    00679     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_Y),
    00680             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
    00681     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_AUTOROAD),
    00682             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
    00683     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEMOLISH),
    00684             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00685     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEPOT),
    00686             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
    00687     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUS_STATION),
    00688             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
    00689     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_TRUCK_STATION),
    00690             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
    00691     NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
    00692     NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, RTW_ONE_WAY), SetMinimalSize(0, 0),
    00693     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_BRIDGE),
    00694             SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
    00695     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_TUNNEL),
    00696             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
    00697     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_REMOVE),
    00698             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
    00699   EndContainer(),
    00700 };
    00701
    00702 static const WindowDesc _build_tramway_desc(
    00703   WDP_ALIGN_TOOLBAR, 0, 0,
    00704   WC_BUILD_TOOLBAR, WC_NONE,
    00705   WDF_CONSTRUCTION,
    00706   _nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets)
    00707 );
    00708
    00709 void ShowBuildRoadToolbar(RoadType roadtype)
    00710 {
    00711   if (!Company::IsValidID(_local_company)) return;
    00712   _cur_roadtype = roadtype;
    00713
    00714   DeleteWindowByClass(WC_BUILD_TOOLBAR);
    00715   AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
    00716 }
    00717
    00718 static const NWidgetPart _nested_build_road_scen_widgets[] = {
    00719   NWidget(NWID_HORIZONTAL),
    00720     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00721     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00722     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00723   EndContainer(),
    00724   NWidget(NWID_HORIZONTAL),
    00725     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_X),
    00726             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00727     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_Y),
    00728             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00729     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_AUTOROAD),
    00730             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
    00731     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEMOLISH),
    00732             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00733     NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
    00734     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ONE_WAY),
    00735             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
    00736     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_BRIDGE),
    00737             SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
    00738     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_TUNNEL),
    00739             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
    00740     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_REMOVE),
    00741             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
    00742   EndContainer(),
    00743 };
    00744
    00745 static const WindowDesc _build_road_scen_desc(
    00746   WDP_AUTO, 0, 0,
    00747   WC_SCEN_BUILD_TOOLBAR, WC_NONE,
    00748   WDF_CONSTRUCTION,
    00749   _nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets)
    00750 );
    00751
    00752 void ShowBuildRoadScenToolbar()
    00753 {
    00754   _cur_roadtype = ROADTYPE_ROAD;
    00755   AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, 0);
    00756 }
    00757
    00759 enum BuildRoadDepotWidgets {
    00760   BRDW_CAPTION,
    00761   BRDW_DEPOT_NE,
    00762   BRDW_DEPOT_SE,
    00763   BRDW_DEPOT_SW,
    00764   BRDW_DEPOT_NW,
    00765 };
    00766
    00767 struct BuildRoadDepotWindow : public PickerWindowBase {
    00768   BuildRoadDepotWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
    00769   {
    00770     this->CreateNestedTree(desc);
    00771
    00772     this->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00773     if ( _cur_roadtype == ROADTYPE_TRAM) {
    00774       this->GetWidget<NWidgetCore>(BRDW_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION;
    00775       for (int i = BRDW_DEPOT_NE; i <= BRDW_DEPOT_NW; i++) this->GetWidget<NWidgetCore>(i)->tool_tip = STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP;
    00776     }
    00777
    00778     this->FinishInitNested(desc, TRANSPORT_ROAD);
    00779   }
    00780
    00781   virtual void OnPaint()
    00782   {
    00783     this->DrawWidgets();
    00784   }
    00785
    00786   virtual void DrawWidget(const Rect &r, int widget) const
    00787   {
    00788     if (!IsInsideMM(widget, BRDW_DEPOT_NE, BRDW_DEPOT_NW + 1)) return;
    00789
    00790     DrawRoadDepotSprite(r.left - 1, r.top, (DiagDirection)(widget - BRDW_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
    00791   }
    00792
    00793   virtual void OnClick(Point pt, int widget)
    00794   {
    00795     switch (widget) {
    00796       case BRDW_DEPOT_NW:
    00797       case BRDW_DEPOT_NE:
    00798       case BRDW_DEPOT_SW:
    00799       case BRDW_DEPOT_SE:
    00800         this->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00801         _road_depot_orientation = (DiagDirection)(widget - BRDW_DEPOT_NE);
    00802         this->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00803         SndPlayFx(SND_15_BEEP);
    00804         this->SetDirty();
    00805         break;
    00806
    00807       default:
    00808         break;
    00809     }
    00810   }
    00811 };
    00812
    00813 static const NWidgetPart _nested_build_road_depot_widgets[] = {
    00814   NWidget(NWID_HORIZONTAL),
    00815     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00816     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, BRDW_CAPTION), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00817   EndContainer(),
    00818   NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
    00819     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00820     NWidget(NWID_HORIZONTAL_LTR),
    00821       NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
    00822       NWidget(NWID_VERTICAL),
    00823         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00824         EndContainer(),
    00825         NWidget(NWID_SPACER), SetMinimalSize(0, 2),
    00826         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00827         EndContainer(),
    00828       EndContainer(),
    00829       NWidget(NWID_SPACER), SetMinimalSize(2, 0),
    00830       NWidget(NWID_VERTICAL),
    00831         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00832         EndContainer(),
    00833         NWidget(NWID_SPACER), SetMinimalSize(0, 2),
    00834         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00835         EndContainer(),
    00836       EndContainer(),
    00837       NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
    00838     EndContainer(),
    00839     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00840   EndContainer(),
    00841 };
    00842
    00843 static const WindowDesc _build_road_depot_desc(
    00844   WDP_AUTO, 0, 0,
    00845   WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
    00846   WDF_CONSTRUCTION,
    00847   _nested_build_road_depot_widgets, lengthof(_nested_build_road_depot_widgets)
    00848 );
    00849
    00850 static void ShowRoadDepotPicker(Window *parent)
    00851 {
    00852   new BuildRoadDepotWindow(&_build_road_depot_desc, parent);
    00853 }
    00854
    00856 enum BuildRoadStationWidgets {
    00857   BRSW_CAPTION,
    00858   BRSW_BACKGROUND,
    00859   BRSW_STATION_NE,
    00860   BRSW_STATION_SE,
    00861   BRSW_STATION_SW,
    00862   BRSW_STATION_NW,
    00863   BRSW_STATION_X,
    00864   BRSW_STATION_Y,
    00865   BRSW_LT_OFF,
    00866   BRSW_LT_ON,
    00867   BRSW_INFO,
    00868 };
    00869
    00870 struct BuildRoadStationWindow : public PickerWindowBase {
    00871   BuildRoadStationWindow(const WindowDesc *desc, Window *parent, RoadStopType rs) : PickerWindowBase(parent)
    00872   {
    00873     this->CreateNestedTree(desc);
    00874
    00875     /* Trams don't have non-drivethrough stations */
    00876     if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) {
    00877       _road_station_picker_orientation = DIAGDIR_END;
    00878     }
    00879     this->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM,
    00880       BRSW_STATION_NE,
    00881       BRSW_STATION_SE,
    00882       BRSW_STATION_SW,
    00883       BRSW_STATION_NW,
    00884       WIDGET_LIST_END);
    00885
    00886     this->GetWidget<NWidgetCore>(BRSW_CAPTION)->widget_data = _road_type_infos[_cur_roadtype].picker_title[rs];
    00887     for (uint i = BRSW_STATION_NE; i < BRSW_LT_OFF; i++) this->GetWidget<NWidgetCore>(i)->tool_tip = _road_type_infos[_cur_roadtype].picker_tooltip[rs];
    00888
    00889     this->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00890     this->LowerWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00891
    00892     this->FinishInitNested(desc, TRANSPORT_ROAD);
    00893
    00894     this->window_class = (rs == ROADSTOP_BUS) ? WC_BUS_STATION : WC_TRUCK_STATION;
    00895   }
    00896
    00897   virtual ~BuildRoadStationWindow()
    00898   {
    00899     DeleteWindowById(WC_SELECT_STATION, 0);
    00900   }
    00901
    00902   virtual void OnPaint()
    00903   {
    00904     this->DrawWidgets();
    00905
    00906     int rad = _settings_game.station.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED;
    00907     if (_settings_client.gui.station_show_coverage) {
    00908       SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
    00909     } else {
    00910       SetTileSelectSize(1, 1);
    00911     }
    00912
    00913     /* 'Accepts' and 'Supplies' texts. */
    00914     StationCoverageType sct = (this->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY;
    00915     int top = this->GetWidget<NWidgetBase>(BRSW_LT_ON)->pos_y + this->GetWidget<NWidgetBase>(BRSW_LT_ON)->current_y + WD_PAR_VSEP_NORMAL;
    00916     NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BRSW_BACKGROUND);
    00917     int right = back_nwi->pos_x +  back_nwi->current_x;
    00918     int bottom = back_nwi->pos_y +  back_nwi->current_y;
    00919     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, false) + WD_PAR_VSEP_NORMAL;
    00920     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, true) + WD_PAR_VSEP_NORMAL;
    00921     /* Resize background if the text is not equally long as the window. */
    00922     if (top > bottom || (top < bottom && back_nwi->current_y > back_nwi->smallest_y)) {
    00923       ResizeWindow(this, 0, top - bottom);
    00924     }
    00925   }
    00926
    00927   virtual void DrawWidget(const Rect &r, int widget) const
    00928   {
    00929     if (!IsInsideMM(widget, BRSW_STATION_NE, BRSW_STATION_Y + 1)) return;
    00930
    00931     StationType st = (this->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
    00932     StationPickerDrawSprite(r.left + TILE_PIXELS, r.bottom - TILE_PIXELS, st, INVALID_RAILTYPE, widget < BRSW_STATION_X ? ROADTYPE_ROAD : _cur_roadtype, widget - BRSW_STATION_NE);
    00933   }
    00934
    00935   virtual void OnClick(Point pt, int widget)
    00936   {
    00937     switch (widget) {
    00938       case BRSW_STATION_NE:
    00939       case BRSW_STATION_SE:
    00940       case BRSW_STATION_SW:
    00941       case BRSW_STATION_NW:
    00942       case BRSW_STATION_X:
    00943       case BRSW_STATION_Y:
    00944         this->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00945         _road_station_picker_orientation = (DiagDirection)(widget - BRSW_STATION_NE);
    00946         this->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00947         SndPlayFx(SND_15_BEEP);
    00948         this->SetDirty();
    00949         DeleteWindowById(WC_SELECT_STATION, 0);
    00950         break;
    00951
    00952       case BRSW_LT_OFF:
    00953       case BRSW_LT_ON:
    00954         this->RaiseWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00955         _settings_client.gui.station_show_coverage = (widget != BRSW_LT_OFF);
    00956         this->LowerWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00957         SndPlayFx(SND_15_BEEP);
    00958         this->SetDirty();
    00959         break;
    00960
    00961       default:
    00962         break;
    00963     }
    00964   }
    00965
    00966   virtual void OnTick()
    00967   {
    00968     CheckRedrawStationCoverage(this);
    00969   }
    00970 };
    00971
    00973 static const NWidgetPart _nested_rv_station_picker_widgets[] = {
    00974   NWidget(NWID_HORIZONTAL),
    00975     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00976     NWidget(WWT_CAPTION,  COLOUR_DARK_GREEN, BRSW_CAPTION),
    00977   EndContainer(),
    00978   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BRSW_BACKGROUND),
    00979     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00980     NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
    00981       NWidget(NWID_SPACER), SetFill(1, 0),
    00982       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_NW), SetMinimalSize(66, 50), EndContainer(),
    00983       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_NE), SetMinimalSize(66, 50), EndContainer(),
    00984       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_X),  SetMinimalSize(66, 50), EndContainer(),
    00985       NWidget(NWID_SPACER), SetFill(1, 0),
    00986     EndContainer(),
    00987     NWidget(NWID_SPACER), SetMinimalSize(0, 2),
    00988     NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
    00989       NWidget(NWID_SPACER), SetFill(1, 0),
    00990       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_SW), SetMinimalSize(66, 50), EndContainer(),
    00991       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_SE), SetMinimalSize(66, 50), EndContainer(),
    00992       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_Y),  SetMinimalSize(66, 50), EndContainer(),
    00993       NWidget(NWID_SPACER), SetFill(1, 0),
    00994     EndContainer(),
    00995     NWidget(NWID_SPACER), SetMinimalSize(0, 1),
    00996     NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
    00997       NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BRSW_INFO), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
    00998       NWidget(NWID_SPACER), SetFill(1, 0),
    00999     EndContainer(),
    01000     NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
    01001       NWidget(NWID_SPACER), SetFill(1, 0),
    01002       NWidget(WWT_TEXTBTN, COLOUR_GREY, BRSW_LT_OFF), SetMinimalSize(60, 12),
    01003                       SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
    01004       NWidget(WWT_TEXTBTN, COLOUR_GREY, BRSW_LT_ON), SetMinimalSize(60, 12),
    01005                       SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
    01006       NWidget(NWID_SPACER), SetFill(1, 0),
    01007     EndContainer(),
    01008     NWidget(NWID_SPACER), SetMinimalSize(0, 10), SetResize(0, 1),
    01009   EndContainer(),
    01010 };
    01011
    01012 static const WindowDesc _rv_station_picker_desc(
    01013   WDP_AUTO, 0, 0,
    01014   WC_BUS_STATION, WC_BUILD_TOOLBAR,
    01015   WDF_CONSTRUCTION,
    01016   _nested_rv_station_picker_widgets, lengthof(_nested_rv_station_picker_widgets)
    01017 );
    01018
    01019 static void ShowRVStationPicker(Window *parent, RoadStopType rs)
    01020 {
    01021   new BuildRoadStationWindow(&_rv_station_picker_desc, parent, rs);
    01022 }
    01023
    01024 void InitializeRoadGui()
    01025 {
    01026   _road_depot_orientation = DIAGDIR_NW;
    01027   _road_station_picker_orientation = DIAGDIR_NW;
    01028 }