OpenTTD Source: src/main_gui.cpp Source File

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