OpenTTD Source: src/main_gui.cpp Source File

OpenTTD Source 15.0-RC2

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
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 SndClickBeep();
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 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;
111 vp.dest_scrollpos_x = vp.scrollpos_x;
112 vp.dest_scrollpos_y = vp.scrollpos_y;
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;
123 vp.dest_scrollpos_x = vp.scrollpos_x;
124 vp.dest_scrollpos_y = vp.scrollpos_y;
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
153 DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
154 }
155 }
156}
157
158void FixTitleGameZoom(int zoom_adjust)
159{
160 if (_game_mode != GM_MENU) return;
161
162 Viewport &vp = *GetMainWindow()->viewport;
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);
177 vp.virtual_height = ScaleByZoom(vp.height, vp.zoom);
178}
179
180static constexpr std::initializer_list<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_TRANSPARENCY,
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
213 struct MainWindow : Window
214{
215 MainWindow(WindowDesc &desc) : Window(desc)
216 {
217 this->InitNested(0);
218 this->flags.Reset(WindowFlag::WhiteBorder);
219 ResizeWindow(this, _screen.width, _screen.height);
220
221 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
222 nvp->InitializeViewport(this, TileXY(32, 32), ScaleZoomGUI(ZoomLevel::Viewport));
223
224 this->viewport->overlay = std::make_shared<LinkGraphOverlay>(this, WID_M_VIEWPORT, 0, CompanyMask{}, 2);
225 this->refresh_timeout.Reset();
226 }
227
229 void RefreshLinkGraph()
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) {
242 RefreshLinkGraph();
243 }};
244
252 TimeoutTimer<TimerWindow> refresh_timeout = {std::chrono::milliseconds(450), [this]() {
253 RefreshLinkGraph();
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;
296 if (_settings_client.gui.autosave_on_exit) {
297 DoExitSave();
298 _switch_mode = SM_MENU;
299 } else {
300 AskExitToGameMenu();
301 }
302 return ES_HANDLED;
303
304 case GHK_CONSOLE:
305 IConsoleSwitch();
306 return ES_HANDLED;
307
308 case GHK_BOUNDING_BOXES:
309 ToggleBoundingBoxes();
310 return ES_HANDLED;
311
312 case GHK_DIRTY_BLOCKS:
313 ToggleDirtyBlocks();
314 return ES_HANDLED;
315
316 case GHK_WIDGET_OUTLINES:
317 ToggleWidgetOutlines();
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. */
347 if (!_networking) Command<CMD_MONEY_CHEAT>::Post(10000000);
348 break;
349
350 case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
351 UpdateAllVirtCoords();
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));
365 MarkWholeScreenDirty();
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));
378 MarkWholeScreenDirty();
379 break;
380
381 case GHK_TRANSPARENCY_TOOLBAR:
382 ShowTransparencyToolbar();
383 break;
384
385 case GHK_TRANSPARENCY:
386 ResetRestoreAllTransparency();
387 break;
388
389 case GHK_CHAT: // smart chat; send to team if any, otherwise to all
390 if (_networking) {
391 const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
392 if (cio == nullptr) break;
393
394 ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas.base());
395 }
396 break;
397
398 case GHK_CHAT_ALL: // send text message to all clients
399 if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
400 break;
401
402 case GHK_CHAT_COMPANY: // send text to all team mates
403 if (_networking) {
404 const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
405 if (cio == nullptr) break;
406
407 ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas.base());
408 }
409 break;
410
411 case GHK_CHAT_SERVER: // send text to the server
412 if (_networking && !_network_server) {
413 ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, CLIENT_ID_SERVER);
414 }
415 break;
416
417 case GHK_CLOSE_NEWS: // close active news window
418 if (!HideActiveNewsMessage()) return ES_NOT_HANDLED;
419 break;
420
421 case GHK_CLOSE_ERROR: // close active error window
422 if (!HideActiveErrorMessage()) return ES_NOT_HANDLED;
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;
442 if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
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) */
478 InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
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_TRANSPARENCY),
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,
530 WC_MAIN_WINDOW, WC_NONE,
531 WindowDefaultFlag::NoClose,
532 _nested_main_window_widgets,
533 &MainWindow::hotkeys
534);
535
541 bool IsQuitKey(uint16_t keycode)
542{
543 int num = MainWindow::hotkeys.CheckMatch(keycode);
544 return num == GHK_QUIT;
545}
546
547
548void ShowSelectGameWindow();
549
553 void SetupColoursAndInitialWindow()
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, PixelColour{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:
574 ShowVitalWindows();
575 break;
576 }
577}
578
582 void ShowVitalWindows()
583{
584 AllocateToolbar();
585
586 /* Status bad only for normal games */
587 if (_game_mode == GM_EDITOR) return;
588
589 ShowStatusBar();
590}
591
596 void GameSizeChanged()
597{
598 _cur_resolution.width = _screen.width;
599 _cur_resolution.height = _screen.height;
600 ScreenSizeChanged();
601 RelocateAllWindows(_screen.width, _screen.height);
602 MarkWholeScreenDirty();
603}
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition afterload.cpp:220
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition command_type.h:168
CompanyMask
Definition company_type.h:43
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:694
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2402
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2393
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:196
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:426
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:29
error.h
Functions related to errors.
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition error_gui.cpp:355
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:965
DrawString
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:665
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:1031
_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:17
SpriteType::Recolour
@ Recolour
Recolour sprite.
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
CursorID
uint32_t CursorID
The number of the cursor (sprite)
Definition gfx_type.h:19
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1546
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:582
GameSizeChanged
void GameSizeChanged()
Size of the application screen changed.
Definition main_gui.cpp:596
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:553
IsQuitKey
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition main_gui.cpp:541
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 TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:385
misc_cmd.h
Miscellaneous command definitions.
_networking
bool _networking
are we in networking mode?
Definition network.cpp:66
_network_server
bool _network_server
network-server is active
Definition network.cpp:67
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition network.cpp:71
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:441
NetworkClientPreferTeamChat
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Definition network_client.cpp:1331
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:71
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition network_type.h:70
DESTTYPE_BROADCAST
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
Definition network_type.h:69
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition network_type.h:45
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition news_gui.cpp:1129
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, PixelColour palette_index)
Set colour gradient palette index.
Definition palette.cpp:399
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:3367
saveload.h
Functions/types related to saving and loading games.
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
SWS_OFF
@ SWS_OFF
Scroll wheel has no effect.
Definition settings_type.h:159
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition smallmap_gui.cpp:2078
SndClickBeep
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
sound_func.h
Functions related to sound.
SND_12_EXPLOSION
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition sound_type.h:63
GetColourPalette
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:188
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:240
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:653
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CommandHelper
Definition command_func.h:83
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
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:197
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition settings_type.h:191
GUISettings::zoom_max
ZoomLevel zoom_max
maximum zoom out level
Definition settings_type.h:192
GUISettings::scrollwheel_scrolling
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
Definition settings_type.h:203
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:301
Hotkey
All data for a single hotkey.
Definition hotkeys.h:21
MainWindow
Definition main_gui.cpp:214
MainWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition main_gui.cpp:279
MainWindow::OnScroll
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition main_gui.cpp:430
MainWindow::OnTooltip
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition main_gui.cpp:463
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:252
MainWindow::refresh_interval
const IntervalTimer< TimerWindow > refresh_interval
Refresh the link-graph overlay on a regular interval.
Definition main_gui.cpp:241
MainWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition main_gui.cpp:454
MainWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition main_gui.cpp:256
MainWindow::OnMouseWheel
void OnMouseWheel(int wheel, WidgetID widget) override
The mouse wheel has been turned.
Definition main_gui.cpp:439
MainWindow::RefreshLinkGraph
void RefreshLinkGraph()
Refresh the link-graph overlay.
Definition main_gui.cpp:229
MainWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition main_gui.cpp:474
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:117
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition network_base.h:28
PixelColour
Colour for pixel/line drawing.
Definition gfx_type.h:405
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition settings_type.h:275
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
ViewportData
Data structure for a window viewport.
Definition window_gui.h:251
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:256
ViewportData::scrollpos_y
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:254
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:255
ViewportData::scrollpos_x
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition window_gui.h:253
Viewport
Data structure for viewport, display of a part of the world.
Definition viewport_type.h:31
Viewport::width
int width
Screen width of the viewport.
Definition viewport_type.h:34
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition viewport_type.h:42
Viewport::virtual_width
int virtual_width
width << zoom
Definition viewport_type.h:39
Viewport::height
int height
Screen height of the viewport.
Definition viewport_type.h:35
Viewport::virtual_height
int virtual_height
height << zoom
Definition viewport_type.h:40
WindowDesc
High level window description.
Definition window_gui.h:168
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:766
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:3234
Window::viewport
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition window_gui.h:319
Window::window_class
WindowClass window_class
Window class.
Definition window_gui.h:302
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:411
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1820
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:301
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:313
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
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:3573
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:3525
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:1103
AllocateToolbar
void AllocateToolbar()
Allocate the toolbar.
Definition toolbar_gui.cpp:2572
ToggleBoundingBoxes
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
Definition toolbar_gui.cpp:1086
ToggleWidgetOutlines
void ToggleWidgetOutlines()
Toggle drawing of widget outlines.
Definition toolbar_gui.cpp:1117
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:115
ToggleTransparency
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition transparency.h:71
ToggleInvisibilityWithTransparency
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition transparency.h:93
TransparencyOption
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition transparency.h:23
ShowTransparencyToolbar
void ShowTransparencyToolbar()
Show the transparency toolbar.
Definition transparency_gui.cpp:162
transparency_gui.h
GUI functions related to transparency.
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:2546
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:80
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition viewport_type.h:81
ZOOM_NONE
@ ZOOM_NONE
Hack, used to update the button status.
Definition viewport_type.h:83
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition viewport_type.h:82
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:73
GetMainWindow
Window * GetMainWindow()
Get the main window, i.e.
Definition window.cpp:1180
CloseNonVitalWindows
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition window.cpp:3336
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2096
DeleteAllMessages
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition window.cpp:3368
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:3294
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition window.cpp:3526
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:3355
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WindowDefaultFlag::NoClose
@ NoClose
This window can't be interactively closed.
WindowFlag::WhiteBorder
@ WhiteBorder
Window white border counter bit mask.
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:143
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
EventState
State of handling an event.
Definition window_type.h:780
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition window_type.h:781
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:782
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition window_type.h:56
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition window_type.h:63
zoom_func.h
Functions related to zooming.
ScaleByZoom
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
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition zoom_func.h:87
ZoomLevel::Viewport
@ Viewport
Default zoom level for viewports.