OpenTTD Source  1.11.0-beta2
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()
156 {
157  if (_game_mode != GM_MENU) return;
158 
160  vp->zoom = _gui_zoom;
161  vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
162  vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
163 }
164 
165 static const struct NWidgetPart _nested_main_window_widgets[] = {
166  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1),
167 };
168 
169 enum {
170  GHK_QUIT,
171  GHK_ABANDON,
172  GHK_CONSOLE,
173  GHK_BOUNDING_BOXES,
174  GHK_DIRTY_BLOCKS,
175  GHK_CENTER,
176  GHK_CENTER_ZOOM,
177  GHK_RESET_OBJECT_TO_PLACE,
178  GHK_DELETE_WINDOWS,
179  GHK_DELETE_NONVITAL_WINDOWS,
180  GHK_DELETE_ALL_MESSAGES,
181  GHK_REFRESH_SCREEN,
182  GHK_CRASH,
183  GHK_MONEY,
184  GHK_UPDATE_COORDS,
185  GHK_TOGGLE_TRANSPARENCY,
186  GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
187  GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
188  GHK_TRANSPARANCY,
189  GHK_CHAT,
190  GHK_CHAT_ALL,
191  GHK_CHAT_COMPANY,
192  GHK_CHAT_SERVER,
193  GHK_CLOSE_NEWS,
194  GHK_CLOSE_ERROR,
195 };
196 
198 {
199  GUITimer refresh;
200 
201  /* Refresh times in milliseconds */
202  static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
203  static const uint LINKGRAPH_DELAY = 450;
204 
205  MainWindow(WindowDesc *desc) : Window(desc)
206  {
207  this->InitNested(0);
208  CLRBITS(this->flags, WF_WHITE_BORDER);
209  ResizeWindow(this, _screen.width, _screen.height);
210 
211  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
212  nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
213 
214  this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 3);
215  this->refresh.SetInterval(LINKGRAPH_DELAY);
216  }
217 
218  void OnRealtimeTick(uint delta_ms) override
219  {
220  if (!this->refresh.Elapsed(delta_ms)) return;
221 
222  this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
223 
224  if (this->viewport->overlay->GetCargoMask() == 0 ||
225  this->viewport->overlay->GetCompanyMask() == 0) {
226  return;
227  }
228 
229  this->viewport->overlay->SetDirty();
230  this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
231  }
232 
233  void OnPaint() override
234  {
235  this->DrawWidgets();
236  if (_game_mode == GM_MENU) {
237  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};
238  static const uint LETTER_SPACING = 10;
239  int name_width = (lengthof(title_sprites) - 1) * LETTER_SPACING;
240 
241  for (uint i = 0; i < lengthof(title_sprites); i++) {
242  name_width += GetSpriteSize(title_sprites[i]).width;
243  }
244  int off_x = (this->width - name_width) / 2;
245 
246  for (uint i = 0; i < lengthof(title_sprites); i++) {
247  DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
248  off_x += GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
249  }
250  }
251  }
252 
253  EventState OnHotkey(int hotkey) override
254  {
255  if (hotkey == GHK_QUIT) {
256  HandleExitGameRequest();
257  return ES_HANDLED;
258  }
259 
260  /* Disable all key shortcuts, except quit shortcuts when
261  * generating the world, otherwise they create threading
262  * problem during the generating, resulting in random
263  * assertions that are hard to trigger and debug */
264  if (HasModalProgress()) return ES_NOT_HANDLED;
265 
266  switch (hotkey) {
267  case GHK_ABANDON:
268  /* No point returning from the main menu to itself */
269  if (_game_mode == GM_MENU) return ES_HANDLED;
271  DoExitSave();
273  } else {
274  AskExitToGameMenu();
275  }
276  return ES_HANDLED;
277 
278  case GHK_CONSOLE:
279  IConsoleSwitch();
280  return ES_HANDLED;
281 
282  case GHK_BOUNDING_BOXES:
284  return ES_HANDLED;
285 
286  case GHK_DIRTY_BLOCKS:
288  return ES_HANDLED;
289  }
290 
291  if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
292 
293  switch (hotkey) {
294  case GHK_CENTER:
295  case GHK_CENTER_ZOOM: {
296  Point pt = GetTileBelowCursor();
297  if (pt.x != -1) {
298  bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
299  if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
300  ScrollMainWindowTo(pt.x, pt.y, -1, instant);
301  }
302  break;
303  }
304 
305  case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
306  case GHK_DELETE_WINDOWS: DeleteNonVitalWindows(); break;
307  case GHK_DELETE_NONVITAL_WINDOWS: DeleteAllNonVitalWindows(); break;
308  case GHK_DELETE_ALL_MESSAGES: DeleteAllMessages(); break;
309  case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
310 
311  case GHK_CRASH: // Crash the game
312  *(volatile byte *)0 = 0;
313  break;
314 
315  case GHK_MONEY: // Gimme money
316  /* You can only cheat for money in singleplayer mode. */
317  if (!_networking) DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
318  break;
319 
320  case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
322  break;
323 
324  case GHK_TOGGLE_TRANSPARENCY:
325  case GHK_TOGGLE_TRANSPARENCY + 1:
326  case GHK_TOGGLE_TRANSPARENCY + 2:
327  case GHK_TOGGLE_TRANSPARENCY + 3:
328  case GHK_TOGGLE_TRANSPARENCY + 4:
329  case GHK_TOGGLE_TRANSPARENCY + 5:
330  case GHK_TOGGLE_TRANSPARENCY + 6:
331  case GHK_TOGGLE_TRANSPARENCY + 7:
332  case GHK_TOGGLE_TRANSPARENCY + 8:
333  /* Transparency toggle hot keys */
334  ToggleTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_TRANSPARENCY));
336  break;
337 
338  case GHK_TOGGLE_INVISIBILITY:
339  case GHK_TOGGLE_INVISIBILITY + 1:
340  case GHK_TOGGLE_INVISIBILITY + 2:
341  case GHK_TOGGLE_INVISIBILITY + 3:
342  case GHK_TOGGLE_INVISIBILITY + 4:
343  case GHK_TOGGLE_INVISIBILITY + 5:
344  case GHK_TOGGLE_INVISIBILITY + 6:
345  case GHK_TOGGLE_INVISIBILITY + 7:
346  /* Invisibility toggle hot keys */
347  ToggleInvisibilityWithTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_INVISIBILITY));
349  break;
350 
351  case GHK_TRANSPARENCY_TOOLBAR:
353  break;
354 
355  case GHK_TRANSPARANCY:
357  break;
358 
359  case GHK_CHAT: // smart chat; send to team if any, otherwise to all
360  if (_networking) {
362  if (cio == nullptr) break;
363 
365  }
366  break;
367 
368  case GHK_CHAT_ALL: // send text message to all clients
370  break;
371 
372  case GHK_CHAT_COMPANY: // send text to all team mates
373  if (_networking) {
375  if (cio == nullptr) break;
376 
378  }
379  break;
380 
381  case GHK_CHAT_SERVER: // send text to the server
382  if (_networking && !_network_server) {
384  }
385  break;
386 
387  case GHK_CLOSE_NEWS: // close active news window
388  if (!HideActiveNewsMessage()) return ES_NOT_HANDLED;
389  break;
390 
391  case GHK_CLOSE_ERROR: // close active error window
392  if (!HideActiveErrorMessage()) return ES_NOT_HANDLED;
393  break;
394 
395  default: return ES_NOT_HANDLED;
396  }
397  return ES_HANDLED;
398  }
399 
400  void OnScroll(Point delta) override
401  {
402  this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
403  this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
406  this->refresh.SetInterval(LINKGRAPH_DELAY);
407  }
408 
409  void OnMouseWheel(int wheel) override
410  {
412  ZoomInOrOutToCursorWindow(wheel < 0, this);
413  }
414  }
415 
416  void OnResize() override
417  {
418  if (this->viewport != nullptr) {
419  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
420  nvp->UpdateViewportCoordinates(this);
421  this->refresh.SetInterval(LINKGRAPH_DELAY);
422  }
423  }
424 
430  void OnInvalidateData(int data = 0, bool gui_scope = true) override
431  {
432  if (!gui_scope) return;
433  /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
434  InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
435  }
436 
437  static HotkeyList hotkeys;
438 };
439 
440 const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
441 const uint16 _ghk_abandon_keys[] = {'W' | WKC_CTRL, 'W' | WKC_META, 0};
442 const uint16 _ghk_chat_keys[] = {WKC_RETURN, 'T', 0};
443 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T', 0};
444 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T', 0};
445 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T', 0};
446 
447 static Hotkey global_hotkeys[] = {
448  Hotkey(_ghk_quit_keys, "quit", GHK_QUIT),
449  Hotkey(_ghk_abandon_keys, "abandon", GHK_ABANDON),
450  Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
451  Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
452  Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS),
453  Hotkey('C', "center", GHK_CENTER),
454  Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM),
455  Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
456  Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
457  Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
458  Hotkey(WKC_DELETE | WKC_CTRL, "delete_all_messages", GHK_DELETE_ALL_MESSAGES),
459  Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
460 #if defined(_DEBUG)
461  Hotkey('0' | WKC_ALT, "crash_game", GHK_CRASH),
462  Hotkey('1' | WKC_ALT, "money", GHK_MONEY),
463  Hotkey('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
464 #endif
465  Hotkey('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
466  Hotkey('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
467  Hotkey('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
468  Hotkey('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
469  Hotkey('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
470  Hotkey('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
471  Hotkey('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
472  Hotkey('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
473  Hotkey('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
474  Hotkey('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
475  Hotkey('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
476  Hotkey('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
477  Hotkey('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
478  Hotkey('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
479  Hotkey('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
480  Hotkey('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
481  Hotkey('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
482  Hotkey('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
483  Hotkey('X', "toggle_transparency", GHK_TRANSPARANCY),
484  Hotkey(_ghk_chat_keys, "chat", GHK_CHAT),
485  Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
486  Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
487  Hotkey(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER),
488  Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS),
489  Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR),
490  HOTKEY_LIST_END
491 };
492 HotkeyList MainWindow::hotkeys("global", global_hotkeys);
493 
494 static WindowDesc _main_window_desc(
495  WDP_MANUAL, nullptr, 0, 0,
497  0,
498  _nested_main_window_widgets, lengthof(_nested_main_window_widgets),
499  &MainWindow::hotkeys
500 );
501 
507 bool IsQuitKey(uint16 keycode)
508 {
509  int num = MainWindow::hotkeys.CheckMatch(keycode);
510  return num == GHK_QUIT;
511 }
512 
513 
514 void ShowSelectGameWindow();
515 
520 {
521  for (uint i = 0; i != 16; i++) {
522  const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, ST_RECOLOUR);
523 
524  assert(b);
525  memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
526  }
527 
528  new MainWindow(&_main_window_desc);
529 
530  /* XXX: these are not done */
531  switch (_game_mode) {
532  default: NOT_REACHED();
533  case GM_MENU:
534  ShowSelectGameWindow();
535  break;
536 
537  case GM_NORMAL:
538  case GM_EDITOR:
540  break;
541  }
542 }
543 
548 {
549  AllocateToolbar();
550 
551  /* Status bad only for normal games */
552  if (_game_mode == GM_EDITOR) return;
553 
554  ShowStatusBar();
555 }
556 
562 {
563  _cur_resolution.width = _screen.width;
564  _cur_resolution.height = _screen.height;
565  ScreenSizeChanged();
566  RelocateAllWindows(_screen.width, _screen.height);
568 }
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:78
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:3321
sound_func.h
MainWindow::OnScroll
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition: main_gui.cpp:400
MainWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: main_gui.cpp:218
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:2397
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:2851
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:114
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:574
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:326
_network_server
bool _network_server
network-server is active
Definition: network.cpp:53
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 where he/she can chat to.
Definition: network_client.cpp:1303
ViewportData::scrollpos_y
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:259
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:929
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:83
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
network_gui.h
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:59
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:110
_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:52
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1871
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
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:166
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:119
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:120
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition: error_gui.cpp:424
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:547
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:1943
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:570
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:1861
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
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:240
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:984
MainWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: main_gui.cpp:233
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:2630
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3569
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:310
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:41
GameSizeChanged
void GameSizeChanged()
Size of the application screen changed.
Definition: main_gui.cpp:561
ToggleDirtyBlocks
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
Definition: toolbar_gui.cpp:1097
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:52
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:978
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:1869
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:261
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:312
ToggleBoundingBoxes
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
Definition: toolbar_gui.cpp:1080
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:3261
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:59
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:109
MainWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: main_gui.cpp:253
DeleteNonVitalWindows
void DeleteNonVitalWindows()
Try to delete a non-vital window.
Definition: window.cpp:3367
spritecache.h
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:46
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:187
ViewportData::scrollpos_x
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:258
PALETTE_RECOLOUR_START
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition: sprites.h:1563
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:507
DeleteAllMessages
void DeleteAllMessages()
Delete all messages and their corresponding window (if any).
Definition: window.cpp:3418
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
DeleteAllNonVitalWindows
void DeleteAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition: window.cpp:3396
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
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:1934
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:493
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:1149
news_gui.h
progress.h
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:311
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
company_func.h
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:31
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:553
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:257
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:430
window_func.h
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:188
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
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:260
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1619
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
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:82
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:1029
console_gui.h
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:84
Window
Data structure for an opened window.
Definition: window_gui.h:276
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:3373
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
HasModalProgress
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:21
MainWindow
Definition: main_gui.cpp:197
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition: console_gui.cpp:437
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:421
main_widget.h
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:474
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:51
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:416
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3421
ShowStatusBar
void ShowStatusBar()
Show our status bar.
Definition: statusbar_gui.cpp:270
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:23
network_func.h
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:23
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:409
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:567
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition: main_gui.cpp:519
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:2153