# dock_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: dock_gui.cpp 24900 2013-01-08 22:46:42Z planetmaker $ */
    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 "terraform_gui.h"
    00014 #include "window_gui.h"
    00015 #include "station_gui.h"
    00016 #include "command_func.h"
    00017 #include "water.h"
    00018 #include "window_func.h"
    00019 #include "vehicle_func.h"
    00020 #include "sound_func.h"
    00021 #include "viewport_func.h"
    00022 #include "gfx_func.h"
    00023 #include "company_func.h"
    00024 #include "slope_func.h"
    00025 #include "tilehighlight_func.h"
    00026 #include "company_base.h"
    00027 #include "hotkeys.h"
    00028
    00029 #include "widgets/dock_widget.h"
    00030
    00031 #include "table/sprites.h"
    00032 #include "table/strings.h"
    00033
    00034 static void ShowBuildDockStationPicker(Window *parent);
    00035 static void ShowBuildDocksDepotPicker(Window *parent);
    00036
    00037 static Axis _ship_depot_direction;
    00038
    00039 void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
    00040 {
    00041   if (result.Failed()) return;
    00042
    00043   if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT, tile);
    00044   if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
    00045 }
    00046
    00047 void CcBuildCanal(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
    00048 {
    00049   if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT, tile);
    00050 }
    00051
    00052
    00059 static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = NULL)
    00060 {
    00061   int z;
    00062   DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, &z));
    00063
    00064   /* If the direction isn't right, just return the next tile so the command
    00065    * complains about the wrong slope instead of the ends not matching up.
    00066    * Make sure the coordinate is always a valid tile within the map, so we
    00067    * don't go "off" the map. That would cause the wrong error message. */
    00068   if (!IsValidDiagDirection(dir)) return TILE_ADDXY(tile_from, TileX(tile_from) > 2 ? -1 : 1, 0);
    00069
    00070   /* Direction the aqueduct is built to. */
    00071   TileIndexDiff offset = TileOffsByDiagDir(ReverseDiagDir(dir));
    00072   /* The maximum length of the aqueduct. */
    00073   int max_length = min(_settings_game.construction.max_bridge_length, DistanceFromEdgeDir(tile_from, ReverseDiagDir(dir)) - 1);
    00074
    00075   TileIndex endtile = tile_from;
    00076   for (int length = 0; IsValidTile(endtile) && TileX(endtile) != 0 && TileY(endtile) != 0; length++) {
    00077     endtile = TILE_ADD(endtile, offset);
    00078
    00079     if (length > max_length) break;
    00080
    00081     if (GetTileMaxZ(endtile) > z) {
    00082       if (tile_to != NULL) *tile_to = endtile;
    00083       break;
    00084     }
    00085   }
    00086
    00087   return endtile;
    00088 }
    00089
    00091 struct BuildDocksToolbarWindow : Window {
    00092   DockToolbarWidgets last_clicked_widget;
    00093
    00094   BuildDocksToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
    00095   {
    00096     this->last_clicked_widget = WID_DT_INVALID;
    00097     this->InitNested(desc, window_number);
    00098     this->OnInvalidateData();
    00099     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
    00100   }
    00101
    00102   ~BuildDocksToolbarWindow()
    00103   {
    00104     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
    00105   }
    00106
    00112   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
    00113   {
    00114     if (!gui_scope) return;
    00115     this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP),
    00116       WID_DT_DEPOT,
    00117       WID_DT_STATION,
    00118       WID_DT_BUOY,
    00119       WIDGET_LIST_END);
    00120   }
    00121
    00122   virtual void OnClick(Point pt, int widget, int click_count)
    00123   {
    00124     switch (widget) {
    00125       case WID_DT_CANAL: // Build canal button
    00126         HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
    00127         break;
    00128
    00129       case WID_DT_LOCK: // Build lock button
    00130         HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
    00131         break;
    00132
    00133       case WID_DT_DEMOLISH: // Demolish aka dynamite button
    00134         HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
    00135         break;
    00136
    00137       case WID_DT_DEPOT: // Build depot button
    00138         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00139         if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
    00140         break;
    00141
    00142       case WID_DT_STATION: // Build station button
    00143         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00144         if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
    00145         break;
    00146
    00147       case WID_DT_BUOY: // Build buoy button
    00148         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00149         HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
    00150         break;
    00151
    00152       case WID_DT_RIVER: // Build river button (in scenario editor)
    00153         if (_game_mode != GM_EDITOR) return;
    00154         HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT);
    00155         break;
    00156
    00157       case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
    00158         HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
    00159         break;
    00160
    00161       default: return;
    00162     }
    00163     this->last_clicked_widget = (DockToolbarWidgets)widget;
    00164   }
    00165
    00166   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00167   {
    00168     int num = CheckHotkeyMatch(dockstoolbar_hotkeys, keycode, this);
    00169     if (num == -1) return ES_NOT_HANDLED;
    00170     this->OnClick(Point(), num, 1);
    00171     return ES_HANDLED;
    00172   }
    00173
    00174   virtual void OnPlaceObject(Point pt, TileIndex tile)
    00175   {
    00176     switch (this->last_clicked_widget) {
    00177       case WID_DT_CANAL: // Build canal button
    00178         VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
    00179         break;
    00180
    00181       case WID_DT_LOCK: // Build lock button
    00182         DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
    00183         break;
    00184
    00185       case WID_DT_DEMOLISH: // Demolish aka dynamite button
    00186         PlaceProc_DemolishArea(tile);
    00187         break;
    00188
    00189       case WID_DT_DEPOT: // Build depot button
    00190         DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
    00191         break;
    00192
    00193       case WID_DT_STATION: { // Build station button
    00194         uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
    00195
    00196         /* tile is always the land tile, so need to evaluate _thd.pos */
    00197         CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
    00198
    00199         /* Determine the watery part of the dock. */
    00200         DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
    00201         TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
    00202
    00203         ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
    00204         break;
    00205       }
    00206
    00207       case WID_DT_BUOY: // Build buoy button
    00208         DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
    00209         break;
    00210
    00211       case WID_DT_RIVER: // Build river button (in scenario editor)
    00212         VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
    00213         break;
    00214
    00215       case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
    00216         DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
    00217         break;
    00218
    00219       default: NOT_REACHED();
    00220     }
    00221   }
    00222
    00223   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
    00224   {
    00225     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
    00226   }
    00227
    00228   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
    00229   {
    00230     if (pt.x != -1) {
    00231       switch (select_proc) {
    00232         case DDSP_DEMOLISH_AREA:
    00233           GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
    00234           break;
    00235         case DDSP_CREATE_WATER:
    00236           DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR && _ctrl_pressed) ? WATER_CLASS_SEA : WATER_CLASS_CANAL, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_BUILD_CANALS), CcBuildCanal);
    00237           break;
    00238         case DDSP_CREATE_RIVER:
    00239           DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal);
    00240           break;
    00241
    00242         default: break;
    00243       }
    00244     }
    00245   }
    00246
    00247   virtual void OnPlaceObjectAbort()
    00248   {
    00249     this->RaiseButtons();
    00250
    00251     DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
    00252     DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
    00253     DeleteWindowById(WC_SELECT_STATION, 0);
    00254     DeleteWindowByClass(WC_BUILD_BRIDGE);
    00255   }
    00256
    00257   virtual void OnPlacePresize(Point pt, TileIndex tile_from)
    00258   {
    00259     TileIndex tile_to = tile_from;
    00260
    00261     if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
    00262       GetOtherAqueductEnd(tile_from, &tile_to);
    00263     } else {
    00264       DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
    00265       if (IsValidDiagDirection(dir)) {
    00266         /* Locks and docks always select the tile "down" the slope. */
    00267         tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
    00268         /* Locks also select the tile "up" the slope. */
    00269         if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
    00270       }
    00271     }
    00272
    00273     VpSetPresizeRange(tile_from, tile_to);
    00274   }
    00275
    00276   static Hotkey<BuildDocksToolbarWindow> dockstoolbar_hotkeys[];
    00277 };
    00278
    00279 const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
    00280
    00281 Hotkey<BuildDocksToolbarWindow> BuildDocksToolbarWindow::dockstoolbar_hotkeys[] = {
    00282   Hotkey<BuildDocksToolbarWindow>('1', "canal", WID_DT_CANAL),
    00283   Hotkey<BuildDocksToolbarWindow>('2', "lock", WID_DT_LOCK),
    00284   Hotkey<BuildDocksToolbarWindow>('3', "demolish", WID_DT_DEMOLISH),
    00285   Hotkey<BuildDocksToolbarWindow>('4', "depot", WID_DT_DEPOT),
    00286   Hotkey<BuildDocksToolbarWindow>('5', "dock", WID_DT_STATION),
    00287   Hotkey<BuildDocksToolbarWindow>('6', "buoy", WID_DT_BUOY),
    00288   Hotkey<BuildDocksToolbarWindow>('7', "river", WID_DT_RIVER),
    00289   Hotkey<BuildDocksToolbarWindow>(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
    00290   HOTKEY_LIST_END(BuildDocksToolbarWindow)
    00291 };
    00292 Hotkey<BuildDocksToolbarWindow> *_dockstoolbar_hotkeys = BuildDocksToolbarWindow::dockstoolbar_hotkeys;
    00293
    00298 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
    00299   NWidget(NWID_HORIZONTAL),
    00300     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00301     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00302     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00303   EndContainer(),
    00304   NWidget(NWID_HORIZONTAL_LTR),
    00305     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_BUILD_CANALS_TOOLTIP),
    00306     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
    00307     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
    00308     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00309     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEPOT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIP_DEPOT, STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP),
    00310     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_STATION), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIP_DOCK, STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP),
    00311     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
    00312     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUILD_AQUEDUCT), SetMinimalSize(23, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
    00313   EndContainer(),
    00314 };
    00315
    00316 static const WindowDesc _build_docks_toolbar_desc(
    00317   WDP_ALIGN_TOOLBAR, 0, 0,
    00318   WC_BUILD_TOOLBAR, WC_NONE,
    00319   WDF_CONSTRUCTION,
    00320   _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets)
    00321 );
    00322
    00330 Window *ShowBuildDocksToolbar()
    00331 {
    00332   if (!Company::IsValidID(_local_company)) return NULL;
    00333
    00334   DeleteWindowByClass(WC_BUILD_TOOLBAR);
    00335   return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
    00336 }
    00337
    00338 EventState DockToolbarGlobalHotkeys(uint16 key, uint16 keycode)
    00339 {
    00340   int num = CheckHotkeyMatch<BuildDocksToolbarWindow>(_dockstoolbar_hotkeys, keycode, NULL, true);
    00341   if (num == -1) return ES_NOT_HANDLED;
    00342   Window *w = ShowBuildDocksToolbar();
    00343   if (w == NULL) return ES_NOT_HANDLED;
    00344   return w->OnKeyPress(key, keycode);
    00345 }
    00346
    00351 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
    00352   NWidget(NWID_HORIZONTAL),
    00353     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00354     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00355     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00356   EndContainer(),
    00357   NWidget(NWID_HORIZONTAL),
    00358     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_CREATE_LAKE_TOOLTIP),
    00359     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
    00360     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
    00361     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00362     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_RIVER), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_RIVER, STR_WATERWAYS_TOOLBAR_CREATE_RIVER_TOOLTIP),
    00363     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUILD_AQUEDUCT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
    00364   EndContainer(),
    00365 };
    00366
    00368 static const WindowDesc _build_docks_scen_toolbar_desc(
    00369   WDP_AUTO, 0, 0,
    00370   WC_SCEN_BUILD_TOOLBAR, WC_NONE,
    00371   WDF_CONSTRUCTION,
    00372   _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets)
    00373 );
    00374
    00380 Window *ShowBuildDocksScenToolbar()
    00381 {
    00382   return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
    00383 }
    00384
    00386 enum BuildDockStationWidgets {
    00387   BDSW_BACKGROUND,
    00388   BDSW_LT_OFF,
    00389   BDSW_LT_ON,
    00390   BDSW_INFO,
    00391 };
    00392
    00393 struct BuildDocksStationWindow : public PickerWindowBase {
    00394 public:
    00395   BuildDocksStationWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
    00396   {
    00397     this->InitNested(desc, TRANSPORT_WATER);
    00398     this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
    00399   }
    00400
    00401   virtual ~BuildDocksStationWindow()
    00402   {
    00403     DeleteWindowById(WC_SELECT_STATION, 0);
    00404   }
    00405
    00406   virtual void OnPaint()
    00407   {
    00408     int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
    00409
    00410     this->DrawWidgets();
    00411
    00412     if (_settings_client.gui.station_show_coverage) {
    00413       SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
    00414     } else {
    00415       SetTileSelectSize(1, 1);
    00416     }
    00417
    00418     /* strings such as 'Size' and 'Coverage Area' */
    00419     int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
    00420     NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
    00421     int right  = back_nwi->pos_x + back_nwi->current_x;
    00422     int bottom = back_nwi->pos_y + back_nwi->current_y;
    00423     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
    00424     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
    00425     /* Resize background if the text is not equally long as the window. */
    00426     if (top > bottom || (top < bottom && back_nwi->current_y > back_nwi->smallest_y)) {
    00427       ResizeWindow(this, 0, top - bottom);
    00428     }
    00429   }
    00430
    00431   virtual void OnClick(Point pt, int widget, int click_count)
    00432   {
    00433     switch (widget) {
    00434       case BDSW_LT_OFF:
    00435       case BDSW_LT_ON:
    00436         this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
    00437         _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
    00438         this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
    00439         if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
    00440         this->SetDirty();
    00441         break;
    00442     }
    00443   }
    00444
    00445   virtual void OnTick()
    00446   {
    00447     CheckRedrawStationCoverage(this);
    00448   }
    00449 };
    00450
    00452 static const NWidgetPart _nested_build_dock_station_widgets[] = {
    00453   NWidget(NWID_HORIZONTAL),
    00454     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00455     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00456   EndContainer(),
    00457   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
    00458     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00459     NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetMinimalSize(148, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
    00460     NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14),
    00461       NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_OFF), SetMinimalSize(40, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
    00462       NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_ON), SetMinimalSize(40, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
    00463     EndContainer(),
    00464     NWidget(NWID_SPACER), SetMinimalSize(0, 20), SetResize(0, 1),
    00465   EndContainer(),
    00466 };
    00467
    00468 static const WindowDesc _build_dock_station_desc(
    00469   WDP_AUTO, 0, 0,
    00470   WC_BUILD_STATION, WC_BUILD_TOOLBAR,
    00471   WDF_CONSTRUCTION,
    00472   _nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
    00473 );
    00474
    00475 static void ShowBuildDockStationPicker(Window *parent)
    00476 {
    00477   new BuildDocksStationWindow(&_build_dock_station_desc, parent);
    00478 }
    00479
    00480 struct BuildDocksDepotWindow : public PickerWindowBase {
    00481 private:
    00482   static void UpdateDocksDirection()
    00483   {
    00484     if (_ship_depot_direction != AXIS_X) {
    00485       SetTileSelectSize(1, 2);
    00486     } else {
    00487       SetTileSelectSize(2, 1);
    00488     }
    00489   }
    00490
    00491 public:
    00492   BuildDocksDepotWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
    00493   {
    00494     this->InitNested(desc, TRANSPORT_WATER);
    00495     this->LowerWidget(_ship_depot_direction + WID_BDD_X);
    00496     UpdateDocksDirection();
    00497   }
    00498
    00499   virtual void OnPaint()
    00500   {
    00501     this->DrawWidgets();
    00502
    00503     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + 64, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + 18, AXIS_X, DEPOT_PART_NORTH);
    00504     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + 32, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + 34, AXIS_X, DEPOT_PART_SOUTH);
    00505     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + 32, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + 18, AXIS_Y, DEPOT_PART_NORTH);
    00506     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + 64, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + 34, AXIS_Y, DEPOT_PART_SOUTH);
    00507   }
    00508
    00509   virtual void OnClick(Point pt, int widget, int click_count)
    00510   {
    00511     switch (widget) {
    00512       case WID_BDD_X:
    00513       case WID_BDD_Y:
    00514         this->RaiseWidget(_ship_depot_direction + WID_BDD_X);
    00515         _ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
    00516         this->LowerWidget(_ship_depot_direction + WID_BDD_X);
    00517         if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
    00518         UpdateDocksDirection();
    00519         this->SetDirty();
    00520         break;
    00521     }
    00522   }
    00523 };
    00524
    00525 static const NWidgetPart _nested_build_docks_depot_widgets[] = {
    00526   NWidget(NWID_HORIZONTAL),
    00527     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00528     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00529   EndContainer(),
    00530   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
    00531     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00532     NWidget(NWID_HORIZONTAL_LTR),
    00533       NWidget(NWID_SPACER), SetMinimalSize(3, 0),
    00534       NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
    00535       EndContainer(),
    00536       NWidget(NWID_SPACER), SetMinimalSize(2, 0),
    00537       NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
    00538       EndContainer(),
    00539       NWidget(NWID_SPACER), SetMinimalSize(3, 0),
    00540     EndContainer(),
    00541     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00542   EndContainer(),
    00543 };
    00544
    00545 static const WindowDesc _build_docks_depot_desc(
    00546   WDP_AUTO, 0, 0,
    00547   WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
    00548   WDF_CONSTRUCTION,
    00549   _nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
    00550 );
    00551
    00552
    00553 static void ShowBuildDocksDepotPicker(Window *parent)
    00554 {
    00555   new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
    00556 }
    00557
    00558
    00559 void InitializeDockGui()
    00560 {
    00561   _ship_depot_direction = AXIS_X;
    00562 }