Remove unused string code SCC_STRING_ID
[openttd/fttd.git] / src / dock_gui.cpp
blobcc608bfa846fcec0becf5e1f2902766629aa6db7
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file dock_gui.cpp GUI to create amazing water objects. */
12 #include "stdafx.h"
13 #include "map/slope.h"
14 #include "terraform_gui.h"
15 #include "window_gui.h"
16 #include "station_gui.h"
17 #include "command_func.h"
18 #include "water.h"
19 #include "window_func.h"
20 #include "vehicle_func.h"
21 #include "sound_func.h"
22 #include "viewport_func.h"
23 #include "gfx_func.h"
24 #include "company_func.h"
25 #include "slope_func.h"
26 #include "tilehighlight_func.h"
27 #include "company_base.h"
28 #include "hotkeys.h"
29 #include "gui.h"
31 #include "widgets/dock_widget.h"
33 #include "table/sprites.h"
34 #include "table/strings.h"
36 static void ShowBuildDockStationPicker(Window *parent);
37 static void ShowBuildDocksDepotPicker(Window *parent);
39 static Axis _ship_depot_direction;
41 void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
43 if (result.Failed()) return;
45 if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT, tile);
46 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
49 void CcBuildCanal(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
51 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT, tile);
55 /**
56 * Gets the other end of the aqueduct, if possible.
57 * @param tile_from The begin tile for the aqueduct.
58 * @param [out] tile_to The tile till where to show a selection for the aqueduct.
59 * @return The other end of the aqueduct, or otherwise a tile in line with the aqueduct to cause the right error message.
61 static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = NULL)
63 int z;
64 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, &z));
66 /* If the direction isn't right, just return the next tile so the command
67 * complains about the wrong slope instead of the ends not matching up.
68 * Make sure the coordinate is always a valid tile within the map, so we
69 * don't go "off" the map. That would cause the wrong error message. */
70 if (!IsValidDiagDirection(dir)) return TILE_ADDXY(tile_from, TileX(tile_from) > 2 ? -1 : 1, 0);
72 /* Direction the aqueduct is built to. */
73 TileIndexDiff offset = TileOffsByDiagDir(ReverseDiagDir(dir));
74 /* The maximum length of the aqueduct. */
75 int max_length = min(_settings_game.construction.max_bridge_length, DistanceFromEdgeDir(tile_from, ReverseDiagDir(dir)) - 1);
77 TileIndex endtile = tile_from;
78 for (int length = 0; IsValidTile(endtile) && TileX(endtile) != 0 && TileY(endtile) != 0; length++) {
79 endtile = TILE_ADD(endtile, offset);
81 if (length > max_length) break;
83 if (GetTileMaxZ(endtile) > z) {
84 if (tile_to != NULL) *tile_to = endtile;
85 break;
89 return endtile;
92 /** Toolbar window for constructing water infrastructure. */
93 struct BuildDocksToolbarWindow : Window {
94 DockToolbarWidgets last_clicked_widget; ///< Contains the last widget that has been clicked on this toolbar.
96 BuildDocksToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
98 this->last_clicked_widget = WID_DT_INVALID;
99 this->InitNested(window_number);
100 this->OnInvalidateData();
101 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
104 ~BuildDocksToolbarWindow()
106 if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
110 * Some data on this window has become invalid.
111 * @param data Information about the changed data.
112 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
114 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
116 if (!gui_scope) return;
117 this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP),
118 WID_DT_DEPOT,
119 WID_DT_STATION,
120 WID_DT_BUOY,
121 WIDGET_LIST_END);
124 virtual void OnClick(Point pt, int widget, int click_count)
126 switch (widget) {
127 case WID_DT_CANAL: // Build canal button
128 HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
129 break;
131 case WID_DT_LOCK: // Build lock button
132 HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
133 break;
135 case WID_DT_DEMOLISH: // Demolish aka dynamite button
136 HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
137 break;
139 case WID_DT_DEPOT: // Build depot button
140 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
141 if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
142 break;
144 case WID_DT_STATION: // Build station button
145 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
146 if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
147 break;
149 case WID_DT_BUOY: // Build buoy button
150 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
151 HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
152 break;
154 case WID_DT_RIVER: // Build river button (in scenario editor)
155 if (_game_mode != GM_EDITOR) return;
156 HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT);
157 break;
159 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
160 HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
161 break;
163 default: return;
165 this->last_clicked_widget = (DockToolbarWidgets)widget;
168 virtual void OnPlaceObject(Point pt, TileIndex tile)
170 switch (this->last_clicked_widget) {
171 case WID_DT_CANAL: // Build canal button
172 VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
173 break;
175 case WID_DT_LOCK: // Build lock button
176 DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
177 break;
179 case WID_DT_DEMOLISH: // Demolish aka dynamite button
180 PlaceProc_DemolishArea(tile);
181 break;
183 case WID_DT_DEPOT: // Build depot button
184 DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
185 break;
187 case WID_DT_STATION: { // Build station button
188 uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
190 /* tile is always the land tile, so need to evaluate _thd.pos */
191 CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
193 /* Determine the watery part of the dock. */
194 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
195 TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
197 ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
198 break;
201 case WID_DT_BUOY: // Build buoy button
202 DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
203 break;
205 case WID_DT_RIVER: // Build river button (in scenario editor)
206 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
207 break;
209 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
210 DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 12, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
211 break;
213 default: NOT_REACHED();
217 virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
219 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
222 virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
224 if (pt.x != -1) {
225 switch (select_proc) {
226 case DDSP_DEMOLISH_AREA:
227 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
228 break;
229 case DDSP_CREATE_WATER:
230 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);
231 break;
232 case DDSP_CREATE_RIVER:
233 DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal);
234 break;
236 default: break;
241 virtual void OnPlaceObjectAbort()
243 this->RaiseButtons();
245 DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
246 DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
247 DeleteWindowById(WC_SELECT_STATION, 0);
248 DeleteWindowByClass(WC_BUILD_BRIDGE);
251 virtual void OnPlacePresize(Point pt, TileIndex tile_from)
253 TileIndex tile_to = tile_from;
255 if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
256 GetOtherAqueductEnd(tile_from, &tile_to);
257 } else {
258 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
259 if (IsValidDiagDirection(dir)) {
260 /* Locks and docks always select the tile "down" the slope. */
261 tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
262 /* Locks also select the tile "up" the slope. */
263 if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
267 VpSetPresizeRange(tile_from, tile_to);
270 static HotkeyList hotkeys;
274 * Handler for global hotkeys of the BuildDocksToolbarWindow.
275 * @param hotkey Hotkey
276 * @return ES_HANDLED if hotkey was accepted.
278 static EventState DockToolbarGlobalHotkeys(int hotkey)
280 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
281 Window *w = ShowBuildDocksToolbar();
282 if (w == NULL) return ES_NOT_HANDLED;
283 return w->OnHotkey(hotkey);
286 const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
288 static Hotkey dockstoolbar_hotkeys[] = {
289 Hotkey('1', "canal", WID_DT_CANAL),
290 Hotkey('2', "lock", WID_DT_LOCK),
291 Hotkey('3', "demolish", WID_DT_DEMOLISH),
292 Hotkey('4', "depot", WID_DT_DEPOT),
293 Hotkey('5', "dock", WID_DT_STATION),
294 Hotkey('6', "buoy", WID_DT_BUOY),
295 Hotkey('7', "river", WID_DT_RIVER),
296 Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
297 HOTKEY_LIST_END
299 HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys, DockToolbarGlobalHotkeys);
302 * Nested widget parts of docks toolbar, game version.
303 * Position of #WID_DT_RIVER widget has changed.
305 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
306 NWidget(NWID_HORIZONTAL),
307 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
308 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
309 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
310 EndContainer(),
311 NWidget(NWID_HORIZONTAL_LTR),
312 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),
313 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),
314 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
315 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
316 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),
317 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),
318 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
319 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),
320 EndContainer(),
323 static WindowDesc _build_docks_toolbar_desc(
324 WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0,
325 WC_BUILD_TOOLBAR, WC_NONE,
326 WDF_CONSTRUCTION,
327 _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets),
328 &BuildDocksToolbarWindow::hotkeys
332 * Open the build water toolbar window
334 * If the terraform toolbar is linked to the toolbar, that window is also opened.
336 * @return newly opened water toolbar, or NULL if the toolbar could not be opened.
338 Window *ShowBuildDocksToolbar()
340 if (!Company::IsValidID(_local_company)) return NULL;
342 DeleteWindowByClass(WC_BUILD_TOOLBAR);
343 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
347 * Nested widget parts of docks toolbar, scenario editor version.
348 * Positions of #WID_DT_DEPOT, #WID_DT_STATION, and #WID_DT_BUOY widgets have changed.
350 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
351 NWidget(NWID_HORIZONTAL),
352 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
353 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
354 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
355 EndContainer(),
356 NWidget(NWID_HORIZONTAL),
357 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),
358 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),
359 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
360 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
361 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),
362 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),
363 EndContainer(),
366 /** Window definition for the build docks in scenario editor window. */
367 static WindowDesc _build_docks_scen_toolbar_desc(
368 WDP_AUTO, "toolbar_water_scen", 0, 0,
369 WC_SCEN_BUILD_TOOLBAR, WC_NONE,
370 WDF_CONSTRUCTION,
371 _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets)
375 * Open the build water toolbar window for the scenario editor.
377 * @return newly opened water toolbar, or NULL if the toolbar could not be opened.
379 Window *ShowBuildDocksScenToolbar()
381 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
384 /** Widget numbers of the build-dock GUI. */
385 enum BuildDockStationWidgets {
386 BDSW_BACKGROUND, ///< Background panel.
387 BDSW_LT_OFF, ///< 'Off' button of coverage high light.
388 BDSW_LT_ON, ///< 'On' button of coverage high light.
389 BDSW_INFO, ///< 'Coverage highlight' label.
392 struct BuildDocksStationWindow : public PickerWindowBase {
393 public:
394 BuildDocksStationWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
396 this->InitNested(TRANSPORT_WATER);
397 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
400 virtual ~BuildDocksStationWindow()
402 DeleteWindowById(WC_SELECT_STATION, 0);
405 virtual void OnPaint()
407 int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
409 this->DrawWidgets();
411 if (_settings_client.gui.station_show_coverage) {
412 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
413 } else {
414 SetTileSelectSize(1, 1);
417 /* strings such as 'Size' and 'Coverage Area' */
418 int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
419 NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
420 int right = back_nwi->pos_x + back_nwi->current_x;
421 int bottom = back_nwi->pos_y + back_nwi->current_y;
422 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
423 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
424 /* Resize background if the window is too small.
425 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
426 * (This is the case, if making the window bigger moves the mouse into the window.) */
427 if (top > bottom) {
428 ResizeWindow(this, 0, top - bottom);
432 virtual void OnClick(Point pt, int widget, int click_count)
434 switch (widget) {
435 case BDSW_LT_OFF:
436 case BDSW_LT_ON:
437 this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
438 _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
439 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
440 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
441 this->SetDirty();
442 break;
446 virtual void OnTick()
448 CheckRedrawStationCoverage(this);
452 /** Nested widget parts of a build dock station window. */
453 static const NWidgetPart _nested_build_dock_station_widgets[] = {
454 NWidget(NWID_HORIZONTAL),
455 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
456 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
457 EndContainer(),
458 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
459 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
460 NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetMinimalSize(148, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
461 NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14),
462 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),
463 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),
464 EndContainer(),
465 NWidget(NWID_SPACER), SetMinimalSize(0, 20), SetResize(0, 1),
466 EndContainer(),
469 static WindowDesc _build_dock_station_desc(
470 WDP_AUTO, NULL, 0, 0,
471 WC_BUILD_STATION, WC_BUILD_TOOLBAR,
472 WDF_CONSTRUCTION,
473 _nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
476 static void ShowBuildDockStationPicker(Window *parent)
478 new BuildDocksStationWindow(&_build_dock_station_desc, parent);
481 struct BuildDocksDepotWindow : public PickerWindowBase {
482 private:
483 static void UpdateDocksDirection()
485 if (_ship_depot_direction != AXIS_X) {
486 SetTileSelectSize(1, 2);
487 } else {
488 SetTileSelectSize(2, 1);
492 public:
493 BuildDocksDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
495 this->InitNested(TRANSPORT_WATER);
496 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
497 UpdateDocksDirection();
500 virtual void OnPaint()
502 this->DrawWidgets();
504 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + 64, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + 18, DIAGDIR_NE);
505 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + 32, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + 34, DIAGDIR_SW);
506 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + 32, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + 18, DIAGDIR_NW);
507 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + 64, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + 34, DIAGDIR_SE);
510 virtual void OnClick(Point pt, int widget, int click_count)
512 switch (widget) {
513 case WID_BDD_X:
514 case WID_BDD_Y:
515 this->RaiseWidget(_ship_depot_direction + WID_BDD_X);
516 _ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
517 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
518 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
519 UpdateDocksDirection();
520 this->SetDirty();
521 break;
526 static const NWidgetPart _nested_build_docks_depot_widgets[] = {
527 NWidget(NWID_HORIZONTAL),
528 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
529 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
530 EndContainer(),
531 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
532 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
533 NWidget(NWID_HORIZONTAL_LTR),
534 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
535 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
536 EndContainer(),
537 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
538 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
539 EndContainer(),
540 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
541 EndContainer(),
542 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
543 EndContainer(),
546 static WindowDesc _build_docks_depot_desc(
547 WDP_AUTO, NULL, 0, 0,
548 WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
549 WDF_CONSTRUCTION,
550 _nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
554 static void ShowBuildDocksDepotPicker(Window *parent)
556 new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
560 void InitializeDockGui()
562 _ship_depot_direction = AXIS_X;