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