49 #include "table/strings.h"
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 constexpr
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,
228 if (this->
viewport->overlay->GetCargoMask() == 0 ||
229 this->viewport->overlay->GetCompanyMask() == 0) {
233 this->
viewport->overlay->SetDirty();
256 if (_game_mode == GM_MENU) {
257 static const std::initializer_list<SpriteID> title_sprites = {SPR_OTTD_O, SPR_OTTD_P, SPR_OTTD_E, SPR_OTTD_N, SPR_OTTD_T, SPR_OTTD_T, SPR_OTTD_D};
259 int name_width =
static_cast<int>(std::size(title_sprites) - 1) * letter_spacing;
261 for (
const SpriteID &sprite : title_sprites) {
264 int off_x = (this->
width - name_width) / 2;
266 for (
const SpriteID &sprite : title_sprites) {
275 if (hotkey == GHK_QUIT) {
276 HandleExitGameRequest();
302 case GHK_BOUNDING_BOXES:
306 case GHK_DIRTY_BLOCKS:
310 case GHK_WIDGET_OUTLINES:
319 case GHK_CENTER_ZOOM: {
320 Point pt = GetTileBelowCursor();
336 *(
volatile uint8_t *)
nullptr = 0;
344 case GHK_UPDATE_COORDS:
348 case GHK_TOGGLE_TRANSPARENCY:
349 case GHK_TOGGLE_TRANSPARENCY + 1:
350 case GHK_TOGGLE_TRANSPARENCY + 2:
351 case GHK_TOGGLE_TRANSPARENCY + 3:
352 case GHK_TOGGLE_TRANSPARENCY + 4:
353 case GHK_TOGGLE_TRANSPARENCY + 5:
354 case GHK_TOGGLE_TRANSPARENCY + 6:
355 case GHK_TOGGLE_TRANSPARENCY + 7:
356 case GHK_TOGGLE_TRANSPARENCY + 8:
362 case GHK_TOGGLE_INVISIBILITY:
363 case GHK_TOGGLE_INVISIBILITY + 1:
364 case GHK_TOGGLE_INVISIBILITY + 2:
365 case GHK_TOGGLE_INVISIBILITY + 3:
366 case GHK_TOGGLE_INVISIBILITY + 4:
367 case GHK_TOGGLE_INVISIBILITY + 5:
368 case GHK_TOGGLE_INVISIBILITY + 6:
369 case GHK_TOGGLE_INVISIBILITY + 7:
375 case GHK_TRANSPARENCY_TOOLBAR:
379 case GHK_TRANSPARANCY:
386 if (cio ==
nullptr)
break;
396 case GHK_CHAT_COMPANY:
399 if (cio ==
nullptr)
break;
405 case GHK_CHAT_SERVER:
415 case GHK_CLOSE_ERROR:
424 void OnScroll(
Point delta)
override
430 this->refresh_timeout.
Reset();
433 void OnMouseWheel(
int wheel)
override
442 ZoomInOrOutToCursorWindow(in,
this);
452 this->refresh_timeout.
Reset();
456 bool OnTooltip([[maybe_unused]]
Point pt,
WidgetID widget, TooltipCloseCondition close_cond)
override
459 return this->
viewport->overlay->ShowTooltip(pt, close_cond);
467 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
469 if (!gui_scope)
return;
475 Hotkey({
'Q' | WKC_CTRL,
'Q' | WKC_META},
"quit", GHK_QUIT),
476 Hotkey({
'W' | WKC_CTRL,
'W' | WKC_META},
"abandon", GHK_ABANDON),
477 Hotkey(WKC_BACKQUOTE,
"console", GHK_CONSOLE),
478 Hotkey(
'B' | WKC_CTRL,
"bounding_boxes", GHK_BOUNDING_BOXES),
479 Hotkey(
'I' | WKC_CTRL,
"dirty_blocks", GHK_DIRTY_BLOCKS),
480 Hotkey(
'O' | WKC_CTRL,
"widget_outlines", GHK_WIDGET_OUTLINES),
481 Hotkey(
'C',
"center", GHK_CENTER),
482 Hotkey(
'Z',
"center_zoom", GHK_CENTER_ZOOM),
483 Hotkey(WKC_ESC,
"reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
484 Hotkey(WKC_DELETE,
"delete_windows", GHK_DELETE_WINDOWS),
485 Hotkey(WKC_DELETE | WKC_SHIFT,
"delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
486 Hotkey(WKC_DELETE | WKC_CTRL,
"delete_all_messages", GHK_DELETE_ALL_MESSAGES),
487 Hotkey(
'R' | WKC_CTRL,
"refresh_screen", GHK_REFRESH_SCREEN),
489 Hotkey(
'0' | WKC_ALT,
"crash_game", GHK_CRASH),
490 Hotkey(
'1' | WKC_ALT,
"money", GHK_MONEY),
491 Hotkey(
'2' | WKC_ALT,
"update_coordinates", GHK_UPDATE_COORDS),
493 Hotkey(
'1' | WKC_CTRL,
"transparency_signs", GHK_TOGGLE_TRANSPARENCY),
494 Hotkey(
'2' | WKC_CTRL,
"transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
495 Hotkey(
'3' | WKC_CTRL,
"transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
496 Hotkey(
'4' | WKC_CTRL,
"transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
497 Hotkey(
'5' | WKC_CTRL,
"transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
498 Hotkey(
'6' | WKC_CTRL,
"transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
499 Hotkey(
'7' | WKC_CTRL,
"transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
500 Hotkey(
'8' | WKC_CTRL,
"transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
501 Hotkey(
'9' | WKC_CTRL,
"transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
502 Hotkey(
'1' | WKC_CTRL | WKC_SHIFT,
"invisibility_signs", GHK_TOGGLE_INVISIBILITY),
503 Hotkey(
'2' | WKC_CTRL | WKC_SHIFT,
"invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
504 Hotkey(
'3' | WKC_CTRL | WKC_SHIFT,
"invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
505 Hotkey(
'4' | WKC_CTRL | WKC_SHIFT,
"invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
506 Hotkey(
'5' | WKC_CTRL | WKC_SHIFT,
"invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
507 Hotkey(
'6' | WKC_CTRL | WKC_SHIFT,
"invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
508 Hotkey(
'7' | WKC_CTRL | WKC_SHIFT,
"invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
509 Hotkey(
'8' | WKC_CTRL | WKC_SHIFT,
"invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
510 Hotkey(
'X' | WKC_CTRL,
"transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
511 Hotkey(
'X',
"toggle_transparency", GHK_TRANSPARANCY),
512 Hotkey({WKC_RETURN,
'T'},
"chat", GHK_CHAT),
513 Hotkey({WKC_SHIFT | WKC_RETURN, WKC_SHIFT |
'T'},
"chat_all", GHK_CHAT_ALL),
514 Hotkey({WKC_CTRL | WKC_RETURN, WKC_CTRL |
'T'},
"chat_company", GHK_CHAT_COMPANY),
515 Hotkey({WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT |
'T'},
"chat_server", GHK_CHAT_SERVER),
516 Hotkey(WKC_SPACE,
"close_news", GHK_CLOSE_NEWS),
517 Hotkey(WKC_SPACE,
"close_error", GHK_CLOSE_ERROR),
525 _nested_main_window_widgets,
536 int num = MainWindow::hotkeys.
CheckMatch(keycode);
537 return num == GHK_QUIT;
541 void ShowSelectGameWindow();
548 for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) {
550 assert(b !=
nullptr);
551 for (ColourShade j = SHADE_BEGIN; j < SHADE_END; j++) {
559 switch (_game_mode) {
560 default: NOT_REACHED();
562 ShowSelectGameWindow();
580 if (_game_mode == GM_EDITOR)
return;
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
#define CLRBITS(x, y)
Clears several bits in a variable.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
void Reset()
Reset the timer, so it will fire again after the timeout.
Functions related to commands.
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
Functions related to companies.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
GUI related functions in the console.
Functions to handle different currencies.
Dimension _cur_resolution
The current resolution.
Functions related to errors.
bool HideActiveErrorMessage()
Close active error message window.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
SwitchMode _switch_mode
The next mainloop command.
ZoomLevel _gui_zoom
GUI Zoom level.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ Recolour
Recolour sprite.
uint32_t CursorID
The number of the cursor (sprite)
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Hotkey related functions.
Declaration of linkgraph overlay GUI.
void ShowVitalWindows()
Show the vital in-game windows.
void GameSizeChanged()
Size of the application screen changed.
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Types related to the main widgets.
@ WID_M_VIEWPORT
Main window viewport.
Functions related to maps.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Miscellaneous command definitions.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
ClientID _network_own_client_id
Our client identifier.
Basic functions/variables used all over the place.
Base core network types and some helper functions to access them.
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Network functions used by other parts of OpenTTD.
GUIs related to networking.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
@ CLIENT_ID_SERVER
Servers always have this ID.
bool HideActiveNewsMessage()
Close active news message window.
GUI functions related to the news.
@ SM_MENU
Switch to game intro menu.
void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_index)
Set colour gradient palette index.
Functions related to modal progress.
bool HasModalProgress()
Check if we are currently in a modal progress state.
A number of safeguards to prevent using unsafe methods.
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Functions/types related to saving and loading games.
ClientSettings _settings_client
The current settings for this game.
@ SWS_OFF
Scroll wheel has no effect.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Functions to cache sprites in memory.
This file contains all sprite-related enums and defines.
void ShowStatusBar()
Show our status bar.
Functions, definitions and such used only by the GUI.
Definition of base types and functions in a cross-platform compatible way.
Functions related to OTTD's strings.
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
ZoomLevel zoom_min
minimum zoom out level
ZoomLevel zoom_max
maximum zoom out level
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
List of hotkeys for a window.
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
All data for a single hotkey.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
TimeoutTimer< TimerWindow > refresh_timeout
Sometimes when something happened, force an update to the link-graph a bit sooner.
IntervalTimer< TimerWindow > refresh_interval
Refresh the link-graph overlay on a regular interval.
void OnResize() override
Called after the window got resized.
void OnPaint() override
The window must be repainted.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void RefreshLinkGraph()
Refresh the link-graph overlay.
Container for all information known about a client.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
CompanyID client_playas
As which company is this client playing (CompanyID)
Coordinates of a point in 2D.
bool click_beep
Beep on a random selection of buttons.
bool confirm
Play sound effect on successful constructions or other actions.
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Data structure for viewport, display of a part of the world.
int width
Screen width of the viewport.
ZoomLevel zoom
The zoom level of the viewport.
int virtual_top
Virtual top coordinate.
int virtual_left
Virtual left coordinate.
int virtual_width
width << zoom
int height
Screen height of the viewport.
int virtual_height
height << zoom
High level window description.
Data structure for an opened window.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
WindowClass window_class
Window class.
ViewportData * viewport
Pointer to viewport data, if present.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
WindowFlags flags
Window flags.
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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...
HighLightStyle
Highlighting draw styles.
Definition of Interval and OneShot timers.
Definition of the Window system.
Functions related to transparency.
void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
void ShowTransparencyToolbar()
Show the transparency toolbar.
GUI functions related to transparency.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Functions related to (drawing on) viewports.
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
ZoomStateChange
Directions of zooming.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_NONE
Hack, used to update the button status.
@ ZOOM_OUT
Zoom out (get helicopter view).
void CloseNonVitalWindows()
Try to close a non-vital window.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Window * GetMainWindow()
Get the main window, i.e.
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 RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WF_WHITE_BORDER
Window white border counter bit mask.
@ WDF_NO_CLOSE
This window can't be interactively closed.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_MAIN_WINDOW
Main window; Window numbers:
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Functions related to zooming.
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_MIN) When shifting right,...
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
ZoomLevel
All zoom levels we know.
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.