Go to the documentation of this file.
48 #include "table/strings.h"
139 void ZoomInOrOutToCursorWindow(
bool in,
Window *w)
141 assert(w !=
nullptr);
143 if (_game_mode != GM_MENU) {
147 Point pt = GetTileZoomCenterWindow(in, w);
156 void FixTitleGameZoom(
int zoom_adjust)
158 if (_game_mode != GM_MENU)
return;
178 static const struct NWidgetPart _nested_main_window_widgets[] = {
190 GHK_RESET_OBJECT_TO_PLACE,
192 GHK_DELETE_NONVITAL_WINDOWS,
193 GHK_DELETE_ALL_MESSAGES,
198 GHK_TOGGLE_TRANSPARENCY,
199 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
200 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
215 static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
216 static const uint LINKGRAPH_DELAY = 450;
228 this->refresh.SetInterval(LINKGRAPH_DELAY);
233 if (!this->refresh.
Elapsed(delta_ms))
return;
235 this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
238 this->viewport->overlay->GetCompanyMask() == 0) {
249 if (_game_mode == GM_MENU) {
250 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};
252 int name_width = (
lengthof(title_sprites) - 1) * letter_spacing;
254 for (uint i = 0; i <
lengthof(title_sprites); i++) {
257 int off_x = (this->
width - name_width) / 2;
259 for (uint i = 0; i <
lengthof(title_sprites); i++) {
261 off_x +=
GetSpriteSize(title_sprites[i]).width + letter_spacing;
268 if (hotkey == GHK_QUIT) {
269 HandleExitGameRequest();
295 case GHK_BOUNDING_BOXES:
299 case GHK_DIRTY_BLOCKS:
308 case GHK_CENTER_ZOOM: {
309 Point pt = GetTileBelowCursor();
325 *(
volatile byte *)
nullptr = 0;
333 case GHK_UPDATE_COORDS:
337 case GHK_TOGGLE_TRANSPARENCY:
338 case GHK_TOGGLE_TRANSPARENCY + 1:
339 case GHK_TOGGLE_TRANSPARENCY + 2:
340 case GHK_TOGGLE_TRANSPARENCY + 3:
341 case GHK_TOGGLE_TRANSPARENCY + 4:
342 case GHK_TOGGLE_TRANSPARENCY + 5:
343 case GHK_TOGGLE_TRANSPARENCY + 6:
344 case GHK_TOGGLE_TRANSPARENCY + 7:
345 case GHK_TOGGLE_TRANSPARENCY + 8:
351 case GHK_TOGGLE_INVISIBILITY:
352 case GHK_TOGGLE_INVISIBILITY + 1:
353 case GHK_TOGGLE_INVISIBILITY + 2:
354 case GHK_TOGGLE_INVISIBILITY + 3:
355 case GHK_TOGGLE_INVISIBILITY + 4:
356 case GHK_TOGGLE_INVISIBILITY + 5:
357 case GHK_TOGGLE_INVISIBILITY + 6:
358 case GHK_TOGGLE_INVISIBILITY + 7:
364 case GHK_TRANSPARENCY_TOOLBAR:
368 case GHK_TRANSPARANCY:
375 if (cio ==
nullptr)
break;
385 case GHK_CHAT_COMPANY:
388 if (cio ==
nullptr)
break;
394 case GHK_CHAT_SERVER:
404 case GHK_CLOSE_ERROR:
419 this->refresh.SetInterval(LINKGRAPH_DELAY);
425 ZoomInOrOutToCursorWindow(wheel < 0,
this);
434 this->refresh.SetInterval(LINKGRAPH_DELAY);
441 return this->
viewport->overlay->ShowTooltip(pt, close_cond);
451 if (!gui_scope)
return;
459 const uint16 _ghk_quit_keys[] = {
'Q' | WKC_CTRL,
'Q' | WKC_META, 0};
460 const uint16 _ghk_abandon_keys[] = {
'W' | WKC_CTRL,
'W' | WKC_META, 0};
461 const uint16 _ghk_chat_keys[] = {WKC_RETURN,
'T', 0};
462 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT |
'T', 0};
463 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL |
'T', 0};
464 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT |
'T', 0};
466 static Hotkey global_hotkeys[] = {
467 Hotkey(_ghk_quit_keys,
"quit", GHK_QUIT),
468 Hotkey(_ghk_abandon_keys,
"abandon", GHK_ABANDON),
469 Hotkey(WKC_BACKQUOTE,
"console", GHK_CONSOLE),
470 Hotkey(
'B' | WKC_CTRL,
"bounding_boxes", GHK_BOUNDING_BOXES),
471 Hotkey(
'I' | WKC_CTRL,
"dirty_blocks", GHK_DIRTY_BLOCKS),
472 Hotkey(
'C',
"center", GHK_CENTER),
473 Hotkey(
'Z',
"center_zoom", GHK_CENTER_ZOOM),
474 Hotkey(WKC_ESC,
"reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
475 Hotkey(WKC_DELETE,
"delete_windows", GHK_DELETE_WINDOWS),
476 Hotkey(WKC_DELETE | WKC_SHIFT,
"delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
477 Hotkey(WKC_DELETE | WKC_CTRL,
"delete_all_messages", GHK_DELETE_ALL_MESSAGES),
478 Hotkey(
'R' | WKC_CTRL,
"refresh_screen", GHK_REFRESH_SCREEN),
480 Hotkey(
'0' | WKC_ALT,
"crash_game", GHK_CRASH),
481 Hotkey(
'1' | WKC_ALT,
"money", GHK_MONEY),
482 Hotkey(
'2' | WKC_ALT,
"update_coordinates", GHK_UPDATE_COORDS),
484 Hotkey(
'1' | WKC_CTRL,
"transparency_signs", GHK_TOGGLE_TRANSPARENCY),
485 Hotkey(
'2' | WKC_CTRL,
"transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
486 Hotkey(
'3' | WKC_CTRL,
"transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
487 Hotkey(
'4' | WKC_CTRL,
"transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
488 Hotkey(
'5' | WKC_CTRL,
"transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
489 Hotkey(
'6' | WKC_CTRL,
"transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
490 Hotkey(
'7' | WKC_CTRL,
"transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
491 Hotkey(
'8' | WKC_CTRL,
"transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
492 Hotkey(
'9' | WKC_CTRL,
"transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
493 Hotkey(
'1' | WKC_CTRL | WKC_SHIFT,
"invisibility_signs", GHK_TOGGLE_INVISIBILITY),
494 Hotkey(
'2' | WKC_CTRL | WKC_SHIFT,
"invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
495 Hotkey(
'3' | WKC_CTRL | WKC_SHIFT,
"invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
496 Hotkey(
'4' | WKC_CTRL | WKC_SHIFT,
"invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
497 Hotkey(
'5' | WKC_CTRL | WKC_SHIFT,
"invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
498 Hotkey(
'6' | WKC_CTRL | WKC_SHIFT,
"invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
499 Hotkey(
'7' | WKC_CTRL | WKC_SHIFT,
"invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
500 Hotkey(
'8' | WKC_CTRL | WKC_SHIFT,
"invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
501 Hotkey(
'X' | WKC_CTRL,
"transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
502 Hotkey(
'X',
"toggle_transparency", GHK_TRANSPARANCY),
503 Hotkey(_ghk_chat_keys,
"chat", GHK_CHAT),
504 Hotkey(_ghk_chat_all_keys,
"chat_all", GHK_CHAT_ALL),
505 Hotkey(_ghk_chat_company_keys,
"chat_company", GHK_CHAT_COMPANY),
506 Hotkey(_ghk_chat_server_keys,
"chat_server", GHK_CHAT_SERVER),
507 Hotkey(WKC_SPACE,
"close_news", GHK_CLOSE_NEWS),
508 Hotkey(WKC_SPACE,
"close_error", GHK_CLOSE_ERROR),
511 HotkeyList MainWindow::hotkeys(
"global", global_hotkeys);
517 _nested_main_window_widgets,
lengthof(_nested_main_window_widgets),
528 int num = MainWindow::hotkeys.
CheckMatch(keycode);
529 return num == GHK_QUIT;
533 void ShowSelectGameWindow();
540 for (uint i = 0; i != 16; i++) {
550 switch (_game_mode) {
551 default: NOT_REACHED();
553 ShowSelectGameWindow();
571 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.
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)
Commands
List of commands.
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)
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.
static ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
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)
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.
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
@ 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.