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/>.
10 /** @file main_gui.cpp Handling of the main viewport. */
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"
22 #include "transparency_gui.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"
36 #include "saveload/saveload.h"
38 #include "widgets/main_widget.h"
40 #include "network/network.h"
41 #include "network/network_func.h"
42 #include "network/network_gui.h"
43 #include "network/network_base.h"
45 #include "table/sprites.h"
46 #include "table/strings.h"
48 #include "safeguards.h"
50 static int _rename_id
= 1;
51 static int _rename_what
= -1;
53 void CcGiveMoney(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
56 if (result
.Failed() || !_settings_game
.economy
.give_money
) return;
58 /* Inform the company of the action of one of its clients (controllers). */
61 GetString(msg
, STR_COMPANY_NAME
, lastof(msg
));
63 if (!_network_server
) {
64 NetworkClientSendChat(NETWORK_ACTION_GIVE_MONEY
, DESTTYPE_TEAM
, p2
, msg
, p1
);
66 NetworkServerSendChat(NETWORK_ACTION_GIVE_MONEY
, DESTTYPE_TEAM
, p2
, msg
, CLIENT_ID_SERVER
, p1
);
68 #endif /* ENABLE_NETWORK */
71 void HandleOnEditText(const char *str
)
73 switch (_rename_what
) {
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
== nullptr) break;
78 Money money
= min(c
->money
- c
->current_loan
, (Money
)(atoi(str
) / _currency
->rate
));
80 uint32 money_c
= Clamp(ClampToI32(money
), 0, 20000000); // Clamp between 20 million and 0
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
);
86 #endif /* ENABLE_NETWORK */
87 default: NOT_REACHED();
90 _rename_id
= _rename_what
= -1;
94 * This code is shared for the majority of the pushbuttons.
95 * Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters
97 * @param w Window which called the function
98 * @param widget ID of the widget (=button) that called this function
99 * @param cursor How should the cursor image change? E.g. cursor with depot image in it
100 * @param mode Tile highlighting mode, e.g. drawing a rectangle or a dot on the ground
101 * @return true if the button is clicked, false if it's unclicked
103 bool HandlePlacePushButton(Window
*w
, int widget
, CursorID cursor
, HighLightStyle mode
)
105 if (w
->IsWidgetDisabled(widget
)) return false;
107 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
110 if (w
->IsWidgetLowered(widget
)) {
111 ResetObjectToPlace();
115 SetObjectToPlace(cursor
, PAL_NONE
, mode
, w
->window_class
, w
->window_number
);
116 w
->LowerWidget(widget
);
121 void CcPlaySound_EXPLOSION(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
123 if (result
.Succeeded() && _settings_client
.sound
.confirm
) SndPlayTileFx(SND_12_EXPLOSION
, tile
);
126 #ifdef ENABLE_NETWORK
127 void ShowNetworkGiveMoneyWindow(CompanyID company
)
129 _rename_id
= company
;
131 ShowQueryString(STR_EMPTY
, STR_NETWORK_GIVE_MONEY_CAPTION
, 30, nullptr, CS_NUMERAL
, QSF_NONE
);
133 #endif /* ENABLE_NETWORK */
137 * Zooms a viewport in a window in or out.
138 * @param how Zooming direction.
139 * @param w Window owning the viewport.
140 * @return Returns \c true if zooming step could be done, \c false if further zooming is not possible.
141 * @note No button handling or what so ever is done.
143 bool DoZoomInOutWindow(ZoomStateChange how
, Window
*w
)
147 assert(w
!= nullptr);
152 /* On initialisation of the viewport we don't do anything. */
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;
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
;
168 if (vp
->zoom
>= _settings_client
.gui
.zoom_max
) return false;
169 vp
->zoom
= (ZoomLevel
)((int)vp
->zoom
+ 1);
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
;
176 vp
->virtual_width
<<= 1;
177 vp
->virtual_height
<<= 1;
178 w
->viewport
->follow_vehicle
= INVALID_VEHICLE
;
181 if (vp
!= nullptr) { // 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
;
185 /* Update the windows that have zoom-buttons to perhaps disable their buttons */
187 if (how
!= ZOOM_NONE
) {
188 RebuildViewportOverlay(w
);
193 void ZoomInOrOutToCursorWindow(bool in
, Window
*w
)
195 assert(w
!= nullptr);
197 if (_game_mode
!= GM_MENU
) {
198 ViewPort
*vp
= w
->viewport
;
199 if ((in
&& vp
->zoom
<= _settings_client
.gui
.zoom_min
) || (!in
&& vp
->zoom
>= _settings_client
.gui
.zoom_max
)) return;
201 Point pt
= GetTileZoomCenterWindow(in
, w
);
203 ScrollWindowTo(pt
.x
, pt
.y
, -1, w
, true);
205 DoZoomInOutWindow(in
? ZOOM_IN
: ZOOM_OUT
, w
);
210 static const struct NWidgetPart _nested_main_window_widgets
[] = {
211 NWidget(NWID_VIEWPORT
, INVALID_COLOUR
, WID_M_VIEWPORT
), SetResize(1, 1),
222 GHK_RESET_OBJECT_TO_PLACE
,
224 GHK_DELETE_NONVITAL_WINDOWS
,
229 GHK_TOGGLE_TRANSPARENCY
,
230 GHK_TOGGLE_INVISIBILITY
= GHK_TOGGLE_TRANSPARENCY
+ 9,
231 GHK_TRANSPARENCY_TOOLBAR
= GHK_TOGGLE_INVISIBILITY
+ 8,
237 GHK_CHANGE_MAP_MODE_PREV
,
238 GHK_CHANGE_MAP_MODE_NEXT
,
241 struct MainWindow
: Window
245 static const uint LINKGRAPH_REFRESH_PERIOD
= 0xff;
246 static const uint LINKGRAPH_DELAY
= 0xf;
248 MainWindow(WindowDesc
*desc
) : Window(desc
)
251 CLRBITS(this->flags
, WF_WHITE_BORDER
);
252 ResizeWindow(this, _screen
.width
, _screen
.height
);
254 NWidgetViewport
*nvp
= this->GetWidget
<NWidgetViewport
>(WID_M_VIEWPORT
);
255 nvp
->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT
);
257 this->viewport
->map_type
= (ViewportMapType
)_settings_client
.gui
.default_viewport_map_mode
;
258 this->viewport
->overlay
= new LinkGraphOverlay(this, WID_M_VIEWPORT
, 0, 0, 3);
259 this->refresh
= LINKGRAPH_DELAY
;
262 virtual void OnTick()
264 if (--this->refresh
> 0) return;
266 this->refresh
= LINKGRAPH_REFRESH_PERIOD
;
268 if (this->viewport
->overlay
->GetCargoMask() == 0 ||
269 this->viewport
->overlay
->GetCompanyMask() == 0) {
273 this->viewport
->overlay
->RebuildCache();
274 this->GetWidget
<NWidgetBase
>(WID_M_VIEWPORT
)->SetDirty(this);
277 virtual void OnPaint()
280 if (_game_mode
== GM_MENU
) {
281 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
};
282 static const uint LETTER_SPACING
= 10;
283 int name_width
= (lengthof(title_sprites
) - 1) * LETTER_SPACING
;
285 for (uint i
= 0; i
< lengthof(title_sprites
); i
++) {
286 name_width
+= GetSpriteSize(title_sprites
[i
]).width
;
288 int off_x
= (this->width
- name_width
) / 2;
290 for (uint i
= 0; i
< lengthof(title_sprites
); i
++) {
291 DrawSprite(title_sprites
[i
], PAL_NONE
, off_x
, 50);
292 off_x
+= GetSpriteSize(title_sprites
[i
]).width
+ LETTER_SPACING
;
297 virtual EventState
OnHotkey(int hotkey
)
299 if (hotkey
== GHK_QUIT
) {
300 HandleExitGameRequest();
304 /* Disable all key shortcuts, except quit shortcuts when
305 * generating the world, otherwise they create threading
306 * problem during the generating, resulting in random
307 * assertions that are hard to trigger and debug */
308 if (HasModalProgress()) return ES_NOT_HANDLED
;
312 /* No point returning from the main menu to itself */
313 if (_game_mode
== GM_MENU
) return ES_HANDLED
;
314 if (_settings_client
.gui
.autosave_on_exit
) {
316 _switch_mode
= SM_MENU
;
326 case GHK_BOUNDING_BOXES
:
327 ToggleBoundingBoxes();
330 case GHK_DIRTY_BLOCKS
:
335 if (_game_mode
== GM_MENU
) return ES_NOT_HANDLED
;
339 case GHK_CENTER_ZOOM
: {
340 Point pt
= GetTileBelowCursor();
342 bool instant
= (hotkey
== GHK_CENTER_ZOOM
&& this->viewport
->zoom
!= _settings_client
.gui
.zoom_min
);
343 if (hotkey
== GHK_CENTER_ZOOM
) MaxZoomInOut(ZOOM_IN
, this);
344 ScrollMainWindowTo(pt
.x
, pt
.y
, -1, instant
);
349 case GHK_RESET_OBJECT_TO_PLACE
: ResetObjectToPlace(); break;
350 case GHK_DELETE_WINDOWS
: DeleteNonVitalWindows(); break;
351 case GHK_DELETE_NONVITAL_WINDOWS
: DeleteAllNonVitalWindows(); break;
352 case GHK_REFRESH_SCREEN
: MarkWholeScreenDirty(); break;
354 case GHK_CRASH
: // Crash the game
355 *(volatile byte
*)0 = 0;
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
);
363 case GHK_UPDATE_COORDS
: // Update the coordinates of all station signs
364 UpdateAllVirtCoords();
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
));
378 MarkWholeScreenDirty();
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
));
391 MarkWholeScreenDirty();
394 case GHK_TRANSPARENCY_TOOLBAR
:
395 ShowTransparencyToolbar();
398 case GHK_TRANSPARANCY
:
399 ResetRestoreAllTransparency();
402 #ifdef ENABLE_NETWORK
403 case GHK_CHAT
: // smart chat; send to team if any, otherwise to all
405 const NetworkClientInfo
*cio
= NetworkClientInfo::GetByClientID(_network_own_client_id
);
406 if (cio
== nullptr) break;
408 ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio
) ? DESTTYPE_TEAM
: DESTTYPE_BROADCAST
, cio
->client_playas
);
412 case GHK_CHAT_ALL
: // send text message to all clients
413 if (_networking
) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST
, 0);
416 case GHK_CHAT_COMPANY
: // send text to all team mates
418 const NetworkClientInfo
*cio
= NetworkClientInfo::GetByClientID(_network_own_client_id
);
419 if (cio
== nullptr) break;
421 ShowNetworkChatQueryWindow(DESTTYPE_TEAM
, cio
->client_playas
);
425 case GHK_CHAT_SERVER
: // send text to the server
426 if (_networking
&& !_network_server
) {
427 ShowNetworkChatQueryWindow(DESTTYPE_CLIENT
, CLIENT_ID_SERVER
);
432 case GHK_CHANGE_MAP_MODE_PREV
:
433 if (_focused_window
&& _focused_window
->viewport
&& _focused_window
->viewport
->zoom
>= ZOOM_LVL_DRAW_MAP
) {
434 _focused_window
->viewport
->map_type
= ChangeRenderMode(_focused_window
->viewport
, true);
435 _focused_window
->SetDirty();
437 else if (this->viewport
->zoom
>= ZOOM_LVL_DRAW_MAP
) {
438 this->viewport
->map_type
= ChangeRenderMode(this->viewport
, true);
442 case GHK_CHANGE_MAP_MODE_NEXT
:
443 if (_focused_window
&& _focused_window
->viewport
&& _focused_window
->viewport
->zoom
>= ZOOM_LVL_DRAW_MAP
) {
444 _focused_window
->viewport
->map_type
= ChangeRenderMode(_focused_window
->viewport
, false);
445 _focused_window
->SetDirty();
447 else if (this->viewport
->zoom
>= ZOOM_LVL_DRAW_MAP
) {
448 this->viewport
->map_type
= ChangeRenderMode(this->viewport
, false);
453 default: return ES_NOT_HANDLED
;
458 virtual void OnScroll(Point delta
)
460 this->viewport
->scrollpos_x
+= ScaleByZoom(delta
.x
, this->viewport
->zoom
);
461 this->viewport
->scrollpos_y
+= ScaleByZoom(delta
.y
, this->viewport
->zoom
);
462 this->viewport
->dest_scrollpos_x
= this->viewport
->scrollpos_x
;
463 this->viewport
->dest_scrollpos_y
= this->viewport
->scrollpos_y
;
464 this->refresh
= LINKGRAPH_DELAY
;
467 virtual void OnMouseWheel(int wheel
)
470 /* Cycle through the drawing modes */
471 this->viewport
->map_type
= ChangeRenderMode(this->viewport
, wheel
< 0);
474 else if (_settings_client
.gui
.scrollwheel_scrolling
== 0) {
475 ZoomInOrOutToCursorWindow(wheel
< 0, this);
479 virtual void OnResize()
481 if (this->viewport
!= nullptr) {
482 NWidgetViewport
*nvp
= this->GetWidget
<NWidgetViewport
>(WID_M_VIEWPORT
);
483 nvp
->UpdateViewportCoordinates(this);
484 this->refresh
= LINKGRAPH_DELAY
;
489 * Some data on this window has become invalid.
490 * @param data Information about the changed data.
491 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
493 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
495 if (!gui_scope
) return;
496 /* Forward the message to the appropriate toolbar (ingame or scenario editor) */
497 InvalidateWindowData(WC_MAIN_TOOLBAR
, 0, data
, true);
500 static HotkeyList hotkeys
;
503 const uint16 _ghk_quit_keys
[] = {'Q' | WKC_CTRL
, 'Q' | WKC_META
, 0};
504 const uint16 _ghk_abandon_keys
[] = {'W' | WKC_CTRL
, 'W' | WKC_META
, 0};
505 const uint16 _ghk_chat_keys
[] = {WKC_RETURN
, 'T', 0};
506 const uint16 _ghk_chat_all_keys
[] = {WKC_SHIFT
| WKC_RETURN
, WKC_SHIFT
| 'T', 0};
507 const uint16 _ghk_chat_company_keys
[] = {WKC_CTRL
| WKC_RETURN
, WKC_CTRL
| 'T', 0};
508 const uint16 _ghk_chat_server_keys
[] = {WKC_CTRL
| WKC_SHIFT
| WKC_RETURN
, WKC_CTRL
| WKC_SHIFT
| 'T', 0};
510 static Hotkey global_hotkeys
[] = {
511 Hotkey(_ghk_quit_keys
, "quit", GHK_QUIT
),
512 Hotkey(_ghk_abandon_keys
, "abandon", GHK_ABANDON
),
513 Hotkey(WKC_BACKQUOTE
, "console", GHK_CONSOLE
),
514 Hotkey('B' | WKC_CTRL
, "bounding_boxes", GHK_BOUNDING_BOXES
),
515 Hotkey('I' | WKC_CTRL
, "dirty_blocks", GHK_DIRTY_BLOCKS
),
516 Hotkey('C', "center", GHK_CENTER
),
517 Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM
),
518 Hotkey(WKC_ESC
, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE
),
519 Hotkey(WKC_DELETE
, "delete_windows", GHK_DELETE_WINDOWS
),
520 Hotkey(WKC_DELETE
| WKC_SHIFT
, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS
),
521 Hotkey('R' | WKC_CTRL
, "refresh_screen", GHK_REFRESH_SCREEN
),
523 Hotkey('0' | WKC_ALT
, "crash_game", GHK_CRASH
),
524 Hotkey('1' | WKC_ALT
, "money", GHK_MONEY
),
525 Hotkey('2' | WKC_ALT
, "update_coordinates", GHK_UPDATE_COORDS
),
527 Hotkey('1' | WKC_CTRL
, "transparency_signs", GHK_TOGGLE_TRANSPARENCY
),
528 Hotkey('2' | WKC_CTRL
, "transparency_trees", GHK_TOGGLE_TRANSPARENCY
+ 1),
529 Hotkey('3' | WKC_CTRL
, "transparency_houses", GHK_TOGGLE_TRANSPARENCY
+ 2),
530 Hotkey('4' | WKC_CTRL
, "transparency_industries", GHK_TOGGLE_TRANSPARENCY
+ 3),
531 Hotkey('5' | WKC_CTRL
, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY
+ 4),
532 Hotkey('6' | WKC_CTRL
, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY
+ 5),
533 Hotkey('7' | WKC_CTRL
, "transparency_structures", GHK_TOGGLE_TRANSPARENCY
+ 6),
534 Hotkey('8' | WKC_CTRL
, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY
+ 7),
535 Hotkey('9' | WKC_CTRL
, "transparency_loading", GHK_TOGGLE_TRANSPARENCY
+ 8),
536 Hotkey('1' | WKC_CTRL
| WKC_SHIFT
, "invisibility_signs", GHK_TOGGLE_INVISIBILITY
),
537 Hotkey('2' | WKC_CTRL
| WKC_SHIFT
, "invisibility_trees", GHK_TOGGLE_INVISIBILITY
+ 1),
538 Hotkey('3' | WKC_CTRL
| WKC_SHIFT
, "invisibility_houses", GHK_TOGGLE_INVISIBILITY
+ 2),
539 Hotkey('4' | WKC_CTRL
| WKC_SHIFT
, "invisibility_industries", GHK_TOGGLE_INVISIBILITY
+ 3),
540 Hotkey('5' | WKC_CTRL
| WKC_SHIFT
, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY
+ 4),
541 Hotkey('6' | WKC_CTRL
| WKC_SHIFT
, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY
+ 5),
542 Hotkey('7' | WKC_CTRL
| WKC_SHIFT
, "invisibility_structures", GHK_TOGGLE_INVISIBILITY
+ 6),
543 Hotkey('8' | WKC_CTRL
| WKC_SHIFT
, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY
+ 7),
544 Hotkey('X' | WKC_CTRL
, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR
),
545 Hotkey('X', "toggle_transparency", GHK_TRANSPARANCY
),
546 #ifdef ENABLE_NETWORK
547 Hotkey(_ghk_chat_keys
, "chat", GHK_CHAT
),
548 Hotkey(_ghk_chat_all_keys
, "chat_all", GHK_CHAT_ALL
),
549 Hotkey(_ghk_chat_company_keys
, "chat_company", GHK_CHAT_COMPANY
),
550 Hotkey(_ghk_chat_server_keys
, "chat_server", GHK_CHAT_SERVER
),
552 Hotkey(WKC_PAGEUP
, "previous_map_mode", GHK_CHANGE_MAP_MODE_PREV
),
553 Hotkey(WKC_PAGEDOWN
, "next_map_mode", GHK_CHANGE_MAP_MODE_NEXT
),
556 HotkeyList
MainWindow::hotkeys("global", global_hotkeys
);
558 static WindowDesc
_main_window_desc(
559 WDP_MANUAL
, nullptr, 0, 0,
560 WC_MAIN_WINDOW
, WC_NONE
,
562 _nested_main_window_widgets
, lengthof(_nested_main_window_widgets
),
567 * Does the given keycode match one of the keycodes bound to 'quit game'?
568 * @param keycode The keycode that was pressed by the user.
569 * @return True iff the keycode matches one of the hotkeys for 'quit'.
571 bool IsQuitKey(uint16 keycode
)
573 int num
= MainWindow::hotkeys
.CheckMatch(keycode
);
574 return num
== GHK_QUIT
;
578 void ShowSelectGameWindow();
581 * Initialise the default colours (remaps and the likes), and load the main windows.
583 void SetupColoursAndInitialWindow()
585 for (uint i
= 0; i
!= 16; i
++) {
586 const byte
*b
= GetNonSprite(PALETTE_RECOLOUR_START
+ i
, ST_RECOLOUR
);
589 memcpy(_colour_gradient
[i
], b
+ 0xC6, sizeof(_colour_gradient
[i
]));
592 new MainWindow(&_main_window_desc
);
594 /* XXX: these are not done */
595 switch (_game_mode
) {
596 default: NOT_REACHED();
598 ShowSelectGameWindow();
609 * Show the vital in-game windows.
611 void ShowVitalWindows()
615 /* Status bad only for normal games */
616 if (_game_mode
== GM_EDITOR
) return;
622 * Size of the application screen changed.
623 * Adapt the game screen-size, re-allocate the open windows, and repaint everything
625 void GameSizeChanged()
627 _cur_resolution
.width
= _screen
.width
;
628 _cur_resolution
.height
= _screen
.height
;
630 RelocateAllWindows(_screen
.width
, _screen
.height
);
631 MarkWholeScreenDirty();