OpenTTD Source: src/main_gui.cpp Source File

OpenTTD Source 15.0-beta1

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"
30#include "linkgraph/linkgraph_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"
44#include "network/network_func.h"
45#include "network/network_gui.h"
46#include "network/network_base.h"
47
48#include "table/sprites.h"
49#include "table/strings.h"
50
51#include "safeguards.h"
52
63 bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
64{
65 if (w->IsWidgetDisabled(widget)) return false;
66
67 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
68 w->SetDirty();
69
70 if (w->IsWidgetLowered(widget)) {
71 ResetObjectToPlace();
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
93 bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
94{
95 Viewport *vp;
96
97 assert(w != nullptr);
98 vp = w->viewport;
99
100 switch (how) {
101 case ZOOM_NONE:
102 /* On initialisation of the viewport we don't do anything. */
103 break;
104
105 case ZOOM_IN:
106 if (vp->zoom <= _settings_client.gui.zoom_min) return false;
107 vp->zoom = (ZoomLevel)((int)vp->zoom - 1);
108 vp->virtual_width >>= 1;
109 vp->virtual_height >>= 1;
110
111 w->viewport->scrollpos_x += vp->virtual_width >> 1;
112 w->viewport->scrollpos_y += vp->virtual_height >> 1;
113 w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
114 w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
115 break;
116 case ZOOM_OUT:
117 if (vp->zoom >= _settings_client.gui.zoom_max) return false;
118 vp->zoom = (ZoomLevel)((int)vp->zoom + 1);
119
120 w->viewport->scrollpos_x -= vp->virtual_width >> 1;
121 w->viewport->scrollpos_y -= vp->virtual_height >> 1;
122 w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
123 w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
124
125 vp->virtual_width <<= 1;
126 vp->virtual_height <<= 1;
127 break;
128 }
129 if (vp != nullptr) { // the vp can be null when how == ZOOM_NONE
130 vp->virtual_left = w->viewport->scrollpos_x;
131 vp->virtual_top = w->viewport->scrollpos_y;
132 }
133 /* Update the windows that have zoom-buttons to perhaps disable their buttons */
134 w->InvalidateData();
135 return true;
136}
137
138void ZoomInOrOutToCursorWindow(bool in, Window *w)
139{
140 assert(w != nullptr);
141
142 if (_game_mode != GM_MENU) {
143 Viewport *vp = w->viewport;
144 if ((in && vp->zoom <= _settings_client.gui.zoom_min) || (!in && vp->zoom >= _settings_client.gui.zoom_max)) return;
145
146 Point pt = GetTileZoomCenterWindow(in, w);
147 if (pt.x != -1) {
148 ScrollWindowTo(pt.x, pt.y, -1, w, true);
149
150 DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
151 }
152 }
153}
154
155void FixTitleGameZoom(int zoom_adjust)
156{
157 if (_game_mode != GM_MENU) return;
158
159 Viewport *vp = GetMainWindow()->viewport;
160
161 /* Adjust the zoom in/out.
162 * Can't simply add, since operator+ is not defined on the ZoomLevel type. */
163 vp->zoom = _gui_zoom;
164 while (zoom_adjust < 0 && vp->zoom != _settings_client.gui.zoom_min) {
165 vp->zoom--;
166 zoom_adjust++;
167 }
168 while (zoom_adjust > 0 && vp->zoom != _settings_client.gui.zoom_max) {
169 vp->zoom++;
170 zoom_adjust--;
171 }
172
173 vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
174 vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
175}
176
177static constexpr NWidgetPart _nested_main_window_widgets[] = {
178 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1),
179};
180
181enum {
182 GHK_QUIT,
183 GHK_ABANDON,
184 GHK_CONSOLE,
185 GHK_BOUNDING_BOXES,
186 GHK_DIRTY_BLOCKS,
187 GHK_WIDGET_OUTLINES,
188 GHK_CENTER,
189 GHK_CENTER_ZOOM,
190 GHK_RESET_OBJECT_TO_PLACE,
191 GHK_DELETE_WINDOWS,
192 GHK_DELETE_NONVITAL_WINDOWS,
193 GHK_DELETE_ALL_MESSAGES,
194 GHK_REFRESH_SCREEN,
195 GHK_CRASH,
196 GHK_MONEY,
197 GHK_UPDATE_COORDS,
198 GHK_TOGGLE_TRANSPARENCY,
199 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
200 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
201 GHK_TRANSPARANCY,
202 GHK_CHAT,
203 GHK_CHAT_ALL,
204 GHK_CHAT_COMPANY,
205 GHK_CHAT_SERVER,
206 GHK_CLOSE_NEWS,
207 GHK_CLOSE_ERROR,
208};
209
210 struct MainWindow : Window
211{
212 MainWindow(WindowDesc &desc) : Window(desc)
213 {
214 this->InitNested(0);
215 CLRBITS(this->flags, WF_WHITE_BORDER);
216 ResizeWindow(this, _screen.width, _screen.height);
217
218 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
219 nvp->InitializeViewport(this, TileXY(32, 32), ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
220
221 this->viewport->overlay = std::make_shared<LinkGraphOverlay>(this, WID_M_VIEWPORT, 0, 0, 2);
222 this->refresh_timeout.Reset();
223 }
224
226 void RefreshLinkGraph()
227 {
228 if (this->viewport->overlay->GetCargoMask() == 0 ||
229 this->viewport->overlay->GetCompanyMask() == 0) {
230 return;
231 }
232
233 this->viewport->overlay->SetDirty();
234 this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
235 }
236
238 IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(7650), [this](auto) {
239 RefreshLinkGraph();
240 }};
241
249 TimeoutTimer<TimerWindow> refresh_timeout = {std::chrono::milliseconds(450), [this]() {
250 RefreshLinkGraph();
251 }};
252
253 void OnPaint() override
254 {
255 this->DrawWidgets();
256 if (_game_mode == GM_MENU) {
257 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};
258 uint letter_spacing = ScaleGUITrad(10);
259 int name_width = static_cast<int>(std::size(title_sprites) - 1) * letter_spacing;
260
261 for (const SpriteID &sprite : title_sprites) {
262 name_width += GetSpriteSize(sprite).width;
263 }
264 int off_x = (this->width - name_width) / 2;
265
266 for (const SpriteID &sprite : title_sprites) {
267 DrawSprite(sprite, PAL_NONE, off_x, ScaleGUITrad(50));
268 off_x += GetSpriteSize(sprite).width + letter_spacing;
269 }
270 }
271 }
272
273 EventState OnHotkey(int hotkey) override
274 {
275 if (hotkey == GHK_QUIT) {
276 HandleExitGameRequest();
277 return ES_HANDLED;
278 }
279
280 /* Disable all key shortcuts, except quit shortcuts when
281 * generating the world, otherwise they create threading
282 * problem during the generating, resulting in random
283 * assertions that are hard to trigger and debug */
284 if (HasModalProgress()) return ES_NOT_HANDLED;
285
286 switch (hotkey) {
287 case GHK_ABANDON:
288 /* No point returning from the main menu to itself */
289 if (_game_mode == GM_MENU) return ES_HANDLED;
290 if (_settings_client.gui.autosave_on_exit) {
291 DoExitSave();
292 _switch_mode = SM_MENU;
293 } else {
294 AskExitToGameMenu();
295 }
296 return ES_HANDLED;
297
298 case GHK_CONSOLE:
299 IConsoleSwitch();
300 return ES_HANDLED;
301
302 case GHK_BOUNDING_BOXES:
303 ToggleBoundingBoxes();
304 return ES_HANDLED;
305
306 case GHK_DIRTY_BLOCKS:
307 ToggleDirtyBlocks();
308 return ES_HANDLED;
309
310 case GHK_WIDGET_OUTLINES:
311 ToggleWidgetOutlines();
312 return ES_HANDLED;
313 }
314
315 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
316
317 switch (hotkey) {
318 case GHK_CENTER:
319 case GHK_CENTER_ZOOM: {
320 Point pt = GetTileBelowCursor();
321 if (pt.x != -1) {
322 bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
323 if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
324 ScrollMainWindowTo(pt.x, pt.y, -1, instant);
325 }
326 break;
327 }
328
329 case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
330 case GHK_DELETE_WINDOWS: CloseNonVitalWindows(); break;
331 case GHK_DELETE_NONVITAL_WINDOWS: CloseAllNonVitalWindows(); break;
332 case GHK_DELETE_ALL_MESSAGES: DeleteAllMessages(); break;
333 case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
334
335 case GHK_CRASH: // Crash the game
336 *(volatile uint8_t *)nullptr = 0;
337 break;
338
339 case GHK_MONEY: // Gimme money
340 /* You can only cheat for money in singleplayer mode. */
341 if (!_networking) Command<CMD_MONEY_CHEAT>::Post(10000000);
342 break;
343
344 case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
345 UpdateAllVirtCoords();
346 break;
347
348 case GHK_TOGGLE_TRANSPARENCY:
349 case GHK_TOGGLE_TRANSPARENCY + 1:
350 case GHK_TOGGLE_TRANSPARENCY + 2:
351 case GHK_TOGGLE_TRANSPARENCY + 3:
352 case GHK_TOGGLE_TRANSPARENCY + 4:
353 case GHK_TOGGLE_TRANSPARENCY + 5:
354 case GHK_TOGGLE_TRANSPARENCY + 6:
355 case GHK_TOGGLE_TRANSPARENCY + 7:
356 case GHK_TOGGLE_TRANSPARENCY + 8:
357 /* Transparency toggle hot keys */
358 ToggleTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_TRANSPARENCY));
359 MarkWholeScreenDirty();
360 break;
361
362 case GHK_TOGGLE_INVISIBILITY:
363 case GHK_TOGGLE_INVISIBILITY + 1:
364 case GHK_TOGGLE_INVISIBILITY + 2:
365 case GHK_TOGGLE_INVISIBILITY + 3:
366 case GHK_TOGGLE_INVISIBILITY + 4:
367 case GHK_TOGGLE_INVISIBILITY + 5:
368 case GHK_TOGGLE_INVISIBILITY + 6:
369 case GHK_TOGGLE_INVISIBILITY + 7:
370 /* Invisibility toggle hot keys */
371 ToggleInvisibilityWithTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_INVISIBILITY));
372 MarkWholeScreenDirty();
373 break;
374
375 case GHK_TRANSPARENCY_TOOLBAR:
376 ShowTransparencyToolbar();
377 break;
378
379 case GHK_TRANSPARANCY:
380 ResetRestoreAllTransparency();
381 break;
382
383 case GHK_CHAT: // smart chat; send to team if any, otherwise to all
384 if (_networking) {
385 const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
386 if (cio == nullptr) break;
387
388 ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
389 }
390 break;
391
392 case GHK_CHAT_ALL: // send text message to all clients
393 if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
394 break;
395
396 case GHK_CHAT_COMPANY: // send text to all team mates
397 if (_networking) {
398 const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
399 if (cio == nullptr) break;
400
401 ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
402 }
403 break;
404
405 case GHK_CHAT_SERVER: // send text to the server
406 if (_networking && !_network_server) {
407 ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, CLIENT_ID_SERVER);
408 }
409 break;
410
411 case GHK_CLOSE_NEWS: // close active news window
412 if (!HideActiveNewsMessage()) return ES_NOT_HANDLED;
413 break;
414
415 case GHK_CLOSE_ERROR: // close active error window
416 if (!HideActiveErrorMessage()) return ES_NOT_HANDLED;
417 break;
418
419 default: return ES_NOT_HANDLED;
420 }
421 return ES_HANDLED;
422 }
423
424 void OnScroll(Point delta) override
425 {
426 this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
427 this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
428 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
429 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
430 this->refresh_timeout.Reset();
431 }
432
433 void OnMouseWheel(int wheel) override
434 {
435 if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
436 bool in = wheel < 0;
437
438 /* When following, only change zoom - otherwise zoom to the cursor. */
439 if (this->viewport->follow_vehicle != INVALID_VEHICLE) {
440 DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, this);
441 } else {
442 ZoomInOrOutToCursorWindow(in, this);
443 }
444 }
445 }
446
447 void OnResize() override
448 {
449 if (this->viewport != nullptr) {
450 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
451 nvp->UpdateViewportCoordinates(this);
452 this->refresh_timeout.Reset();
453 }
454 }
455
456 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
457 {
458 if (widget != WID_M_VIEWPORT) return false;
459 return this->viewport->overlay->ShowTooltip(pt, close_cond);
460 }
461
467 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
468 {
469 if (!gui_scope) return;
470 /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
471 InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
472 }
473
474 static inline HotkeyList hotkeys{"global", {
475 Hotkey({'Q' | WKC_CTRL, 'Q' | WKC_META}, "quit", GHK_QUIT),
476 Hotkey({'W' | WKC_CTRL, 'W' | WKC_META}, "abandon", GHK_ABANDON),
477 Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
478 Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
479 Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS),
480 Hotkey('O' | WKC_CTRL, "widget_outlines", GHK_WIDGET_OUTLINES),
481 Hotkey('C', "center", GHK_CENTER),
482 Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM),
483 Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
484 Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
485 Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
486 Hotkey(WKC_DELETE | WKC_CTRL, "delete_all_messages", GHK_DELETE_ALL_MESSAGES),
487 Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
488#if defined(_DEBUG)
489 Hotkey('0' | WKC_ALT, "crash_game", GHK_CRASH),
490 Hotkey('1' | WKC_ALT, "money", GHK_MONEY),
491 Hotkey('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
492#endif
493 Hotkey('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
494 Hotkey('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
495 Hotkey('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
496 Hotkey('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
497 Hotkey('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
498 Hotkey('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
499 Hotkey('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
500 Hotkey('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
501 Hotkey('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
502 Hotkey('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
503 Hotkey('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
504 Hotkey('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
505 Hotkey('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
506 Hotkey('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
507 Hotkey('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
508 Hotkey('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
509 Hotkey('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
510 Hotkey('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
511 Hotkey('X', "toggle_transparency", GHK_TRANSPARANCY),
512 Hotkey({WKC_RETURN, 'T'}, "chat", GHK_CHAT),
513 Hotkey({WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T'}, "chat_all", GHK_CHAT_ALL),
514 Hotkey({WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T'}, "chat_company", GHK_CHAT_COMPANY),
515 Hotkey({WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T'}, "chat_server", GHK_CHAT_SERVER),
516 Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS),
517 Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR),
518 }};
519};
520
521static WindowDesc _main_window_desc(
522 WDP_MANUAL, nullptr, 0, 0,
523 WC_MAIN_WINDOW, WC_NONE,
524 WDF_NO_CLOSE,
525 _nested_main_window_widgets,
526 &MainWindow::hotkeys
527);
528
534 bool IsQuitKey(uint16_t keycode)
535{
536 int num = MainWindow::hotkeys.CheckMatch(keycode);
537 return num == GHK_QUIT;
538}
539
540
541void ShowSelectGameWindow();
542
546 void SetupColoursAndInitialWindow()
547{
548 for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) {
549 const uint8_t *b = GetNonSprite(GENERAL_SPRITE_COLOUR(i), SpriteType::Recolour) + 1;
550 assert(b != nullptr);
551 for (ColourShade j = SHADE_BEGIN; j < SHADE_END; j++) {
552 SetColourGradient(i, j, b[0xC6 + j]);
553 }
554 }
555
556 new MainWindow(_main_window_desc);
557
558 /* XXX: these are not done */
559 switch (_game_mode) {
560 default: NOT_REACHED();
561 case GM_MENU:
562 ShowSelectGameWindow();
563 break;
564
565 case GM_NORMAL:
566 case GM_EDITOR:
567 ShowVitalWindows();
568 break;
569 }
570}
571
575 void ShowVitalWindows()
576{
577 AllocateToolbar();
578
579 /* Status bad only for normal games */
580 if (_game_mode == GM_EDITOR) return;
581
582 ShowStatusBar();
583}
584
589 void GameSizeChanged()
590{
591 _cur_resolution.width = _screen.width;
592 _cur_resolution.height = _screen.height;
593 ScreenSizeChanged();
594 RelocateAllWindows(_screen.width, _screen.height);
595 MarkWholeScreenDirty();
596}
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition afterload.cpp:224
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition bitmath_func.hpp:166
CommandCost
Common return value for all commands.
Definition command_type.h:23
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition command_type.h:162
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
NWidgetViewport
Nested widget to display a viewport in a window.
Definition widget_type.h:680
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2354
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2345
TimeoutTimer
A timeout timer will fire once after the interval.
Definition timer.h:116
TimeoutTimer::Reset
void Reset()
Reset the timer, so it will fire again after the timeout.
Definition timer.h:140
command_func.h
Functions related to commands.
Commands
Commands
List of commands.
Definition command_type.h:187
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
company_func.h
Functions related to companies.
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition console_gui.cpp:429
console_gui.h
GUI related functions in the console.
currency.h
Functions to handle different currencies.
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition driver.cpp:26
error.h
Functions related to errors.
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition error_gui.cpp:439
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:922
DrawSprite
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:988
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:49
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition gfx.cpp:61
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:18
SpriteType::Recolour
@ Recolour
Recolour sprite.
CursorID
uint32_t CursorID
The number of the cursor (sprite)
Definition gfx_type.h:20
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1529
hotkeys.h
Hotkey related functions.
linkgraph_gui.h
Declaration of linkgraph overlay GUI.
ShowVitalWindows
void ShowVitalWindows()
Show the vital in-game windows.
Definition main_gui.cpp:575
GameSizeChanged
void GameSizeChanged()
Size of the application screen changed.
Definition main_gui.cpp:589
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:546
IsQuitKey
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition main_gui.cpp:534
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition main_gui.cpp:93
HandlePlacePushButton
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
main_widget.h
Types related to the main widgets.
WID_M_VIEWPORT
@ WID_M_VIEWPORT
Main window viewport.
Definition main_widget.h:15
map_func.h
Functions related to maps.
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:373
misc_cmd.h
Miscellaneous command definitions.
_networking
bool _networking
are we in networking mode?
Definition network.cpp:65
_network_server
bool _network_server
network-server is active
Definition network.cpp:66
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition network.cpp:70
network.h
Basic functions/variables used all over the place.
network_base.h
Base core network types and some helper functions to access them.
ShowNetworkChatQueryWindow
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Definition network_chat_gui.cpp:445
NetworkClientPreferTeamChat
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Definition network_client.cpp:1373
network_func.h
Network functions used by other parts of OpenTTD.
network_gui.h
GUIs related to networking.
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition network_type.h:82
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition network_type.h:81
DESTTYPE_BROADCAST
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
Definition network_type.h:80
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition network_type.h:51
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition news_gui.cpp:1098
news_gui.h
GUI functions related to the news.
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition openttd.h:33
SetColourGradient
void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_index)
Set colour gradient palette index.
Definition palette.cpp:325
progress.h
Functions related to modal progress.
HasModalProgress
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition progress.h:17
safeguards.h
A number of safeguards to prevent using unsafe methods.
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition saveload.cpp:3237
saveload.h
Functions/types related to saving and loading games.
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:56
SWS_OFF
@ SWS_OFF
Scroll wheel has no effect.
Definition settings_type.h:133
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition smallmap_gui.cpp:2077
sound_func.h
Functions related to sound.
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
SND_12_EXPLOSION
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition sound_type.h:63
spritecache.h
Functions to cache sprites in memory.
sprites.h
This file contains all sprite-related enums and defines.
ShowStatusBar
void ShowStatusBar()
Show our status bar.
Definition statusbar_gui.cpp:250
statusbar_gui.h
Functions, definitions and such used only by the GUI.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
strings_func.h
Functions related to OTTD's strings.
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:613
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:610
CommandHelper
Definition command_func.h:83
GUISettings::autosave_on_exit
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
Definition settings_type.h:171
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition settings_type.h:165
GUISettings::zoom_max
ZoomLevel zoom_max
maximum zoom out level
Definition settings_type.h:166
GUISettings::scrollwheel_scrolling
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
Definition settings_type.h:177
HotkeyList
List of hotkeys for a window.
Definition hotkeys.h:37
HotkeyList::CheckMatch
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition hotkeys.cpp:309
Hotkey
All data for a single hotkey.
Definition hotkeys.h:21
MainWindow
Definition main_gui.cpp:211
MainWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition main_gui.cpp:273
MainWindow::OnScroll
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition main_gui.cpp:424
MainWindow::OnTooltip
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition main_gui.cpp:456
MainWindow::refresh_timeout
TimeoutTimer< TimerWindow > refresh_timeout
Sometimes when something happened, force an update to the link-graph a bit sooner.
Definition main_gui.cpp:249
MainWindow::refresh_interval
IntervalTimer< TimerWindow > refresh_interval
Refresh the link-graph overlay on a regular interval.
Definition main_gui.cpp:238
MainWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition main_gui.cpp:447
MainWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition main_gui.cpp:253
MainWindow::RefreshLinkGraph
void RefreshLinkGraph()
Refresh the link-graph overlay.
Definition main_gui.cpp:226
MainWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition main_gui.cpp:433
MainWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition main_gui.cpp:467
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
NetworkClientInfo
Container for all information known about a client.
Definition network_base.h:24
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition network.cpp:116
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition settings_type.h:249
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition settings_type.h:248
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
ViewportData::dest_scrollpos_y
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:257
ViewportData::scrollpos_y
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:255
ViewportData::dest_scrollpos_x
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition window_gui.h:256
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition window_gui.h:253
ViewportData::scrollpos_x
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:254
Viewport
Data structure for viewport, display of a part of the world.
Definition viewport_type.h:22
Viewport::width
int width
Screen width of the viewport.
Definition viewport_type.h:25
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition viewport_type.h:33
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition viewport_type.h:29
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition viewport_type.h:28
Viewport::virtual_width
int virtual_width
width << zoom
Definition viewport_type.h:30
Viewport::height
int height
Screen height of the viewport.
Definition viewport_type.h:26
Viewport::virtual_height
int virtual_height
height << zoom
Definition viewport_type.h:31
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:732
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3159
Window::window_class
WindowClass window_class
Window class.
Definition window_gui.h:301
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition window_gui.h:318
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:497
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:416
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:466
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1746
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:300
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
textbuf_gui.h
Stuff related to the text buffer GUI.
tilehighlight_func.h
Functions related to tile highlights.
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition viewport.cpp:3498
SetObjectToPlace
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...
Definition viewport.cpp:3450
HighLightStyle
HighLightStyle
Highlighting draw styles.
Definition tilehighlight_type.h:19
timer.h
Definition of Interval and OneShot timers.
timer_window.h
Definition of the Window system.
ToggleDirtyBlocks
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
Definition toolbar_gui.cpp:1084
AllocateToolbar
void AllocateToolbar()
Allocate the toolbar.
Definition toolbar_gui.cpp:2558
ToggleBoundingBoxes
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
Definition toolbar_gui.cpp:1067
ToggleWidgetOutlines
void ToggleWidgetOutlines()
Toggle drawing of widget outlihes.
Definition toolbar_gui.cpp:1098
toolbar_gui.h
Stuff related to the (main) toolbar.
transparency.h
Functions related to transparency.
ResetRestoreAllTransparency
void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Definition transparency.h:113
ToggleTransparency
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition transparency.h:69
TransparencyOption
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition transparency.h:22
ToggleInvisibilityWithTransparency
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition transparency.h:91
ShowTransparencyToolbar
void ShowTransparencyToolbar()
Show the transparency toolbar.
Definition transparency_gui.cpp:161
transparency_gui.h
GUI functions related to transparency.
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition vehicle_type.h:54
ScrollWindowTo
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition viewport.cpp:2469
viewport_func.h
Functions related to (drawing on) viewports.
MaxZoomInOut
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition viewport_func.h:46
ZoomStateChange
ZoomStateChange
Directions of zooming.
Definition viewport_type.h:76
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition viewport_type.h:77
ZOOM_NONE
@ ZOOM_NONE
Hack, used to update the button status.
Definition viewport_type.h:79
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition viewport_type.h:78
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:35
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:82
GetMainWindow
Window * GetMainWindow()
Get the main window, i.e.
Definition window.cpp:1127
CloseNonVitalWindows
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition window.cpp:3261
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2022
DeleteAllMessages
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition window.cpp:3293
InvalidateWindowData
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:3219
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition window.cpp:3451
CloseAllNonVitalWindows
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition window.cpp:3280
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition window_gui.h:236
WDF_NO_CLOSE
@ WDF_NO_CLOSE
This window can't be interactively closed.
Definition window_gui.h:206
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:146
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
EventState
EventState
State of handling an event.
Definition window_type.h:743
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition window_type.h:744
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:745
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition window_type.h:51
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition window_type.h:58
zoom_func.h
Functions related to zooming.
ScaleByZoom
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_MIN) When shifting right,...
Definition zoom_func.h:22
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition zoom_func.h:87
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:16
ZOOM_LVL_VIEWPORT
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
Definition zoom_type.h:28