OpenTTD Source 20261112-master-gbcbec5e63f
main_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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "spritecache.h"
12#include "window_gui.h"
13#include "window_func.h"
14#include "viewport_func.h"
15#include "command_func.h"
16#include "console_gui.h"
17#include "progress.h"
18#include "transparency_gui.h"
19#include "map_func.h"
20#include "sound_func.h"
21#include "transparency.h"
22#include "zoom_func.h"
23#include "toolbar_gui.h"
24#include "statusbar_gui.h"
26#include "tilehighlight_func.h"
27#include "hotkeys.h"
28#include "error.h"
29#include "news_gui.h"
30#include "misc_cmd.h"
31#include "timer/timer.h"
32#include "timer/timer_window.h"
33
35
36#include "widgets/main_widget.h"
37
38#include "network/network.h"
40#include "network/network_gui.h"
42
43#include "table/sprites.h"
44#include "table/strings.h"
45
46#include "safeguards.h"
47
59{
60 if (w->IsWidgetDisabled(widget)) return false;
61
63 w->SetDirty();
64
65 if (w->IsWidgetLowered(widget)) {
67 return false;
68 }
69
70 SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
71 w->LowerWidget(widget);
72 return true;
73}
74
75
76void CcPlaySound_EXPLOSION(Commands, const CommandCost &result, TileIndex tile)
77{
78 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
79}
80
89{
90 assert(w != nullptr);
91
92 switch (how) {
93 case ZOOM_NONE:
94 /* On initialisation of the viewport we don't do anything. */
95 break;
96
97 case ZOOM_IN: {
98 ViewportData &vp = *w->viewport;
99 if (vp.zoom <= _settings_client.gui.zoom_min) return false;
100 --vp.zoom;
101 vp.virtual_width >>= 1;
102 vp.virtual_height >>= 1;
103
104 vp.scrollpos_x += vp.virtual_width >> 1;
105 vp.scrollpos_y += vp.virtual_height >> 1;
108 break;
109 }
110
111 case ZOOM_OUT: {
112 ViewportData &vp = *w->viewport;
113 if (vp.zoom >= _settings_client.gui.zoom_max) return false;
114 ++vp.zoom;
115
116 vp.scrollpos_x -= vp.virtual_width >> 1;
117 vp.scrollpos_y -= vp.virtual_height >> 1;
120
121 vp.virtual_width <<= 1;
122 vp.virtual_height <<= 1;
123 break;
124 }
125 }
126
127 if (w->viewport != nullptr) { // the viewport can be null when how == ZOOM_NONE
128 w->viewport->virtual_left = w->viewport->scrollpos_x;
129 w->viewport->virtual_top = w->viewport->scrollpos_y;
130 }
131
132 /* Update the windows that have zoom-buttons to perhaps disable their buttons */
133 w->InvalidateData();
134 return true;
135}
136
137void ZoomInOrOutToCursorWindow(bool in, Window *w)
138{
139 assert(w != nullptr);
140
141 if (_game_mode != GameMode::Menu) {
142 if ((in && w->viewport->zoom <= _settings_client.gui.zoom_min) || (!in && w->viewport->zoom >= _settings_client.gui.zoom_max)) return;
143
144 Point pt = GetTileZoomCenterWindow(in, w);
145 if (pt.x != -1) {
146 ScrollWindowTo(pt.x, pt.y, -1, w, true);
147
149 }
150 }
151}
152
153void FixTitleGameZoom(int zoom_adjust)
154{
155 if (_game_mode != GameMode::Menu) return;
156
158
159 /* Adjust the zoom in/out.
160 * Can't simply add, since operator+ is not defined on the ZoomLevel type. */
161 vp.zoom = _gui_zoom;
162 while (zoom_adjust < 0 && vp.zoom != _settings_client.gui.zoom_min) {
163 vp.zoom--;
164 zoom_adjust++;
165 }
166 while (zoom_adjust > 0 && vp.zoom != _settings_client.gui.zoom_max) {
167 vp.zoom++;
168 zoom_adjust--;
169 }
170
171 vp.virtual_width = ScaleByZoom(vp.width, vp.zoom);
173}
174
175static constexpr std::initializer_list<NWidgetPart> _nested_main_window_widgets = {
177};
178
179enum GlobalHotKeys : int32_t {
180 GHK_QUIT,
181 GHK_ABANDON,
182 GHK_CONSOLE,
183 GHK_BOUNDING_BOXES,
184 GHK_DIRTY_BLOCKS,
185 GHK_WIDGET_OUTLINES,
186 GHK_CENTER,
187 GHK_CENTER_ZOOM,
188 GHK_RESET_OBJECT_TO_PLACE,
189 GHK_DELETE_WINDOWS,
190 GHK_DELETE_NONVITAL_WINDOWS,
191 GHK_DELETE_ALL_MESSAGES,
192 GHK_REFRESH_SCREEN,
193 GHK_CRASH,
194 GHK_MONEY,
195 GHK_UPDATE_COORDS,
196 GHK_TOGGLE_TRANSPARENCY,
197 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
198 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
199 GHK_TRANSPARENCY,
200 GHK_CHAT,
201 GHK_CHAT_ALL,
202 GHK_CHAT_COMPANY,
203 GHK_CHAT_SERVER,
204 GHK_CLOSE_NEWS,
205 GHK_CLOSE_ERROR,
206};
207
208struct MainWindow : Window
209{
210 MainWindow(WindowDesc &desc) : Window(desc)
211 {
212 this->InitNested(0);
213 this->flags.Reset(WindowFlag::WhiteBorder);
214 ResizeWindow(this, _screen.width, _screen.height);
215
218
219 this->viewport->overlay = std::make_shared<LinkGraphOverlay>(this, WID_M_VIEWPORT, CargoTypes{}, CompanyMask{}, 2);
220 this->refresh_timeout.Reset();
221 }
222
225 {
226 if (this->viewport->overlay->GetCargoMask().None() ||
227 this->viewport->overlay->GetCompanyMask().None()) {
228 return;
229 }
230
231 this->viewport->overlay->SetDirty();
232 this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
233 }
234
236 const IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(7650), [this](auto) {
238 }};
239
247 TimeoutTimer<TimerWindow> refresh_timeout = {std::chrono::milliseconds(450), [this]() {
249 }};
250
251 void OnPaint() override
252 {
253 this->DrawWidgets();
254 if (_game_mode == GameMode::Menu) {
255 static const std::initializer_list<SpriteID> title_sprites = {SPR_OTTD_O, SPR_OTTD_P, SPR_OTTD_E, SPR_OTTD_N, SPR_OTTD_T, SPR_OTTD_T, SPR_OTTD_D};
256 uint letter_spacing = ScaleGUITrad(10);
257 int name_width = static_cast<int>(std::size(title_sprites) - 1) * letter_spacing;
258
259 for (const SpriteID &sprite : title_sprites) {
260 name_width += GetSpriteSize(sprite).width;
261 }
262 int off_x = (this->width - name_width) / 2;
263
264 for (const SpriteID &sprite : title_sprites) {
265 DrawSprite(sprite, PAL_NONE, off_x, ScaleGUITrad(50));
266 off_x += GetSpriteSize(sprite).width + letter_spacing;
267 }
268
269 int text_y = this->height - GetCharacterHeight(FontSize::Normal) * 2;
270 DrawString(0, this->width - 1, text_y, STR_INTRO_VERSION, TextColour::White, {AlignmentH::Centre, AlignmentV::Middle});
271 }
272 }
273
274 EventState OnHotkey(int hotkey) override
275 {
276 if (hotkey == GHK_QUIT) {
277 HandleExitGameRequest();
278 return EventState::Handled;
279 }
280
281 /* Disable all key shortcuts, except quit shortcuts when
282 * generating the world, otherwise they create threading
283 * problem during the generating, resulting in random
284 * assertions that are hard to trigger and debug */
286
287 switch (hotkey) {
288 case GHK_ABANDON:
289 /* No point returning from the main menu to itself */
290 if (_game_mode == GameMode::Menu) return EventState::Handled;
291 if (_settings_client.gui.autosave_on_exit) {
292 DoExitSave();
294 } else {
295 AskExitToGameMenu();
296 }
297 return EventState::Handled;
298
299 case GHK_CONSOLE:
301 return EventState::Handled;
302
303 case GHK_BOUNDING_BOXES:
305 return EventState::Handled;
306
307 case GHK_DIRTY_BLOCKS:
309 return EventState::Handled;
310
311 case GHK_WIDGET_OUTLINES:
313 return EventState::Handled;
314 }
315
316 if (_game_mode == GameMode::Menu) return EventState::NotHandled;
317
318 switch (hotkey) {
319 case GHK_CENTER:
320 case GHK_CENTER_ZOOM: {
321 Point pt = GetTileBelowCursor();
322 if (pt.x != -1) {
323 bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
324 if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
325 ScrollMainWindowTo(pt.x, pt.y, -1, instant);
326 }
327 break;
328 }
329
330 case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
331 case GHK_DELETE_WINDOWS: CloseNonVitalWindows(); break;
332 case GHK_DELETE_NONVITAL_WINDOWS: CloseAllNonVitalWindows(); break;
333 case GHK_DELETE_ALL_MESSAGES: DeleteAllMessages(); break;
334 case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
335
336 case GHK_CRASH: // Crash the game
337 *(volatile uint8_t *)nullptr = 0;
338 break;
339
340 case GHK_MONEY: // Gimme money
341 /* You can only cheat for money in singleplayer mode. */
342 if (!_networking) Command<Commands::MoneyCheat>::Post(10000000);
343 break;
344
345 case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
347 break;
348
349 case GHK_TOGGLE_TRANSPARENCY:
350 case GHK_TOGGLE_TRANSPARENCY + 1:
351 case GHK_TOGGLE_TRANSPARENCY + 2:
352 case GHK_TOGGLE_TRANSPARENCY + 3:
353 case GHK_TOGGLE_TRANSPARENCY + 4:
354 case GHK_TOGGLE_TRANSPARENCY + 5:
355 case GHK_TOGGLE_TRANSPARENCY + 6:
356 case GHK_TOGGLE_TRANSPARENCY + 7:
357 case GHK_TOGGLE_TRANSPARENCY + 8:
358 /* Transparency toggle hot keys */
359 ToggleTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_TRANSPARENCY));
361 break;
362
363 case GHK_TOGGLE_INVISIBILITY:
364 case GHK_TOGGLE_INVISIBILITY + 1:
365 case GHK_TOGGLE_INVISIBILITY + 2:
366 case GHK_TOGGLE_INVISIBILITY + 3:
367 case GHK_TOGGLE_INVISIBILITY + 4:
368 case GHK_TOGGLE_INVISIBILITY + 5:
369 case GHK_TOGGLE_INVISIBILITY + 6:
370 case GHK_TOGGLE_INVISIBILITY + 7:
371 /* Invisibility toggle hot keys */
372 ToggleInvisibilityWithTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_INVISIBILITY));
374 break;
375
376 case GHK_TRANSPARENCY_TOOLBAR:
378 break;
379
380 case GHK_TRANSPARENCY:
382 break;
383
384 case GHK_CHAT: // smart chat; send to team if any, otherwise to all
385 if (_networking) {
387 if (cio == nullptr) break;
388
390 }
391 break;
392
393 case GHK_CHAT_ALL: // send text message to all clients
395 break;
396
397 case GHK_CHAT_COMPANY: // send text to all team mates
398 if (_networking) {
400 if (cio == nullptr) break;
401
403 }
404 break;
405
406 case GHK_CHAT_SERVER: // send text to the server
409 }
410 break;
411
412 case GHK_CLOSE_NEWS: // close active news window
414 break;
415
416 case GHK_CLOSE_ERROR: // close active error window
418 break;
419
420 default: return EventState::NotHandled;
421 }
422 return EventState::Handled;
423 }
424
425 void OnScroll(Point delta) override
426 {
427 this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
428 this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
429 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
430 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
431 this->refresh_timeout.Reset();
432 }
433
434 void OnMouseWheel(int wheel, WidgetID widget) override
435 {
436 if (widget != WID_M_VIEWPORT) return;
437 if (_settings_client.gui.scrollwheel_scrolling != ScrollWheelScrolling::Off) {
438 bool in = wheel < 0;
439
440 /* When following, only change zoom - otherwise zoom to the cursor. */
441 if (this->viewport->follow_vehicle != VehicleID::Invalid()) {
442 DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, this);
443 } else {
444 ZoomInOrOutToCursorWindow(in, this);
445 }
446 }
447 }
448
449 void OnResize() override
450 {
451 if (this->viewport != nullptr) {
453 nvp->UpdateViewportCoordinates(this);
454 this->refresh_timeout.Reset();
455 }
456 }
457
458 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
459 {
460 if (widget != WID_M_VIEWPORT) return false;
461 return this->viewport->overlay->ShowTooltip(pt, close_cond);
462 }
463
469 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
470 {
471 if (!gui_scope) return;
472 /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
473 InvalidateWindowData(WindowClass::MainToolbar, 0, data, true);
474 }
475
476 static inline HotkeyList hotkeys{"global", {
477 Hotkey({'Q' | WKC_CTRL, 'Q' | WKC_META}, "quit", GHK_QUIT),
478 Hotkey({'W' | WKC_CTRL, 'W' | WKC_META}, "abandon", GHK_ABANDON),
479 Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
480 Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
481 Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS),
482 Hotkey('O' | WKC_CTRL, "widget_outlines", GHK_WIDGET_OUTLINES),
483 Hotkey('C', "center", GHK_CENTER),
484 Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM),
485 Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
486 Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
487 Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
488 Hotkey(WKC_DELETE | WKC_CTRL, "delete_all_messages", GHK_DELETE_ALL_MESSAGES),
489 Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
490#if defined(_DEBUG)
491 Hotkey('0' | WKC_ALT, "crash_game", GHK_CRASH),
492 Hotkey('1' | WKC_ALT, "money", GHK_MONEY),
493 Hotkey('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
494#endif
495 Hotkey('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
496 Hotkey('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
497 Hotkey('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
498 Hotkey('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
499 Hotkey('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
500 Hotkey('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
501 Hotkey('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
502 Hotkey('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
503 Hotkey('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
504 Hotkey('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
505 Hotkey('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
506 Hotkey('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
507 Hotkey('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
508 Hotkey('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
509 Hotkey('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
510 Hotkey('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
511 Hotkey('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
512 Hotkey('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
513 Hotkey('X', "toggle_transparency", GHK_TRANSPARENCY),
514 Hotkey({WKC_RETURN, 'T'}, "chat", GHK_CHAT),
515 Hotkey({WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T'}, "chat_all", GHK_CHAT_ALL),
516 Hotkey({WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T'}, "chat_company", GHK_CHAT_COMPANY),
517 Hotkey({WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T'}, "chat_server", GHK_CHAT_SERVER),
518 Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS),
519 Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR),
520 }};
521};
522
525 WindowPosition::Manual, {}, 0, 0,
526 WindowClass::MainWindow, WindowClass::None,
528 _nested_main_window_widgets,
529 &MainWindow::hotkeys
530);
531
537bool IsQuitKey(uint16_t keycode)
538{
539 int num = MainWindow::hotkeys.CheckMatch(keycode);
540 return num == GHK_QUIT;
541}
542
543
544void ShowSelectGameWindow();
545
550{
551 for (Colours i : EnumRange(Colours::End)) {
552 const uint8_t *b = GetNonSprite(GetColourPalette(i), SpriteType::Recolour) + 1;
553 assert(b != nullptr);
554 for (Shade j : EnumRange(Shade::End)) {
555 SetColourGradient(i, j, PixelColour{b[0xC6 + to_underlying(j)]});
556 }
557 }
558
560
561 /* XXX: these are not done */
562 switch (_game_mode) {
563 default: NOT_REACHED();
564 case GameMode::Menu:
565 ShowSelectGameWindow();
566 break;
567
568 case GameMode::Normal:
569 case GameMode::Editor:
571 break;
572 }
573}
574
579{
581
582 /* Status bad only for normal games */
583 if (_game_mode == GameMode::Editor) return;
584
586}
587
593{
594 _cur_resolution.width = _screen.width;
595 _cur_resolution.height = _screen.height;
596 ScreenSizeChanged();
597 RelocateAllWindows(_screen.width, _screen.height);
599}
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
Definition cargo_type.h:115
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
Iterate a range of enum values.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
Nested widget to display a viewport in a window.
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2451
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2442
A timeout timer will fire once after the interval.
Definition timer.h:116
void Reset()
Reset the timer, so it will fire again after the timeout.
Definition timer.h:140
Functions related to commands.
Commands
List of commands.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
GUI related functions in the console.
Dimension _cur_resolution
The current resolution.
Definition driver.cpp:29
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
Functions related to errors.
bool HideActiveErrorMessage()
Close active error message window.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
@ Centre
Align to the centre.
@ Middle
Align to the middle.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:1032
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:45
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
ZoomLevel _gui_zoom
GUI Zoom level.
Definition gfx.cpp:57
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ Recolour
Recolour sprite.
Definition gfx_type.h:408
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
uint32_t CursorID
The number of the cursor (sprite).
Definition gfx_type.h:19
Colours
One of 16 base colours used for companies and windows/widgets.
Definition gfx_type.h:283
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ End
End-of-array marker.
Definition gfx_type.h:301
@ White
White colour.
Definition gfx_type.h:330
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1548
Hotkey related functions.
Declaration of linkgraph overlay GUI.
#define Point
Macro that prevents name conflicts between included headers.
void ShowVitalWindows()
Show the vital in-game windows.
Definition main_gui.cpp:578
void GameSizeChanged()
Size of the application screen changed.
Definition main_gui.cpp:592
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:549
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition main_gui.cpp:537
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition main_gui.cpp:88
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition main_gui.cpp:58
static WindowDesc _main_window_desc(WindowPosition::Manual, {}, 0, 0, WindowClass::MainWindow, WindowClass::None, WindowDefaultFlag::NoClose, _nested_main_window_widgets, &MainWindow::hotkeys)
Window definition for the main window.
Types related to the main widgets.
@ WID_M_VIEWPORT
Main window viewport.
Definition main_widget.h:15
Functions related to maps.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:376
Miscellaneous command definitions.
bool _networking
are we in networking mode?
Definition network.cpp:63
bool _network_server
network-server is active
Definition network.cpp:64
ClientID _network_own_client_id
Our client identifier.
Definition network.cpp:68
Basic functions/variables used all over the place.
Base core network types and some helper functions to access them.
void ShowNetworkChatQueryWindow(NetworkChatDestinationType type, int dest)
Show the chat window.
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Network functions used by other parts of OpenTTD.
GUIs related to networking.
@ Client
Send message/notice to only a certain client (Private).
@ Team
Send message/notice to everyone playing the same company (Team).
@ Broadcast
Send message/notice to all clients (All).
@ Server
Servers always have this ID.
bool HideActiveNewsMessage()
Close active news message window.
GUI functions related to the news.
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Normal
Playing a game.
Definition openttd.h:20
@ Menu
In the main menu.
Definition openttd.h:19
@ Menu
Switch to game intro menu.
Definition openttd.h:33
void SetColourGradient(Colours colour, Shade shade, PixelColour palette_index)
Set colour gradient palette index.
Definition palette.cpp:404
Shade
The eight shades of each company colour.
@ End
End marker for iteration.
Functions related to modal progress.
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition progress.h:17
A number of safeguards to prevent using unsafe methods.
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit).
Functions related to saving and loading games.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
@ Off
Scroll wheel has no effect.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:252
Functions related to sound.
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition sound_type.h:63
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:221
Functions to cache sprites in memory.
This file contains all sprite-related enums and defines.
static const SpriteID SPR_OTTD_D
Definition sprites.h:1286
static const SpriteID SPR_OTTD_E
Definition sprites.h:1285
static const SpriteID SPR_OTTD_O
Definition sprites.h:1283
static const SpriteID SPR_OTTD_N
Definition sprites.h:1287
static const SpriteID SPR_OTTD_T
Definition sprites.h:1288
static const SpriteID SPR_OTTD_P
Definition sprites.h:1284
void ShowStatusBar()
Show our status bar.
Functions, definitions and such used only by the GUI.
Definition of base types and functions in a cross-platform compatible way.
T y
Y coordinate.
T x
X coordinate.
value_type width
The width of the rectangle.
List of hotkeys for a window.
Definition hotkeys.h:44
All data for a single hotkey.
Definition hotkeys.h:20
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition main_gui.cpp:274
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition main_gui.cpp:425
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition main_gui.cpp:458
TimeoutTimer< TimerWindow > refresh_timeout
Sometimes when something happened, force an update to the link-graph a bit sooner.
Definition main_gui.cpp:247
const IntervalTimer< TimerWindow > refresh_interval
Refresh the link-graph overlay on a regular interval.
Definition main_gui.cpp:236
void OnResize() override
Called after the window got resized.
Definition main_gui.cpp:449
void OnPaint() override
The window must be repainted.
Definition main_gui.cpp:251
void OnMouseWheel(int wheel, WidgetID widget) override
The mouse wheel has been turned.
Definition main_gui.cpp:434
void RefreshLinkGraph()
Refresh the link-graph overlay.
Definition main_gui.cpp:224
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition main_gui.cpp:469
Container for all information known about a client.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition network.cpp:114
CompanyID client_playas
As which company is this client playing (CompanyID).
Colour for pixel/line drawing.
Definition gfx_type.h:307
Data structure for a window viewport.
Definition window_gui.h:249
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:254
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:252
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:253
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:251
Data structure for viewport, display of a part of the world.
int width
Screen width of the viewport.
ZoomLevel zoom
The zoom level of the viewport.
int virtual_width
width << zoom
int height
Screen height of the viewport.
int virtual_height
height << zoom
High level window description.
Definition window_gui.h:171
Data structure for an opened window.
Definition window_gui.h:272
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3317
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition window_gui.h:317
WindowClass window_class
Window class.
Definition window_gui.h:300
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:490
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:409
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:459
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1869
WindowFlags flags
Window flags.
Definition window_gui.h:299
int height
Height of the window (number of pixels down in y direction).
Definition window_gui.h:311
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:310
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
HighLightStyle
Highlighting draw styles.
Definition of Interval and OneShot timers.
Definition of the Window system.
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
void AllocateToolbar()
Allocate the toolbar.
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
void ToggleWidgetOutlines()
Toggle drawing of widget outlines.
Stuff related to the (main) toolbar.
Functions related to transparency.
void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
void ShowTransparencyToolbar()
Show the transparency toolbar.
GUI functions related to transparency.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Functions related to (drawing on) viewports.
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
ZoomStateChange
Directions of zooming.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_NONE
Hack, used to update the button status.
@ ZOOM_OUT
Zoom out (get helicopter view).
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:73
Window * GetMainWindow()
Get the main window, i.e.
Definition window.cpp:1228
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition window.cpp:3420
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2146
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition window.cpp:3452
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3377
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition window.cpp:3610
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition window.cpp:3439
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ NoClose
This window can't be interactively closed.
Definition window_gui.h:157
TooltipCloseCondition
Definition window_gui.h:262
@ WhiteBorder
Window white border counter bit mask.
Definition window_gui.h:231
@ Manual
Manually align the window (so no automatic location finding).
Definition window_gui.h:144
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.
@ MainWindow
Main window; Window numbers:
Definition window_type.h:68
Functions related to zooming.
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZoomLevel::Min) When shifting right,...
Definition zoom_func.h:22
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition zoom_func.h:87
@ Viewport
Default zoom level for viewports.
Definition zoom_type.h:34