OpenTTD Source  12.2
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 "guitimer_func.h"
34 #include "error.h"
35 #include "news_gui.h"
36 
37 #include "saveload/saveload.h"
38 
39 #include "widgets/main_widget.h"
40 
41 #include "network/network.h"
42 #include "network/network_func.h"
43 #include "network/network_gui.h"
44 #include "network/network_base.h"
45 
46 #include "table/sprites.h"
47 #include "table/strings.h"
48 
49 #include "safeguards.h"
50 
61 bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
62 {
63  if (w->IsWidgetDisabled(widget)) return false;
64 
66  w->SetDirty();
67 
68  if (w->IsWidgetLowered(widget)) {
70  return false;
71  }
72 
73  SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
74  w->LowerWidget(widget);
75  return true;
76 }
77 
78 
79 void CcPlaySound_EXPLOSION(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
80 {
81  if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
82 }
83 
92 {
93  Viewport *vp;
94 
95  assert(w != nullptr);
96  vp = w->viewport;
97 
98  switch (how) {
99  case ZOOM_NONE:
100  /* On initialisation of the viewport we don't do anything. */
101  break;
102 
103  case ZOOM_IN:
104  if (vp->zoom <= _settings_client.gui.zoom_min) return false;
105  vp->zoom = (ZoomLevel)((int)vp->zoom - 1);
106  vp->virtual_width >>= 1;
107  vp->virtual_height >>= 1;
108 
109  w->viewport->scrollpos_x += vp->virtual_width >> 1;
110  w->viewport->scrollpos_y += vp->virtual_height >> 1;
114  break;
115  case ZOOM_OUT:
116  if (vp->zoom >= _settings_client.gui.zoom_max) return false;
117  vp->zoom = (ZoomLevel)((int)vp->zoom + 1);
118 
119  w->viewport->scrollpos_x -= vp->virtual_width >> 1;
120  w->viewport->scrollpos_y -= vp->virtual_height >> 1;
123 
124  vp->virtual_width <<= 1;
125  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 const struct 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_CENTER,
188  GHK_CENTER_ZOOM,
189  GHK_RESET_OBJECT_TO_PLACE,
190  GHK_DELETE_WINDOWS,
191  GHK_DELETE_NONVITAL_WINDOWS,
192  GHK_DELETE_ALL_MESSAGES,
193  GHK_REFRESH_SCREEN,
194  GHK_CRASH,
195  GHK_MONEY,
196  GHK_UPDATE_COORDS,
197  GHK_TOGGLE_TRANSPARENCY,
198  GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
199  GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
200  GHK_TRANSPARANCY,
201  GHK_CHAT,
202  GHK_CHAT_ALL,
203  GHK_CHAT_COMPANY,
204  GHK_CHAT_SERVER,
205  GHK_CLOSE_NEWS,
206  GHK_CLOSE_ERROR,
207 };
208 
210 {
211  GUITimer refresh;
212 
213  /* Refresh times in milliseconds */
214  static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
215  static const uint LINKGRAPH_DELAY = 450;
216 
217  MainWindow(WindowDesc *desc) : Window(desc)
218  {
219  this->InitNested(0);
220  CLRBITS(this->flags, WF_WHITE_BORDER);
221  ResizeWindow(this, _screen.width, _screen.height);
222 
223  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
224  nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
225 
226  this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 3);
227  this->refresh.SetInterval(LINKGRAPH_DELAY);
228  }
229 
230  void OnRealtimeTick(uint delta_ms) override
231  {
232  if (!this->refresh.Elapsed(delta_ms)) return;
233 
234  this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
235 
236  if (this->viewport->overlay->GetCargoMask() == 0 ||
237  this->viewport->overlay->GetCompanyMask() == 0) {
238  return;
239  }
240 
241  this->viewport->overlay->SetDirty();
242  this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
243  }
244 
245  void OnPaint() override
246  {
247  this->DrawWidgets();
248  if (_game_mode == GM_MENU) {
249  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};
250  static const uint LETTER_SPACING = 10;
251  int name_width = (lengthof(title_sprites) - 1) * LETTER_SPACING;
252 
253  for (uint i = 0; i < lengthof(title_sprites); i++) {
254  name_width += GetSpriteSize(title_sprites[i]).width;
255  }
256  int off_x = (this->width - name_width) / 2;
257 
258  for (uint i = 0; i < lengthof(title_sprites); i++) {
259  DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
260  off_x += GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
261  }
262  }
263  }
264 
265  EventState OnHotkey(int hotkey) override
266  {
267  if (hotkey == GHK_QUIT) {
268  HandleExitGameRequest();
269  return ES_HANDLED;
270  }
271 
272  /* Disable all key shortcuts, except quit shortcuts when
273  * generating the world, otherwise they create threading
274  * problem during the generating, resulting in random
275  * assertions that are hard to trigger and debug */
276  if (HasModalProgress()) return ES_NOT_HANDLED;
277 
278  switch (hotkey) {
279  case GHK_ABANDON:
280  /* No point returning from the main menu to itself */
281  if (_game_mode == GM_MENU) return ES_HANDLED;
283  DoExitSave();
285  } else {
286  AskExitToGameMenu();
287  }
288  return ES_HANDLED;
289 
290  case GHK_CONSOLE:
291  IConsoleSwitch();
292  return ES_HANDLED;
293 
294  case GHK_BOUNDING_BOXES:
296  return ES_HANDLED;
297 
298  case GHK_DIRTY_BLOCKS:
300  return ES_HANDLED;
301  }
302 
303  if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
304 
305  switch (hotkey) {
306  case GHK_CENTER:
307  case GHK_CENTER_ZOOM: {
308  Point pt = GetTileBelowCursor();
309  if (pt.x != -1) {
310  bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
311  if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
312  ScrollMainWindowTo(pt.x, pt.y, -1, instant);
313  }
314  break;
315  }
316 
317  case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
318  case GHK_DELETE_WINDOWS: CloseNonVitalWindows(); break;
319  case GHK_DELETE_NONVITAL_WINDOWS: CloseAllNonVitalWindows(); break;
320  case GHK_DELETE_ALL_MESSAGES: DeleteAllMessages(); break;
321  case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
322 
323  case GHK_CRASH: // Crash the game
324  *(volatile byte *)nullptr = 0;
325  break;
326 
327  case GHK_MONEY: // Gimme money
328  /* You can only cheat for money in singleplayer mode. */
329  if (!_networking) DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
330  break;
331 
332  case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
334  break;
335 
336  case GHK_TOGGLE_TRANSPARENCY:
337  case GHK_TOGGLE_TRANSPARENCY + 1:
338  case GHK_TOGGLE_TRANSPARENCY + 2:
339  case GHK_TOGGLE_TRANSPARENCY + 3:
340  case GHK_TOGGLE_TRANSPARENCY + 4:
341  case GHK_TOGGLE_TRANSPARENCY + 5:
342  case GHK_TOGGLE_TRANSPARENCY + 6:
343  case GHK_TOGGLE_TRANSPARENCY + 7:
344  case GHK_TOGGLE_TRANSPARENCY + 8:
345  /* Transparency toggle hot keys */
346  ToggleTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_TRANSPARENCY));
348  break;
349 
350  case GHK_TOGGLE_INVISIBILITY:
351  case GHK_TOGGLE_INVISIBILITY + 1:
352  case GHK_TOGGLE_INVISIBILITY + 2:
353  case GHK_TOGGLE_INVISIBILITY + 3:
354  case GHK_TOGGLE_INVISIBILITY + 4:
355  case GHK_TOGGLE_INVISIBILITY + 5:
356  case GHK_TOGGLE_INVISIBILITY + 6:
357  case GHK_TOGGLE_INVISIBILITY + 7:
358  /* Invisibility toggle hot keys */
359  ToggleInvisibilityWithTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_INVISIBILITY));
361  break;
362 
363  case GHK_TRANSPARENCY_TOOLBAR:
365  break;
366 
367  case GHK_TRANSPARANCY:
369  break;
370 
371  case GHK_CHAT: // smart chat; send to team if any, otherwise to all
372  if (_networking) {
374  if (cio == nullptr) break;
375 
377  }
378  break;
379 
380  case GHK_CHAT_ALL: // send text message to all clients
382  break;
383 
384  case GHK_CHAT_COMPANY: // send text to all team mates
385  if (_networking) {
387  if (cio == nullptr) break;
388 
390  }
391  break;
392 
393  case GHK_CHAT_SERVER: // send text to the server
394  if (_networking && !_network_server) {
396  }
397  break;
398 
399  case GHK_CLOSE_NEWS: // close active news window
400  if (!HideActiveNewsMessage()) return ES_NOT_HANDLED;
401  break;
402 
403  case GHK_CLOSE_ERROR: // close active error window
404  if (!HideActiveErrorMessage()) return ES_NOT_HANDLED;
405  break;
406 
407  default: return ES_NOT_HANDLED;
408  }
409  return ES_HANDLED;
410  }
411 
412  void OnScroll(Point delta) override
413  {
414  this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
415  this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
418  this->refresh.SetInterval(LINKGRAPH_DELAY);
419  }
420 
421  void OnMouseWheel(int wheel) override
422  {
424  ZoomInOrOutToCursorWindow(wheel < 0, this);
425  }
426  }
427 
428  void OnResize() override
429  {
430  if (this->viewport != nullptr) {
431  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
432  nvp->UpdateViewportCoordinates(this);
433  this->refresh.SetInterval(LINKGRAPH_DELAY);
434  }
435  }
436 
442  void OnInvalidateData(int data = 0, bool gui_scope = true) override
443  {
444  if (!gui_scope) return;
445  /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
446  InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
447  }
448 
449  static HotkeyList hotkeys;
450 };
451 
452 const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
453 const uint16 _ghk_abandon_keys[] = {'W' | WKC_CTRL, 'W' | WKC_META, 0};
454 const uint16 _ghk_chat_keys[] = {WKC_RETURN, 'T', 0};
455 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T', 0};
456 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T', 0};
457 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T', 0};
458 
459 static Hotkey global_hotkeys[] = {
460  Hotkey(_ghk_quit_keys, "quit", GHK_QUIT),
461  Hotkey(_ghk_abandon_keys, "abandon", GHK_ABANDON),
462  Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
463  Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
464  Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS),
465  Hotkey('C', "center", GHK_CENTER),
466  Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM),
467  Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
468  Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
469  Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
470  Hotkey(WKC_DELETE | WKC_CTRL, "delete_all_messages", GHK_DELETE_ALL_MESSAGES),
471  Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
472 #if defined(_DEBUG)
473  Hotkey('0' | WKC_ALT, "crash_game", GHK_CRASH),
474  Hotkey('1' | WKC_ALT, "money", GHK_MONEY),
475  Hotkey('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
476 #endif
477  Hotkey('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
478  Hotkey('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
479  Hotkey('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
480  Hotkey('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
481  Hotkey('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
482  Hotkey('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
483  Hotkey('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
484  Hotkey('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
485  Hotkey('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
486  Hotkey('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
487  Hotkey('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
488  Hotkey('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
489  Hotkey('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
490  Hotkey('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
491  Hotkey('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
492  Hotkey('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
493  Hotkey('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
494  Hotkey('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
495  Hotkey('X', "toggle_transparency", GHK_TRANSPARANCY),
496  Hotkey(_ghk_chat_keys, "chat", GHK_CHAT),
497  Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
498  Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
499  Hotkey(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER),
500  Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS),
501  Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR),
502  HOTKEY_LIST_END
503 };
504 HotkeyList MainWindow::hotkeys("global", global_hotkeys);
505 
506 static WindowDesc _main_window_desc(
507  WDP_MANUAL, nullptr, 0, 0,
509  0,
510  _nested_main_window_widgets, lengthof(_nested_main_window_widgets),
511  &MainWindow::hotkeys
512 );
513 
519 bool IsQuitKey(uint16 keycode)
520 {
521  int num = MainWindow::hotkeys.CheckMatch(keycode);
522  return num == GHK_QUIT;
523 }
524 
525 
526 void ShowSelectGameWindow();
527 
532 {
533  for (uint i = 0; i != 16; i++) {
534  const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, ST_RECOLOUR);
535 
536  assert(b);
537  memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
538  }
539 
540  new MainWindow(&_main_window_desc);
541 
542  /* XXX: these are not done */
543  switch (_game_mode) {
544  default: NOT_REACHED();
545  case GM_MENU:
546  ShowSelectGameWindow();
547  break;
548 
549  case GM_NORMAL:
550  case GM_EDITOR:
552  break;
553  }
554 }
555 
560 {
561  AllocateToolbar();
562 
563  /* Status bad only for normal games */
564  if (_game_mode == GM_EDITOR) return;
565 
566  ShowStatusBar();
567 }
568 
574 {
575  _cur_resolution.width = _screen.width;
576  _cur_resolution.height = _screen.height;
577  ScreenSizeChanged();
578  RelocateAllWindows(_screen.width, _screen.height);
580 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
MaxZoomInOut
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:44
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
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:3234
sound_func.h
MainWindow::OnScroll
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition: main_gui.cpp:412
MainWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: main_gui.cpp:230
ResetRestoreAllTransparency
static void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Definition: transparency.h:113
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:40
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:2399
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition: viewport_type.h:82
command_func.h
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:3350
toolbar_gui.h
guitimer_func.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:137
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:615
Viewport::width
int width
Screen width of the viewport.
Definition: viewport_type.h:25
currency.h
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:321
_network_server
bool _network_server
network-server is active
Definition: network.cpp:58
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:1313
ViewportData::scrollpos_y
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:261
map_func.h
ZOOM_NONE
@ ZOOM_NONE
Hack, used to update the button status.
Definition: viewport_type.h:83
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
ToggleInvisibilityWithTransparency
static void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition: transparency.h:91
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:91
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
saveload.h
zoom_func.h
LinkGraphOverlay::GetCargoMask
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
Definition: linkgraph_gui.h:65
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:91
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
network_gui.h
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:62
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:132
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1799
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:971
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
textbuf_gui.h
network_base.h
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
WindowDesc
High level window description.
Definition: window_gui.h:168
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:113
window_gui.h
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition: viewport_type.h:81
GUISettings::scrollwheel_scrolling
uint8 scrollwheel_scrolling
scrolling using the scroll wheel?
Definition: settings_type.h:143
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition: error_gui.cpp:435
LinkGraphOverlay
Handles drawing of links into some window.
Definition: linkgraph_gui.h:37
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
GUITimer
Definition: guitimer_func.h:13
ShowVitalWindows
void ShowVitalWindows()
Show the vital in-game windows.
Definition: main_gui.cpp:559
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:2076
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:597
CursorID
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1789
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
CloseNonVitalWindows
void CloseNonVitalWindows()
Try to close a non-vital window.
Definition: window.cpp:3276
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:242
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
MainWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: main_gui.cpp:245
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
AllocateToolbar
void AllocateToolbar()
Allocate the toolbar.
Definition: toolbar_gui.cpp:2577
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3459
linkgraph_gui.h
safeguards.h
HandlePlacePushButton
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:61
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:305
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:49
GameSizeChanged
void GameSizeChanged()
Size of the application screen changed.
Definition: main_gui.cpp:573
ToggleDirtyBlocks
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
Definition: toolbar_gui.cpp:1085
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:57
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:1042
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:1879
error.h
ViewportData::dest_scrollpos_y
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:263
WID_M_VIEWPORT
@ WID_M_VIEWPORT
Main window viewport.
Definition: main_widget.h:15
stdafx.h
ZOOM_LVL_VIEWPORT
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
Definition: zoom_type.h:35
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
ToggleBoundingBoxes
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
Definition: toolbar_gui.cpp:1068
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:3174
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:63
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:977
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:131
MainWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: main_gui.cpp:265
spritecache.h
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:47
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:210
ViewportData::scrollpos_x
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:260
PALETTE_RECOLOUR_START
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition: sprites.h:1569
TransparencyOption
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition: transparency.h:22
strings_func.h
ScaleByZoom
static 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
IsQuitKey
bool IsQuitKey(uint16 keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition: main_gui.cpp:519
DeleteAllMessages
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition: window.cpp:3315
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
ShowTransparencyToolbar
void ShowTransparencyToolbar()
Show the transparency toolbar.
Definition: transparency_gui.cpp:159
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2067
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:217
transparency.h
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:487
EventState
EventState
State of handling an event.
Definition: window_type.h:717
transparency_gui.h
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1161
news_gui.h
progress.h
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:306
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:43
company_func.h
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:32
HotkeyList::CheckMatch
int CheckMatch(uint16 keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:325
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
ShowNetworkChatQueryWindow
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Definition: network_chat_gui.cpp:534
HighLightStyle
HighLightStyle
Highlighting draw styles.
Definition: tilehighlight_type.h:19
network.h
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:259
LinkGraphOverlay::SetDirty
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
Definition: linkgraph_gui.h:62
MainWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: main_gui.cpp:442
window_func.h
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:211
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
ViewportData::dest_scrollpos_x
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:262
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1751
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
ToggleTransparency
static void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition: transparency.h:69
DESTTYPE_BROADCAST
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
Definition: network_type.h:90
CMD_MONEY_CHEAT
@ CMD_MONEY_CHEAT
do the money cheat
Definition: command_type.h:276
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition: news_gui.cpp:1032
console_gui.h
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:92
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:3299
Window
Data structure for an opened window.
Definition: window_gui.h:279
ST_RECOLOUR
@ ST_RECOLOUR
Recolour sprite.
Definition: gfx_type.h:305
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:3375
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
HasModalProgress
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:17
MainWindow
Definition: main_gui.cpp:209
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition: console_gui.cpp:438
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
Window::IsWidgetDisabled
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:415
main_widget.h
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:468
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:50
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:428
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3423
ShowStatusBar
void ShowStatusBar()
Show our status bar.
Definition: statusbar_gui.cpp:274
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:25
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:80
MainWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition: main_gui.cpp:421
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:594
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition: main_gui.cpp:531
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:22
hotkeys.h
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2069