# road_gui.cpp

Go to the documentation of this file.

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