OpenTTD: src/dock_gui.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

dock_gui.cpp
Go to the documentation of this file.
1 /* $Id: dock_gui.cpp 27134 2015-02-01 20:54:24Z frosch $ */
2
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 */
9
12 #include "stdafx.h"
13 #include "terraform_gui.h"
14 #include "window_gui.h"
15 #include "station_gui.h"
16 #include "command_func.h"
17 #include "water.h"
18 #include "window_func.h"
19 #include "vehicle_func.h"
20 #include "sound_func.h"
21 #include "viewport_func.h"
22 #include "gfx_func.h"
23 #include "company_func.h"
24 #include "slope_func.h"
25 #include "tilehighlight_func.h"
26 #include "company_base.h"
27 #include "hotkeys.h"
28 #include "gui.h"
29 #include "zoom_func.h"
30
31 #include "widgets/dock_widget.h"
32
33 #include "table/sprites.h"
34 #include "table/strings.h"
35
36 #include "safeguards.h"
37
38 static void ShowBuildDockStationPicker(Window *parent);
39 static void ShowBuildDocksDepotPicker(Window *parent);
40
41 static Axis _ship_depot_direction;
42
43 void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
44 {
45 if (result.Failed()) return;
46
47 if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, tile);
48 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
49 }
50
51 void CcBuildCanal(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
52 {
53 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, tile);
54 }
55
56
63 static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = NULL)
64 {
65 int z;
66 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, &z));
67
68 /* If the direction isn't right, just return the next tile so the command
69 * complains about the wrong slope instead of the ends not matching up.
70 * Make sure the coordinate is always a valid tile within the map, so we
71 * don't go "off" the map. That would cause the wrong error message. */
72 if (!IsValidDiagDirection(dir)) return TILE_ADDXY(tile_from, TileX(tile_from) > 2 ? -1 : 1, 0);
73
74 /* Direction the aqueduct is built to. */
75 TileIndexDiff offset = TileOffsByDiagDir(ReverseDiagDir(dir));
76 /* The maximum length of the aqueduct. */
77 int max_length = min(_settings_game.construction.max_bridge_length, DistanceFromEdgeDir(tile_from, ReverseDiagDir(dir)) - 1);
78
79 TileIndex endtile = tile_from;
80 for (int length = 0; IsValidTile(endtile) && TileX(endtile) != 0 && TileY(endtile) != 0; length++) {
81 endtile = TILE_ADD(endtile, offset);
82
83 if (length > max_length) break;
84
85 if (GetTileMaxZ(endtile) > z) {
86 if (tile_to != NULL) *tile_to = endtile;
87 break;
88 }
89 }
90
91 return endtile;
92 }
93
95 struct BuildDocksToolbarWindow : Window {
96 DockToolbarWidgets last_clicked_widget;
97
98 BuildDocksToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
99 {
100 this->last_clicked_widget = WID_DT_INVALID;
101 this->InitNested(window_number);
102 this->OnInvalidateData();
103 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
104 }
105
106 ~BuildDocksToolbarWindow()
107 {
108 if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
109 }
110
116 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
117 {
118 if (!gui_scope) return;
119 this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP),
120 WID_DT_DEPOT,
121 WID_DT_STATION,
122 WID_DT_BUOY,
123 WIDGET_LIST_END);
124 }
125
126 virtual void OnClick(Point pt, int widget, int click_count)
127 {
128 switch (widget) {
129 case WID_DT_CANAL: // Build canal button
130 HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
131 break;
132
133 case WID_DT_LOCK: // Build lock button
134 HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
135 break;
136
137 case WID_DT_DEMOLISH: // Demolish aka dynamite button
138 HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
139 break;
140
141 case WID_DT_DEPOT: // Build depot button
142 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
143 if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
144 break;
145
146 case WID_DT_STATION: // Build station button
147 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
148 if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
149 break;
150
151 case WID_DT_BUOY: // Build buoy button
152 if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
153 HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
154 break;
155
156 case WID_DT_RIVER: // Build river button (in scenario editor)
157 if (_game_mode != GM_EDITOR) return;
158 HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT);
159 break;
160
161 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
162 HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
163 break;
164
165 default: return;
166 }
167 this->last_clicked_widget = (DockToolbarWidgets)widget;
168 }
169
170 virtual void OnPlaceObject(Point pt, TileIndex tile)
171 {
172 switch (this->last_clicked_widget) {
173 case WID_DT_CANAL: // Build canal button
174 VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
175 break;
176
177 case WID_DT_LOCK: // Build lock button
178 DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
179 break;
180
181 case WID_DT_DEMOLISH: // Demolish aka dynamite button
182 PlaceProc_DemolishArea(tile);
183 break;
184
185 case WID_DT_DEPOT: // Build depot button
186 DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
187 break;
188
189 case WID_DT_STATION: { // Build station button
190 uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
191
192 /* tile is always the land tile, so need to evaluate _thd.pos */
193 CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
194
195 /* Determine the watery part of the dock. */
196 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
197 TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
198
199 ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
200 break;
201 }
202
203 case WID_DT_BUOY: // Build buoy button
204 DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
205 break;
206
207 case WID_DT_RIVER: // Build river button (in scenario editor)
208 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
209 break;
210
211 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
212 DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
213 break;
214
215 default: NOT_REACHED();
216 }
217 }
218
219 virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
220 {
221 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
222 }
223
224 virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
225 {
226 if (pt.x != -1) {
227 switch (select_proc) {
228 case DDSP_DEMOLISH_AREA:
229 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
230 break;
231 case DDSP_CREATE_WATER:
232 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);
233 break;
234 case DDSP_CREATE_RIVER:
235 DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal);
236 break;
237
238 default: break;
239 }
240 }
241 }
242
243 virtual void OnPlaceObjectAbort()
244 {
245 this->RaiseButtons();
246
247 DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
248 DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
249 DeleteWindowById(WC_SELECT_STATION, 0);
250 DeleteWindowByClass(WC_BUILD_BRIDGE);
251 }
252
253 virtual void OnPlacePresize(Point pt, TileIndex tile_from)
254 {
255 TileIndex tile_to = tile_from;
256
257 if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
258 GetOtherAqueductEnd(tile_from, &tile_to);
259 } else {
260 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
261 if (IsValidDiagDirection(dir)) {
262 /* Locks and docks always select the tile "down" the slope. */
263 tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
264 /* Locks also select the tile "up" the slope. */
265 if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
266 }
267 }
268
269 VpSetPresizeRange(tile_from, tile_to);
270 }
271
272 static HotkeyList hotkeys;
273 };
274
280 static EventState DockToolbarGlobalHotkeys(int hotkey)
281 {
282 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
283 Window *w = ShowBuildDocksToolbar();
284 if (w == NULL) return ES_NOT_HANDLED;
285 return w->OnHotkey(hotkey);
286 }
287
288 const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
289
290 static Hotkey dockstoolbar_hotkeys[] = {
291 Hotkey('1', "canal", WID_DT_CANAL),
292 Hotkey('2', "lock", WID_DT_LOCK),
293 Hotkey('3', "demolish", WID_DT_DEMOLISH),
294 Hotkey('4', "depot", WID_DT_DEPOT),
295 Hotkey('5', "dock", WID_DT_STATION),
296 Hotkey('6', "buoy", WID_DT_BUOY),
297 Hotkey('7', "river", WID_DT_RIVER),
298 Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
299 HOTKEY_LIST_END
300 };
301 HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys, DockToolbarGlobalHotkeys);
302
307 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
308 NWidget(NWID_HORIZONTAL),
309 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
310 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
311 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
312 EndContainer(),
313 NWidget(NWID_HORIZONTAL_LTR),
314 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),
315 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),
316 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
317 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
318 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),
319 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),
320 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
321 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),
322 EndContainer(),
323 };
324
325 static WindowDesc _build_docks_toolbar_desc(
326 WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0,
327 WC_BUILD_TOOLBAR, WC_NONE,
328 WDF_CONSTRUCTION,
329 _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets),
330 &BuildDocksToolbarWindow::hotkeys
331 );
332
340 Window *ShowBuildDocksToolbar()
341 {
342 if (!Company::IsValidID(_local_company)) return NULL;
343
344 DeleteWindowByClass(WC_BUILD_TOOLBAR);
345 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
346 }
347
352 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
353 NWidget(NWID_HORIZONTAL),
354 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
355 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
356 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
357 EndContainer(),
358 NWidget(NWID_HORIZONTAL),
359 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),
360 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),
361 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
362 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
363 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),
364 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),
365 EndContainer(),
366 };
367
369 static WindowDesc _build_docks_scen_toolbar_desc(
370 WDP_AUTO, "toolbar_water_scen", 0, 0,
371 WC_SCEN_BUILD_TOOLBAR, WC_NONE,
372 WDF_CONSTRUCTION,
373 _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets)
374 );
375
381 Window *ShowBuildDocksScenToolbar()
382 {
383 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
384 }
385
387 enum BuildDockStationWidgets {
388 BDSW_BACKGROUND,
389 BDSW_LT_OFF,
390 BDSW_LT_ON,
391 BDSW_INFO,
392 };
393
394 struct BuildDocksStationWindow : public PickerWindowBase {
395 public:
396 BuildDocksStationWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
397 {
398 this->InitNested(TRANSPORT_WATER);
399 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
400 }
401
402 virtual ~BuildDocksStationWindow()
403 {
404 DeleteWindowById(WC_SELECT_STATION, 0);
405 }
406
407 virtual void OnPaint()
408 {
409 int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
410
411 this->DrawWidgets();
412
413 if (_settings_client.gui.station_show_coverage) {
414 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
415 } else {
416 SetTileSelectSize(1, 1);
417 }
418
419 /* strings such as 'Size' and 'Coverage Area' */
420 int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
421 NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
422 int right = back_nwi->pos_x + back_nwi->current_x;
423 int bottom = back_nwi->pos_y + back_nwi->current_y;
424 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
425 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
426 /* Resize background if the window is too small.
427 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
428 * (This is the case, if making the window bigger moves the mouse into the window.) */
429 if (top > bottom) {
430 ResizeWindow(this, 0, top - bottom);
431 }
432 }
433
434 virtual void OnClick(Point pt, int widget, int click_count)
435 {
436 switch (widget) {
437 case BDSW_LT_OFF:
438 case BDSW_LT_ON:
439 this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
440 _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
441 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
442 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
443 this->SetDirty();
444 break;
445 }
446 }
447
448 virtual void OnTick()
449 {
450 CheckRedrawStationCoverage(this);
451 }
452 };
453
455 static const NWidgetPart _nested_build_dock_station_widgets[] = {
456 NWidget(NWID_HORIZONTAL),
457 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
458 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
459 EndContainer(),
460 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
461 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
462 NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetMinimalSize(148, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
463 NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14),
464 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),
465 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),
466 EndContainer(),
467 NWidget(NWID_SPACER), SetMinimalSize(0, 20), SetResize(0, 1),
468 EndContainer(),
469 };
470
471 static WindowDesc _build_dock_station_desc(
472 WDP_AUTO, NULL, 0, 0,
473 WC_BUILD_STATION, WC_BUILD_TOOLBAR,
474 WDF_CONSTRUCTION,
475 _nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
476 );
477
478 static void ShowBuildDockStationPicker(Window *parent)
479 {
480 new BuildDocksStationWindow(&_build_dock_station_desc, parent);
481 }
482
483 struct BuildDocksDepotWindow : public PickerWindowBase {
484 private:
485 static void UpdateDocksDirection()
486 {
487 if (_ship_depot_direction != AXIS_X) {
488 SetTileSelectSize(1, 2);
489 } else {
490 SetTileSelectSize(2, 1);
491 }
492 }
493
494 public:
495 BuildDocksDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
496 {
497 this->InitNested(TRANSPORT_WATER);
498 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
499 UpdateDocksDirection();
500 }
501
502 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
503 {
504 switch (widget) {
505 case WID_BDD_X:
506 case WID_BDD_Y:
507 size->width = ScaleGUITrad(96) + 2;
508 size->height = ScaleGUITrad(64) + 2;
509 break;
510 }
511 }
512
513 virtual void OnPaint()
514 {
515 this->DrawWidgets();
516
517 int x1 = ScaleGUITrad(63) + 1;
518 int x2 = ScaleGUITrad(31) + 1;
519 int y1 = ScaleGUITrad(17) + 1;
520 int y2 = ScaleGUITrad(33) + 1;
521
522 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + x1, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + y1, AXIS_X, DEPOT_PART_NORTH);
523 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + x2, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + y2, AXIS_X, DEPOT_PART_SOUTH);
524 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + x2, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + y1, AXIS_Y, DEPOT_PART_NORTH);
525 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + x1, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + y2, AXIS_Y, DEPOT_PART_SOUTH);
526 }
527
528 virtual void OnClick(Point pt, int widget, int click_count)
529 {
530 switch (widget) {
531 case WID_BDD_X:
532 case WID_BDD_Y:
533 this->RaiseWidget(_ship_depot_direction + WID_BDD_X);
534 _ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
535 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
536 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
537 UpdateDocksDirection();
538 this->SetDirty();
539 break;
540 }
541 }
542 };
543
544 static const NWidgetPart _nested_build_docks_depot_widgets[] = {
545 NWidget(NWID_HORIZONTAL),
546 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
547 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
548 EndContainer(),
549 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
550 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
551 NWidget(NWID_HORIZONTAL_LTR),
552 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
553 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
554 EndContainer(),
555 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
556 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
557 EndContainer(),
558 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
559 EndContainer(),
560 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
561 EndContainer(),
562 };
563
564 static WindowDesc _build_docks_depot_desc(
565 WDP_AUTO, NULL, 0, 0,
566 WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
567 WDF_CONSTRUCTION,
568 _nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
569 );
570
571
572 static void ShowBuildDocksDepotPicker(Window *parent)
573 {
574 new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
575 }
576
577
578 void InitializeDockGui()
579 {
580 _ship_depot_direction = AXIS_X;
581 }