OpenTTD Source 20250524-master-gc366e6a48e
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 <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "currency.h"
12#include "spritecache.h"
13#include "window_gui.h"
14#include "window_func.h"
15#include "textbuf_gui.h"
16#include "viewport_func.h"
17#include "command_func.h"
18#include "console_gui.h"
19#include "progress.h"
20#include "transparency_gui.h"
21#include "map_func.h"
22#include "sound_func.h"
23#include "transparency.h"
24#include "strings_func.h"
25#include "zoom_func.h"
26#include "company_base.h"
27#include "company_func.h"
28#include "toolbar_gui.h"
29#include "statusbar_gui.h"
31#include "tilehighlight_func.h"
32#include "hotkeys.h"
33#include "error.h"
34#include "news_gui.h"
35#include "misc_cmd.h"
36#include "timer/timer.h"
37#include "timer/timer_window.h"
38
39#include "saveload/saveload.h"
40
41#include "widgets/main_widget.h"
42
43#include "network/network.h"
45#include "network/network_gui.h"
47
48#include "table/sprites.h"
49#include "table/strings.h"
50
51#include "safeguards.h"
52
64{
65 if (w->IsWidgetDisabled(widget)) return false;
66
68 w->SetDirty();
69
70 if (w->IsWidgetLowered(widget)) {
72 return false;
73 }
74
75 SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
76 w->LowerWidget(widget);
77 return true;
78}
79
80
81void CcPlaySound_EXPLOSION(Commands, const CommandCost &result, TileIndex tile)
82{
83 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
84}
85
94{
95 assert(w != nullptr);
96
97 switch (how) {
98 case ZOOM_NONE:
99 /* On initialisation of the viewport we don't do anything. */
100 break;
101
102 case ZOOM_IN: {
103 ViewportData &vp = *w->viewport;
104 if (vp.zoom <= _settings_client.gui.zoom_min) return false;
105 --vp.zoom;
106 vp.virtual_width >>= 1;
107 vp.virtual_height >>= 1;
108
109 vp.scrollpos_x += vp.virtual_width >> 1;
110 vp.scrollpos_y += vp.virtual_height >> 1;
113 break;
114 }
115
116 case ZOOM_OUT: {
117 ViewportData &vp = *w->viewport;
118 if (vp.zoom >= _settings_client.gui.zoom_max) return false;
119 ++vp.zoom;
120
121 vp.scrollpos_x -= vp.virtual_width >> 1;
122 vp.scrollpos_y -= vp.virtual_height >> 1;
125
126 vp.virtual_width <<= 1;
127 vp.virtual_height <<= 1;
128 break;
129 }
130 }
131
132 if (w->viewport != nullptr) { // the viewport can be null when how == ZOOM_NONE
133 w->viewport->virtual_left = w->viewport->scrollpos_x;
134 w->viewport->virtual_top = w->viewport->scrollpos_y;
135 }
136
137 /* Update the windows that have zoom-buttons to perhaps disable their buttons */
138 w->InvalidateData();
139 return true;
140}
141
142void ZoomInOrOutToCursorWindow(bool in, Window *w)
143{
144 assert(w != nullptr);
145
146 if (_game_mode != GM_MENU) {
147 if ((in && w->viewport->zoom <= _settings_client.gui.zoom_min) || (!in && w->viewport->zoom >= _settings_client.gui.zoom_max)) return;
148
149 Point pt = GetTileZoomCenterWindow(in, w);
150 if (pt.x != -1) {
151 ScrollWindowTo(pt.x, pt.y, -1, w, true);
152
154 }
155 }
156}
157
158void FixTitleGameZoom(int zoom_adjust)
159{
160 if (_game_mode != GM_MENU) return;
161
163
164 /* Adjust the zoom in/out.
165 * Can't simply add, since operator+ is not defined on the ZoomLevel type. */
166 vp.zoom = _gui_zoom;
167 while (zoom_adjust < 0 && vp.zoom != _settings_client.gui.zoom_min) {
168 vp.zoom--;
169 zoom_adjust++;
170 }
171 while (zoom_adjust > 0 && vp.zoom != _settings_client.gui.zoom_max) {
172 vp.zoom++;
173 zoom_adjust--;
174 }
175
176 vp.virtual_width = ScaleByZoom(vp.width, vp.zoom);
178}
179
180static constexpr NWidgetPart _nested_main_window_widgets[] = {
181 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1),
182};
183
184enum GlobalHotKeys : int32_t {
185 GHK_QUIT,
186 GHK_ABANDON,
187 GHK_CONSOLE,
188 GHK_BOUNDING_BOXES,
189 GHK_DIRTY_BLOCKS,
190 GHK_WIDGET_OUTLINES,
191 GHK_CENTER,
192 GHK_CENTER_ZOOM,
193 GHK_RESET_OBJECT_TO_PLACE,
194 GHK_DELETE_WINDOWS,
195 GHK_DELETE_NONVITAL_WINDOWS,
196 GHK_DELETE_ALL_MESSAGES,
197 GHK_REFRESH_SCREEN,
198 GHK_CRASH,
199 GHK_MONEY,
200 GHK_UPDATE_COORDS,
201 GHK_TOGGLE_TRANSPARENCY,
202 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
203 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
204 GHK_TRANSPARANCY,
205 GHK_CHAT,
206 GHK_CHAT_ALL,
207 GHK_CHAT_COMPANY,
208 GHK_CHAT_SERVER,
209 GHK_CLOSE_NEWS,
210 GHK_CLOSE_ERROR,
211};
212
214{
215 MainWindow(WindowDesc &desc) : Window(desc)
216 {
217 this->InitNested(0);
219 ResizeWindow(this, _screen.width, _screen.height);
220
221 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
223
224 this->viewport->overlay = std::make_shared<LinkGraphOverlay>(this, WID_M_VIEWPORT, 0, CompanyMask{}, 2);
225 this->refresh_timeout.Reset();
226 }
227
230 {
231 if (this->viewport->overlay->GetCargoMask() == 0 ||
232 this->viewport->overlay->GetCompanyMask().None()) {
233 return;
234 }
235
236 this->viewport->overlay->SetDirty();
237 this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
238 }
239
241 const IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(7650), [this](auto) {
243 }};
244
252 TimeoutTimer<TimerWindow> refresh_timeout = {std::chrono::milliseconds(450), [this]() {
254 }};
255
256 void OnPaint() override
257 {
258 this->DrawWidgets();
259 if (_game_mode == GM_MENU) {
260 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};
261 uint letter_spacing = ScaleGUITrad(10);
262 int name_width = static_cast<int>(std::size(title_sprites) - 1) * letter_spacing;
263
264 for (const SpriteID &sprite : title_sprites) {
265 name_width += GetSpriteSize(sprite).width;
266 }
267 int off_x = (this->width - name_width) / 2;
268
269 for (const SpriteID &sprite : title_sprites) {
270 DrawSprite(sprite, PAL_NONE, off_x, ScaleGUITrad(50));
271 off_x += GetSpriteSize(sprite).width + letter_spacing;
272 }
273
274 int text_y = this->height - GetCharacterHeight(FS_NORMAL) * 2;
275 DrawString(0, this->width - 1, text_y, STR_INTRO_VERSION, TC_WHITE, SA_CENTER);
276 }
277 }
278
279 EventState OnHotkey(int hotkey) override
280 {
281 if (hotkey == GHK_QUIT) {
282 HandleExitGameRequest();
283 return ES_HANDLED;
284 }
285
286 /* Disable all key shortcuts, except quit shortcuts when
287 * generating the world, otherwise they create threading
288 * problem during the generating, resulting in random
289 * assertions that are hard to trigger and debug */
290 if (HasModalProgress()) return ES_NOT_HANDLED;
291
292 switch (hotkey) {
293 case GHK_ABANDON:
294 /* No point returning from the main menu to itself */
295 if (_game_mode == GM_MENU) return ES_HANDLED;
297 DoExitSave();
299 } else {
300 AskExitToGameMenu();
301 }
302 return ES_HANDLED;
303
304 case GHK_CONSOLE:
306 return ES_HANDLED;
307
308 case GHK_BOUNDING_BOXES:
310 return ES_HANDLED;
311
312 case GHK_DIRTY_BLOCKS:
314 return ES_HANDLED;
315
316 case GHK_WIDGET_OUTLINES:
318 return ES_HANDLED;
319 }
320
321 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
322
323 switch (hotkey) {
324 case GHK_CENTER:
325 case GHK_CENTER_ZOOM: {
326 Point pt = GetTileBelowCursor();
327 if (pt.x != -1) {
328 bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
329 if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
330 ScrollMainWindowTo(pt.x, pt.y, -1, instant);
331 }
332 break;
333 }
334
335 case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
336 case GHK_DELETE_WINDOWS: CloseNonVitalWindows(); break;
337 case GHK_DELETE_NONVITAL_WINDOWS: CloseAllNonVitalWindows(); break;
338 case GHK_DELETE_ALL_MESSAGES: DeleteAllMessages(); break;
339 case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
340
341 case GHK_CRASH: // Crash the game
342 *(volatile uint8_t *)nullptr = 0;
343 break;
344
345 case GHK_MONEY: // Gimme money
346 /* You can only cheat for money in singleplayer mode. */
348 break;
349
350 case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
352 break;
353
354 case GHK_TOGGLE_TRANSPARENCY:
355 case GHK_TOGGLE_TRANSPARENCY + 1:
356 case GHK_TOGGLE_TRANSPARENCY + 2:
357 case GHK_TOGGLE_TRANSPARENCY + 3:
358 case GHK_TOGGLE_TRANSPARENCY + 4:
359 case GHK_TOGGLE_TRANSPARENCY + 5:
360 case GHK_TOGGLE_TRANSPARENCY + 6:
361 case GHK_TOGGLE_TRANSPARENCY + 7:
362 case GHK_TOGGLE_TRANSPARENCY + 8:
363 /* Transparency toggle hot keys */
364 ToggleTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_TRANSPARENCY));
366 break;
367
368 case GHK_TOGGLE_INVISIBILITY:
369 case GHK_TOGGLE_INVISIBILITY + 1:
370 case GHK_TOGGLE_INVISIBILITY + 2:
371 case GHK_TOGGLE_INVISIBILITY + 3:
372 case GHK_TOGGLE_INVISIBILITY + 4:
373 case GHK_TOGGLE_INVISIBILITY + 5:
374 case GHK_TOGGLE_INVISIBILITY + 6:
375 case GHK_TOGGLE_INVISIBILITY + 7:
376 /* Invisibility toggle hot keys */
377 ToggleInvisibilityWithTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_INVISIBILITY));
379 break;
380
381 case GHK_TRANSPARENCY_TOOLBAR:
383 break;
384
385 case GHK_TRANSPARANCY:
387 break;
388
389 case GHK_CHAT: // smart chat; send to team if any, otherwise to all
390 if (_networking) {
392 if (cio == nullptr) break;
393
395 }
396 break;
397
398 case GHK_CHAT_ALL: // send text message to all clients
400 break;
401
402 case GHK_CHAT_COMPANY: // send text to all team mates
403 if (_networking) {
405 if (cio == nullptr) break;
406
408 }
409 break;
410
411 case GHK_CHAT_SERVER: // send text to the server
414 }
415 break;
416
417 case GHK_CLOSE_NEWS: // close active news window
419 break;
420
421 case GHK_CLOSE_ERROR: // close active error window
423 break;
424
425 default: return ES_NOT_HANDLED;
426 }
427 return ES_HANDLED;
428 }
429
430 void OnScroll(Point delta) override
431 {
432 this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
433 this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
434 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
435 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
436 this->refresh_timeout.Reset();
437 }
438
439 void OnMouseWheel(int wheel, WidgetID widget) override
440 {
441 if (widget != WID_M_VIEWPORT) return;
443 bool in = wheel < 0;
444
445 /* When following, only change zoom - otherwise zoom to the cursor. */
446 if (this->viewport->follow_vehicle != VehicleID::Invalid()) {
447 DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, this);
448 } else {
449 ZoomInOrOutToCursorWindow(in, this);
450 }
451 }
452 }
453
454 void OnResize() override
455 {
456 if (this->viewport != nullptr) {
457 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
458 nvp->UpdateViewportCoordinates(this);
459 this->refresh_timeout.Reset();
460 }
461 }
462
463 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
464 {
465 if (widget != WID_M_VIEWPORT) return false;
466 return this->viewport->overlay->ShowTooltip(pt, close_cond);
467 }
468
474 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
475 {
476 if (!gui_scope) return;
477 /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
479 }
480
481 static inline HotkeyList hotkeys{"global", {
482 Hotkey({'Q' | WKC_CTRL, 'Q' | WKC_META}, "quit", GHK_QUIT),
483 Hotkey({'W' | WKC_CTRL, 'W' | WKC_META}, "abandon", GHK_ABANDON),
484 Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
485 Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
486 Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS),
487 Hotkey('O' | WKC_CTRL, "widget_outlines", GHK_WIDGET_OUTLINES),
488 Hotkey('C', "center", GHK_CENTER),
489 Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM),
490 Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
491 Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
492 Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
493 Hotkey(WKC_DELETE | WKC_CTRL, "delete_all_messages", GHK_DELETE_ALL_MESSAGES),
494 Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
495#if defined(_DEBUG)
496 Hotkey('0' | WKC_ALT, "crash_game", GHK_CRASH),
497 Hotkey('1' | WKC_ALT, "money", GHK_MONEY),
498 Hotkey('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
499#endif
500 Hotkey('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
501 Hotkey('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
502 Hotkey('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
503 Hotkey('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
504 Hotkey('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
505 Hotkey('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
506 Hotkey('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
507 Hotkey('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
508 Hotkey('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
509 Hotkey('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
510 Hotkey('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
511 Hotkey('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
512 Hotkey('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
513 Hotkey('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
514 Hotkey('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
515 Hotkey('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
516 Hotkey('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
517 Hotkey('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
518 Hotkey('X', "toggle_transparency", GHK_TRANSPARANCY),
519 Hotkey({WKC_RETURN, 'T'}, "chat", GHK_CHAT),
520 Hotkey({WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T'}, "chat_all", GHK_CHAT_ALL),
521 Hotkey({WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T'}, "chat_company", GHK_CHAT_COMPANY),
522 Hotkey({WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T'}, "chat_server", GHK_CHAT_SERVER),
523 Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS),
524 Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR),
525 }};
526};
527
528static WindowDesc _main_window_desc(
529 WDP_MANUAL, {}, 0, 0,
532 _nested_main_window_widgets,
533 &MainWindow::hotkeys
534);
535
541bool IsQuitKey(uint16_t keycode)
542{
543 int num = MainWindow::hotkeys.CheckMatch(keycode);
544 return num == GHK_QUIT;
545}
546
547
548void ShowSelectGameWindow();
549
554{
555 for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) {
556 const uint8_t *b = GetNonSprite(GetColourPalette(i), SpriteType::Recolour) + 1;
557 assert(b != nullptr);
558 for (ColourShade j = SHADE_BEGIN; j < SHADE_END; j++) {
559 SetColourGradient(i, j, b[0xC6 + j]);
560 }
561 }
562
563 new MainWindow(_main_window_desc);
564
565 /* XXX: these are not done */
566 switch (_game_mode) {
567 default: NOT_REACHED();
568 case GM_MENU:
569 ShowSelectGameWindow();
570 break;
571
572 case GM_NORMAL:
573 case GM_EDITOR:
575 break;
576 }
577}
578
583{
585
586 /* Status bad only for normal games */
587 if (_game_mode == GM_EDITOR) return;
588
590}
591
597{
598 _cur_resolution.width = _screen.width;
599 _cur_resolution.height = _screen.height;
600 ScreenSizeChanged();
601 RelocateAllWindows(_screen.width, _screen.height);
603}
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
constexpr Timpl & Reset()
Reset all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
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:2459
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2450
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.
Definition of stuff that is very close to a company, like the company struct itself.
Functions related to companies.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
GUI related functions in the console.
Functions to handle different currencies.
Dimension _cur_resolution
The current resolution.
Definition driver.cpp:29
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:77
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:958
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:658
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:1024
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:49
ZoomLevel _gui_zoom
GUI Zoom level.
Definition gfx.cpp:61
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ Recolour
Recolour sprite.
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:251
uint32_t CursorID
The number of the cursor (sprite)
Definition gfx_type.h:19
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:393
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
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:955
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1535
Hotkey related functions.
Declaration of linkgraph overlay GUI.
void ShowVitalWindows()
Show the vital in-game windows.
Definition main_gui.cpp:582
void GameSizeChanged()
Size of the application screen changed.
Definition main_gui.cpp:596
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:553
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition main_gui.cpp:541
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition main_gui.cpp:93
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
Types related to the main widgets.
@ WID_M_VIEWPORT
Main window viewport.
Definition main_widget.h:15
Functions related to maps.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:372
Miscellaneous command definitions.
bool _networking
are we in networking mode?
Definition network.cpp:67
bool _network_server
network-server is active
Definition network.cpp:68
ClientID _network_own_client_id
Our client identifier.
Definition network.cpp:72
Basic functions/variables used all over the place.
Base core network types and some helper functions to access them.
void ShowNetworkChatQueryWindow(DestType 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.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
@ CLIENT_ID_SERVER
Servers always have this ID.
bool HideActiveNewsMessage()
Close active news message window.
GUI functions related to the news.
@ SM_MENU
Switch to game intro menu.
Definition openttd.h:33
void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_index)
Set colour gradient palette index.
Definition palette.cpp:399
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/types related to saving and loading games.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:59
@ SWS_OFF
Scroll wheel has no effect.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
@ 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:184
Functions to cache sprites in memory.
This file contains all sprite-related enums and defines.
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.
Functions related to OTTD's strings.
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
ZoomLevel zoom_min
minimum zoom out level
ZoomLevel zoom_max
maximum zoom out level
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
List of hotkeys for a window.
Definition hotkeys.h:37
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition hotkeys.cpp:301
All data for a single hotkey.
Definition hotkeys.h:21
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition main_gui.cpp:279
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition main_gui.cpp:430
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition main_gui.cpp:463
TimeoutTimer< TimerWindow > refresh_timeout
Sometimes when something happened, force an update to the link-graph a bit sooner.
Definition main_gui.cpp:252
const IntervalTimer< TimerWindow > refresh_interval
Refresh the link-graph overlay on a regular interval.
Definition main_gui.cpp:241
void OnResize() override
Called after the window got resized.
Definition main_gui.cpp:454
void OnPaint() override
The window must be repainted.
Definition main_gui.cpp:256
void OnMouseWheel(int wheel, WidgetID widget) override
The mouse wheel has been turned.
Definition main_gui.cpp:439
void RefreshLinkGraph()
Refresh the link-graph overlay.
Definition main_gui.cpp:229
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition main_gui.cpp:474
Partial widget specification to allow NWidgets to be written nested.
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:118
CompanyID client_playas
As which company is this client playing (CompanyID)
Coordinates of a point in 2D.
bool click_beep
Beep on a random selection of buttons.
bool confirm
Play sound effect on successful constructions or other actions.
Data structure for a window viewport.
Definition window_gui.h:250
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:255
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:253
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:254
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:252
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:167
Data structure for an opened window.
Definition window_gui.h:273
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:777
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3205
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition window_gui.h:318
WindowClass window_class
Window class.
Definition window_gui.h:301
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:491
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:410
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:460
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1791
WindowFlags flags
Window flags.
Definition window_gui.h:300
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:312
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
Stuff related to the text buffer GUI.
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 outlihes.
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:74
Window * GetMainWindow()
Get the main window, i.e.
Definition window.cpp:1169
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition window.cpp:3307
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2067
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition window.cpp:3339
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:3265
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition window.cpp:3497
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition window.cpp:3326
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.
@ WhiteBorder
Window white border counter bit mask.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:143
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition window_type.h:53
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition window_type.h:60
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.