OpenTTD Source  13.2.1
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 #include "misc_cmd.h"
37 
38 #include "saveload/saveload.h"
39 
40 #include "widgets/main_widget.h"
41 
42 #include "network/network.h"
43 #include "network/network_func.h"
44 #include "network/network_gui.h"
45 #include "network/network_base.h"
46 
47 #include "table/sprites.h"
48 #include "table/strings.h"
49 
50 #include "safeguards.h"
51 
62 bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
63 {
64  if (w->IsWidgetDisabled(widget)) return false;
65 
67  w->SetDirty();
68 
69  if (w->IsWidgetLowered(widget)) {
71  return false;
72  }
73 
74  SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
75  w->LowerWidget(widget);
76  return true;
77 }
78 
79 
80 void CcPlaySound_EXPLOSION(Commands cmd, const CommandCost &result, TileIndex tile)
81 {
82  if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
83 }
84 
93 {
94  Viewport *vp;
95 
96  assert(w != nullptr);
97  vp = w->viewport;
98 
99  switch (how) {
100  case ZOOM_NONE:
101  /* On initialisation of the viewport we don't do anything. */
102  break;
103 
104  case ZOOM_IN:
105  if (vp->zoom <= _settings_client.gui.zoom_min) return false;
106  vp->zoom = (ZoomLevel)((int)vp->zoom - 1);
107  vp->virtual_width >>= 1;
108  vp->virtual_height >>= 1;
109 
110  w->viewport->scrollpos_x += vp->virtual_width >> 1;
111  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;
128  break;
129  }
130  if (vp != nullptr) { // the vp can be null when how == ZOOM_NONE
132  vp->virtual_top = w->viewport->scrollpos_y;
133  }
134  /* Update the windows that have zoom-buttons to perhaps disable their buttons */
135  w->InvalidateData();
136  return true;
137 }
138 
139 void ZoomInOrOutToCursorWindow(bool in, Window *w)
140 {
141  assert(w != nullptr);
142 
143  if (_game_mode != GM_MENU) {
144  Viewport *vp = w->viewport;
145  if ((in && vp->zoom <= _settings_client.gui.zoom_min) || (!in && vp->zoom >= _settings_client.gui.zoom_max)) return;
146 
147  Point pt = GetTileZoomCenterWindow(in, w);
148  if (pt.x != -1) {
149  ScrollWindowTo(pt.x, pt.y, -1, w, true);
150 
152  }
153  }
154 }
155 
156 void FixTitleGameZoom(int zoom_adjust)
157 {
158  if (_game_mode != GM_MENU) return;
159 
161 
162  /* Adjust the zoom in/out.
163  * Can't simply add, since operator+ is not defined on the ZoomLevel type. */
164  vp->zoom = _gui_zoom;
165  while (zoom_adjust < 0 && vp->zoom != _settings_client.gui.zoom_min) {
166  vp->zoom--;
167  zoom_adjust++;
168  }
169  while (zoom_adjust > 0 && vp->zoom != _settings_client.gui.zoom_max) {
170  vp->zoom++;
171  zoom_adjust--;
172  }
173 
174  vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
175  vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
176 }
177 
178 static const struct NWidgetPart _nested_main_window_widgets[] = {
179  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1),
180 };
181 
182 enum {
183  GHK_QUIT,
184  GHK_ABANDON,
185  GHK_CONSOLE,
186  GHK_BOUNDING_BOXES,
187  GHK_DIRTY_BLOCKS,
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  GUITimer refresh;
213 
214  /* Refresh times in milliseconds */
215  static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
216  static const uint LINKGRAPH_DELAY = 450;
217 
218  MainWindow(WindowDesc *desc) : Window(desc)
219  {
220  this->InitNested(0);
221  CLRBITS(this->flags, WF_WHITE_BORDER);
222  ResizeWindow(this, _screen.width, _screen.height);
223 
224  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
226 
227  this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 2);
228  this->refresh.SetInterval(LINKGRAPH_DELAY);
229  }
230 
231  void OnRealtimeTick(uint delta_ms) override
232  {
233  if (!this->refresh.Elapsed(delta_ms)) return;
234 
235  this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
236 
237  if (this->viewport->overlay->GetCargoMask() == 0 ||
238  this->viewport->overlay->GetCompanyMask() == 0) {
239  return;
240  }
241 
242  this->viewport->overlay->SetDirty();
243  this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
244  }
245 
246  void OnPaint() override
247  {
248  this->DrawWidgets();
249  if (_game_mode == GM_MENU) {
250  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};
251  uint letter_spacing = ScaleGUITrad(10);
252  int name_width = (lengthof(title_sprites) - 1) * letter_spacing;
253 
254  for (uint i = 0; i < lengthof(title_sprites); i++) {
255  name_width += GetSpriteSize(title_sprites[i]).width;
256  }
257  int off_x = (this->width - name_width) / 2;
258 
259  for (uint i = 0; i < lengthof(title_sprites); i++) {
260  DrawSprite(title_sprites[i], PAL_NONE, off_x, ScaleGUITrad(50));
261  off_x += GetSpriteSize(title_sprites[i]).width + letter_spacing;
262  }
263  }
264  }
265 
266  EventState OnHotkey(int hotkey) override
267  {
268  if (hotkey == GHK_QUIT) {
269  HandleExitGameRequest();
270  return ES_HANDLED;
271  }
272 
273  /* Disable all key shortcuts, except quit shortcuts when
274  * generating the world, otherwise they create threading
275  * problem during the generating, resulting in random
276  * assertions that are hard to trigger and debug */
277  if (HasModalProgress()) return ES_NOT_HANDLED;
278 
279  switch (hotkey) {
280  case GHK_ABANDON:
281  /* No point returning from the main menu to itself */
282  if (_game_mode == GM_MENU) return ES_HANDLED;
284  DoExitSave();
286  } else {
287  AskExitToGameMenu();
288  }
289  return ES_HANDLED;
290 
291  case GHK_CONSOLE:
292  IConsoleSwitch();
293  return ES_HANDLED;
294 
295  case GHK_BOUNDING_BOXES:
297  return ES_HANDLED;
298 
299  case GHK_DIRTY_BLOCKS:
301  return ES_HANDLED;
302  }
303 
304  if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
305 
306  switch (hotkey) {
307  case GHK_CENTER:
308  case GHK_CENTER_ZOOM: {
309  Point pt = GetTileBelowCursor();
310  if (pt.x != -1) {
311  bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
312  if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
313  ScrollMainWindowTo(pt.x, pt.y, -1, instant);
314  }
315  break;
316  }
317 
318  case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
319  case GHK_DELETE_WINDOWS: CloseNonVitalWindows(); break;
320  case GHK_DELETE_NONVITAL_WINDOWS: CloseAllNonVitalWindows(); break;
321  case GHK_DELETE_ALL_MESSAGES: DeleteAllMessages(); break;
322  case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
323 
324  case GHK_CRASH: // Crash the game
325  *(volatile byte *)nullptr = 0;
326  break;
327 
328  case GHK_MONEY: // Gimme money
329  /* You can only cheat for money in singleplayer mode. */
331  break;
332 
333  case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
335  break;
336 
337  case GHK_TOGGLE_TRANSPARENCY:
338  case GHK_TOGGLE_TRANSPARENCY + 1:
339  case GHK_TOGGLE_TRANSPARENCY + 2:
340  case GHK_TOGGLE_TRANSPARENCY + 3:
341  case GHK_TOGGLE_TRANSPARENCY + 4:
342  case GHK_TOGGLE_TRANSPARENCY + 5:
343  case GHK_TOGGLE_TRANSPARENCY + 6:
344  case GHK_TOGGLE_TRANSPARENCY + 7:
345  case GHK_TOGGLE_TRANSPARENCY + 8:
346  /* Transparency toggle hot keys */
347  ToggleTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_TRANSPARENCY));
349  break;
350 
351  case GHK_TOGGLE_INVISIBILITY:
352  case GHK_TOGGLE_INVISIBILITY + 1:
353  case GHK_TOGGLE_INVISIBILITY + 2:
354  case GHK_TOGGLE_INVISIBILITY + 3:
355  case GHK_TOGGLE_INVISIBILITY + 4:
356  case GHK_TOGGLE_INVISIBILITY + 5:
357  case GHK_TOGGLE_INVISIBILITY + 6:
358  case GHK_TOGGLE_INVISIBILITY + 7:
359  /* Invisibility toggle hot keys */
360  ToggleInvisibilityWithTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_INVISIBILITY));
362  break;
363 
364  case GHK_TRANSPARENCY_TOOLBAR:
366  break;
367 
368  case GHK_TRANSPARANCY:
370  break;
371 
372  case GHK_CHAT: // smart chat; send to team if any, otherwise to all
373  if (_networking) {
375  if (cio == nullptr) break;
376 
378  }
379  break;
380 
381  case GHK_CHAT_ALL: // send text message to all clients
383  break;
384 
385  case GHK_CHAT_COMPANY: // send text to all team mates
386  if (_networking) {
388  if (cio == nullptr) break;
389 
391  }
392  break;
393 
394  case GHK_CHAT_SERVER: // send text to the server
395  if (_networking && !_network_server) {
397  }
398  break;
399 
400  case GHK_CLOSE_NEWS: // close active news window
401  if (!HideActiveNewsMessage()) return ES_NOT_HANDLED;
402  break;
403 
404  case GHK_CLOSE_ERROR: // close active error window
405  if (!HideActiveErrorMessage()) return ES_NOT_HANDLED;
406  break;
407 
408  default: return ES_NOT_HANDLED;
409  }
410  return ES_HANDLED;
411  }
412 
413  void OnScroll(Point delta) override
414  {
415  this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
416  this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
419  this->refresh.SetInterval(LINKGRAPH_DELAY);
420  }
421 
422  void OnMouseWheel(int wheel) override
423  {
425  ZoomInOrOutToCursorWindow(wheel < 0, this);
426  }
427  }
428 
429  void OnResize() override
430  {
431  if (this->viewport != nullptr) {
432  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
433  nvp->UpdateViewportCoordinates(this);
434  this->refresh.SetInterval(LINKGRAPH_DELAY);
435  }
436  }
437 
438  bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
439  {
440  if (widget != WID_M_VIEWPORT) return false;
441  return this->viewport->overlay->ShowTooltip(pt, close_cond);
442  }
443 
449  void OnInvalidateData(int data = 0, bool gui_scope = true) override
450  {
451  if (!gui_scope) return;
452  /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
453  InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
454  }
455 
456  static HotkeyList hotkeys;
457 };
458 
459 const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
460 const uint16 _ghk_abandon_keys[] = {'W' | WKC_CTRL, 'W' | WKC_META, 0};
461 const uint16 _ghk_chat_keys[] = {WKC_RETURN, 'T', 0};
462 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T', 0};
463 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T', 0};
464 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T', 0};
465 
466 static Hotkey global_hotkeys[] = {
467  Hotkey(_ghk_quit_keys, "quit", GHK_QUIT),
468  Hotkey(_ghk_abandon_keys, "abandon", GHK_ABANDON),
469  Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
470  Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
471  Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS),
472  Hotkey('C', "center", GHK_CENTER),
473  Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM),
474  Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
475  Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
476  Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
477  Hotkey(WKC_DELETE | WKC_CTRL, "delete_all_messages", GHK_DELETE_ALL_MESSAGES),
478  Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
479 #if defined(_DEBUG)
480  Hotkey('0' | WKC_ALT, "crash_game", GHK_CRASH),
481  Hotkey('1' | WKC_ALT, "money", GHK_MONEY),
482  Hotkey('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
483 #endif
484  Hotkey('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
485  Hotkey('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
486  Hotkey('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
487  Hotkey('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
488  Hotkey('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
489  Hotkey('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
490  Hotkey('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
491  Hotkey('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
492  Hotkey('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
493  Hotkey('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
494  Hotkey('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
495  Hotkey('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
496  Hotkey('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
497  Hotkey('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
498  Hotkey('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
499  Hotkey('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
500  Hotkey('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
501  Hotkey('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
502  Hotkey('X', "toggle_transparency", GHK_TRANSPARANCY),
503  Hotkey(_ghk_chat_keys, "chat", GHK_CHAT),
504  Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
505  Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
506  Hotkey(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER),
507  Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS),
508  Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR),
509  HOTKEY_LIST_END
510 };
511 HotkeyList MainWindow::hotkeys("global", global_hotkeys);
512 
513 static WindowDesc _main_window_desc(
514  WDP_MANUAL, nullptr, 0, 0,
516  0,
517  _nested_main_window_widgets, lengthof(_nested_main_window_widgets),
518  &MainWindow::hotkeys
519 );
520 
526 bool IsQuitKey(uint16 keycode)
527 {
528  int num = MainWindow::hotkeys.CheckMatch(keycode);
529  return num == GHK_QUIT;
530 }
531 
532 
533 void ShowSelectGameWindow();
534 
539 {
540  for (uint i = 0; i != 16; i++) {
541  const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, ST_RECOLOUR);
542 
543  assert(b);
544  memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
545  }
546 
547  new MainWindow(&_main_window_desc);
548 
549  /* XXX: these are not done */
550  switch (_game_mode) {
551  default: NOT_REACHED();
552  case GM_MENU:
553  ShowSelectGameWindow();
554  break;
555 
556  case GM_NORMAL:
557  case GM_EDITOR:
559  break;
560  }
561 }
562 
567 {
568  AllocateToolbar();
569 
570  /* Status bad only for normal games */
571  if (_game_mode == GM_EDITOR) return;
572 
573  ShowStatusBar();
574 }
575 
581 {
582  _cur_resolution.width = _screen.width;
583  _cur_resolution.height = _screen.height;
584  ScreenSizeChanged();
585  RelocateAllWindows(_screen.width, _screen.height);
587 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:720
MaxZoomInOut
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:44
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:3254
sound_func.h
MainWindow::OnScroll
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition: main_gui.cpp:413
MainWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: main_gui.cpp:231
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:2410
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition: viewport_type.h:74
command_func.h
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:3344
Commands
Commands
List of commands.
Definition: command_type.h:176
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:140
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:622
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:255
_network_server
bool _network_server
network-server is active
Definition: network.cpp:59
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:1311
ViewportData::scrollpos_y
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:195
map_func.h
ZOOM_NONE
@ ZOOM_NONE
Hack, used to update the button status.
Definition: viewport_type.h:75
misc_cmd.h
SND_12_EXPLOSION
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition: sound_type.h:55
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
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:92
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
saveload.h
zoom_func.h
LinkGraphOverlay::GetCargoMask
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
Definition: linkgraph_gui.h:73
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
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:53
network_gui.h
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:64
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:135
_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:55
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1814
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
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:102
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:114
window_gui.h
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition: viewport_type.h:73
GUISettings::scrollwheel_scrolling
uint8 scrollwheel_scrolling
scrolling using the scroll wheel?
Definition: settings_type.h:146
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition: error_gui.cpp:429
LinkGraphOverlay
Handles drawing of links into some window.
Definition: linkgraph_gui.h:43
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:566
CommandCost
Common return value for all commands.
Definition: command_type.h:24
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2331
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:607
CursorID
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1804
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:3296
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:176
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:1008
MainWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: main_gui.cpp:246
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:721
AllocateToolbar
void AllocateToolbar()
Allocate the toolbar.
Definition: toolbar_gui.cpp:2627
RelocateAllWindows
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3494
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:62
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
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:580
ToggleDirtyBlocks
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
Definition: toolbar_gui.cpp:1133
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
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:1058
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:1883
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:197
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:33
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
ToggleBoundingBoxes
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
Definition: toolbar_gui.cpp:1116
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:3194
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:64
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:134
MainWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: main_gui.cpp:266
spritecache.h
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:49
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:216
ViewportData::scrollpos_x
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:194
PALETTE_RECOLOUR_START
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition: sprites.h:1567
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:526
DeleteAllMessages
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition: window.cpp:3335
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
ScaleZoomGUI
static ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
ShowTransparencyToolbar
void ShowTransparencyToolbar()
Show the transparency toolbar.
Definition: transparency_gui.cpp:161
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2322
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:218
transparency.h
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:422
EventState
EventState
State of handling an event.
Definition: window_type.h:719
transparency_gui.h
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1176
news_gui.h
progress.h
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:240
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: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:535
HighLightStyle
HighLightStyle
Highlighting draw styles.
Definition: tilehighlight_type.h:19
network.h
CommandHelper
Definition: command_func.h:94
ViewportData::follow_vehicle
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:193
LinkGraphOverlay::SetDirty
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
Definition: linkgraph_gui.h:70
MainWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: main_gui.cpp:449
window_func.h
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:217
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
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:196
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:89
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
HideActiveNewsMessage
bool HideActiveNewsMessage()
Close active news message window.
Definition: news_gui.cpp:1046
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:3319
Window
Data structure for an opened window.
Definition: window_gui.h:213
ST_RECOLOUR
@ ST_RECOLOUR
Recolour sprite.
Definition: gfx_type.h:311
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:3386
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
HasModalProgress
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:17
MainWindow
Definition: main_gui.cpp:210
IConsoleSwitch
void IConsoleSwitch()
Toggle in-game console between opened and closed.
Definition: console_gui.cpp:396
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:350
main_widget.h
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:403
MainWindow::OnTooltip
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition: main_gui.cpp:438
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:429
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3434
ShowStatusBar
void ShowStatusBar()
Show our status bar.
Definition: statusbar_gui.cpp:274
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:32
network_func.h
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
ZoomStateChange
ZoomStateChange
Directions of zooming.
Definition: viewport_type.h:72
MainWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition: main_gui.cpp:422
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition: main_gui.cpp:538
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:22
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
hotkeys.h
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2088