# dock_gui.cpp

Go to the documentation of this file.

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