Codechange: Use lowercase name for winnls.h (#13170)
[openttd-github.git] / src / dock_gui.cpp
blobffbf5aa63e3c2fd4084082287f08f99f61ba5394
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"
28 #include "tunnelbridge_cmd.h"
29 #include "dock_cmd.h"
30 #include "station_cmd.h"
31 #include "water_cmd.h"
32 #include "waypoint_cmd.h"
33 #include "timer/timer.h"
34 #include "timer/timer_game_calendar.h"
36 #include "widgets/dock_widget.h"
38 #include "table/sprites.h"
39 #include "table/strings.h"
41 #include "safeguards.h"
43 static void ShowBuildDockStationPicker(Window *parent);
44 static void ShowBuildDocksDepotPicker(Window *parent);
46 static Axis _ship_depot_direction;
48 void CcBuildDocks(Commands, const CommandCost &result, TileIndex tile)
50 if (result.Failed()) return;
52 if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
53 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
56 void CcPlaySound_CONSTRUCTION_WATER(Commands, const CommandCost &result, TileIndex tile)
58 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
62 /**
63 * Gets the other end of the aqueduct, if possible.
64 * @param tile_from The begin tile for the aqueduct.
65 * @param[out] tile_to The tile till where to show a selection for the aqueduct.
66 * @return The other end of the aqueduct, or otherwise a tile in line with the aqueduct to cause the right error message.
68 static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = nullptr)
70 auto [slope, z] = GetTileSlopeZ(tile_from);
71 DiagDirection dir = GetInclinedSlopeDirection(slope);
73 /* If the direction isn't right, just return the next tile so the command
74 * complains about the wrong slope instead of the ends not matching up.
75 * Make sure the coordinate is always a valid tile within the map, so we
76 * don't go "off" the map. That would cause the wrong error message. */
77 if (!IsValidDiagDirection(dir)) return TileAddXY(tile_from, TileX(tile_from) > 2 ? -1 : 1, 0);
79 /* Direction the aqueduct is built to. */
80 TileIndexDiff offset = TileOffsByDiagDir(ReverseDiagDir(dir));
81 /* The maximum length of the aqueduct. */
82 int max_length = std::min<int>(_settings_game.construction.max_bridge_length, DistanceFromEdgeDir(tile_from, ReverseDiagDir(dir)) - 1);
84 TileIndex endtile = tile_from;
85 for (int length = 0; IsValidTile(endtile) && TileX(endtile) != 0 && TileY(endtile) != 0; length++) {
86 endtile = TileAdd(endtile, offset);
88 if (length > max_length) break;
90 if (GetTileMaxZ(endtile) > z) {
91 if (tile_to != nullptr) *tile_to = endtile;
92 break;
96 return endtile;
99 /** Toolbar window for constructing water infrastructure. */
100 struct BuildDocksToolbarWindow : Window {
101 DockToolbarWidgets last_clicked_widget; ///< Contains the last widget that has been clicked on this toolbar.
103 BuildDocksToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
105 this->last_clicked_widget = WID_DT_INVALID;
106 this->InitNested(window_number);
107 this->OnInvalidateData();
108 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
111 void Close([[maybe_unused]] int data = 0) override
113 if (_game_mode == GM_NORMAL && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true);
114 if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WC_SCEN_LAND_GEN, 0, false);
115 this->Window::Close();
119 * Some data on this window has become invalid.
120 * @param data Information about the changed data.
121 * @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.
123 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
125 if (!gui_scope) return;
127 bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP);
128 this->SetWidgetsDisabledState(!can_build,
129 WID_DT_DEPOT,
130 WID_DT_STATION,
131 WID_DT_BUOY);
132 if (!can_build) {
133 CloseWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
134 CloseWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
137 if (_game_mode != GM_EDITOR) {
138 if (!can_build) {
139 /* Show in the tooltip why this button is disabled. */
140 this->GetWidget<NWidgetCore>(WID_DT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
141 this->GetWidget<NWidgetCore>(WID_DT_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
142 this->GetWidget<NWidgetCore>(WID_DT_BUOY)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
143 } else {
144 this->GetWidget<NWidgetCore>(WID_DT_DEPOT)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP);
145 this->GetWidget<NWidgetCore>(WID_DT_STATION)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP);
146 this->GetWidget<NWidgetCore>(WID_DT_BUOY)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP);
151 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
153 switch (widget) {
154 case WID_DT_CANAL: // Build canal button
155 HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
156 break;
158 case WID_DT_LOCK: // Build lock button
159 HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
160 break;
162 case WID_DT_DEMOLISH: // Demolish aka dynamite button
163 HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
164 break;
166 case WID_DT_DEPOT: // Build depot button
167 if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
168 break;
170 case WID_DT_STATION: // Build station button
171 if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
172 break;
174 case WID_DT_BUOY: // Build buoy button
175 HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
176 break;
178 case WID_DT_RIVER: // Build river button (in scenario editor)
179 if (_game_mode != GM_EDITOR) return;
180 HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT | HT_DIAGONAL);
181 break;
183 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
184 HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
185 break;
187 default: return;
189 this->last_clicked_widget = (DockToolbarWidgets)widget;
192 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
194 switch (this->last_clicked_widget) {
195 case WID_DT_CANAL: // Build canal button
196 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_WATER);
197 break;
199 case WID_DT_LOCK: // Build lock button
200 Command<CMD_BUILD_LOCK>::Post(STR_ERROR_CAN_T_BUILD_LOCKS, CcBuildDocks, tile);
201 break;
203 case WID_DT_DEMOLISH: // Demolish aka dynamite button
204 PlaceProc_DemolishArea(tile);
205 break;
207 case WID_DT_DEPOT: // Build depot button
208 Command<CMD_BUILD_SHIP_DEPOT>::Post(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT, CcBuildDocks, tile, _ship_depot_direction);
209 break;
211 case WID_DT_STATION: { // Build station button
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 bool adjacent = _ctrl_pressed;
217 auto proc = [=](bool test, StationID to_join) -> bool {
218 if (test) {
219 return Command<CMD_BUILD_DOCK>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_DOCK>()), tile, INVALID_STATION, adjacent).Succeeded();
220 } else {
221 return Command<CMD_BUILD_DOCK>::Post(STR_ERROR_CAN_T_BUILD_DOCK_HERE, CcBuildDocks, tile, to_join, adjacent);
225 ShowSelectStationIfNeeded(TileArea(tile, tile_to), proc);
226 break;
229 case WID_DT_BUOY: // Build buoy button
230 Command<CMD_BUILD_BUOY>::Post(STR_ERROR_CAN_T_POSITION_BUOY_HERE, CcBuildDocks, tile);
231 break;
233 case WID_DT_RIVER: // Build river button (in scenario editor)
234 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
235 break;
237 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
238 Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE, CcBuildBridge, tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER, 0, 0);
239 break;
241 default: NOT_REACHED();
245 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
247 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
250 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
252 if (pt.x != -1) {
253 switch (select_proc) {
254 case DDSP_DEMOLISH_AREA:
255 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
256 break;
257 case DDSP_CREATE_WATER:
258 Command<CMD_BUILD_CANAL>::Post(STR_ERROR_CAN_T_BUILD_CANALS, CcPlaySound_CONSTRUCTION_WATER, end_tile, start_tile, (_game_mode == GM_EDITOR && _ctrl_pressed) ? WATER_CLASS_SEA : WATER_CLASS_CANAL, false);
259 break;
260 case DDSP_CREATE_RIVER:
261 Command<CMD_BUILD_CANAL>::Post(STR_ERROR_CAN_T_PLACE_RIVERS, CcPlaySound_CONSTRUCTION_WATER, end_tile, start_tile, WATER_CLASS_RIVER, _ctrl_pressed);
262 break;
264 default: break;
269 void OnPlaceObjectAbort() override
271 if (_game_mode != GM_EDITOR && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true);
273 this->RaiseButtons();
275 CloseWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
276 CloseWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
277 CloseWindowById(WC_SELECT_STATION, 0);
278 CloseWindowByClass(WC_BUILD_BRIDGE);
281 void OnPlacePresize([[maybe_unused]] Point pt, TileIndex tile_from) override
283 TileIndex tile_to = tile_from;
285 if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
286 GetOtherAqueductEnd(tile_from, &tile_to);
287 } else {
288 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
289 if (IsValidDiagDirection(dir)) {
290 /* Locks and docks always select the tile "down" the slope. */
291 tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
292 /* Locks also select the tile "up" the slope. */
293 if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
297 VpSetPresizeRange(tile_from, tile_to);
301 * Handler for global hotkeys of the BuildDocksToolbarWindow.
302 * @param hotkey Hotkey
303 * @return ES_HANDLED if hotkey was accepted.
305 static EventState DockToolbarGlobalHotkeys(int hotkey)
307 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
308 Window *w = ShowBuildDocksToolbar();
309 if (w == nullptr) return ES_NOT_HANDLED;
310 return w->OnHotkey(hotkey);
313 static inline HotkeyList hotkeys{"dockstoolbar", {
314 Hotkey('1', "canal", WID_DT_CANAL),
315 Hotkey('2', "lock", WID_DT_LOCK),
316 Hotkey('3', "demolish", WID_DT_DEMOLISH),
317 Hotkey('4', "depot", WID_DT_DEPOT),
318 Hotkey('5', "dock", WID_DT_STATION),
319 Hotkey('6', "buoy", WID_DT_BUOY),
320 Hotkey('7', "river", WID_DT_RIVER),
321 Hotkey({'B', '8'}, "aqueduct", WID_DT_BUILD_AQUEDUCT),
322 }, DockToolbarGlobalHotkeys};
326 * Nested widget parts of docks toolbar, game version.
327 * Position of #WID_DT_RIVER widget has changed.
329 static constexpr NWidgetPart _nested_build_docks_toolbar_widgets[] = {
330 NWidget(NWID_HORIZONTAL),
331 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
332 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
333 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
334 EndContainer(),
335 NWidget(NWID_HORIZONTAL_LTR),
336 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),
337 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),
338 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
339 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
340 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),
341 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),
342 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
343 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),
344 EndContainer(),
347 static WindowDesc _build_docks_toolbar_desc(
348 WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0,
349 WC_BUILD_TOOLBAR, WC_NONE,
350 WDF_CONSTRUCTION,
351 _nested_build_docks_toolbar_widgets,
352 &BuildDocksToolbarWindow::hotkeys
356 * Open the build water toolbar window
358 * If the terraform toolbar is linked to the toolbar, that window is also opened.
360 * @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
362 Window *ShowBuildDocksToolbar()
364 if (!Company::IsValidID(_local_company)) return nullptr;
366 CloseWindowByClass(WC_BUILD_TOOLBAR);
367 return AllocateWindowDescFront<BuildDocksToolbarWindow>(_build_docks_toolbar_desc, TRANSPORT_WATER);
371 * Nested widget parts of docks toolbar, scenario editor version.
372 * Positions of #WID_DT_DEPOT, #WID_DT_STATION, and #WID_DT_BUOY widgets have changed.
374 static constexpr NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
375 NWidget(NWID_HORIZONTAL),
376 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
377 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
378 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
379 EndContainer(),
380 NWidget(NWID_HORIZONTAL),
381 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),
382 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),
383 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
384 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
385 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),
386 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),
387 EndContainer(),
390 /** Window definition for the build docks in scenario editor window. */
391 static WindowDesc _build_docks_scen_toolbar_desc(
392 WDP_AUTO, "toolbar_water_scen", 0, 0,
393 WC_SCEN_BUILD_TOOLBAR, WC_NONE,
394 WDF_CONSTRUCTION,
395 _nested_build_docks_scen_toolbar_widgets
399 * Open the build water toolbar window for the scenario editor.
401 * @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
403 Window *ShowBuildDocksScenToolbar()
405 return AllocateWindowDescFront<BuildDocksToolbarWindow>(_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
408 /** Widget numbers of the build-dock GUI. */
409 enum BuildDockStationWidgets {
410 BDSW_BACKGROUND, ///< Background panel.
411 BDSW_LT_OFF, ///< 'Off' button of coverage high light.
412 BDSW_LT_ON, ///< 'On' button of coverage high light.
413 BDSW_INFO, ///< 'Coverage highlight' label.
414 BDSW_ACCEPTANCE, ///< Acceptance info.
417 struct BuildDocksStationWindow : public PickerWindowBase {
418 public:
419 BuildDocksStationWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
421 this->InitNested(TRANSPORT_WATER);
422 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
425 void Close([[maybe_unused]] int data = 0) override
427 CloseWindowById(WC_SELECT_STATION, 0);
428 this->PickerWindowBase::Close();
431 void OnPaint() override
433 int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
435 this->DrawWidgets();
437 if (_settings_client.gui.station_show_coverage) {
438 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
439 } else {
440 SetTileSelectSize(1, 1);
443 /* strings such as 'Size' and 'Coverage Area' */
444 Rect r = this->GetWidget<NWidgetBase>(BDSW_ACCEPTANCE)->GetCurrentRect();
445 int top = r.top;
446 top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
447 top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, true);
448 /* Resize background if the window is too small.
449 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
450 * (This is the case, if making the window bigger moves the mouse into the window.) */
451 if (top > r.bottom) {
452 ResizeWindow(this, 0, top - r.bottom, false);
456 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
458 switch (widget) {
459 case BDSW_LT_OFF:
460 case BDSW_LT_ON:
461 this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
462 _settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
463 this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
464 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
465 this->SetDirty();
466 SetViewportCatchmentStation(nullptr, true);
467 break;
471 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
473 CheckRedrawStationCoverage(this);
476 IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
477 this->InvalidateData();
481 /** Nested widget parts of a build dock station window. */
482 static constexpr NWidgetPart _nested_build_dock_station_widgets[] = {
483 NWidget(NWID_HORIZONTAL),
484 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
485 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
486 EndContainer(),
487 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
488 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(WidgetDimensions::unscaled.picker),
489 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0),
490 NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetFill(1, 0),
491 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(14, 0, 14),
492 NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_OFF), SetMinimalSize(60, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
493 NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_ON), SetMinimalSize(60, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
494 EndContainer(),
495 EndContainer(),
496 NWidget(WWT_EMPTY, COLOUR_GREY, BDSW_ACCEPTANCE), SetResize(0, 1), SetMinimalTextLines(2, WidgetDimensions::unscaled.vsep_normal),
497 EndContainer(),
498 EndContainer(),
501 static WindowDesc _build_dock_station_desc(
502 WDP_AUTO, nullptr, 0, 0,
503 WC_BUILD_STATION, WC_BUILD_TOOLBAR,
504 WDF_CONSTRUCTION,
505 _nested_build_dock_station_widgets
508 static void ShowBuildDockStationPicker(Window *parent)
510 new BuildDocksStationWindow(_build_dock_station_desc, parent);
513 struct BuildDocksDepotWindow : public PickerWindowBase {
514 private:
515 static void UpdateDocksDirection()
517 if (_ship_depot_direction != AXIS_X) {
518 SetTileSelectSize(1, 2);
519 } else {
520 SetTileSelectSize(2, 1);
524 public:
525 BuildDocksDepotWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
527 this->InitNested(TRANSPORT_WATER);
528 this->LowerWidget(WID_BDD_X + _ship_depot_direction);
529 UpdateDocksDirection();
532 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
534 switch (widget) {
535 case WID_BDD_X:
536 case WID_BDD_Y:
537 size.width = ScaleGUITrad(96) + WidgetDimensions::scaled.fullbevel.Horizontal();
538 size.height = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Vertical();
539 break;
543 void DrawWidget(const Rect &r, WidgetID widget) const override
545 DrawPixelInfo tmp_dpi;
547 switch (widget) {
548 case WID_BDD_X:
549 case WID_BDD_Y: {
550 Axis axis = widget == WID_BDD_X ? AXIS_X : AXIS_Y;
552 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
553 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
554 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
555 int x = (ir.Width() - ScaleSpriteTrad(96)) / 2;
556 int y = (ir.Height() - ScaleSpriteTrad(64)) / 2;
557 int x1 = ScaleSpriteTrad(63);
558 int x2 = ScaleSpriteTrad(31);
559 DrawShipDepotSprite(x + (axis == AXIS_X ? x1 : x2), y + ScaleSpriteTrad(17), axis, DEPOT_PART_NORTH);
560 DrawShipDepotSprite(x + (axis == AXIS_X ? x2 : x1), y + ScaleSpriteTrad(33), axis, DEPOT_PART_SOUTH);
562 break;
567 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
569 switch (widget) {
570 case WID_BDD_X:
571 case WID_BDD_Y:
572 this->RaiseWidget(WID_BDD_X + _ship_depot_direction);
573 _ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
574 this->LowerWidget(WID_BDD_X + _ship_depot_direction);
575 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
576 UpdateDocksDirection();
577 this->SetDirty();
578 break;
583 static constexpr NWidgetPart _nested_build_docks_depot_widgets[] = {
584 NWidget(NWID_HORIZONTAL),
585 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
586 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
587 EndContainer(),
588 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
589 NWidget(NWID_HORIZONTAL_LTR), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPIPRatio(1, 0, 1), SetPadding(WidgetDimensions::unscaled.picker),
590 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BDD_X), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
591 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BDD_Y), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
592 EndContainer(),
593 EndContainer(),
596 static WindowDesc _build_docks_depot_desc(
597 WDP_AUTO, nullptr, 0, 0,
598 WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
599 WDF_CONSTRUCTION,
600 _nested_build_docks_depot_widgets
604 static void ShowBuildDocksDepotPicker(Window *parent)
606 new BuildDocksDepotWindow(_build_docks_depot_desc, parent);
610 void InitializeDockGui()
612 _ship_depot_direction = AXIS_X;