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(
int zoom_adjust)
157 if (_game_mode != GM_MENU)
return;
177 static const struct NWidgetPart _nested_main_window_widgets[] = {
189 GHK_RESET_OBJECT_TO_PLACE,
191 GHK_DELETE_NONVITAL_WINDOWS,
192 GHK_DELETE_ALL_MESSAGES,
197 GHK_TOGGLE_TRANSPARENCY,
198 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
199 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
214 static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
215 static const uint LINKGRAPH_DELAY = 450;
227 this->refresh.SetInterval(LINKGRAPH_DELAY);
232 if (!this->refresh.
Elapsed(delta_ms))
return;
234 this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
237 this->viewport->overlay->GetCompanyMask() == 0) {
248 if (_game_mode == GM_MENU) {
249 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};
250 static const uint LETTER_SPACING = 10;
251 int name_width = (
lengthof(title_sprites) - 1) * LETTER_SPACING;
253 for (uint i = 0; i <
lengthof(title_sprites); i++) {
256 int off_x = (this->
width - name_width) / 2;
258 for (uint i = 0; i <
lengthof(title_sprites); i++) {
259 DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
260 off_x +=
GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
267 if (hotkey == GHK_QUIT) {
268 HandleExitGameRequest();
294 case GHK_BOUNDING_BOXES:
298 case GHK_DIRTY_BLOCKS:
307 case GHK_CENTER_ZOOM: {
308 Point pt = GetTileBelowCursor();
324 *(
volatile byte *)
nullptr = 0;
332 case GHK_UPDATE_COORDS:
336 case GHK_TOGGLE_TRANSPARENCY:
337 case GHK_TOGGLE_TRANSPARENCY + 1:
338 case GHK_TOGGLE_TRANSPARENCY + 2:
339 case GHK_TOGGLE_TRANSPARENCY + 3:
340 case GHK_TOGGLE_TRANSPARENCY + 4:
341 case GHK_TOGGLE_TRANSPARENCY + 5:
342 case GHK_TOGGLE_TRANSPARENCY + 6:
343 case GHK_TOGGLE_TRANSPARENCY + 7:
344 case GHK_TOGGLE_TRANSPARENCY + 8:
350 case GHK_TOGGLE_INVISIBILITY:
351 case GHK_TOGGLE_INVISIBILITY + 1:
352 case GHK_TOGGLE_INVISIBILITY + 2:
353 case GHK_TOGGLE_INVISIBILITY + 3:
354 case GHK_TOGGLE_INVISIBILITY + 4:
355 case GHK_TOGGLE_INVISIBILITY + 5:
356 case GHK_TOGGLE_INVISIBILITY + 6:
357 case GHK_TOGGLE_INVISIBILITY + 7:
363 case GHK_TRANSPARENCY_TOOLBAR:
367 case GHK_TRANSPARANCY:
374 if (cio ==
nullptr)
break;
384 case GHK_CHAT_COMPANY:
387 if (cio ==
nullptr)
break;
393 case GHK_CHAT_SERVER:
403 case GHK_CLOSE_ERROR:
418 this->refresh.SetInterval(LINKGRAPH_DELAY);
424 ZoomInOrOutToCursorWindow(wheel < 0,
this);
433 this->refresh.SetInterval(LINKGRAPH_DELAY);
444 if (!gui_scope)
return;
452 const uint16 _ghk_quit_keys[] = {
'Q' | WKC_CTRL,
'Q' | WKC_META, 0};
453 const uint16 _ghk_abandon_keys[] = {
'W' | WKC_CTRL,
'W' | WKC_META, 0};
454 const uint16 _ghk_chat_keys[] = {WKC_RETURN,
'T', 0};
455 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT |
'T', 0};
456 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL |
'T', 0};
457 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT |
'T', 0};
459 static Hotkey global_hotkeys[] = {
460 Hotkey(_ghk_quit_keys,
"quit", GHK_QUIT),
461 Hotkey(_ghk_abandon_keys,
"abandon", GHK_ABANDON),
462 Hotkey(WKC_BACKQUOTE,
"console", GHK_CONSOLE),
463 Hotkey(
'B' | WKC_CTRL,
"bounding_boxes", GHK_BOUNDING_BOXES),
464 Hotkey(
'I' | WKC_CTRL,
"dirty_blocks", GHK_DIRTY_BLOCKS),
465 Hotkey(
'C',
"center", GHK_CENTER),
466 Hotkey(
'Z',
"center_zoom", GHK_CENTER_ZOOM),
467 Hotkey(WKC_ESC,
"reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
468 Hotkey(WKC_DELETE,
"delete_windows", GHK_DELETE_WINDOWS),
469 Hotkey(WKC_DELETE | WKC_SHIFT,
"delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
470 Hotkey(WKC_DELETE | WKC_CTRL,
"delete_all_messages", GHK_DELETE_ALL_MESSAGES),
471 Hotkey(
'R' | WKC_CTRL,
"refresh_screen", GHK_REFRESH_SCREEN),
473 Hotkey(
'0' | WKC_ALT,
"crash_game", GHK_CRASH),
474 Hotkey(
'1' | WKC_ALT,
"money", GHK_MONEY),
475 Hotkey(
'2' | WKC_ALT,
"update_coordinates", GHK_UPDATE_COORDS),
477 Hotkey(
'1' | WKC_CTRL,
"transparency_signs", GHK_TOGGLE_TRANSPARENCY),
478 Hotkey(
'2' | WKC_CTRL,
"transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
479 Hotkey(
'3' | WKC_CTRL,
"transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
480 Hotkey(
'4' | WKC_CTRL,
"transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
481 Hotkey(
'5' | WKC_CTRL,
"transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
482 Hotkey(
'6' | WKC_CTRL,
"transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
483 Hotkey(
'7' | WKC_CTRL,
"transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
484 Hotkey(
'8' | WKC_CTRL,
"transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
485 Hotkey(
'9' | WKC_CTRL,
"transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
486 Hotkey(
'1' | WKC_CTRL | WKC_SHIFT,
"invisibility_signs", GHK_TOGGLE_INVISIBILITY),
487 Hotkey(
'2' | WKC_CTRL | WKC_SHIFT,
"invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
488 Hotkey(
'3' | WKC_CTRL | WKC_SHIFT,
"invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
489 Hotkey(
'4' | WKC_CTRL | WKC_SHIFT,
"invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
490 Hotkey(
'5' | WKC_CTRL | WKC_SHIFT,
"invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
491 Hotkey(
'6' | WKC_CTRL | WKC_SHIFT,
"invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
492 Hotkey(
'7' | WKC_CTRL | WKC_SHIFT,
"invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
493 Hotkey(
'8' | WKC_CTRL | WKC_SHIFT,
"invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
494 Hotkey(
'X' | WKC_CTRL,
"transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
495 Hotkey(
'X',
"toggle_transparency", GHK_TRANSPARANCY),
496 Hotkey(_ghk_chat_keys,
"chat", GHK_CHAT),
497 Hotkey(_ghk_chat_all_keys,
"chat_all", GHK_CHAT_ALL),
498 Hotkey(_ghk_chat_company_keys,
"chat_company", GHK_CHAT_COMPANY),
499 Hotkey(_ghk_chat_server_keys,
"chat_server", GHK_CHAT_SERVER),
500 Hotkey(WKC_SPACE,
"close_news", GHK_CLOSE_NEWS),
501 Hotkey(WKC_SPACE,
"close_error", GHK_CLOSE_ERROR),
504 HotkeyList MainWindow::hotkeys(
"global", global_hotkeys);
510 _nested_main_window_widgets,
lengthof(_nested_main_window_widgets),
521 int num = MainWindow::hotkeys.
CheckMatch(keycode);
522 return num == GHK_QUIT;
526 void ShowSelectGameWindow();
533 for (uint i = 0; i != 16; i++) {
543 switch (_game_mode) {
544 default: NOT_REACHED();
546 ShowSelectGameWindow();
564 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 who they 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.
void CloseNonVitalWindows()
Try to close a non-vital window.
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.
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 close their corresponding window (if any).
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
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)
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
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.