Translations update
[openttd/fttd.git] / src / dock_gui.cpp
blobe3782e6dafb2e959948f9df333e2958b07a43a00
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"
30 #include "zoom_func.h"
32 #include "widgets/dock_widget.h"
34 #include "table/sprites.h"
35 #include "table/strings.h"
37 static void ShowBuildDockStationPicker(Window *parent);
38 static void ShowBuildDocksDepotPicker(Window *parent);
40 static Axis _ship_depot_direction;
42 void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
44 if (result.Failed()) return;
46 if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, tile);
47 if (!_settings_client.gui.persistent_buildingtools) ResetPointerMode();
50 void CcPlaySound_SPLAT_WATER(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
52 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, tile);
55 StringID GetErrBuildCanal (TileIndex tile, uint32 p1, uint32 p2, const char *text)
57 return p2 == WATER_CLASS_RIVER ? STR_ERROR_CAN_T_PLACE_RIVERS : STR_ERROR_CAN_T_BUILD_CANALS;
61 /**
62 * Gets the other end of the aqueduct, if possible.
63 * @param tile_from The begin tile for the aqueduct.
64 * @param [out] tile_to The tile till where to show a selection for the aqueduct.
65 * @return The other end of the aqueduct, or otherwise a tile in line with the aqueduct to cause the right error message.
67 static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = NULL)
69 int z;
70 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, &z));
72 /* If the direction isn't right, just return the next tile so the command
73 * complains about the wrong slope instead of the ends not matching up.
74 * Make sure the coordinate is always a valid tile within the map, so we
75 * don't go "off" the map. That would cause the wrong error message. */
76 if (!IsValidDiagDirection(dir)) return TILE_ADDXY(tile_from, TileX(tile_from) > 2 ? -1 : 1, 0);
78 /* Direction the aqueduct is built to. */
79 TileIndexDiff offset = TileOffsByDiagDir(ReverseDiagDir(dir));
80 /* The maximum length of the aqueduct. */
81 int max_length = min(_settings_game.construction.max_bridge_length, DistanceFromEdgeDir(tile_from, ReverseDiagDir(dir)) - 1);
83 TileIndex endtile = tile_from;
84 for (int length = 0; IsValidTile(endtile) && TileX(endtile) != 0 && TileY(endtile) != 0; length++) {
85 endtile = TILE_ADD(endtile, offset);
87 if (length > max_length) break;
89 if (GetTileMaxZ(endtile) > z) {
90 if (tile_to != NULL) *tile_to = endtile;
91 break;
95 return endtile;
98 /** Toolbar window for constructing water infrastructure. */
99 struct BuildDocksToolbarWindow : Window {
100 /** Dragging actions for this window. */
101 enum {
102 DRAG_DEMOLISH_AREA, ///< Clear area
103 DRAG_CREATE_WATER, ///< Create a canal
104 DRAG_CREATE_RIVER, ///< Create rivers
107 DockToolbarWidgets last_clicked_widget; ///< Contains the last widget that has been clicked on this toolbar.
109 BuildDocksToolbarWindow (const WindowDesc *desc, WindowNumber window_number)
110 : Window (desc), last_clicked_widget (WID_DT_INVALID)
112 this->InitNested(window_number);
113 this->OnInvalidateData();
114 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
117 void OnDelete (void) FINAL_OVERRIDE
119 if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
123 * Some data on this window has become invalid.
124 * @param data Information about the changed data.
125 * @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.
127 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
129 if (!gui_scope) return;
131 bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP);
132 this->SetWidgetsDisabledState(!can_build,
133 WID_DT_DEPOT,
134 WID_DT_STATION,
135 WID_DT_BUOY,
136 WIDGET_LIST_END);
137 if (!can_build) {
138 DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
139 DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
143 virtual void OnClick(Point pt, int widget, int click_count)
145 switch (widget) {
146 case WID_DT_CANAL: // Build canal button
147 HandlePlacePushButton (this, WID_DT_CANAL, SPR_CURSOR_CANAL, POINTER_TILE);
148 break;
150 case WID_DT_LOCK: // Build lock button
151 HandlePlacePushButton (this, WID_DT_LOCK, SPR_CURSOR_LOCK, POINTER_AREA);
152 break;
154 case WID_DT_DEMOLISH: // Demolish aka dynamite button
155 HandlePlacePushButton (this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, POINTER_TILE);
156 break;
158 case WID_DT_DEPOT: // Build depot button
159 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
160 if (HandlePlacePushButton (this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, POINTER_TILE)) ShowBuildDocksDepotPicker(this);
161 break;
163 case WID_DT_STATION: // Build station button
164 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
165 if (HandlePlacePushButton (this, WID_DT_STATION, SPR_CURSOR_DOCK, POINTER_AREA)) ShowBuildDockStationPicker(this);
166 break;
168 case WID_DT_BUOY: // Build buoy button
169 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
170 HandlePlacePushButton (this, WID_DT_BUOY, SPR_CURSOR_BUOY, POINTER_TILE);
171 break;
173 case WID_DT_RIVER: // Build river button (in scenario editor)
174 if (_game_mode != GM_EDITOR) return;
175 HandlePlacePushButton (this, WID_DT_RIVER, SPR_CURSOR_RIVER, POINTER_TILE);
176 break;
178 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
179 HandlePlacePushButton (this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, POINTER_AREA);
180 break;
182 default: return;
184 this->last_clicked_widget = (DockToolbarWidgets)widget;
187 virtual void OnPlaceObject(Point pt, TileIndex tile)
189 switch (this->last_clicked_widget) {
190 case WID_DT_CANAL: // Build canal button
191 VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DRAG_CREATE_WATER);
192 break;
194 case WID_DT_LOCK: // Build lock button
195 DoCommandP(tile, 0, 0, CMD_BUILD_LOCK);
196 break;
198 case WID_DT_DEMOLISH: // Demolish aka dynamite button
199 VpStartPlaceSizing (tile, VPM_X_AND_Y_ROTATED, DRAG_DEMOLISH_AREA);
200 break;
202 case WID_DT_DEPOT: // Build depot button
203 DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT);
204 break;
206 case WID_DT_STATION: { // Build station button
207 uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
209 /* tile is always the land tile, so need to evaluate _thd.pos */
210 Command cmdcont (tile, _ctrl_pressed, p2, CMD_BUILD_DOCK);
212 /* Determine the watery part of the dock. */
213 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
214 TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
216 ShowSelectStationIfNeeded (&cmdcont, TileArea(tile, tile_to));
217 break;
220 case WID_DT_BUOY: // Build buoy button
221 DoCommandP(tile, 0, 0, CMD_BUILD_BUOY);
222 break;
224 case WID_DT_RIVER: // Build river button (in scenario editor)
225 VpStartPlaceSizing(tile, VPM_X_AND_Y, DRAG_CREATE_RIVER);
226 break;
228 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
229 DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 12, CMD_BUILD_BRIDGE);
230 break;
232 default: NOT_REACHED();
236 void OnPlaceMouseUp (int userdata, Point pt, TileIndex start_tile, TileIndex end_tile) OVERRIDE
238 if (pt.x != -1) {
239 switch (userdata) {
240 case DRAG_DEMOLISH_AREA:
241 HandleDemolishMouseUp (start_tile, end_tile);
242 break;
243 case DRAG_CREATE_WATER:
244 DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR && _ctrl_pressed) ? WATER_CLASS_SEA : WATER_CLASS_CANAL, CMD_BUILD_CANAL);
245 break;
246 case DRAG_CREATE_RIVER:
247 DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER, CMD_BUILD_CANAL);
248 break;
250 default: break;
255 virtual void OnPlaceObjectAbort()
257 this->RaiseButtons();
259 DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
260 DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
261 DeleteWindowById(WC_SELECT_STATION, 0);
262 DeleteWindowByClass(WC_BUILD_BRIDGE);
265 void OnPlacePresize (TileIndex *tile1, TileIndex *tile2) OVERRIDE
267 if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
268 GetOtherAqueductEnd (*tile1, tile2);
269 } else {
270 TileIndex tile_from = *tile1;
271 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
272 if (IsValidDiagDirection(dir)) {
273 /* Locks and docks always select the tile "down" the slope. */
274 *tile2 = TileAddByDiagDir (tile_from, ReverseDiagDir(dir));
275 /* Locks also select the tile "up" the slope. */
276 if (this->last_clicked_widget == WID_DT_LOCK) *tile1 = TileAddByDiagDir (tile_from, dir);
281 static HotkeyList hotkeys;
285 * Handler for global hotkeys of the BuildDocksToolbarWindow.
286 * @param hotkey Hotkey
287 * @return ES_HANDLED if hotkey was accepted.
289 static EventState DockToolbarGlobalHotkeys(int hotkey)
291 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
292 Window *w = ShowBuildDocksToolbar();
293 if (w == NULL) return ES_NOT_HANDLED;
294 return w->OnHotkey(hotkey);
297 static const Hotkey dockstoolbar_hotkeys[] = {
298 Hotkey ("canal", WID_DT_CANAL, '1'),
299 Hotkey ("lock", WID_DT_LOCK, '2'),
300 Hotkey ("demolish", WID_DT_DEMOLISH, '3'),
301 Hotkey ("depot", WID_DT_DEPOT, '4'),
302 Hotkey ("dock", WID_DT_STATION, '5'),
303 Hotkey ("buoy", WID_DT_BUOY, '6'),
304 Hotkey ("river", WID_DT_RIVER, '7'),
305 Hotkey ("aqueduct", WID_DT_BUILD_AQUEDUCT, '8', 'B'),
307 HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys, DockToolbarGlobalHotkeys);
310 * Nested widget parts of docks toolbar, game version.
311 * Position of #WID_DT_RIVER widget has changed.
313 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
314 NWidget(NWID_HORIZONTAL),
315 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
316 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
317 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
318 EndContainer(),
319 NWidget(NWID_HORIZONTAL_LTR),
320 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),
321 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),
322 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
323 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
324 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),
325 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),
326 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
327 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),
328 EndContainer(),
331 static WindowDesc::Prefs _build_docks_toolbar_prefs ("toolbar_water");
333 static const WindowDesc _build_docks_toolbar_desc(
334 WDP_ALIGN_TOOLBAR, 0, 0,
335 WC_BUILD_TOOLBAR, WC_NONE,
336 WDF_CONSTRUCTION,
337 _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets),
338 &_build_docks_toolbar_prefs, &BuildDocksToolbarWindow::hotkeys
342 * Open the build water toolbar window
344 * If the terraform toolbar is linked to the toolbar, that window is also opened.
346 * @return newly opened water toolbar, or NULL if the toolbar could not be opened.
348 Window *ShowBuildDocksToolbar()
350 if (!Company::IsValidID(_local_company)) return NULL;
352 DeleteWindowByClass(WC_BUILD_TOOLBAR);
353 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
357 * Nested widget parts of docks toolbar, scenario editor version.
358 * Positions of #WID_DT_DEPOT, #WID_DT_STATION, and #WID_DT_BUOY widgets have changed.
360 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
361 NWidget(NWID_HORIZONTAL),
362 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
363 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
364 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
365 EndContainer(),
366 NWidget(NWID_HORIZONTAL),
367 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),
368 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),
369 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
370 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
371 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),
372 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),
373 EndContainer(),
376 /** Window preferences for the build docks in scenario editor window. */
377 static WindowDesc::Prefs _build_docks_scen_toolbar_prefs ("toolbar_water_scen");
379 /** Window definition for the build docks in scenario editor window. */
380 static const WindowDesc _build_docks_scen_toolbar_desc(
381 WDP_AUTO, 0, 0,
382 WC_SCEN_BUILD_TOOLBAR, WC_NONE,
383 WDF_CONSTRUCTION,
384 _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets),
385 &_build_docks_scen_toolbar_prefs
389 * Open the build water toolbar window for the scenario editor.
391 * @return newly opened water toolbar, or NULL if the toolbar could not be opened.
393 Window *ShowBuildDocksScenToolbar()
395 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
398 /** Widget numbers of the build-dock GUI. */
399 enum BuildDockStationWidgets {
400 BDSW_BACKGROUND, ///< Background panel.
401 BDSW_LT_OFF, ///< 'Off' button of coverage high light.
402 BDSW_LT_ON, ///< 'On' button of coverage high light.
403 BDSW_INFO, ///< 'Coverage highlight' label.
406 struct BuildDocksStationWindow : public PickerWindowBase {
407 public:
408 BuildDocksStationWindow (const WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
410 this->InitNested(TRANSPORT_WATER);
411 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
414 void OnDelete (void) FINAL_OVERRIDE
416 DeleteWindowById(WC_SELECT_STATION, 0);
417 this->PickerWindowBase::OnDelete();
420 void OnPaint (BlitArea *dpi) OVERRIDE
422 int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
424 this->DrawWidgets (dpi);
426 if (_settings_client.gui.station_show_coverage) {
427 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
428 } else {
429 SetTileSelectSize(1, 1);
432 /* strings such as 'Size' and 'Coverage Area' */
433 int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
434 NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
435 int right = back_nwi->pos_x + back_nwi->current_x;
436 int bottom = back_nwi->pos_y + back_nwi->current_y;
437 top = DrawStationCoverageAreaText (dpi, back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, rad);
438 /* Resize background if the window is too small.
439 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
440 * (This is the case, if making the window bigger moves the mouse into the window.) */
441 if (top > bottom) {
442 ResizeWindow(this, 0, top - bottom, false);
446 virtual void OnClick(Point pt, int widget, int click_count)
448 switch (widget) {
449 case BDSW_LT_OFF:
450 case BDSW_LT_ON:
451 this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
452 _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
453 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
454 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
455 this->SetDirty();
456 break;
460 virtual void OnTick()
462 CheckRedrawStationCoverage(this);
466 /** Nested widget parts of a build dock station window. */
467 static const NWidgetPart _nested_build_dock_station_widgets[] = {
468 NWidget(NWID_HORIZONTAL),
469 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
470 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
471 EndContainer(),
472 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
473 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
474 NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetMinimalSize(148, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
475 NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14),
476 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),
477 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),
478 EndContainer(),
479 NWidget(NWID_SPACER), SetMinimalSize(0, 20), SetResize(0, 1),
480 EndContainer(),
483 static const WindowDesc _build_dock_station_desc(
484 WDP_AUTO, 0, 0,
485 WC_BUILD_STATION, WC_BUILD_TOOLBAR,
486 WDF_CONSTRUCTION,
487 _nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
490 static void ShowBuildDockStationPicker(Window *parent)
492 new BuildDocksStationWindow(&_build_dock_station_desc, parent);
495 struct BuildDocksDepotWindow : public PickerWindowBase {
496 private:
497 static void UpdateDocksDirection()
499 if (_ship_depot_direction != AXIS_X) {
500 SetTileSelectSize(1, 2);
501 } else {
502 SetTileSelectSize(2, 1);
506 public:
507 BuildDocksDepotWindow (const WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
509 this->InitNested(TRANSPORT_WATER);
510 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
511 UpdateDocksDirection();
514 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
516 switch (widget) {
517 case WID_BDD_X:
518 case WID_BDD_Y:
519 size->width = ScaleGUITrad(96) + 2;
520 size->height = ScaleGUITrad(64) + 2;
521 break;
525 void OnPaint (BlitArea *dpi) OVERRIDE
527 this->DrawWidgets (dpi);
529 int x1 = ScaleGUITrad(63) + 1;
530 int x2 = ScaleGUITrad(31) + 1;
531 int y1 = ScaleGUITrad(17) + 1;
532 int y2 = ScaleGUITrad(33) + 1;
534 NWidgetBase *wid_x = this->GetWidget<NWidgetBase> (WID_BDD_X);
535 DrawShipDepotSprite (dpi, wid_x->pos_x + x1, wid_x->pos_y + y1, DIAGDIR_NE);
536 DrawShipDepotSprite (dpi, wid_x->pos_x + x2, wid_x->pos_y + y2, DIAGDIR_SW);
538 NWidgetBase *wid_y = this->GetWidget<NWidgetBase> (WID_BDD_Y);
539 DrawShipDepotSprite (dpi, wid_y->pos_x + x2, wid_y->pos_y + y1, DIAGDIR_NW);
540 DrawShipDepotSprite (dpi, wid_y->pos_x + x1, wid_y->pos_y + y2, DIAGDIR_SE);
543 virtual void OnClick(Point pt, int widget, int click_count)
545 switch (widget) {
546 case WID_BDD_X:
547 case WID_BDD_Y:
548 this->RaiseWidget(_ship_depot_direction + WID_BDD_X);
549 _ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
550 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
551 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
552 UpdateDocksDirection();
553 this->SetDirty();
554 break;
559 static const NWidgetPart _nested_build_docks_depot_widgets[] = {
560 NWidget(NWID_HORIZONTAL),
561 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
562 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
563 EndContainer(),
564 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
565 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
566 NWidget(NWID_HORIZONTAL_LTR),
567 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
568 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
569 EndContainer(),
570 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
571 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
572 EndContainer(),
573 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
574 EndContainer(),
575 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
576 EndContainer(),
579 static const WindowDesc _build_docks_depot_desc(
580 WDP_AUTO, 0, 0,
581 WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
582 WDF_CONSTRUCTION,
583 _nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
587 static void ShowBuildDocksDepotPicker(Window *parent)
589 new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
593 void InitializeDockGui()
595 _ship_depot_direction = AXIS_X;