OpenTTD Source  20241108-master-g80f628063a
main_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "currency.h"
12 #include "spritecache.h"
13 #include "window_gui.h"
14 #include "window_func.h"
15 #include "textbuf_gui.h"
16 #include "viewport_func.h"
17 #include "command_func.h"
18 #include "console_gui.h"
19 #include "progress.h"
20 #include "transparency_gui.h"
21 #include "map_func.h"
22 #include "sound_func.h"
23 #include "transparency.h"
24 #include "strings_func.h"
25 #include "zoom_func.h"
26 #include "company_base.h"
27 #include "company_func.h"
28 #include "toolbar_gui.h"
29 #include "statusbar_gui.h"
31 #include "tilehighlight_func.h"
32 #include "hotkeys.h"
33 #include "error.h"
34 #include "news_gui.h"
35 #include "misc_cmd.h"
36 #include "timer/timer.h"
37 #include "timer/timer_window.h"
38 
39 #include "saveload/saveload.h"
40 
41 #include "widgets/main_widget.h"
42 
43 #include "network/network.h"
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 
64 {
65  if (w->IsWidgetDisabled(widget)) return false;
66 
68  w->SetDirty();
69 
70  if (w->IsWidgetLowered(widget)) {
72  return false;
73  }
74 
75  SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
76  w->LowerWidget(widget);
77  return true;
78 }
79 
80 
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 
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;
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;
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
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 
138 void 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 
151  }
152  }
153 }
154 
155 void FixTitleGameZoom(int zoom_adjust)
156 {
157  if (_game_mode != GM_MENU) return;
158 
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 
177 static constexpr NWidgetPart _nested_main_window_widgets[] = {
178  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1),
179 };
180 
181 enum {
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 
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);
220 
221  this->viewport->overlay = std::make_shared<LinkGraphOverlay>(this, WID_M_VIEWPORT, 0, 0, 2);
222  this->refresh_timeout.Reset();
223  }
224 
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) {
240  }};
241 
249  TimeoutTimer<TimerWindow> refresh_timeout = {std::chrono::milliseconds(450), [this]() {
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;
291  DoExitSave();
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:
304  return ES_HANDLED;
305 
306  case GHK_DIRTY_BLOCKS:
308  return ES_HANDLED;
309 
310  case GHK_WIDGET_OUTLINES:
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. */
342  break;
343 
344  case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
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));
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));
373  break;
374 
375  case GHK_TRANSPARENCY_TOOLBAR:
377  break;
378 
379  case GHK_TRANSPARANCY:
381  break;
382 
383  case GHK_CHAT: // smart chat; send to team if any, otherwise to all
384  if (_networking) {
386  if (cio == nullptr) break;
387 
389  }
390  break;
391 
392  case GHK_CHAT_ALL: // send text message to all clients
394  break;
395 
396  case GHK_CHAT_COMPANY: // send text to all team mates
397  if (_networking) {
399  if (cio == nullptr) break;
400 
402  }
403  break;
404 
405  case GHK_CHAT_SERVER: // send text to the server
406  if (_networking && !_network_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);
430  this->refresh_timeout.Reset();
431  }
432 
433  void OnMouseWheel(int wheel) override
434  {
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 
521 static WindowDesc _main_window_desc(
522  WDP_MANUAL, nullptr, 0, 0,
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 
541 void ShowSelectGameWindow();
542 
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:
568  break;
569  }
570 }
571 
576 {
577  AllocateToolbar();
578 
579  /* Status bad only for normal games */
580  if (_game_mode == GM_EDITOR) return;
581 
582  ShowStatusBar();
583 }
584 
590 {
591  _cur_resolution.width = _screen.width;
592  _cur_resolution.height = _screen.height;
593  ScreenSizeChanged();
594  RelocateAllWindows(_screen.width, _screen.height);
596 }
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:223
#define CLRBITS(x, y)
Clears several bits in a variable.
Common return value for all commands.
Definition: command_type.h:23
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
Nested widget to display a viewport in a window.
Definition: widget_type.h:680
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2297
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2288
void Reset()
Reset the timer, so it will fire again after the timeout.
Definition: timer.h:140
Functions related to commands.
Commands
List of commands.
Definition: command_type.h:187
Definition of stuff that is very close to a company, like the company struct itself.
Functions related to companies.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
GUI related functions in the console.
Functions to handle different currencies.
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:26
Functions related to errors.
bool HideActiveErrorMessage()
Close active error message window.
Definition: error_gui.cpp:439
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:922
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
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:49
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:61
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
@ Recolour
Recolour sprite.
uint32_t CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:20
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1126
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:940
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1529
Hotkey related functions.
Declaration of linkgraph overlay GUI.
void ShowVitalWindows()
Show the vital in-game windows.
Definition: main_gui.cpp:575
void GameSizeChanged()
Size of the application screen changed.
Definition: main_gui.cpp:589
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition: main_gui.cpp:546
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition: main_gui.cpp:534
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:93
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:63
Types related to the main widgets.
@ WID_M_VIEWPORT
Main window viewport.
Definition: main_widget.h:15
Functions related to maps.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:373
Miscellaneous command definitions.
bool _networking
are we in networking mode?
Definition: network.cpp:65
bool _network_server
network-server is active
Definition: network.cpp:66
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:70
Basic functions/variables used all over the place.
Base core network types and some helper functions to access them.
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Network functions used by other parts of OpenTTD.
GUIs related to networking.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:82
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:81
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
Definition: network_type.h:80
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:51
bool HideActiveNewsMessage()
Close active news message window.
Definition: news_gui.cpp:1030
GUI functions related to the news.
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:33
void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_index)
Set colour gradient palette index.
Definition: palette.cpp:325
Functions related to modal progress.
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:17
A number of safeguards to prevent using unsafe methods.
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:3201
Functions/types related to saving and loading games.
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:56
@ SWS_OFF
Scroll wheel has no effect.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition: sound_type.h:58
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition: sound_type.h:55
Functions to cache sprites in memory.
This file contains all sprite-related enums and defines.
void ShowStatusBar()
Show our status bar.
Functions, definitions and such used only by the GUI.
Definition of base types and functions in a cross-platform compatible way.
Functions related to OTTD's strings.
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
ZoomLevel zoom_min
minimum zoom out level
ZoomLevel zoom_max
maximum zoom out level
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
List of hotkeys for a window.
Definition: hotkeys.h:37
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:309
All data for a single hotkey.
Definition: hotkeys.h:21
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: main_gui.cpp:273
TimeoutTimer< TimerWindow > refresh_timeout
Sometimes when something happened, force an update to the link-graph a bit sooner.
Definition: main_gui.cpp:249
IntervalTimer< TimerWindow > refresh_interval
Refresh the link-graph overlay on a regular interval.
Definition: main_gui.cpp:238
void OnResize() override
Called after the window got resized.
Definition: main_gui.cpp:447
void OnPaint() override
The window must be repainted.
Definition: main_gui.cpp:253
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:467
void RefreshLinkGraph()
Refresh the link-graph overlay.
Definition: main_gui.cpp:226
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1075
Container for all information known about a client.
Definition: network_base.h:24
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:118
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:28
Coordinates of a point in 2D.
bool click_beep
Beep on a random selection of buttons.
bool confirm
Play sound effect on successful constructions or other actions.
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
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:255
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
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:253
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:254
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
int width
Screen width of the viewport.
Definition: viewport_type.h:25
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:29
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:28
int virtual_width
width << zoom
Definition: viewport_type.h:30
int height
Screen height of the viewport.
Definition: viewport_type.h:26
int virtual_height
height << zoom
Definition: viewport_type.h:31
High level window description.
Definition: window_gui.h:159
Data structure for an opened window.
Definition: window_gui.h:273
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3151
WindowClass window_class
Window class.
Definition: window_gui.h:301
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:318
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:497
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:416
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1756
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition: window_gui.h:466
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1746
WindowFlags flags
Window flags.
Definition: window_gui.h:300
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:311
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:302
Stuff related to the text buffer GUI.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3498
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
Highlighting draw styles.
Definition of Interval and OneShot timers.
Definition of the Window system.
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
void AllocateToolbar()
Allocate the toolbar.
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
void ToggleWidgetOutlines()
Toggle drawing of widget outlihes.
Stuff related to the (main) toolbar.
Functions related to transparency.
void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Definition: transparency.h:113
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition: transparency.h:69
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition: transparency.h:22
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition: transparency.h:91
void ShowTransparencyToolbar()
Show the transparency toolbar.
GUI functions related to transparency.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:54
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
Functions related to (drawing on) viewports.
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:46
ZoomStateChange
Directions of zooming.
Definition: viewport_type.h:76
@ ZOOM_IN
Zoom in (get more detailed view).
Definition: viewport_type.h:77
@ ZOOM_NONE
Hack, used to update the button status.
Definition: viewport_type.h:79
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition: viewport_type.h:78
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:81
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition: window.cpp:3253
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition: window.cpp:2022
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition: window.cpp:3285
Window * GetMainWindow()
Get the main window, i.e.
Definition: window.cpp:1127
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:3211
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3443
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition: window.cpp:3272
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:236
@ WDF_NO_CLOSE
This window can't be interactively closed.
Definition: window_gui.h:206
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:146
int WidgetID
Widget ID.
Definition: window_type.h:18
EventState
State of handling an event.
Definition: window_type.h:743
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:744
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:745
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:51
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:58
Functions related to zooming.
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
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:16
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
Definition: zoom_type.h:28