# road_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: road_gui.cpp 19665 2010-04-17 22:27:49Z 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->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
    00417       RTW_DEPOT,
    00418       RTW_BUS_STATION,
    00419       RTW_TRUCK_STATION,
    00420       WIDGET_LIST_END);
    00421
    00422     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
    00423   }
    00424
    00425   ~BuildRoadToolbarWindow()
    00426   {
    00427     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
    00428   }
    00429
    00435   void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
    00436   {
    00437     /* The remove and the one way button state is driven
    00438      * by the other buttons so they don't act on themselfs.
    00439      * Both are only valid if they are able to apply as options. */
    00440     switch (clicked_widget) {
    00441       case RTW_REMOVE:
    00442         this->RaiseWidget(RTW_ONE_WAY);
    00443         this->SetWidgetDirty(RTW_ONE_WAY);
    00444         break;
    00445
    00446       case RTW_ONE_WAY:
    00447         this->RaiseWidget(RTW_REMOVE);
    00448         this->SetWidgetDirty(RTW_REMOVE);
    00449         break;
    00450
    00451       case RTW_BUS_STATION:
    00452       case RTW_TRUCK_STATION:
    00453         this->DisableWidget(RTW_ONE_WAY);
    00454         this->SetWidgetDisabledState(RTW_REMOVE, !this->IsWidgetLowered(clicked_widget));
    00455         break;
    00456
    00457       case RTW_ROAD_X:
    00458       case RTW_ROAD_Y:
    00459       case RTW_AUTOROAD:
    00460         this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
    00461           RTW_REMOVE,
    00462           RTW_ONE_WAY,
    00463           WIDGET_LIST_END);
    00464         break;
    00465
    00466       default:
    00467         /* When any other buttons than road/station, raise and
    00468          * disable the removal button */
    00469         this->SetWidgetsDisabledState(true,
    00470           RTW_REMOVE,
    00471           RTW_ONE_WAY,
    00472           WIDGET_LIST_END);
    00473         this->SetWidgetsLoweredState(false,
    00474           RTW_REMOVE,
    00475           RTW_ONE_WAY,
    00476           WIDGET_LIST_END);
    00477         break;
    00478     }
    00479   }
    00480
    00481   virtual void OnPaint()
    00482   {
    00483     this->DrawWidgets();
    00484   }
    00485
    00486   virtual void OnClick(Point pt, int widget, int click_count)
    00487   {
    00488     if (widget >= RTW_ROAD_X) {
    00489       _remove_button_clicked = false;
    00490       _one_way_button_clicked = false;
    00491       _build_road_button_proc[widget - RTW_ROAD_X](this);
    00492     }
    00493     this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget);
    00494     if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
    00495   }
    00496
    00497   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00498   {
    00499     EventState state = ES_NOT_HANDLED;
    00500     for (uint i = 0; i != lengthof(_road_keycodes); i++) {
    00501       if (keycode == _road_keycodes[i]) {
    00502         _remove_button_clicked = false;
    00503         _one_way_button_clicked = false;
    00504         _build_road_button_proc[i](this);
    00505         this->UpdateOptionWidgetStatus((RoadToolbarWidgets)(i + RTW_ROAD_X));
    00506         if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
    00507         state = ES_HANDLED;
    00508         break;
    00509       }
    00510     }
    00511     MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
    00512     return state;
    00513   }
    00514
    00515   virtual void OnPlaceObject(Point pt, TileIndex tile)
    00516   {
    00517     _remove_button_clicked = this->IsWidgetLowered(RTW_REMOVE);
    00518     _one_way_button_clicked = this->IsWidgetLowered(RTW_ONE_WAY);
    00519     _place_proc(tile);
    00520   }
    00521
    00522   virtual void OnPlaceObjectAbort()
    00523   {
    00524     this->RaiseButtons();
    00525     this->SetWidgetsDisabledState(true,
    00526       RTW_REMOVE,
    00527       RTW_ONE_WAY,
    00528       WIDGET_LIST_END);
    00529     this->SetWidgetDirty(RTW_REMOVE);
    00530     this->SetWidgetDirty(RTW_ONE_WAY);
    00531
    00532     DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD);
    00533     DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD);
    00534     DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD);
    00535     DeleteWindowById(WC_SELECT_STATION, 0);
    00536     DeleteWindowByClass(WC_BUILD_BRIDGE);
    00537   }
    00538
    00539   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
    00540   {
    00541     /* Here we update the end tile flags
    00542      * of the road placement actions.
    00543      * At first we reset the end halfroad
    00544      * bits and if needed we set them again. */
    00545     switch (select_proc) {
    00546       case DDSP_PLACE_ROAD_X_DIR:
    00547         _place_road_flag &= ~RF_END_HALFROAD_X;
    00548         if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
    00549         break;
    00550
    00551       case DDSP_PLACE_ROAD_Y_DIR:
    00552         _place_road_flag &= ~RF_END_HALFROAD_Y;
    00553         if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
    00554         break;
    00555
    00556       case DDSP_PLACE_AUTOROAD:
    00557         _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
    00558         if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
    00559         if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
    00560
    00561         /* For autoroad we need to update the
    00562          * direction of the road */
    00563         if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
    00564             ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
    00565             (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
    00566           /* Set dir = X */
    00567           _place_road_flag &= ~RF_DIR_Y;
    00568         } else {
    00569           /* Set dir = Y */
    00570           _place_road_flag |= RF_DIR_Y;
    00571         }
    00572
    00573         break;
    00574
    00575       default:
    00576         break;
    00577     }
    00578
    00579     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
    00580   }
    00581
    00582   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
    00583   {
    00584     if (pt.x != -1) {
    00585       switch (select_proc) {
    00586         default: NOT_REACHED();
    00587         case DDSP_BUILD_BRIDGE:
    00588           if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00589           ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
    00590           break;
    00591
    00592         case DDSP_DEMOLISH_AREA:
    00593           GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
    00594           break;
    00595
    00596         case DDSP_PLACE_ROAD_X_DIR:
    00597         case DDSP_PLACE_ROAD_Y_DIR:
    00598         case DDSP_PLACE_AUTOROAD:
    00599           /* Flag description:
    00600            * Use the first three bits (0x07) if dir == Y
    00601            * else use the last 2 bits (X dir has
    00602            * not the 3rd bit set) */
    00603           _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
    00604
    00605           DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
    00606             _remove_button_clicked ?
    00607             CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
    00608             CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
    00609           break;
    00610       }
    00611     }
    00612   }
    00613
    00614   virtual void OnPlacePresize(Point pt, TileIndex tile)
    00615   {
    00616     DoCommand(tile, RoadTypeToRoadTypes(_cur_roadtype) | (TRANSPORT_ROAD << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL);
    00617     VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
    00618   }
    00619
    00620   virtual EventState OnCTRLStateChange()
    00621   {
    00622     if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
    00623     return ES_NOT_HANDLED;
    00624   }
    00625 };
    00626
    00627 static const NWidgetPart _nested_build_road_widgets[] = {
    00628   NWidget(NWID_HORIZONTAL),
    00629     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00630     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00631     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00632   EndContainer(),
    00633   NWidget(NWID_HORIZONTAL),
    00634     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_X),
    00635             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00636     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_Y),
    00637             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00638     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_AUTOROAD),
    00639             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
    00640     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEMOLISH),
    00641             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00642     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEPOT),
    00643             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
    00644     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUS_STATION),
    00645             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
    00646     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_TRUCK_STATION),
    00647             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
    00648     NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
    00649     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ONE_WAY),
    00650             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
    00651     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_BRIDGE),
    00652             SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
    00653     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_TUNNEL),
    00654             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
    00655     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_REMOVE),
    00656             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
    00657   EndContainer(),
    00658 };
    00659
    00660 static const WindowDesc _build_road_desc(
    00661   WDP_ALIGN_TOOLBAR, 0, 0,
    00662   WC_BUILD_TOOLBAR, WC_NONE,
    00663   WDF_CONSTRUCTION,
    00664   _nested_build_road_widgets, lengthof(_nested_build_road_widgets)
    00665 );
    00666
    00667 static const NWidgetPart _nested_build_tramway_widgets[] = {
    00668   NWidget(NWID_HORIZONTAL),
    00669     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00670     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_TRAM_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00671     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00672   EndContainer(),
    00673   NWidget(NWID_HORIZONTAL),
    00674     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_X),
    00675             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
    00676     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_Y),
    00677             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
    00678     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_AUTOROAD),
    00679             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
    00680     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEMOLISH),
    00681             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00682     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEPOT),
    00683             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
    00684     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUS_STATION),
    00685             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
    00686     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_TRUCK_STATION),
    00687             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
    00688     NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
    00689     NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, RTW_ONE_WAY), SetMinimalSize(0, 0),
    00690     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_BRIDGE),
    00691             SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
    00692     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_TUNNEL),
    00693             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
    00694     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_REMOVE),
    00695             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
    00696   EndContainer(),
    00697 };
    00698
    00699 static const WindowDesc _build_tramway_desc(
    00700   WDP_ALIGN_TOOLBAR, 0, 0,
    00701   WC_BUILD_TOOLBAR, WC_NONE,
    00702   WDF_CONSTRUCTION,
    00703   _nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets)
    00704 );
    00705
    00706 void ShowBuildRoadToolbar(RoadType roadtype)
    00707 {
    00708   if (!Company::IsValidID(_local_company)) return;
    00709   _cur_roadtype = roadtype;
    00710
    00711   DeleteWindowByClass(WC_BUILD_TOOLBAR);
    00712   AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
    00713 }
    00714
    00715 static const NWidgetPart _nested_build_road_scen_widgets[] = {
    00716   NWidget(NWID_HORIZONTAL),
    00717     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00718     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00719     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00720   EndContainer(),
    00721   NWidget(NWID_HORIZONTAL),
    00722     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_X),
    00723             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00724     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ROAD_Y),
    00725             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
    00726     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_AUTOROAD),
    00727             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
    00728     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_DEMOLISH),
    00729             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00730     NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
    00731     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_ONE_WAY),
    00732             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
    00733     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_BRIDGE),
    00734             SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
    00735     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_BUILD_TUNNEL),
    00736             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
    00737     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, RTW_REMOVE),
    00738             SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
    00739   EndContainer(),
    00740 };
    00741
    00742 static const WindowDesc _build_road_scen_desc(
    00743   WDP_AUTO, 0, 0,
    00744   WC_SCEN_BUILD_TOOLBAR, WC_NONE,
    00745   WDF_CONSTRUCTION,
    00746   _nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets)
    00747 );
    00748
    00749 void ShowBuildRoadScenToolbar()
    00750 {
    00751   _cur_roadtype = ROADTYPE_ROAD;
    00752   AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, 0);
    00753 }
    00754
    00756 enum BuildRoadDepotWidgets {
    00757   BRDW_CAPTION,
    00758   BRDW_DEPOT_NE,
    00759   BRDW_DEPOT_SE,
    00760   BRDW_DEPOT_SW,
    00761   BRDW_DEPOT_NW,
    00762 };
    00763
    00764 struct BuildRoadDepotWindow : public PickerWindowBase {
    00765   BuildRoadDepotWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
    00766   {
    00767     this->CreateNestedTree(desc);
    00768
    00769     this->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00770     if ( _cur_roadtype == ROADTYPE_TRAM) {
    00771       this->GetWidget<NWidgetCore>(BRDW_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION;
    00772       for (int i = BRDW_DEPOT_NE; i <= BRDW_DEPOT_NW; i++) this->GetWidget<NWidgetCore>(i)->tool_tip = STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP;
    00773     }
    00774
    00775     this->FinishInitNested(desc, TRANSPORT_ROAD);
    00776   }
    00777
    00778   virtual void OnPaint()
    00779   {
    00780     this->DrawWidgets();
    00781   }
    00782
    00783   virtual void DrawWidget(const Rect &r, int widget) const
    00784   {
    00785     if (!IsInsideMM(widget, BRDW_DEPOT_NE, BRDW_DEPOT_NW + 1)) return;
    00786
    00787     DrawRoadDepotSprite(r.left - 1, r.top, (DiagDirection)(widget - BRDW_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
    00788   }
    00789
    00790   virtual void OnClick(Point pt, int widget, int click_count)
    00791   {
    00792     switch (widget) {
    00793       case BRDW_DEPOT_NW:
    00794       case BRDW_DEPOT_NE:
    00795       case BRDW_DEPOT_SW:
    00796       case BRDW_DEPOT_SE:
    00797         this->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00798         _road_depot_orientation = (DiagDirection)(widget - BRDW_DEPOT_NE);
    00799         this->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
    00800         SndPlayFx(SND_15_BEEP);
    00801         this->SetDirty();
    00802         break;
    00803
    00804       default:
    00805         break;
    00806     }
    00807   }
    00808 };
    00809
    00810 static const NWidgetPart _nested_build_road_depot_widgets[] = {
    00811   NWidget(NWID_HORIZONTAL),
    00812     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00813     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, BRDW_CAPTION), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00814   EndContainer(),
    00815   NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
    00816     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00817     NWidget(NWID_HORIZONTAL_LTR),
    00818       NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
    00819       NWidget(NWID_VERTICAL),
    00820         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00821         EndContainer(),
    00822         NWidget(NWID_SPACER), SetMinimalSize(0, 2),
    00823         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00824         EndContainer(),
    00825       EndContainer(),
    00826       NWidget(NWID_SPACER), SetMinimalSize(2, 0),
    00827       NWidget(NWID_VERTICAL),
    00828         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00829         EndContainer(),
    00830         NWidget(NWID_SPACER), SetMinimalSize(0, 2),
    00831         NWidget(WWT_PANEL, COLOUR_GREY, BRDW_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
    00832         EndContainer(),
    00833       EndContainer(),
    00834       NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
    00835     EndContainer(),
    00836     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00837   EndContainer(),
    00838 };
    00839
    00840 static const WindowDesc _build_road_depot_desc(
    00841   WDP_AUTO, 0, 0,
    00842   WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
    00843   WDF_CONSTRUCTION,
    00844   _nested_build_road_depot_widgets, lengthof(_nested_build_road_depot_widgets)
    00845 );
    00846
    00847 static void ShowRoadDepotPicker(Window *parent)
    00848 {
    00849   new BuildRoadDepotWindow(&_build_road_depot_desc, parent);
    00850 }
    00851
    00853 enum BuildRoadStationWidgets {
    00854   BRSW_CAPTION,
    00855   BRSW_BACKGROUND,
    00856   BRSW_STATION_NE,
    00857   BRSW_STATION_SE,
    00858   BRSW_STATION_SW,
    00859   BRSW_STATION_NW,
    00860   BRSW_STATION_X,
    00861   BRSW_STATION_Y,
    00862   BRSW_LT_OFF,
    00863   BRSW_LT_ON,
    00864   BRSW_INFO,
    00865 };
    00866
    00867 struct BuildRoadStationWindow : public PickerWindowBase {
    00868   BuildRoadStationWindow(const WindowDesc *desc, Window *parent, RoadStopType rs) : PickerWindowBase(parent)
    00869   {
    00870     this->CreateNestedTree(desc);
    00871
    00872     /* Trams don't have non-drivethrough stations */
    00873     if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) {
    00874       _road_station_picker_orientation = DIAGDIR_END;
    00875     }
    00876     this->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM,
    00877       BRSW_STATION_NE,
    00878       BRSW_STATION_SE,
    00879       BRSW_STATION_SW,
    00880       BRSW_STATION_NW,
    00881       WIDGET_LIST_END);
    00882
    00883     this->GetWidget<NWidgetCore>(BRSW_CAPTION)->widget_data = _road_type_infos[_cur_roadtype].picker_title[rs];
    00884     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];
    00885
    00886     this->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00887     this->LowerWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00888
    00889     this->FinishInitNested(desc, TRANSPORT_ROAD);
    00890
    00891     this->window_class = (rs == ROADSTOP_BUS) ? WC_BUS_STATION : WC_TRUCK_STATION;
    00892   }
    00893
    00894   virtual ~BuildRoadStationWindow()
    00895   {
    00896     DeleteWindowById(WC_SELECT_STATION, 0);
    00897   }
    00898
    00899   virtual void OnPaint()
    00900   {
    00901     this->DrawWidgets();
    00902
    00903     int rad = _settings_game.station.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED;
    00904     if (_settings_client.gui.station_show_coverage) {
    00905       SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
    00906     } else {
    00907       SetTileSelectSize(1, 1);
    00908     }
    00909
    00910     /* 'Accepts' and 'Supplies' texts. */
    00911     StationCoverageType sct = (this->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY;
    00912     int top = this->GetWidget<NWidgetBase>(BRSW_LT_ON)->pos_y + this->GetWidget<NWidgetBase>(BRSW_LT_ON)->current_y + WD_PAR_VSEP_NORMAL;
    00913     NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BRSW_BACKGROUND);
    00914     int right = back_nwi->pos_x +  back_nwi->current_x;
    00915     int bottom = back_nwi->pos_y +  back_nwi->current_y;
    00916     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, false) + WD_PAR_VSEP_NORMAL;
    00917     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, true) + WD_PAR_VSEP_NORMAL;
    00918     /* Resize background if the text is not equally long as the window. */
    00919     if (top > bottom || (top < bottom && back_nwi->current_y > back_nwi->smallest_y)) {
    00920       ResizeWindow(this, 0, top - bottom);
    00921     }
    00922   }
    00923
    00924   virtual void DrawWidget(const Rect &r, int widget) const
    00925   {
    00926     if (!IsInsideMM(widget, BRSW_STATION_NE, BRSW_STATION_Y + 1)) return;
    00927
    00928     StationType st = (this->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
    00929     StationPickerDrawSprite(r.left + TILE_PIXELS, r.bottom - TILE_PIXELS, st, INVALID_RAILTYPE, widget < BRSW_STATION_X ? ROADTYPE_ROAD : _cur_roadtype, widget - BRSW_STATION_NE);
    00930   }
    00931
    00932   virtual void OnClick(Point pt, int widget, int click_count)
    00933   {
    00934     switch (widget) {
    00935       case BRSW_STATION_NE:
    00936       case BRSW_STATION_SE:
    00937       case BRSW_STATION_SW:
    00938       case BRSW_STATION_NW:
    00939       case BRSW_STATION_X:
    00940       case BRSW_STATION_Y:
    00941         this->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00942         _road_station_picker_orientation = (DiagDirection)(widget - BRSW_STATION_NE);
    00943         this->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
    00944         SndPlayFx(SND_15_BEEP);
    00945         this->SetDirty();
    00946         DeleteWindowById(WC_SELECT_STATION, 0);
    00947         break;
    00948
    00949       case BRSW_LT_OFF:
    00950       case BRSW_LT_ON:
    00951         this->RaiseWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00952         _settings_client.gui.station_show_coverage = (widget != BRSW_LT_OFF);
    00953         this->LowerWidget(_settings_client.gui.station_show_coverage + BRSW_LT_OFF);
    00954         SndPlayFx(SND_15_BEEP);
    00955         this->SetDirty();
    00956         break;
    00957
    00958       default:
    00959         break;
    00960     }
    00961   }
    00962
    00963   virtual void OnTick()
    00964   {
    00965     CheckRedrawStationCoverage(this);
    00966   }
    00967 };
    00968
    00970 static const NWidgetPart _nested_rv_station_picker_widgets[] = {
    00971   NWidget(NWID_HORIZONTAL),
    00972     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00973     NWidget(WWT_CAPTION,  COLOUR_DARK_GREEN, BRSW_CAPTION),
    00974   EndContainer(),
    00975   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BRSW_BACKGROUND),
    00976     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00977     NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
    00978       NWidget(NWID_SPACER), SetFill(1, 0),
    00979       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_NW), SetMinimalSize(66, 50), EndContainer(),
    00980       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_NE), SetMinimalSize(66, 50), EndContainer(),
    00981       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_X),  SetMinimalSize(66, 50), EndContainer(),
    00982       NWidget(NWID_SPACER), SetFill(1, 0),
    00983     EndContainer(),
    00984     NWidget(NWID_SPACER), SetMinimalSize(0, 2),
    00985     NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
    00986       NWidget(NWID_SPACER), SetFill(1, 0),
    00987       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_SW), SetMinimalSize(66, 50), EndContainer(),
    00988       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_SE), SetMinimalSize(66, 50), EndContainer(),
    00989       NWidget(WWT_PANEL, COLOUR_GREY, BRSW_STATION_Y),  SetMinimalSize(66, 50), EndContainer(),
    00990       NWidget(NWID_SPACER), SetFill(1, 0),
    00991     EndContainer(),
    00992     NWidget(NWID_SPACER), SetMinimalSize(0, 1),
    00993     NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
    00994       NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BRSW_INFO), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
    00995       NWidget(NWID_SPACER), SetFill(1, 0),
    00996     EndContainer(),
    00997     NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
    00998       NWidget(NWID_SPACER), SetFill(1, 0),
    00999       NWidget(WWT_TEXTBTN, COLOUR_GREY, BRSW_LT_OFF), SetMinimalSize(60, 12),
    01000                       SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
    01001       NWidget(WWT_TEXTBTN, COLOUR_GREY, BRSW_LT_ON), SetMinimalSize(60, 12),
    01002                       SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
    01003       NWidget(NWID_SPACER), SetFill(1, 0),
    01004     EndContainer(),
    01005     NWidget(NWID_SPACER), SetMinimalSize(0, 10), SetResize(0, 1),
    01006   EndContainer(),
    01007 };
    01008
    01009 static const WindowDesc _rv_station_picker_desc(
    01010   WDP_AUTO, 0, 0,
    01011   WC_BUS_STATION, WC_BUILD_TOOLBAR,
    01012   WDF_CONSTRUCTION,
    01013   _nested_rv_station_picker_widgets, lengthof(_nested_rv_station_picker_widgets)
    01014 );
    01015
    01016 static void ShowRVStationPicker(Window *parent, RoadStopType rs)
    01017 {
    01018   new BuildRoadStationWindow(&_rv_station_picker_desc, parent, rs);
    01019 }
    01020
    01021 void InitializeRoadGui()
    01022 {
    01023   _road_depot_orientation = DIAGDIR_NW;
    01024   _road_station_picker_orientation = DIAGDIR_NW;
    01025 }