Go to the documentation of this file.
47 #include "table/strings.h"
79 void CcPlaySound_EXPLOSION(
const CommandCost &result,
TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
138 void ZoomInOrOutToCursorWindow(
bool in,
Window *w)
140 assert(w !=
nullptr);
142 if (_game_mode != GM_MENU) {
146 Point pt = GetTileZoomCenterWindow(in, w);
155 void FixTitleGameZoom()
157 if (_game_mode != GM_MENU)
return;
165 static const struct NWidgetPart _nested_main_window_widgets[] = {
177 GHK_RESET_OBJECT_TO_PLACE,
179 GHK_DELETE_NONVITAL_WINDOWS,
180 GHK_DELETE_ALL_MESSAGES,
185 GHK_TOGGLE_TRANSPARENCY,
186 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
187 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
202 static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
203 static const uint LINKGRAPH_DELAY = 450;
215 this->refresh.SetInterval(LINKGRAPH_DELAY);
220 if (!this->refresh.
Elapsed(delta_ms))
return;
222 this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
225 this->viewport->overlay->GetCompanyMask() == 0) {
236 if (_game_mode == GM_MENU) {
237 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};
238 static const uint LETTER_SPACING = 10;
239 int name_width = (
lengthof(title_sprites) - 1) * LETTER_SPACING;
241 for (uint i = 0; i <
lengthof(title_sprites); i++) {
244 int off_x = (this->
width - name_width) / 2;
246 for (uint i = 0; i <
lengthof(title_sprites); i++) {
247 DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
248 off_x +=
GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
255 if (hotkey == GHK_QUIT) {
256 HandleExitGameRequest();
282 case GHK_BOUNDING_BOXES:
286 case GHK_DIRTY_BLOCKS:
295 case GHK_CENTER_ZOOM: {
296 Point pt = GetTileBelowCursor();
312 *(
volatile byte *)0 = 0;
320 case GHK_UPDATE_COORDS:
324 case GHK_TOGGLE_TRANSPARENCY:
325 case GHK_TOGGLE_TRANSPARENCY + 1:
326 case GHK_TOGGLE_TRANSPARENCY + 2:
327 case GHK_TOGGLE_TRANSPARENCY + 3:
328 case GHK_TOGGLE_TRANSPARENCY + 4:
329 case GHK_TOGGLE_TRANSPARENCY + 5:
330 case GHK_TOGGLE_TRANSPARENCY + 6:
331 case GHK_TOGGLE_TRANSPARENCY + 7:
332 case GHK_TOGGLE_TRANSPARENCY + 8:
338 case GHK_TOGGLE_INVISIBILITY:
339 case GHK_TOGGLE_INVISIBILITY + 1:
340 case GHK_TOGGLE_INVISIBILITY + 2:
341 case GHK_TOGGLE_INVISIBILITY + 3:
342 case GHK_TOGGLE_INVISIBILITY + 4:
343 case GHK_TOGGLE_INVISIBILITY + 5:
344 case GHK_TOGGLE_INVISIBILITY + 6:
345 case GHK_TOGGLE_INVISIBILITY + 7:
351 case GHK_TRANSPARENCY_TOOLBAR:
355 case GHK_TRANSPARANCY:
362 if (cio ==
nullptr)
break;
372 case GHK_CHAT_COMPANY:
375 if (cio ==
nullptr)
break;
381 case GHK_CHAT_SERVER:
391 case GHK_CLOSE_ERROR:
406 this->refresh.SetInterval(LINKGRAPH_DELAY);
412 ZoomInOrOutToCursorWindow(wheel < 0,
this);
421 this->refresh.SetInterval(LINKGRAPH_DELAY);
432 if (!gui_scope)
return;
440 const uint16 _ghk_quit_keys[] = {
'Q' | WKC_CTRL,
'Q' | WKC_META, 0};
441 const uint16 _ghk_abandon_keys[] = {
'W' | WKC_CTRL,
'W' | WKC_META, 0};
442 const uint16 _ghk_chat_keys[] = {WKC_RETURN,
'T', 0};
443 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT |
'T', 0};
444 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL |
'T', 0};
445 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT |
'T', 0};
447 static Hotkey global_hotkeys[] = {
448 Hotkey(_ghk_quit_keys,
"quit", GHK_QUIT),
449 Hotkey(_ghk_abandon_keys,
"abandon", GHK_ABANDON),
450 Hotkey(WKC_BACKQUOTE,
"console", GHK_CONSOLE),
451 Hotkey(
'B' | WKC_CTRL,
"bounding_boxes", GHK_BOUNDING_BOXES),
452 Hotkey(
'I' | WKC_CTRL,
"dirty_blocks", GHK_DIRTY_BLOCKS),
453 Hotkey(
'C',
"center", GHK_CENTER),
454 Hotkey(
'Z',
"center_zoom", GHK_CENTER_ZOOM),
455 Hotkey(WKC_ESC,
"reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
456 Hotkey(WKC_DELETE,
"delete_windows", GHK_DELETE_WINDOWS),
457 Hotkey(WKC_DELETE | WKC_SHIFT,
"delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
458 Hotkey(WKC_DELETE | WKC_CTRL,
"delete_all_messages", GHK_DELETE_ALL_MESSAGES),
459 Hotkey(
'R' | WKC_CTRL,
"refresh_screen", GHK_REFRESH_SCREEN),
461 Hotkey(
'0' | WKC_ALT,
"crash_game", GHK_CRASH),
462 Hotkey(
'1' | WKC_ALT,
"money", GHK_MONEY),
463 Hotkey(
'2' | WKC_ALT,
"update_coordinates", GHK_UPDATE_COORDS),
465 Hotkey(
'1' | WKC_CTRL,
"transparency_signs", GHK_TOGGLE_TRANSPARENCY),
466 Hotkey(
'2' | WKC_CTRL,
"transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
467 Hotkey(
'3' | WKC_CTRL,
"transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
468 Hotkey(
'4' | WKC_CTRL,
"transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
469 Hotkey(
'5' | WKC_CTRL,
"transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
470 Hotkey(
'6' | WKC_CTRL,
"transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
471 Hotkey(
'7' | WKC_CTRL,
"transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
472 Hotkey(
'8' | WKC_CTRL,
"transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
473 Hotkey(
'9' | WKC_CTRL,
"transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
474 Hotkey(
'1' | WKC_CTRL | WKC_SHIFT,
"invisibility_signs", GHK_TOGGLE_INVISIBILITY),
475 Hotkey(
'2' | WKC_CTRL | WKC_SHIFT,
"invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
476 Hotkey(
'3' | WKC_CTRL | WKC_SHIFT,
"invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
477 Hotkey(
'4' | WKC_CTRL | WKC_SHIFT,
"invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
478 Hotkey(
'5' | WKC_CTRL | WKC_SHIFT,
"invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
479 Hotkey(
'6' | WKC_CTRL | WKC_SHIFT,
"invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
480 Hotkey(
'7' | WKC_CTRL | WKC_SHIFT,
"invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
481 Hotkey(
'8' | WKC_CTRL | WKC_SHIFT,
"invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
482 Hotkey(
'X' | WKC_CTRL,
"transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
483 Hotkey(
'X',
"toggle_transparency", GHK_TRANSPARANCY),
484 Hotkey(_ghk_chat_keys,
"chat", GHK_CHAT),
485 Hotkey(_ghk_chat_all_keys,
"chat_all", GHK_CHAT_ALL),
486 Hotkey(_ghk_chat_company_keys,
"chat_company", GHK_CHAT_COMPANY),
487 Hotkey(_ghk_chat_server_keys,
"chat_server", GHK_CHAT_SERVER),
488 Hotkey(WKC_SPACE,
"close_news", GHK_CLOSE_NEWS),
489 Hotkey(WKC_SPACE,
"close_error", GHK_CLOSE_ERROR),
492 HotkeyList MainWindow::hotkeys(
"global", global_hotkeys);
498 _nested_main_window_widgets,
lengthof(_nested_main_window_widgets),
509 int num = MainWindow::hotkeys.
CheckMatch(keycode);
510 return num == GHK_QUIT;
514 void ShowSelectGameWindow();
521 for (uint i = 0; i != 16; i++) {
531 switch (_game_mode) {
532 default: NOT_REACHED();
534 ShowSelectGameWindow();
552 if (_game_mode == GM_EDITOR)
return;
@ ES_HANDLED
The passed event is handled.
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
uint32 TileIndex
The index/ID of a Tile.
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-...
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
static void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
List of hotkeys for a window.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
@ ZOOM_OUT
Zoom out (get helicopter view).
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
CompanyID client_playas
As which company is this client playing (CompanyID)
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
int width
Screen width of the viewport.
ViewportData * viewport
Pointer to viewport data, if present.
bool _network_server
network-server is active
int height
Screen height of the viewport.
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members where he/she can chat to.
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
@ ZOOM_NONE
Hack, used to update the button status.
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
@ SND_15_BEEP
19 == 0x13 GUI button click
static void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
ZoomLevel
All zoom levels we know.
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
ClientSettings _settings_client
The current settings for this game.
ZoomLevel _gui_zoom
GUI Zoom level.
int virtual_top
Virtual top coordinate.
ZoomLevel zoom_max
maximum zoom out level
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
bool Succeeded() const
Did this command succeed?
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
High level window description.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
@ ZOOM_IN
Zoom in (get more detailed view).
uint8 scrollwheel_scrolling
scrolling using the scroll wheel?
bool HideActiveErrorMessage()
Close active error message window.
Handles drawing of links into some window.
Data structure for viewport, display of a part of the world.
void ShowVitalWindows()
Show the vital in-game windows.
Common return value for all commands.
SoundSettings sound
sound effect settings
uint32 CursorID
The number of the cursor (sprite)
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
int virtual_left
Virtual left coordinate.
@ WF_WHITE_BORDER
Window white border counter bit mask.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void OnPaint() override
The window must be repainted.
@ ES_NOT_HANDLED
The passed event is not handled.
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
WindowFlags flags
Window flags.
@ CLIENT_ID_SERVER
Servers always have this ID.
void GameSizeChanged()
Size of the application screen changed.
bool _networking
are we in networking mode?
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int virtual_width
width << zoom
Coordinates of a point in 2D.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
@ WID_M_VIEWPORT
Main window viewport.
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
WindowNumber window_number
Window number within the window class.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
ClientID _network_own_client_id
Our client identifier.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
ZoomLevel zoom_min
minimum zoom out level
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void DeleteNonVitalWindows()
Try to delete a non-vital window.
SwitchMode _switch_mode
The next mainloop command.
bool confirm
Play sound effect on successful constructions or other actions.
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
bool IsQuitKey(uint16 keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
void DeleteAllMessages()
Delete all messages and their corresponding window (if any).
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
void DeleteAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
void ShowTransparencyToolbar()
Show the transparency toolbar.
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
EventState
State of handling an event.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
WindowClass window_class
Window class.
@ WC_MAIN_WINDOW
Main window; Window numbers:
@ SM_MENU
Switch to game intro menu.
int CheckMatch(uint16 keycode, bool global_only=false) const
Check if a keycode is bound to something.
bool Elapsed(uint delta)
Test if a timer has elapsed.
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
HighLightStyle
Highlighting draw styles.
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool click_beep
Beep on a random selection of buttons.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
ZoomLevel zoom
The zoom level of the viewport.
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
static void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
@ CMD_MONEY_CHEAT
do the money cheat
bool HideActiveNewsMessage()
Close active news message window.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Data structure for an opened window.
@ ST_RECOLOUR
Recolour sprite.
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...
void DrawWidgets() const
Paint all widgets of a window.
static bool HasModalProgress()
Check if we are currently in a modal progress state.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
int virtual_height
height << zoom
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
#define CLRBITS(x, y)
Clears several bits in a variable.
void OnResize() override
Called after the window got resized.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void ShowStatusBar()
Show our status bar.
Dimension _cur_resolution
The current resolution.
Container for all information known about a client.
ZoomStateChange
Directions of zooming.
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
GUISettings gui
settings related to the GUI
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
All data for a single hotkey.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.