Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / dock_gui.cpp
blob77ebe1be782d5b2fafcb96cfc3eccf9e943aa763
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file dock_gui.cpp GUI to create amazing water objects. */
10 #include "stdafx.h"
11 #include "terraform_gui.h"
12 #include "window_gui.h"
13 #include "station_gui.h"
14 #include "command_func.h"
15 #include "water.h"
16 #include "window_func.h"
17 #include "vehicle_func.h"
18 #include "sound_func.h"
19 #include "viewport_func.h"
20 #include "gfx_func.h"
21 #include "company_func.h"
22 #include "slope_func.h"
23 #include "tilehighlight_func.h"
24 #include "company_base.h"
25 #include "hotkeys.h"
26 #include "gui.h"
27 #include "zoom_func.h"
29 #include "widgets/dock_widget.h"
31 #include "table/sprites.h"
32 #include "table/strings.h"
34 #include "safeguards.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, uint32 cmd)
43 if (result.Failed()) return;
45 if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
46 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
49 void CcPlaySound_CONSTRUCTION_WATER(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
51 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, 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 = nullptr)
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 = std::min<int>(_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 != nullptr) *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 void Close() override
106 if (_game_mode == GM_NORMAL && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true);
107 if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WC_SCEN_LAND_GEN, 0, false);
108 this->Window::Close();
112 * Some data on this window has become invalid.
113 * @param data Information about the changed data.
114 * @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.
116 void OnInvalidateData(int data = 0, bool gui_scope = true) override
118 if (!gui_scope) return;
120 bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP);
121 this->SetWidgetsDisabledState(!can_build,
122 WID_DT_DEPOT,
123 WID_DT_STATION,
124 WID_DT_BUOY,
125 WIDGET_LIST_END);
126 if (!can_build) {
127 CloseWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
128 CloseWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
131 if (_game_mode != GM_EDITOR) {
132 if (!can_build) {
133 /* Show in the tooltip why this button is disabled. */
134 this->GetWidget<NWidgetCore>(WID_DT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
135 this->GetWidget<NWidgetCore>(WID_DT_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
136 this->GetWidget<NWidgetCore>(WID_DT_BUOY)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
137 } else {
138 this->GetWidget<NWidgetCore>(WID_DT_DEPOT)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP);
139 this->GetWidget<NWidgetCore>(WID_DT_STATION)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP);
140 this->GetWidget<NWidgetCore>(WID_DT_BUOY)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP);
145 void OnClick(Point pt, int widget, int click_count) override
147 switch (widget) {
148 case WID_DT_CANAL: // Build canal button
149 HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
150 break;
152 case WID_DT_LOCK: // Build lock button
153 HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
154 break;
156 case WID_DT_DEMOLISH: // Demolish aka dynamite button
157 HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
158 break;
160 case WID_DT_DEPOT: // Build depot button
161 if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
162 break;
164 case WID_DT_STATION: // Build station button
165 if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
166 break;
168 case WID_DT_BUOY: // Build buoy button
169 HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
170 break;
172 case WID_DT_RIVER: // Build river button (in scenario editor)
173 if (_game_mode != GM_EDITOR) return;
174 HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT | HT_DIAGONAL);
175 break;
177 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
178 HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
179 break;
181 default: return;
183 this->last_clicked_widget = (DockToolbarWidgets)widget;
186 void OnPlaceObject(Point pt, TileIndex tile) override
188 switch (this->last_clicked_widget) {
189 case WID_DT_CANAL: // Build canal button
190 VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_WATER);
191 break;
193 case WID_DT_LOCK: // Build lock button
194 DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
195 break;
197 case WID_DT_DEMOLISH: // Demolish aka dynamite button
198 PlaceProc_DemolishArea(tile);
199 break;
201 case WID_DT_DEPOT: // Build depot button
202 DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
203 break;
205 case WID_DT_STATION: { // Build station button
206 uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join
208 /* tile is always the land tile, so need to evaluate _thd.pos */
209 CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks, "" };
211 /* Determine the watery part of the dock. */
212 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
213 TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
215 ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
216 break;
219 case WID_DT_BUOY: // Build buoy button
220 DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
221 break;
223 case WID_DT_RIVER: // Build river button (in scenario editor)
224 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
225 break;
227 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
228 DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
229 break;
231 default: NOT_REACHED();
235 void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
237 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
240 void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
242 if (pt.x != -1) {
243 switch (select_proc) {
244 case DDSP_DEMOLISH_AREA:
245 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
246 break;
247 case DDSP_CREATE_WATER:
248 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), CcPlaySound_CONSTRUCTION_WATER);
249 break;
250 case DDSP_CREATE_RIVER:
251 DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER | (_ctrl_pressed ? 1 << 2 : 0), CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcPlaySound_CONSTRUCTION_WATER);
252 break;
254 default: break;
259 void OnPlaceObjectAbort() override
261 if (_game_mode != GM_EDITOR && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true);
263 this->RaiseButtons();
265 CloseWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
266 CloseWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
267 CloseWindowById(WC_SELECT_STATION, 0);
268 CloseWindowByClass(WC_BUILD_BRIDGE);
271 void OnPlacePresize(Point pt, TileIndex tile_from) override
273 TileIndex tile_to = tile_from;
275 if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
276 GetOtherAqueductEnd(tile_from, &tile_to);
277 } else {
278 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
279 if (IsValidDiagDirection(dir)) {
280 /* Locks and docks always select the tile "down" the slope. */
281 tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
282 /* Locks also select the tile "up" the slope. */
283 if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
287 VpSetPresizeRange(tile_from, tile_to);
290 static HotkeyList hotkeys;
294 * Handler for global hotkeys of the BuildDocksToolbarWindow.
295 * @param hotkey Hotkey
296 * @return ES_HANDLED if hotkey was accepted.
298 static EventState DockToolbarGlobalHotkeys(int hotkey)
300 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
301 Window *w = ShowBuildDocksToolbar();
302 if (w == nullptr) return ES_NOT_HANDLED;
303 return w->OnHotkey(hotkey);
306 const uint16 _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
308 static Hotkey dockstoolbar_hotkeys[] = {
309 Hotkey('1', "canal", WID_DT_CANAL),
310 Hotkey('2', "lock", WID_DT_LOCK),
311 Hotkey('3', "demolish", WID_DT_DEMOLISH),
312 Hotkey('4', "depot", WID_DT_DEPOT),
313 Hotkey('5', "dock", WID_DT_STATION),
314 Hotkey('6', "buoy", WID_DT_BUOY),
315 Hotkey('7', "river", WID_DT_RIVER),
316 Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
317 HOTKEY_LIST_END
319 HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys, DockToolbarGlobalHotkeys);
322 * Nested widget parts of docks toolbar, game version.
323 * Position of #WID_DT_RIVER widget has changed.
325 static const NWidgetPart _nested_build_docks_toolbar_widgets[] = {
326 NWidget(NWID_HORIZONTAL),
327 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
328 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
329 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
330 EndContainer(),
331 NWidget(NWID_HORIZONTAL_LTR),
332 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),
333 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),
334 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
335 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
336 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),
337 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),
338 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
339 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),
340 EndContainer(),
343 static WindowDesc _build_docks_toolbar_desc(
344 WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0,
345 WC_BUILD_TOOLBAR, WC_NONE,
346 WDF_CONSTRUCTION,
347 _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets),
348 &BuildDocksToolbarWindow::hotkeys
352 * Open the build water toolbar window
354 * If the terraform toolbar is linked to the toolbar, that window is also opened.
356 * @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
358 Window *ShowBuildDocksToolbar()
360 if (!Company::IsValidID(_local_company)) return nullptr;
362 CloseWindowByClass(WC_BUILD_TOOLBAR);
363 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
367 * Nested widget parts of docks toolbar, scenario editor version.
368 * Positions of #WID_DT_DEPOT, #WID_DT_STATION, and #WID_DT_BUOY widgets have changed.
370 static const NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
371 NWidget(NWID_HORIZONTAL),
372 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
373 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
374 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
375 EndContainer(),
376 NWidget(NWID_HORIZONTAL),
377 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),
378 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),
379 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
380 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
381 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),
382 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),
383 EndContainer(),
386 /** Window definition for the build docks in scenario editor window. */
387 static WindowDesc _build_docks_scen_toolbar_desc(
388 WDP_AUTO, "toolbar_water_scen", 0, 0,
389 WC_SCEN_BUILD_TOOLBAR, WC_NONE,
390 WDF_CONSTRUCTION,
391 _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets)
395 * Open the build water toolbar window for the scenario editor.
397 * @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
399 Window *ShowBuildDocksScenToolbar()
401 return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
404 /** Widget numbers of the build-dock GUI. */
405 enum BuildDockStationWidgets {
406 BDSW_BACKGROUND, ///< Background panel.
407 BDSW_LT_OFF, ///< 'Off' button of coverage high light.
408 BDSW_LT_ON, ///< 'On' button of coverage high light.
409 BDSW_INFO, ///< 'Coverage highlight' label.
412 struct BuildDocksStationWindow : public PickerWindowBase {
413 public:
414 BuildDocksStationWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
416 this->InitNested(TRANSPORT_WATER);
417 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
420 void Close() override
422 CloseWindowById(WC_SELECT_STATION, 0);
423 this->PickerWindowBase::Close();
426 void OnPaint() override
428 int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
430 this->DrawWidgets();
432 if (_settings_client.gui.station_show_coverage) {
433 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
434 } else {
435 SetTileSelectSize(1, 1);
438 /* strings such as 'Size' and 'Coverage Area' */
439 int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
440 NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(BDSW_BACKGROUND);
441 int right = back_nwi->pos_x + back_nwi->current_x;
442 int bottom = back_nwi->pos_y + back_nwi->current_y;
443 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
444 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
445 /* Resize background if the window is too small.
446 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
447 * (This is the case, if making the window bigger moves the mouse into the window.) */
448 if (top > bottom) {
449 ResizeWindow(this, 0, top - bottom, false);
453 void OnClick(Point pt, int widget, int click_count) override
455 switch (widget) {
456 case BDSW_LT_OFF:
457 case BDSW_LT_ON:
458 this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
459 _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
460 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
461 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
462 this->SetDirty();
463 SetViewportCatchmentStation(nullptr, true);
464 break;
468 void OnRealtimeTick(uint delta_ms) override
470 CheckRedrawStationCoverage(this);
474 /** Nested widget parts of a build dock station window. */
475 static const NWidgetPart _nested_build_dock_station_widgets[] = {
476 NWidget(NWID_HORIZONTAL),
477 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
478 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
479 EndContainer(),
480 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
481 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
482 NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetMinimalSize(148, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
483 NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14),
484 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),
485 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),
486 EndContainer(),
487 NWidget(NWID_SPACER), SetMinimalSize(0, 20), SetResize(0, 1),
488 EndContainer(),
491 static WindowDesc _build_dock_station_desc(
492 WDP_AUTO, nullptr, 0, 0,
493 WC_BUILD_STATION, WC_BUILD_TOOLBAR,
494 WDF_CONSTRUCTION,
495 _nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
498 static void ShowBuildDockStationPicker(Window *parent)
500 new BuildDocksStationWindow(&_build_dock_station_desc, parent);
503 struct BuildDocksDepotWindow : public PickerWindowBase {
504 private:
505 static void UpdateDocksDirection()
507 if (_ship_depot_direction != AXIS_X) {
508 SetTileSelectSize(1, 2);
509 } else {
510 SetTileSelectSize(2, 1);
514 public:
515 BuildDocksDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
517 this->InitNested(TRANSPORT_WATER);
518 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
519 UpdateDocksDirection();
522 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
524 switch (widget) {
525 case WID_BDD_X:
526 case WID_BDD_Y:
527 size->width = ScaleGUITrad(96) + 2;
528 size->height = ScaleGUITrad(64) + 2;
529 break;
533 void OnPaint() override
535 this->DrawWidgets();
537 int x1 = ScaleGUITrad(63) + 1;
538 int x2 = ScaleGUITrad(31) + 1;
539 int y1 = ScaleGUITrad(17) + 1;
540 int y2 = ScaleGUITrad(33) + 1;
542 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + x1, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + y1, AXIS_X, DEPOT_PART_NORTH);
543 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_x + x2, this->GetWidget<NWidgetBase>(WID_BDD_X)->pos_y + y2, AXIS_X, DEPOT_PART_SOUTH);
544 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + x2, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + y1, AXIS_Y, DEPOT_PART_NORTH);
545 DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + x1, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + y2, AXIS_Y, DEPOT_PART_SOUTH);
548 void OnClick(Point pt, int widget, int click_count) override
550 switch (widget) {
551 case WID_BDD_X:
552 case WID_BDD_Y:
553 this->RaiseWidget(_ship_depot_direction + WID_BDD_X);
554 _ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
555 this->LowerWidget(_ship_depot_direction + WID_BDD_X);
556 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
557 UpdateDocksDirection();
558 this->SetDirty();
559 break;
564 static const NWidgetPart _nested_build_docks_depot_widgets[] = {
565 NWidget(NWID_HORIZONTAL),
566 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
567 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
568 EndContainer(),
569 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
570 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
571 NWidget(NWID_HORIZONTAL_LTR),
572 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
573 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
574 EndContainer(),
575 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
576 NWidget(WWT_PANEL, COLOUR_GREY, WID_BDD_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
577 EndContainer(),
578 NWidget(NWID_SPACER), SetMinimalSize(3, 0),
579 EndContainer(),
580 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
581 EndContainer(),
584 static WindowDesc _build_docks_depot_desc(
585 WDP_AUTO, nullptr, 0, 0,
586 WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
587 WDF_CONSTRUCTION,
588 _nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
592 static void ShowBuildDocksDepotPicker(Window *parent)
594 new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
598 void InitializeDockGui()
600 _ship_depot_direction = AXIS_X;