# dock_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: dock_gui.cpp 26460 2014-04-13 10:47:39Z frosch $ */
    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 #include "gui.h"
    00029
    00030 #include "widgets/dock_widget.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   if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, 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() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, tile);
    00051 }
    00052
    00053
    00060 static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = NULL)
    00061 {
    00062   int 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 struct BuildDocksToolbarWindow : Window {
    00093   DockToolbarWidgets last_clicked_widget;
    00094
    00095   BuildDocksToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
    00096   {
    00097     this->last_clicked_widget = WID_DT_INVALID;
    00098     this->InitNested(window_number);
    00099     this->OnInvalidateData();
    00100     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
    00101   }
    00102
    00103   ~BuildDocksToolbarWindow()
    00104   {
    00105     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
    00106   }
    00107
    00113   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
    00114   {
    00115     if (!gui_scope) return;
    00116     this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP),
    00117       WID_DT_DEPOT,
    00118       WID_DT_STATION,
    00119       WID_DT_BUOY,
    00120       WIDGET_LIST_END);
    00121   }
    00122
    00123   virtual void OnClick(Point pt, int widget, int click_count)
    00124   {
    00125     switch (widget) {
    00126       case WID_DT_CANAL: // Build canal button
    00127         HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
    00128         break;
    00129
    00130       case WID_DT_LOCK: // Build lock button
    00131         HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
    00132         break;
    00133
    00134       case WID_DT_DEMOLISH: // Demolish aka dynamite button
    00135         HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
    00136         break;
    00137
    00138       case WID_DT_DEPOT: // Build depot button
    00139         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00140         if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
    00141         break;
    00142
    00143       case WID_DT_STATION: // Build station button
    00144         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00145         if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
    00146         break;
    00147
    00148       case WID_DT_BUOY: // Build buoy button
    00149         if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
    00150         HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
    00151         break;
    00152
    00153       case WID_DT_RIVER: // Build river button (in scenario editor)
    00154         if (_game_mode != GM_EDITOR) return;
    00155         HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT);
    00156         break;
    00157
    00158       case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
    00159         HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
    00160         break;
    00161
    00162       default: return;
    00163     }
    00164     this->last_clicked_widget = (DockToolbarWidgets)widget;
    00165   }
    00166
    00167   virtual void OnPlaceObject(Point pt, TileIndex tile)
    00168   {
    00169     switch (this->last_clicked_widget) {
    00170       case WID_DT_CANAL: // Build canal button
    00171         VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
    00172         break;
    00173
    00174       case WID_DT_LOCK: // Build lock button
    00175         DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
    00176         break;
    00177
    00178       case WID_DT_DEMOLISH: // Demolish aka dynamite button
    00179         PlaceProc_DemolishArea(tile);
    00180         break;
    00181
    00182       case WID_DT_DEPOT: // Build depot button
    00183         DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
    00184         break;
    00185
    00186       case WID_DT_STATION: { // Build station button
    00187         uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
    00188
    00189         /* tile is always the land tile, so need to evaluate _thd.pos */
    00190         CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
    00191
    00192         /* Determine the watery part of the dock. */
    00193         DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
    00194         TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
    00195
    00196         ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
    00197         break;
    00198       }
    00199
    00200       case WID_DT_BUOY: // Build buoy button
    00201         DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
    00202         break;
    00203
    00204       case WID_DT_RIVER: // Build river button (in scenario editor)
    00205         VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
    00206         break;
    00207
    00208       case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
    00209         DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
    00210         break;
    00211
    00212       default: NOT_REACHED();
    00213     }
    00214   }
    00215
    00216   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
    00217   {
    00218     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
    00219   }
    00220
    00221   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
    00222   {
    00223     if (pt.x != -1) {
    00224       switch (select_proc) {
    00225         case DDSP_DEMOLISH_AREA:
    00226           GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
    00227           break;
    00228         case DDSP_CREATE_WATER:
    00229           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);
    00230           break;
    00231         case DDSP_CREATE_RIVER:
    00232           DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal);
    00233           break;
    00234
    00235         default: break;
    00236       }
    00237     }
    00238   }
    00239
    00240   virtual void OnPlaceObjectAbort()
    00241   {
    00242     this->RaiseButtons();
    00243
    00244     DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
    00245     DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
    00246     DeleteWindowById(WC_SELECT_STATION, 0);
    00247     DeleteWindowByClass(WC_BUILD_BRIDGE);
    00248   }
    00249
    00250   virtual void OnPlacePresize(Point pt, TileIndex tile_from)
    00251   {
    00252     TileIndex tile_to = tile_from;
    00253
    00254     if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
    00255       GetOtherAqueductEnd(tile_from, &tile_to);
    00256     } else {
    00257       DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
    00258       if (IsValidDiagDirection(dir)) {
    00259         /* Locks and docks always select the tile "down" the slope. */
    00260         tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
    00261         /* Locks also select the tile "up" the slope. */
    00262         if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
    00263       }
    00264     }
    00265
    00266     VpSetPresizeRange(tile_from, tile_to);
    00267   }
    00268
    00269   static HotkeyList hotkeys;
    00270 };
    00271
    00277 static EventState DockToolbarGlobalHotkeys(int hotkey)
    00278 {
    00279   if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
    00280   Window *w = ShowBuildDocksToolbar();
    00281   if (w == NULL) return ES_NOT_HANDLED;
    00282   return w->OnHotkey(hotkey);
    00283 }
    00284
    00285 const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
    00286
    00287 static Hotkey dockstoolbar_hotkeys[] = {
    00288   Hotkey('1', "canal", WID_DT_CANAL),
    00289   Hotkey('2', "lock", WID_DT_LOCK),
    00290   Hotkey('3', "demolish", WID_DT_DEMOLISH),
    00291   Hotkey('4', "depot", WID_DT_DEPOT),
    00292   Hotkey('5', "dock", WID_DT_STATION),
    00293   Hotkey('6', "buoy", WID_DT_BUOY),
    00294   Hotkey('7', "river", WID_DT_RIVER),
    00295   Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
    00296   HOTKEY_LIST_END
    00297 };
    00298 HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys, DockToolbarGlobalHotkeys);
    00299
    00304 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
    00305   NWidget(NWID_HORIZONTAL),
    00306     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00307     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00308     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00309   EndContainer(),
    00310   NWidget(NWID_HORIZONTAL_LTR),
    00311     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),
    00312     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),
    00313     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
    00314     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00315     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),
    00316     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),
    00317     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
    00318     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),
    00319   EndContainer(),
    00320 };
    00321
    00322 static WindowDesc _build_docks_toolbar_desc(
    00323   WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0,
    00324   WC_BUILD_TOOLBAR, WC_NONE,
    00325   WDF_CONSTRUCTION,
    00326   _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets),
    00327   &BuildDocksToolbarWindow::hotkeys
    00328 );
    00329
    00337 Window *ShowBuildDocksToolbar()
    00338 {
    00339   if (!Company::IsValidID(_local_company)) return NULL;
    00340
    00341   DeleteWindowByClass(WC_BUILD_TOOLBAR);
    00342   return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
    00343 }
    00344
    00349 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
    00350   NWidget(NWID_HORIZONTAL),
    00351     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
    00352     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    00353     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
    00354   EndContainer(),
    00355   NWidget(NWID_HORIZONTAL),
    00356     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),
    00357     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),
    00358     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
    00359     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
    00360     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),
    00361     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),
    00362   EndContainer(),
    00363 };
    00364
    00366 static WindowDesc _build_docks_scen_toolbar_desc(
    00367   WDP_AUTO, "toolbar_water_scen", 0, 0,
    00368   WC_SCEN_BUILD_TOOLBAR, WC_NONE,
    00369   WDF_CONSTRUCTION,
    00370   _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets)
    00371 );
    00372
    00378 Window *ShowBuildDocksScenToolbar()
    00379 {
    00380   return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
    00381 }
    00382
    00384 enum BuildDockStationWidgets {
    00385   BDSW_BACKGROUND,
    00386   BDSW_LT_OFF,
    00387   BDSW_LT_ON,
    00388   BDSW_INFO,
    00389 };
    00390
    00391 struct BuildDocksStationWindow : public PickerWindowBase {
    00392 public:
    00393   BuildDocksStationWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
    00394   {
    00395     this->InitNested(TRANSPORT_WATER);
    00396     this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
    00397   }
    00398
    00399   virtual ~BuildDocksStationWindow()
    00400   {
    00401     DeleteWindowById(WC_SELECT_STATION, 0);
    00402   }
    00403
    00404   virtual void OnPaint()
    00405   {
    00406     int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
    00407
    00408     this->DrawWidgets();
    00409
    00410     if (_settings_client.gui.station_show_coverage) {
    00411       SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
    00412     } else {
    00413       SetTileSelectSize(1, 1);
    00414     }
    00415
    00416     /* strings such as 'Size' and 'Coverage Area' */
    00417     int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
    00418     NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
    00419     int right  = back_nwi->pos_x + back_nwi->current_x;
    00420     int bottom = back_nwi->pos_y + back_nwi->current_y;
    00421     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
    00422     top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
    00423     /* Resize background if the window is too small.
    00424      * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
    00425      * (This is the case, if making the window bigger moves the mouse into the window.) */
    00426     if (top > bottom) {
    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 WindowDesc _build_dock_station_desc(
    00469   WDP_AUTO, NULL, 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(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
    00493   {
    00494     this->InitNested(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 WindowDesc _build_docks_depot_desc(
    00546   WDP_AUTO, NULL, 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 }