# dock_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: dock_gui.cpp 21959 2011-02-04 15:37:23Z 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 "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
    00122   void OnInvalidateData(int data = 0)
    00123   {
    00124     this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP),
    00125       DTW_DEPOT,
    00126       DTW_STATION,
    00127       DTW_BUOY,
    00128       WIDGET_LIST_END);
    00129   }
    00130
    00131   virtual void OnClick(Point pt, int widget, int click_count)
    00132   {
    00133     this->last_clicked_widget = (DockToolbarWidgets)widget;
    00134     switch (widget) {
    00135       case DTW_CANAL: // Build canal button
    00136         HandlePlacePushButton(this, DTW_CANAL, SPR_CURSOR_CANAL, HT_RECT);
    00137         break;
    00138
    00139       case DTW_LOCK: // Build lock button
    00140         HandlePlacePushButton(this, DTW_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
    00141         break;
    00142
    00143       case DTW_DEMOLISH: // Demolish aka dynamite button
    00144         HandlePlacePushButton(this, DTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
    00145         break;
    00146
    00147       case DTW_DEPOT: // Build depot button
    00148         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00149         if (HandlePlacePushButton(this, DTW_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
    00150         break;
    00151
    00152       case DTW_STATION: // Build station button
    00153         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00154         if (HandlePlacePushButton(this, DTW_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
    00155         break;
    00156
    00157       case DTW_BUOY: // Build buoy button
    00158         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00159         HandlePlacePushButton(this, DTW_BUOY, SPR_CURSOR_BUOY, HT_RECT);
    00160         break;
    00161
    00162       case DTW_RIVER: // Build river button (in scenario editor)
    00163         if (_game_mode != GM_EDITOR) return;
    00164         HandlePlacePushButton(this, DTW_RIVER, SPR_CURSOR_RIVER, HT_RECT);
    00165         break;
    00166
    00167       case DTW_BUILD_AQUEDUCT: // Build aqueduct button
    00168         HandlePlacePushButton(this, DTW_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
    00169         break;
    00170
    00171       default: break;
    00172     }
    00173   }
    00174
    00175   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00176   {
    00177     int num = CheckHotkeyMatch(dockstoolbar_hotkeys, keycode, this);
    00178     if (num == -1) return ES_NOT_HANDLED;
    00179     this->OnClick(Point(), num, 1);
    00180     return ES_HANDLED;
    00181   }
    00182
    00183   virtual void OnPlaceObject(Point pt, TileIndex tile)
    00184   {
    00185     switch (this->last_clicked_widget) {
    00186       case DTW_CANAL: // Build canal button
    00187         VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
    00188         break;
    00189
    00190       case DTW_LOCK: // Build lock button
    00191         DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
    00192         break;
    00193
    00194       case DTW_DEMOLISH: // Demolish aka dynamite button
    00195         PlaceProc_DemolishArea(tile);
    00196         break;
    00197
    00198       case DTW_DEPOT: // Build depot button
    00199         DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
    00200         break;
    00201
    00202       case DTW_STATION: { // Build station button
    00203         uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
    00204
    00205         /* tile is always the land tile, so need to evaluate _thd.pos */
    00206         CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
    00207
    00208         /* Determine the watery part of the dock. */
    00209         DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
    00210         TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
    00211
    00212         ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
    00213         break;
    00214       }
    00215
    00216       case DTW_BUOY: // Build buoy button
    00217         DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
    00218         break;
    00219
    00220       case DTW_RIVER: // Build river button (in scenario editor)
    00221         VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
    00222         break;
    00223
    00224       case DTW_BUILD_AQUEDUCT: // Build aqueduct button
    00225         DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
    00226         break;
    00227
    00228       default: NOT_REACHED();
    00229     }
    00230   }
    00231
    00232   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
    00233   {
    00234     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
    00235   }
    00236
    00237   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
    00238   {
    00239     if (pt.x != -1) {
    00240       switch (select_proc) {
    00241         case DDSP_DEMOLISH_AREA:
    00242           GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
    00243           break;
    00244         case DDSP_CREATE_WATER:
    00245           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);
    00246           break;
    00247         case DDSP_CREATE_RIVER:
    00248           DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal);
    00249           break;
    00250
    00251         default: break;
    00252       }
    00253     }
    00254   }
    00255
    00256   virtual void OnPlaceObjectAbort()
    00257   {
    00258     this->RaiseButtons();
    00259
    00260     DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
    00261     DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
    00262     DeleteWindowById(WC_SELECT_STATION, 0);
    00263     DeleteWindowByClass(WC_BUILD_BRIDGE);
    00264   }
    00265
    00266   virtual void OnPlacePresize(Point pt, TileIndex tile_from)
    00267   {
    00268     TileIndex tile_to = tile_from;
    00269
    00270     if (this->last_clicked_widget == DTW_BUILD_AQUEDUCT) {
    00271       GetOtherAqueductEnd(tile_from, &tile_to);
    00272     } else {
    00273       DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, NULL));
    00274       if (IsValidDiagDirection(dir)) {
    00275         /* Locks and docks always select the tile "down" the slope. */
    00276         tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
    00277         /* Locks also select the tile "up" the slope. */
    00278         if (this->last_clicked_widget == DTW_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
    00279       }
    00280     }
    00281
    00282     VpSetPresizeRange(tile_from, tile_to);
    00283   }
    00284
    00285   static Hotkey<BuildDocksToolbarWindow> dockstoolbar_hotkeys[];
    00286 };
    00287
    00288 const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
    00289
    00290 Hotkey<BuildDocksToolbarWindow> BuildDocksToolbarWindow::dockstoolbar_hotkeys[] = {
    00291   Hotkey<BuildDocksToolbarWindow>('1', "canal", DTW_CANAL),
    00292   Hotkey<BuildDocksToolbarWindow>('2', "lock", DTW_LOCK),
    00293   Hotkey<BuildDocksToolbarWindow>('3', "demolish", DTW_DEMOLISH),
    00294   Hotkey<BuildDocksToolbarWindow>('4', "depot", DTW_DEPOT),
    00295   Hotkey<BuildDocksToolbarWindow>('5', "dock", DTW_STATION),
    00296   Hotkey<BuildDocksToolbarWindow>('6', "buoy", DTW_BUOY),
    00297   Hotkey<BuildDocksToolbarWindow>('7', "river", DTW_RIVER),
    00298   Hotkey<BuildDocksToolbarWindow>(_dockstoolbar_aqueduct_keys, "aqueduct", DTW_BUILD_AQUEDUCT),
    00299   HOTKEY_LIST_END(BuildDocksToolbarWindow)
    00300 };
    00301 Hotkey<BuildDocksToolbarWindow> *_dockstoolbar_hotkeys = BuildDocksToolbarWindow::dockstoolbar_hotkeys;
    00302
    00307 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
    00308   NWidget(NWID_HORIZONTAL),
    00309     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00310     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00311     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00312   EndContainer(),
    00313   NWidget(NWID_HORIZONTAL_LTR),
    00314     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),
    00315     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),
    00316     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
    00317     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00318     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),
    00319     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),
    00320     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
    00321     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),
    00322   EndContainer(),
    00323 };
    00324
    00325 static const WindowDesc _build_docks_toolbar_desc(
    00326   WDP_ALIGN_TOOLBAR, 0, 0,
    00327   WC_BUILD_TOOLBAR, WC_NONE,
    00328   WDF_CONSTRUCTION,
    00329   _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets)
    00330 );
    00331
    00339 Window *ShowBuildDocksToolbar()
    00340 {
    00341   if (!Company::IsValidID(_local_company)) return NULL;
    00342
    00343   DeleteWindowByClass(WC_BUILD_TOOLBAR);
    00344   return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
    00345 }
    00346
    00347 EventState DockToolbarGlobalHotkeys(uint16 key, uint16 keycode)
    00348 {
    00349   int num = CheckHotkeyMatch<BuildDocksToolbarWindow>(_dockstoolbar_hotkeys, keycode, NULL, true);
    00350   if (num == -1) return ES_NOT_HANDLED;
    00351   Window *w = ShowBuildDocksToolbar();
    00352   if (w == NULL) return ES_NOT_HANDLED;
    00353   return w->OnKeyPress(key, keycode);
    00354 }
    00355
    00360 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
    00361   NWidget(NWID_HORIZONTAL),
    00362     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00363     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00364     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00365   EndContainer(),
    00366   NWidget(NWID_HORIZONTAL),
    00367     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),
    00368     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),
    00369     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
    00370     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, DTW_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00371     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),
    00372     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),
    00373   EndContainer(),
    00374 };
    00375
    00377 static const WindowDesc _build_docks_scen_toolbar_desc(
    00378   WDP_AUTO, 0, 0,
    00379   WC_SCEN_BUILD_TOOLBAR, WC_NONE,
    00380   WDF_CONSTRUCTION,
    00381   _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets)
    00382 );
    00383
    00389 Window *ShowBuildDocksScenToolbar()
    00390 {
    00391   return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
    00392 }
    00393
    00395 enum BuildDockStationWidgets {
    00396   BDSW_BACKGROUND,
    00397   BDSW_LT_OFF,
    00398   BDSW_LT_ON,
    00399   BDSW_INFO,
    00400 };
    00401
    00402 struct BuildDocksStationWindow : public PickerWindowBase {
    00403 public:
    00404   BuildDocksStationWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
    00405   {
    00406     this->InitNested(desc, TRANSPORT_WATER);
    00407     this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
    00408   }
    00409
    00410   virtual ~BuildDocksStationWindow()
    00411   {
    00412     DeleteWindowById(WC_SELECT_STATION, 0);
    00413   }
    00414
    00415   virtual void OnPaint()
    00416   {
    00417     int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
    00418
    00419     this->DrawWidgets();
    00420
    00421     if (_settings_client.gui.station_show_coverage) {
    00422       SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
    00423     } else {
    00424       SetTileSelectSize(1, 1);
    00425     }
    00426
    00427     /* strings such as 'Size' and 'Coverage Area' */
    00428     int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
    00429     NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
    00430     int right  = back_nwi->pos_x + back_nwi->current_x;
    00431     int bottom = back_nwi->pos_y + back_nwi->current_y;
    00432     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
    00433     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
    00434     /* Resize background if the text is not equally long as the window. */
    00435     if (top > bottom || (top < bottom && back_nwi->current_y > back_nwi->smallest_y)) {
    00436       ResizeWindow(this, 0, top - bottom);
    00437     }
    00438   }
    00439
    00440   virtual void OnClick(Point pt, int widget, int click_count)
    00441   {
    00442     switch (widget) {
    00443       case BDSW_LT_OFF:
    00444       case BDSW_LT_ON:
    00445         this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
    00446         _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
    00447         this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
    00448         SndPlayFx(SND_15_BEEP);
    00449         this->SetDirty();
    00450         break;
    00451     }
    00452   }
    00453
    00454   virtual void OnTick()
    00455   {
    00456     CheckRedrawStationCoverage(this);
    00457   }
    00458 };
    00459
    00461 static const NWidgetPart _nested_build_dock_station_widgets[] = {
    00462   NWidget(NWID_HORIZONTAL),
    00463     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00464     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00465   EndContainer(),
    00466   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
    00467     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00468     NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetMinimalSize(148, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
    00469     NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14),
    00470       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),
    00471       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),
    00472     EndContainer(),
    00473     NWidget(NWID_SPACER), SetMinimalSize(0, 20), SetResize(0, 1),
    00474   EndContainer(),
    00475 };
    00476
    00477 static const WindowDesc _build_dock_station_desc(
    00478   WDP_AUTO, 0, 0,
    00479   WC_BUILD_STATION, WC_BUILD_TOOLBAR,
    00480   WDF_CONSTRUCTION,
    00481   _nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
    00482 );
    00483
    00484 static void ShowBuildDockStationPicker(Window *parent)
    00485 {
    00486   new BuildDocksStationWindow(&_build_dock_station_desc, parent);
    00487 }
    00488
    00490 enum BuildDockDepotWidgets {
    00491   BDDW_BACKGROUND,
    00492   BDDW_X,
    00493   BDDW_Y,
    00494 };
    00495
    00496 struct BuildDocksDepotWindow : public PickerWindowBase {
    00497 private:
    00498   static void UpdateDocksDirection()
    00499   {
    00500     if (_ship_depot_direction != AXIS_X) {
    00501       SetTileSelectSize(1, 2);
    00502     } else {
    00503       SetTileSelectSize(2, 1);
    00504     }
    00505   }
    00506
    00507 public:
    00508   BuildDocksDepotWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
    00509   {
    00510     this->InitNested(desc, TRANSPORT_WATER);
    00511     this->LowerWidget(_ship_depot_direction + BDDW_X);
    00512     UpdateDocksDirection();
    00513   }
    00514
    00515   virtual void OnPaint()
    00516   {
    00517     this->DrawWidgets();
    00518
    00519     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_X)->pos_x + 64, this->GetWidget<NWidgetBase>(BDDW_X)->pos_y + 18, 0);
    00520     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_X)->pos_x + 32, this->GetWidget<NWidgetBase>(BDDW_X)->pos_y + 34, 1);
    00521     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_Y)->pos_x + 32, this->GetWidget<NWidgetBase>(BDDW_Y)->pos_y + 18, 2);
    00522     DrawShipDepotSprite(this->GetWidget<NWidgetBase>(BDDW_Y)->pos_x + 64, this->GetWidget<NWidgetBase>(BDDW_Y)->pos_y + 34, 3);
    00523   }
    00524
    00525   virtual void OnClick(Point pt, int widget, int click_count)
    00526   {
    00527     switch (widget) {
    00528       case BDDW_X:
    00529       case BDDW_Y:
    00530         this->RaiseWidget(_ship_depot_direction + BDDW_X);
    00531         _ship_depot_direction = (widget == BDDW_X ? AXIS_X : AXIS_Y);
    00532         this->LowerWidget(_ship_depot_direction + BDDW_X);
    00533         SndPlayFx(SND_15_BEEP);
    00534         UpdateDocksDirection();
    00535         this->SetDirty();
    00536         break;
    00537     }
    00538   }
    00539 };
    00540
    00541 static const NWidgetPart _nested_build_docks_depot_widgets[] = {
    00542   NWidget(NWID_HORIZONTAL),
    00543     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00544     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00545   EndContainer(),
    00546   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDDW_BACKGROUND),
    00547     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00548     NWidget(NWID_HORIZONTAL_LTR),
    00549       NWidget(NWID_SPACER), SetMinimalSize(3, 0),
    00550       NWidget(WWT_PANEL, COLOUR_GREY, BDDW_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
    00551       EndContainer(),
    00552       NWidget(NWID_SPACER), SetMinimalSize(2, 0),
    00553       NWidget(WWT_PANEL, COLOUR_GREY, BDDW_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
    00554       EndContainer(),
    00555       NWidget(NWID_SPACER), SetMinimalSize(3, 0),
    00556     EndContainer(),
    00557     NWidget(NWID_SPACER), SetMinimalSize(0, 3),
    00558   EndContainer(),
    00559 };
    00560
    00561 static const WindowDesc _build_docks_depot_desc(
    00562   WDP_AUTO, 0, 0,
    00563   WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
    00564   WDF_CONSTRUCTION,
    00565   _nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
    00566 );
    00567
    00568
    00569 static void ShowBuildDocksDepotPicker(Window *parent)
    00570 {
    00571   new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
    00572 }
    00573
    00574
    00575 void InitializeDockGui()
    00576 {
    00577   _ship_depot_direction = AXIS_X;
    00578 }