OpenTTD

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