OpenTTD Source 20250328-master-gc3457cd4c0
dock_gui.cpp
Go to the documentation of this file.
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 */
7
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"
35
36#include "widgets/dock_widget.h"
37
38#include "table/sprites.h"
39#include "table/strings.h"
40
41#include "safeguards.h"
42
43static void ShowBuildDockStationPicker(Window *parent);
44static void ShowBuildDocksDepotPicker(Window *parent);
45
46static Axis _ship_depot_direction;
47
48void CcBuildDocks(Commands, const CommandCost &result, TileIndex tile)
49{
50 if (result.Failed()) return;
51
54}
55
56void CcPlaySound_CONSTRUCTION_WATER(Commands, const CommandCost &result, TileIndex tile)
57{
58 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
59}
60
61
68static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = nullptr)
69{
70 auto [slope, z] = GetTileSlopeZ(tile_from);
72
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);
78
79 /* Direction the aqueduct is built to. */
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);
83
84 TileIndex endtile = tile_from;
85 for (int length = 0; IsValidTile(endtile) && TileX(endtile) != 0 && TileY(endtile) != 0; length++) {
86 endtile = TileAdd(endtile, offset);
87
88 if (length > max_length) break;
89
90 if (GetTileMaxZ(endtile) > z) {
91 if (tile_to != nullptr) *tile_to = endtile;
92 break;
93 }
94 }
95
96 return endtile;
97}
98
102
104 {
105 this->InitNested(window_number);
106 this->OnInvalidateData();
108 }
109
110 void Close([[maybe_unused]] int data = 0) override
111 {
112 if (_game_mode == GM_NORMAL && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true);
114 this->Window::Close();
115 }
116
122 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
123 {
124 if (!gui_scope) return;
125
127 this->SetWidgetsDisabledState(!can_build,
131 if (!can_build) {
134 }
135
136 if (_game_mode != GM_EDITOR) {
137 if (!can_build) {
138 /* Show in the tooltip why this button is disabled. */
142 } else {
146 }
147 }
148 }
149
150 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
151 {
152 switch (widget) {
153 case WID_DT_CANAL: // Build canal button
154 if (_game_mode == GM_EDITOR) {
155 HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
156 } else {
157 HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT | HT_DIAGONAL);
158 }
159 break;
160
161 case WID_DT_LOCK: // Build lock button
162 HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
163 break;
164
165 case WID_DT_DEMOLISH: // Demolish aka dynamite button
167 break;
168
169 case WID_DT_DEPOT: // Build depot button
170 if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
171 break;
172
173 case WID_DT_STATION: // Build station button
174 if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
175 break;
176
177 case WID_DT_BUOY: // Build buoy button
178 HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
179 break;
180
181 case WID_DT_RIVER: // Build river button (in scenario editor)
182 if (_game_mode != GM_EDITOR) return;
183 HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, HT_RECT | HT_DIAGONAL);
184 break;
185
186 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
187 HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
188 break;
189
190 default: return;
191 }
192 this->last_clicked_widget = (DockToolbarWidgets)widget;
193 }
194
195 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
196 {
197 switch (this->last_clicked_widget) {
198 case WID_DT_CANAL: // Build canal button
200 break;
201
202 case WID_DT_LOCK: // Build lock button
204 break;
205
206 case WID_DT_DEMOLISH: // Demolish aka dynamite button
208 break;
209
210 case WID_DT_DEPOT: // Build depot button
211 Command<CMD_BUILD_SHIP_DEPOT>::Post(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT, CcBuildDocks, tile, _ship_depot_direction);
212 break;
213
214 case WID_DT_STATION: { // Build station button
215 /* Determine the watery part of the dock. */
217 TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
218
219 bool adjacent = _ctrl_pressed;
220 auto proc = [=](bool test, StationID to_join) -> bool {
221 if (test) {
222 return Command<CMD_BUILD_DOCK>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_DOCK>()), tile, StationID::Invalid(), adjacent).Succeeded();
223 } else {
225 }
226 };
227
229 break;
230 }
231
232 case WID_DT_BUOY: // Build buoy button
234 break;
235
236 case WID_DT_RIVER: // Build river button (in scenario editor)
238 break;
239
240 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
242 break;
243
244 default: NOT_REACHED();
245 }
246 }
247
249 {
250 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
251 }
252
253 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
254 {
255 if (pt.x != -1) {
256 switch (select_proc) {
258 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
259 break;
261 if (_game_mode == GM_EDITOR) {
262 Command<CMD_BUILD_CANAL>::Post(STR_ERROR_CAN_T_BUILD_CANALS, CcPlaySound_CONSTRUCTION_WATER, end_tile, start_tile, _ctrl_pressed ? WATER_CLASS_SEA : WATER_CLASS_CANAL, false);
263 } else {
264 Command<CMD_BUILD_CANAL>::Post(STR_ERROR_CAN_T_BUILD_CANALS, CcPlaySound_CONSTRUCTION_WATER, end_tile, start_tile, WATER_CLASS_CANAL, _ctrl_pressed);
265 }
266 break;
268 Command<CMD_BUILD_CANAL>::Post(STR_ERROR_CAN_T_PLACE_RIVERS, CcPlaySound_CONSTRUCTION_WATER, end_tile, start_tile, WATER_CLASS_RIVER, _ctrl_pressed);
269 break;
270
271 default: break;
272 }
273 }
274 }
275
287
289 {
291
292 if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
294 } else {
296 if (IsValidDiagDirection(dir)) {
297 /* Locks and docks always select the tile "down" the slope. */
299 /* Locks also select the tile "up" the slope. */
300 if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
301 }
302 }
303
305 }
306
313 {
314 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
316 if (w == nullptr) return ES_NOT_HANDLED;
317 return w->OnHotkey(hotkey);
318 }
319
320 static inline HotkeyList hotkeys{"dockstoolbar", {
321 Hotkey('1', "canal", WID_DT_CANAL),
322 Hotkey('2', "lock", WID_DT_LOCK),
323 Hotkey('3', "demolish", WID_DT_DEMOLISH),
324 Hotkey('4', "depot", WID_DT_DEPOT),
325 Hotkey('5', "dock", WID_DT_STATION),
326 Hotkey('6', "buoy", WID_DT_BUOY),
327 Hotkey('7', "river", WID_DT_RIVER),
328 Hotkey({'B', '8'}, "aqueduct", WID_DT_BUILD_AQUEDUCT),
330};
331
338 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
339 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
340 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
341 EndContainer(),
343 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_BUILD_CANALS_TOOLTIP),
344 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
345 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
346 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
347 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEPOT), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_SHIP_DEPOT, STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP),
348 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_STATION), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_SHIP_DOCK, STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP),
349 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
350 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUILD_AQUEDUCT), SetMinimalSize(23, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
351 EndContainer(),
352};
353
354static WindowDesc _build_docks_toolbar_desc(
355 WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0,
359 &BuildDocksToolbarWindow::hotkeys
360);
361
370{
371 if (!Company::IsValidID(_local_company)) return nullptr;
372
374 return AllocateWindowDescFront<BuildDocksToolbarWindow>(_build_docks_toolbar_desc, TRANSPORT_WATER);
375}
376
383 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
384 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
385 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
386 EndContainer(),
388 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_CREATE_LAKE_TOOLTIP),
389 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
390 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
391 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
392 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_RIVER), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_BUILD_RIVER, STR_WATERWAYS_TOOLBAR_CREATE_RIVER_TOOLTIP),
393 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUILD_AQUEDUCT), SetMinimalSize(22, 22), SetFill(0, 1), SetSpriteTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
394 EndContainer(),
395};
396
399 WDP_AUTO, "toolbar_water_scen", 0, 0,
403);
404
411{
412 return AllocateWindowDescFront<BuildDocksToolbarWindow>(_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
413}
414
423
425public:
427 {
430 }
431
432 void Close([[maybe_unused]] int data = 0) override
433 {
436 }
437
438 void OnPaint() override
439 {
441
442 this->DrawWidgets();
443
445 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
446 } else {
447 SetTileSelectSize(1, 1);
448 }
449
450 /* strings such as 'Size' and 'Coverage Area' */
451 Rect r = this->GetWidget<NWidgetBase>(BDSW_ACCEPTANCE)->GetCurrentRect();
452 const int bottom = r.bottom;
453 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
455 r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
456 /* Resize background if the window is too small.
457 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
458 * (This is the case, if making the window bigger moves the mouse into the window.) */
459 if (r.top > bottom) {
460 ResizeWindow(this, 0, r.top - bottom, false);
461 }
462 }
463
464 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
465 {
466 switch (widget) {
467 case BDSW_LT_OFF:
468 case BDSW_LT_ON:
473 this->SetDirty();
474 SetViewportCatchmentStation(nullptr, true);
475 break;
476 }
477 }
478
479 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
480 {
482 }
483
484 IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
485 this->InvalidateData();
486 }};
487};
488
492 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
493 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
494 EndContainer(),
495 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
498 NWidget(WWT_LABEL, INVALID_COLOUR, BDSW_INFO), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
500 NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_OFF), SetMinimalSize(60, 12), SetFill(1, 0), SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
501 NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_ON), SetMinimalSize(60, 12), SetFill(1, 0), SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
502 EndContainer(),
503 EndContainer(),
505 EndContainer(),
506 EndContainer(),
507};
508
509static WindowDesc _build_dock_station_desc(
510 WDP_AUTO, nullptr, 0, 0,
514);
515
516static void ShowBuildDockStationPicker(Window *parent)
517{
518 new BuildDocksStationWindow(_build_dock_station_desc, parent);
519}
520
522private:
523 static void UpdateDocksDirection()
524 {
525 if (_ship_depot_direction != AXIS_X) {
526 SetTileSelectSize(1, 2);
527 } else {
528 SetTileSelectSize(2, 1);
529 }
530 }
531
532public:
534 {
536 this->LowerWidget(WID_BDD_X + _ship_depot_direction);
537 UpdateDocksDirection();
538 }
539
541 {
542 switch (widget) {
543 case WID_BDD_X:
544 case WID_BDD_Y:
547 break;
548 }
549 }
550
551 void DrawWidget(const Rect &r, WidgetID widget) const override
552 {
554
555 switch (widget) {
556 case WID_BDD_X:
557 case WID_BDD_Y: {
558 Axis axis = widget == WID_BDD_X ? AXIS_X : AXIS_Y;
559
563 int x = (ir.Width() - ScaleSpriteTrad(96)) / 2;
564 int y = (ir.Height() - ScaleSpriteTrad(64)) / 2;
565 int x1 = ScaleSpriteTrad(63);
566 int x2 = ScaleSpriteTrad(31);
567 DrawShipDepotSprite(x + (axis == AXIS_X ? x1 : x2), y + ScaleSpriteTrad(17), axis, DEPOT_PART_NORTH);
568 DrawShipDepotSprite(x + (axis == AXIS_X ? x2 : x1), y + ScaleSpriteTrad(33), axis, DEPOT_PART_SOUTH);
569 }
570 break;
571 }
572 }
573 }
574
575 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
576 {
577 switch (widget) {
578 case WID_BDD_X:
579 case WID_BDD_Y:
580 this->RaiseWidget(WID_BDD_X + _ship_depot_direction);
581 _ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
582 this->LowerWidget(WID_BDD_X + _ship_depot_direction);
584 UpdateDocksDirection();
585 this->SetDirty();
586 break;
587 }
588 }
589};
590
591static constexpr NWidgetPart _nested_build_docks_depot_widgets[] = {
593 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
594 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
595 EndContainer(),
596 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
598 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BDD_X), SetToolTip(STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
599 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BDD_Y), SetToolTip(STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
600 EndContainer(),
601 EndContainer(),
602};
603
604static WindowDesc _build_docks_depot_desc(
605 WDP_AUTO, nullptr, 0, 0,
608 _nested_build_docks_depot_widgets
609);
610
611
612static void ShowBuildDocksDepotPicker(Window *parent)
613{
614 new BuildDocksDepotWindow(_build_docks_depot_desc, parent);
615}
616
617
618void InitializeDockGui()
619{
620 _ship_depot_direction = AXIS_X;
621}
void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, uint8_t)
Callback executed after a build Bridge CMD has been called.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
Base class for windows opened from a toolbar.
Definition window_gui.h:982
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:3531
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Axis
Allow incrementing of DiagDirDiff variables.
@ AXIS_X
The X axis.
@ AXIS_Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Command definitions related to docks.
BuildDockStationWidgets
Widget numbers of the build-dock GUI.
Definition dock_gui.cpp:416
@ BDSW_LT_OFF
'Off' button of coverage high light.
Definition dock_gui.cpp:418
@ BDSW_BACKGROUND
Background panel.
Definition dock_gui.cpp:417
@ BDSW_INFO
'Coverage highlight' label.
Definition dock_gui.cpp:420
@ BDSW_ACCEPTANCE
Acceptance info.
Definition dock_gui.cpp:421
@ BDSW_LT_ON
'On' button of coverage high light.
Definition dock_gui.cpp:419
static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to=nullptr)
Gets the other end of the aqueduct, if possible.
Definition dock_gui.cpp:68
Window * ShowBuildDocksScenToolbar()
Open the build water toolbar window for the scenario editor.
Definition dock_gui.cpp:410
Window * ShowBuildDocksToolbar()
Open the build water toolbar window.
Definition dock_gui.cpp:369
static constexpr NWidgetPart _nested_build_docks_scen_toolbar_widgets[]
Nested widget parts of docks toolbar, scenario editor version.
Definition dock_gui.cpp:381
static constexpr NWidgetPart _nested_build_docks_toolbar_widgets[]
Nested widget parts of docks toolbar, game version.
Definition dock_gui.cpp:336
static constexpr NWidgetPart _nested_build_dock_station_widgets[]
Nested widget parts of a build dock station window.
Definition dock_gui.cpp:490
static WindowDesc _build_docks_scen_toolbar_desc(WDP_AUTO, "toolbar_water_scen", 0, 0, WC_SCEN_BUILD_TOOLBAR, WC_NONE, WindowDefaultFlag::Construction, _nested_build_docks_scen_toolbar_widgets)
Window definition for the build docks in scenario editor window.
Types related to the dock widgets.
DockToolbarWidgets
Widgets of the BuildDocksToolbarWindow class.
Definition dock_widget.h:21
@ WID_DT_CANAL
Build canal button.
Definition dock_widget.h:22
@ WID_DT_DEMOLISH
Demolish aka dynamite button.
Definition dock_widget.h:24
@ WID_DT_STATION
Build station button.
Definition dock_widget.h:26
@ WID_DT_RIVER
Build river button (in scenario editor).
Definition dock_widget.h:28
@ WID_DT_LOCK
Build lock button.
Definition dock_widget.h:23
@ WID_DT_DEPOT
Build depot button.
Definition dock_widget.h:25
@ WID_DT_INVALID
Used to initialize a variable.
Definition dock_widget.h:31
@ WID_DT_BUOY
Build buoy button.
Definition dock_widget.h:27
@ WID_DT_BUILD_AQUEDUCT
Build aqueduct button.
Definition dock_widget.h:29
@ WID_BDD_X
X-direction button.
Definition dock_widget.h:16
@ WID_BDD_Y
Y-direction button.
Definition dock_widget.h:17
@ WID_BDD_BACKGROUND
Background of the window.
Definition dock_widget.h:15
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition gfx.cpp:1519
Functions related to the gfx engine.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:945
GUI functions that shouldn't be here.
Hotkey related functions.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition main_gui.cpp:63
uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir)
Gets the distance to the edge of the map in given direction.
Definition map.cpp:219
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:469
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition map_func.h:610
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
Definition map_func.h:456
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:424
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:414
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:569
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:59
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:58
Functions related to slopes.
DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition slope_func.h:239
Functions related to sound.
@ SND_02_CONSTRUCTION_WATER
0 == 0x00 Construction: water infrastructure
Definition sound_type.h:47
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
This file contains all sprite-related enums and defines.
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1512
Command definitions related to stations.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Contains enums and function declarations connected with stations GUI.
@ SCT_ALL
Draw all cargoes.
Definition station_gui.h:24
static constexpr uint CA_DOCK
Catchment for docks with "modified catchment" enabled.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition of base types and functions in a cross-platform compatible way.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition dock_gui.cpp:551
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition dock_gui.cpp:575
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition dock_gui.cpp:540
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition dock_gui.cpp:464
void OnPaint() override
The window must be repainted.
Definition dock_gui.cpp:438
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition dock_gui.cpp:479
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition dock_gui.cpp:432
Toolbar window for constructing water infrastructure.
Definition dock_gui.cpp:100
void OnPlacePresize(Point pt, TileIndex tile_from) override
The user moves over the map when a tile highlight mode has been set when the special mouse mode has b...
Definition dock_gui.cpp:288
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition dock_gui.cpp:150
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition dock_gui.cpp:276
static EventState DockToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildDocksToolbarWindow.
Definition dock_gui.cpp:312
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
The user is dragging over the map when the tile highlight mode has been set.
Definition dock_gui.cpp:248
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition dock_gui.cpp:195
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
The user has dragged over the map when the tile highlight mode has been set.
Definition dock_gui.cpp:253
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition dock_gui.cpp:122
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition dock_gui.cpp:110
DockToolbarWidgets last_clicked_widget
Contains the last widget that has been clicked on this toolbar.
Definition dock_gui.cpp:101
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
uint16_t max_bridge_length
maximum length of bridges
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
Definition gfx_type.h:158
bool persistent_buildingtools
keep the building tools active after usage
bool station_show_coverage
whether to highlight coverage area
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
ConstructionSettings construction
construction of things in-game
StationSettings station
settings related to station management
List of hotkeys for a window.
Definition hotkeys.h:37
All data for a single hotkey.
Definition hotkeys.h:21
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool click_beep
Beep on a random selection of buttons.
bool confirm
Play sound effect on successful constructions or other actions.
bool modified_catchment
different-size catchment areas
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1052
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:744
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3166
Window * parent
Parent window.
Definition window_gui.h:329
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:530
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:973
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1751
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:570
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
GUI stuff related to terraforming.
std::tuple< Slope, int > GetTileSlopeZ(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.cpp:55
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition tile_map.cpp:136
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
@ TRANSPORT_WATER
Transport over water.
Command definitions related to tunnels and bridges.
bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1913
Functions related to vehicles.
@ VEH_SHIP
Ship vehicle type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
@ VPM_X_AND_Y
area of land in X and Y directions
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_DEMOLISH_AREA
Clear area.
@ DDSP_CREATE_WATER
Create a canal.
@ DDSP_CREATE_RIVER
Create rivers.
Functions related to water (management)
Command definitions related to water tiles.
@ WATER_CLASS_SEA
Sea.
Definition water_map.h:40
@ WATER_CLASS_CANAL
Canal.
Definition water_map.h:41
@ WATER_CLASS_RIVER
River.
Definition water_map.h:42
@ DEPOT_PART_NORTH
Northern part of a depot.
Definition water_map.h:59
@ DEPOT_PART_SOUTH
Southern part of a depot.
Definition water_map.h:60
Command definitions related to waypoints.
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:48
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:42
@ WWT_LABEL
Centered label.
Definition widget_type.h:47
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:45
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:66
@ EqualSize
Containers should keep all their (resizing) children equally large.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1145
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2027
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1157
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:145
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
Definition window_gui.h:147
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_BUILD_STATION
Build station; Window numbers:
@ WC_SCEN_BUILD_TOOLBAR
Scenario build toolbar; Window numbers:
Definition window_type.h:82
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:75
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_BUILD_DEPOT
Build depot; Window numbers:
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107