OpenTTD
main_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "currency.h"
14 #include "spritecache.h"
15 #include "window_gui.h"
16 #include "window_func.h"
17 #include "textbuf_gui.h"
18 #include "viewport_func.h"
19 #include "command_func.h"
20 #include "console_gui.h"
21 #include "progress.h"
22 #include "transparency_gui.h"
23 #include "map_func.h"
24 #include "sound_func.h"
25 #include "transparency.h"
26 #include "strings_func.h"
27 #include "zoom_func.h"
28 #include "company_base.h"
29 #include "company_func.h"
30 #include "toolbar_gui.h"
31 #include "statusbar_gui.h"
33 #include "tilehighlight_func.h"
34 #include "hotkeys.h"
35 #include "guitimer_func.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 
51 static int _rename_id = 1;
52 static int _rename_what = -1;
53 
54 void CcGiveMoney(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
55 {
56 #ifdef ENABLE_NETWORK
57  if (result.Failed() || !_settings_game.economy.give_money) return;
58 
59  /* Inform the company of the action of one of its clients (controllers). */
60  char msg[64];
61  SetDParam(0, p2);
62  GetString(msg, STR_COMPANY_NAME, lastof(msg));
63 
64  if (!_network_server) {
65  NetworkClientSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, p1);
66  } else {
67  NetworkServerSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, CLIENT_ID_SERVER, p1);
68  }
69 #endif /* ENABLE_NETWORK */
70 }
71 
72 void HandleOnEditText(const char *str)
73 {
74  switch (_rename_what) {
75 #ifdef ENABLE_NETWORK
76  case 3: { // Give money, you can only give money in excess of loan
78  if (c == NULL) break;
79  Money money = min(c->money - c->current_loan, (Money)(atoi(str) / _currency->rate));
80 
81  uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0
82 
83  /* Give 'id' the money, and subtract it from ourself */
84  DoCommandP(0, money_c, _rename_id, CMD_GIVE_MONEY | CMD_MSG(STR_ERROR_INSUFFICIENT_FUNDS), CcGiveMoney, str);
85  break;
86  }
87 #endif /* ENABLE_NETWORK */
88  default: NOT_REACHED();
89  }
90 
91  _rename_id = _rename_what = -1;
92 }
93 
104 bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
105 {
106  if (w->IsWidgetDisabled(widget)) return false;
107 
108  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
109  w->SetDirty();
110 
111  if (w->IsWidgetLowered(widget)) {
113  return false;
114  }
115 
116  SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
117  w->LowerWidget(widget);
118  return true;
119 }
120 
121 
122 void CcPlaySound_EXPLOSION(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
123 {
124  if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
125 }
126 
127 #ifdef ENABLE_NETWORK
128 void ShowNetworkGiveMoneyWindow(CompanyID company)
129 {
130  _rename_id = company;
131  _rename_what = 3;
132  ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, NULL, CS_NUMERAL, QSF_NONE);
133 }
134 #endif /* ENABLE_NETWORK */
135 
136 
145 {
146  ViewPort *vp;
147 
148  assert(w != NULL);
149  vp = w->viewport;
150 
151  switch (how) {
152  case ZOOM_NONE:
153  /* On initialisation of the viewport we don't do anything. */
154  break;
155 
156  case ZOOM_IN:
157  if (vp->zoom <= _settings_client.gui.zoom_min) return false;
158  vp->zoom = (ZoomLevel)((int)vp->zoom - 1);
159  vp->virtual_width >>= 1;
160  vp->virtual_height >>= 1;
161 
162  w->viewport->scrollpos_x += vp->virtual_width >> 1;
163  w->viewport->scrollpos_y += vp->virtual_height >> 1;
167  break;
168  case ZOOM_OUT:
169  if (vp->zoom >= _settings_client.gui.zoom_max) return false;
170  vp->zoom = (ZoomLevel)((int)vp->zoom + 1);
171 
172  w->viewport->scrollpos_x -= vp->virtual_width >> 1;
173  w->viewport->scrollpos_y -= vp->virtual_height >> 1;
176 
177  vp->virtual_width <<= 1;
178  vp->virtual_height <<= 1;
180  break;
181  }
182  if (vp != NULL) { // the vp can be null when how == ZOOM_NONE
184  vp->virtual_top = w->viewport->scrollpos_y;
185  }
186  /* Update the windows that have zoom-buttons to perhaps disable their buttons */
187  w->InvalidateData();
188  return true;
189 }
190 
191 void ZoomInOrOutToCursorWindow(bool in, Window *w)
192 {
193  assert(w != NULL);
194 
195  if (_game_mode != GM_MENU) {
196  ViewPort *vp = w->viewport;
197  if ((in && vp->zoom <= _settings_client.gui.zoom_min) || (!in && vp->zoom >= _settings_client.gui.zoom_max)) return;
198 
199  Point pt = GetTileZoomCenterWindow(in, w);
200  if (pt.x != -1) {
201  ScrollWindowTo(pt.x, pt.y, -1, w, true);
202 
204  }
205  }
206 }
207 
208 void FixTitleGameZoom()
209 {
210  if (_game_mode != GM_MENU) return;
211 
213  vp->zoom = _gui_zoom;
214  vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
215  vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
216 }
217 
218 static const struct NWidgetPart _nested_main_window_widgets[] = {
219  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1),
220 };
221 
222 enum {
223  GHK_QUIT,
224  GHK_ABANDON,
225  GHK_CONSOLE,
226  GHK_BOUNDING_BOXES,
227  GHK_DIRTY_BLOCKS,
228  GHK_CENTER,
229  GHK_CENTER_ZOOM,
230  GHK_RESET_OBJECT_TO_PLACE,
231  GHK_DELETE_WINDOWS,
232  GHK_DELETE_NONVITAL_WINDOWS,
233  GHK_DELETE_ALL_MESSAGES,
234  GHK_REFRESH_SCREEN,
235  GHK_CRASH,
236  GHK_MONEY,
237  GHK_UPDATE_COORDS,
238  GHK_TOGGLE_TRANSPARENCY,
239  GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
240  GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
241  GHK_TRANSPARANCY,
242  GHK_CHAT,
243  GHK_CHAT_ALL,
244  GHK_CHAT_COMPANY,
245  GHK_CHAT_SERVER,
246 };
247 
249 {
250  GUITimer refresh;
251 
252  /* Refresh times in milliseconds */
253  static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
254  static const uint LINKGRAPH_DELAY = 450;
255 
256  MainWindow(WindowDesc *desc) : Window(desc)
257  {
258  this->InitNested(0);
259  CLRBITS(this->flags, WF_WHITE_BORDER);
260  ResizeWindow(this, _screen.width, _screen.height);
261 
262  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
263  nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
264 
265  this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 3);
266  this->refresh.SetInterval(LINKGRAPH_DELAY);
267  }
268 
269  virtual void OnRealtimeTick(uint delta_ms)
270  {
271  if (!this->refresh.Elapsed(delta_ms)) return;
272 
273  this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
274 
275  if (this->viewport->overlay->GetCargoMask() == 0 ||
276  this->viewport->overlay->GetCompanyMask() == 0) {
277  return;
278  }
279 
280  this->viewport->overlay->SetDirty();
281  this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
282  }
283 
284  virtual void OnPaint()
285  {
286  this->DrawWidgets();
287  if (_game_mode == GM_MENU) {
288  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};
289  static const uint LETTER_SPACING = 10;
290  int name_width = (lengthof(title_sprites) - 1) * LETTER_SPACING;
291 
292  for (uint i = 0; i < lengthof(title_sprites); i++) {
293  name_width += GetSpriteSize(title_sprites[i]).width;
294  }
295  int off_x = (this->width - name_width) / 2;
296 
297  for (uint i = 0; i < lengthof(title_sprites); i++) {
298  DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
299  off_x += GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
300  }
301  }
302  }
303 
304  virtual EventState OnHotkey(int hotkey)
305  {
306  if (hotkey == GHK_QUIT) {
307  HandleExitGameRequest();
308  return ES_HANDLED;
309  }
310 
311  /* Disable all key shortcuts, except quit shortcuts when
312  * generating the world, otherwise they create threading
313  * problem during the generating, resulting in random
314  * assertions that are hard to trigger and debug */
315  if (HasModalProgress()) return ES_NOT_HANDLED;
316 
317  switch (hotkey) {
318  case GHK_ABANDON:
319  /* No point returning from the main menu to itself */
320  if (_game_mode == GM_MENU) return ES_HANDLED;
322  DoExitSave();
324  } else {
325  AskExitToGameMenu();
326  }
327  return ES_HANDLED;
328 
329  case GHK_CONSOLE:
330  IConsoleSwitch();
331  return ES_HANDLED;
332 
333  case GHK_BOUNDING_BOXES:
335  return ES_HANDLED;
336 
337  case GHK_DIRTY_BLOCKS:
339  return ES_HANDLED;
340  }
341 
342  if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
343 
344  switch (hotkey) {
345  case GHK_CENTER:
346  case GHK_CENTER_ZOOM: {
347  Point pt = GetTileBelowCursor();
348  if (pt.x != -1) {
349  bool instant = (hotkey == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
350  if (hotkey == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
351  ScrollMainWindowTo(pt.x, pt.y, -1, instant);
352  }
353  break;
354  }
355 
356  case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
357  case GHK_DELETE_WINDOWS: DeleteNonVitalWindows(); break;
358  case GHK_DELETE_NONVITAL_WINDOWS: DeleteAllNonVitalWindows(); break;
359  case GHK_DELETE_ALL_MESSAGES: DeleteAllMessages(); break;
360  case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
361 
362  case GHK_CRASH: // Crash the game
363  *(volatile byte *)0 = 0;
364  break;
365 
366  case GHK_MONEY: // Gimme money
367  /* You can only cheat for money in single player. */
368  if (!_networking) DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
369  break;
370 
371  case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
373  break;
374 
375  case GHK_TOGGLE_TRANSPARENCY:
376  case GHK_TOGGLE_TRANSPARENCY + 1:
377  case GHK_TOGGLE_TRANSPARENCY + 2:
378  case GHK_TOGGLE_TRANSPARENCY + 3:
379  case GHK_TOGGLE_TRANSPARENCY + 4:
380  case GHK_TOGGLE_TRANSPARENCY + 5:
381  case GHK_TOGGLE_TRANSPARENCY + 6:
382  case GHK_TOGGLE_TRANSPARENCY + 7:
383  case GHK_TOGGLE_TRANSPARENCY + 8:
384  /* Transparency toggle hot keys */
385  ToggleTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_TRANSPARENCY));
387  break;
388 
389  case GHK_TOGGLE_INVISIBILITY:
390  case GHK_TOGGLE_INVISIBILITY + 1:
391  case GHK_TOGGLE_INVISIBILITY + 2:
392  case GHK_TOGGLE_INVISIBILITY + 3:
393  case GHK_TOGGLE_INVISIBILITY + 4:
394  case GHK_TOGGLE_INVISIBILITY + 5:
395  case GHK_TOGGLE_INVISIBILITY + 6:
396  case GHK_TOGGLE_INVISIBILITY + 7:
397  /* Invisibility toggle hot keys */
398  ToggleInvisibilityWithTransparency((TransparencyOption)(hotkey - GHK_TOGGLE_INVISIBILITY));
400  break;
401 
402  case GHK_TRANSPARENCY_TOOLBAR:
404  break;
405 
406  case GHK_TRANSPARANCY:
408  break;
409 
410 #ifdef ENABLE_NETWORK
411  case GHK_CHAT: // smart chat; send to team if any, otherwise to all
412  if (_networking) {
414  if (cio == NULL) break;
415 
417  }
418  break;
419 
420  case GHK_CHAT_ALL: // send text message to all clients
422  break;
423 
424  case GHK_CHAT_COMPANY: // send text to all team mates
425  if (_networking) {
427  if (cio == NULL) break;
428 
430  }
431  break;
432 
433  case GHK_CHAT_SERVER: // send text to the server
434  if (_networking && !_network_server) {
436  }
437  break;
438 #endif
439 
440  default: return ES_NOT_HANDLED;
441  }
442  return ES_HANDLED;
443  }
444 
445  virtual void OnScroll(Point delta)
446  {
447  this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
448  this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
451  this->refresh.SetInterval(LINKGRAPH_DELAY);
452  }
453 
454  virtual void OnMouseWheel(int wheel)
455  {
457  ZoomInOrOutToCursorWindow(wheel < 0, this);
458  }
459  }
460 
461  virtual void OnResize()
462  {
463  if (this->viewport != NULL) {
464  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
465  nvp->UpdateViewportCoordinates(this);
466  this->refresh.SetInterval(LINKGRAPH_DELAY);
467  }
468  }
469 
475  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
476  {
477  if (!gui_scope) return;
478  /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
479  InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
480  }
481 
482  static HotkeyList hotkeys;
483 };
484 
485 const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
486 const uint16 _ghk_abandon_keys[] = {'W' | WKC_CTRL, 'W' | WKC_META, 0};
487 const uint16 _ghk_chat_keys[] = {WKC_RETURN, 'T', 0};
488 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T', 0};
489 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T', 0};
490 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T', 0};
491 
492 static Hotkey global_hotkeys[] = {
493  Hotkey(_ghk_quit_keys, "quit", GHK_QUIT),
494  Hotkey(_ghk_abandon_keys, "abandon", GHK_ABANDON),
495  Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE),
496  Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
497  Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS),
498  Hotkey('C', "center", GHK_CENTER),
499  Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM),
500  Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
501  Hotkey(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
502  Hotkey(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
503  Hotkey(WKC_DELETE | WKC_CTRL, "delete_all_messages", GHK_DELETE_ALL_MESSAGES),
504  Hotkey('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
505 #if defined(_DEBUG)
506  Hotkey('0' | WKC_ALT, "crash_game", GHK_CRASH),
507  Hotkey('1' | WKC_ALT, "money", GHK_MONEY),
508  Hotkey('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
509 #endif
510  Hotkey('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
511  Hotkey('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
512  Hotkey('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
513  Hotkey('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
514  Hotkey('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
515  Hotkey('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
516  Hotkey('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
517  Hotkey('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
518  Hotkey('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
519  Hotkey('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
520  Hotkey('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
521  Hotkey('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
522  Hotkey('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
523  Hotkey('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
524  Hotkey('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
525  Hotkey('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
526  Hotkey('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
527  Hotkey('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
528  Hotkey('X', "toggle_transparency", GHK_TRANSPARANCY),
529 #ifdef ENABLE_NETWORK
530  Hotkey(_ghk_chat_keys, "chat", GHK_CHAT),
531  Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
532  Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
533  Hotkey(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER),
534 #endif
535  HOTKEY_LIST_END
536 };
537 HotkeyList MainWindow::hotkeys("global", global_hotkeys);
538 
539 static WindowDesc _main_window_desc(
540  WDP_MANUAL, NULL, 0, 0,
542  0,
543  _nested_main_window_widgets, lengthof(_nested_main_window_widgets),
544  &MainWindow::hotkeys
545 );
546 
552 bool IsQuitKey(uint16 keycode)
553 {
554  int num = MainWindow::hotkeys.CheckMatch(keycode);
555  return num == GHK_QUIT;
556 }
557 
558 
559 void ShowSelectGameWindow();
560 
565 {
566  for (uint i = 0; i != 16; i++) {
567  const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, ST_RECOLOUR);
568 
569  assert(b);
570  memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
571  }
572 
573  new MainWindow(&_main_window_desc);
574 
575  /* XXX: these are not done */
576  switch (_game_mode) {
577  default: NOT_REACHED();
578  case GM_MENU:
579  ShowSelectGameWindow();
580  break;
581 
582  case GM_NORMAL:
583  case GM_EDITOR:
585  break;
586  }
587 }
588 
593 {
594  AllocateToolbar();
595 
596  /* Status bad only for normal games */
597  if (_game_mode == GM_EDITOR) return;
598 
599  ShowStatusBar();
600 }
601 
607 {
608  _cur_resolution.width = _screen.width;
609  _cur_resolution.height = _screen.height;
610  ScreenSizeChanged();
611  RelocateAllWindows(_screen.width, _screen.height);
613 }
EventState
State of handling an event.
Definition: window_type.h:713
Nested widget containing a viewport.
Definition: widget_type.h:81
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows. ...
Definition: main_gui.cpp:564
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:144
Functions related to OTTD&#39;s strings.
Send message/notice to all clients (All)
Definition: network_type.h:83
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
bool _networking
are we in networking mode?
Definition: network.cpp:56
virtual void OnResize()
Called after the window got resized.
Definition: main_gui.cpp:461
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:30
Container for all information known about a client.
Definition: network_base.h:27
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1851
ZoomLevelByte zoom_max
maximum zoom out level
All data for a single hotkey.
Definition: hotkeys.h:24
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
Definition: linkgraph_gui.h:70
High level window description.
Definition: window_gui.h:168
EconomySettings economy
settings to change the economy
WindowFlags flags
Window flags.
Definition: window_gui.h:312
Zoom out (get helicopter view).
Definition: viewport_type.h:64
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
int height
Screen height of the viewport.
Definition: viewport_type.h:28
Switch to game intro menu.
Definition: openttd.h:32
Hotkey related functions.
GUIs related to networking.
Functions to handle different currencies.
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:1936
bool IsQuitKey(uint16 keycode)
Does the given keycode match one of the keycodes bound to &#39;quit game&#39;?
Definition: main_gui.cpp:552
The passed event is not handled.
Definition: window_type.h:715
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:57
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1064
int virtual_height
height << zoom
Definition: viewport_type.h:33
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:24
bool give_money
allow giving other companies money
Send message/notice to only a certain client (Private)
Definition: network_type.h:85
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:24
Zoom in (get more detailed view).
Definition: viewport_type.h:63
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:2806
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat message.
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
ZoomLevelByte _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:60
Stuff related to the text buffer GUI.
Base core network types and some helper functions to access them.
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:1927
#define CLRBITS(x, y)
Clears several bits in a variable.
void DeleteAllMessages()
Delete all messages and their corresponding window (if any).
Definition: window.cpp:3398
Common return value for all commands.
Definition: command_type.h:25
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:59
void DeleteAllNonVitalWindows()
It is possible that a stickied window gets to a position where the &#39;close&#39; button is outside the gami...
Definition: window.cpp:3376
Nested widget to display a viewport in a window.
Definition: widget_type.h:575
Functions related to maps.
Functions, definitions and such used only by the GUI.
Servers always have this ID.
Definition: network_type.h:45
void ToggleBoundingBoxes()
Toggle drawing of sprites&#39; bounding boxes.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
void AllocateToolbar()
Allocate the toolbar.
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Functions related to (drawing on) viewports.
static void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Definition: transparency.h:115
Declaration of linkgraph overlay GUI.
Data structure for an opened window.
Definition: window_gui.h:278
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition: main_gui.cpp:269
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1841
Main window; Window numbers:
Definition: window_type.h:46
Only numeric ones.
Definition: string_type.h:28
Functions/types related to saving and loading games.
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:31
GUI Timers.
Types related to the main widgets.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:495
SoundSettings sound
sound effect settings
Main window viewport.
Definition: main_widget.h:17
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:219
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:66
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3550
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:63
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
uint8 scrollwheel_scrolling
scrolling using the scroll wheel?
Functions related to modal progress.
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
List of hotkeys for a window.
Definition: hotkeys.h:42
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:423
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:260
GUI functions related to transparency.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:476
GUI related functions in the console.
int virtual_width
width << zoom
Definition: viewport_type.h:32
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?"
Money money
Money owned by the company.
Definition: company_base.h:64
Basic functions/variables used all over the place.
give money to another company
Definition: command_type.h:305
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:531
static void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition: transparency.h:71
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:259
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
do the money cheat
Definition: command_type.h:274
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: main_gui.cpp:475
Functions related to sound.
Functions to cache sprites in memory.
bool Failed() const
Did this command fail?
Definition: command_type.h:161
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
Definition: viewport_func.h:46
Default zoom level for viewports.
Definition: zoom_type.h:35
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:263
virtual void OnMouseWheel(int wheel)
The mouse wheel has been turned.
Definition: main_gui.cpp:454
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members where he/she can chat to.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:968
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
ZoomLevelByte zoom_min
minimum zoom out level
void DeleteNonVitalWindows()
Try to delete a non-vital window.
Definition: window.cpp:3347
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:203
Functions related to companies.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:262
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition: sprites.h:1549
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
GUISettings gui
settings related to the GUI
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:24
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:104
void GameSizeChanged()
Size of the application screen changed.
Definition: main_gui.cpp:606
Functions related to transparency.
Functions related to zooming.
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:47
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1130
bool confirm
Play sound effect on succesful constructions or other actions.
Functions related to commands.
Network functions used by other parts of OpenTTD.
bool _network_server
network-server is active
Definition: network.cpp:57
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:21
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:53
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:769
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:3040
HighLightStyle
Highlighting draw styles.
int CheckMatch(uint16 keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:301
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:35
ZoomStateChange
Directions of zooming.
Definition: viewport_type.h:62
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:321
void ShowStatusBar()
Show our status bar.
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:31
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:369
WindowClass window_class
Window class.
Definition: window_gui.h:313
void IConsoleSwitch()
Toggle in-game console between opened and closed.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3088
Recolour sprite.
Definition: gfx_type.h:301
The passed event is handled.
Definition: window_type.h:714
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:314
Functions related to tile highlights.
Owner
Enum for all companies/owners.
Definition: company_type.h:20
Window functions not directly related to making/drawing windows.
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
Definition: linkgraph_gui.h:64
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it&#39;s client-identifier.
Definition: network.cpp:126
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:328
Functions, definitions and such used only by the GUI.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2126
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
Definition: linkgraph_gui.h:67
Window white border counter bit mask.
Definition: window_gui.h:242
void ShowVitalWindows()
Show the vital in-game windows.
Definition: main_gui.cpp:592
virtual void OnPaint()
The window must be repainted.
Definition: main_gui.cpp:284
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:261
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:84
static void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition: transparency.h:93
Hack, used to update the button status.
Definition: viewport_type.h:65
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:2087
bool click_beep
Beep on a random selection of buttons.
void ShowTransparencyToolbar()
Show the transparency toolbar.
This file contains all sprite-related enums and defines.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:165
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:834
Handles drawing of links into some window.
Definition: linkgraph_gui.h:39
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window&#39;s data as invalid (in need of re-computing)
Definition: window.cpp:3242
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:23
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: main_gui.cpp:304
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:3301
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition: transparency.h:24
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1463
Stuff related to the (main) toolbar.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.
Definition: main_gui.cpp:445
int width
Screen width of the viewport.
Definition: viewport_type.h:27