|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
49 #include "table/strings.h"
140 void ZoomInOrOutToCursorWindow(
bool in,
Window *w)
142 assert(w !=
nullptr);
144 if (_game_mode != GM_MENU) {
148 Point pt = GetTileZoomCenterWindow(in, w);
157 void FixTitleGameZoom(
int zoom_adjust)
159 if (_game_mode != GM_MENU)
return;
179 static constexpr
NWidgetPart _nested_main_window_widgets[] = {
192 GHK_RESET_OBJECT_TO_PLACE,
194 GHK_DELETE_NONVITAL_WINDOWS,
195 GHK_DELETE_ALL_MESSAGES,
200 GHK_TOGGLE_TRANSPARENCY,
201 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
202 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
230 if (this->
viewport->overlay->GetCargoMask() == 0 ||
231 this->viewport->overlay->GetCompanyMask() == 0) {
235 this->
viewport->overlay->SetDirty();
258 if (_game_mode == GM_MENU) {
259 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};
261 int name_width = (
lengthof(title_sprites) - 1) * letter_spacing;
263 for (uint i = 0; i <
lengthof(title_sprites); i++) {
266 int off_x = (this->
width - name_width) / 2;
268 for (uint i = 0; i <
lengthof(title_sprites); i++) {
270 off_x +=
GetSpriteSize(title_sprites[i]).width + letter_spacing;
277 if (hotkey == GHK_QUIT) {
278 HandleExitGameRequest();
304 case GHK_BOUNDING_BOXES:
308 case GHK_DIRTY_BLOCKS:
312 case GHK_WIDGET_OUTLINES:
321 case GHK_CENTER_ZOOM: {
322 Point pt = GetTileBelowCursor();
338 *(
volatile byte *)
nullptr = 0;
346 case GHK_UPDATE_COORDS:
350 case GHK_TOGGLE_TRANSPARENCY:
351 case GHK_TOGGLE_TRANSPARENCY + 1:
352 case GHK_TOGGLE_TRANSPARENCY + 2:
353 case GHK_TOGGLE_TRANSPARENCY + 3:
354 case GHK_TOGGLE_TRANSPARENCY + 4:
355 case GHK_TOGGLE_TRANSPARENCY + 5:
356 case GHK_TOGGLE_TRANSPARENCY + 6:
357 case GHK_TOGGLE_TRANSPARENCY + 7:
358 case GHK_TOGGLE_TRANSPARENCY + 8:
364 case GHK_TOGGLE_INVISIBILITY:
365 case GHK_TOGGLE_INVISIBILITY + 1:
366 case GHK_TOGGLE_INVISIBILITY + 2:
367 case GHK_TOGGLE_INVISIBILITY + 3:
368 case GHK_TOGGLE_INVISIBILITY + 4:
369 case GHK_TOGGLE_INVISIBILITY + 5:
370 case GHK_TOGGLE_INVISIBILITY + 6:
371 case GHK_TOGGLE_INVISIBILITY + 7:
377 case GHK_TRANSPARENCY_TOOLBAR:
381 case GHK_TRANSPARANCY:
388 if (cio ==
nullptr)
break;
398 case GHK_CHAT_COMPANY:
401 if (cio ==
nullptr)
break;
407 case GHK_CHAT_SERVER:
417 case GHK_CLOSE_ERROR:
426 void OnScroll(
Point delta)
override
432 this->refresh_timeout.
Reset();
435 void OnMouseWheel(
int wheel)
override
438 ZoomInOrOutToCursorWindow(wheel < 0,
this);
447 this->refresh_timeout.
Reset();
451 bool OnTooltip([[maybe_unused]]
Point pt,
WidgetID widget, TooltipCloseCondition close_cond)
override
454 return this->
viewport->overlay->ShowTooltip(pt, close_cond);
462 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
464 if (!gui_scope)
return;
470 Hotkey({
'Q' | WKC_CTRL,
'Q' | WKC_META},
"quit", GHK_QUIT),
471 Hotkey({
'W' | WKC_CTRL,
'W' | WKC_META},
"abandon", GHK_ABANDON),
472 Hotkey(WKC_BACKQUOTE,
"console", GHK_CONSOLE),
473 Hotkey(
'B' | WKC_CTRL,
"bounding_boxes", GHK_BOUNDING_BOXES),
474 Hotkey(
'I' | WKC_CTRL,
"dirty_blocks", GHK_DIRTY_BLOCKS),
475 Hotkey(
'O' | WKC_CTRL,
"widget_outlines", GHK_WIDGET_OUTLINES),
476 Hotkey(
'C',
"center", GHK_CENTER),
477 Hotkey(
'Z',
"center_zoom", GHK_CENTER_ZOOM),
478 Hotkey(WKC_ESC,
"reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
479 Hotkey(WKC_DELETE,
"delete_windows", GHK_DELETE_WINDOWS),
480 Hotkey(WKC_DELETE | WKC_SHIFT,
"delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
481 Hotkey(WKC_DELETE | WKC_CTRL,
"delete_all_messages", GHK_DELETE_ALL_MESSAGES),
482 Hotkey(
'R' | WKC_CTRL,
"refresh_screen", GHK_REFRESH_SCREEN),
484 Hotkey(
'0' | WKC_ALT,
"crash_game", GHK_CRASH),
485 Hotkey(
'1' | WKC_ALT,
"money", GHK_MONEY),
486 Hotkey(
'2' | WKC_ALT,
"update_coordinates", GHK_UPDATE_COORDS),
488 Hotkey(
'1' | WKC_CTRL,
"transparency_signs", GHK_TOGGLE_TRANSPARENCY),
489 Hotkey(
'2' | WKC_CTRL,
"transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
490 Hotkey(
'3' | WKC_CTRL,
"transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
491 Hotkey(
'4' | WKC_CTRL,
"transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
492 Hotkey(
'5' | WKC_CTRL,
"transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
493 Hotkey(
'6' | WKC_CTRL,
"transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
494 Hotkey(
'7' | WKC_CTRL,
"transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
495 Hotkey(
'8' | WKC_CTRL,
"transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
496 Hotkey(
'9' | WKC_CTRL,
"transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
497 Hotkey(
'1' | WKC_CTRL | WKC_SHIFT,
"invisibility_signs", GHK_TOGGLE_INVISIBILITY),
498 Hotkey(
'2' | WKC_CTRL | WKC_SHIFT,
"invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
499 Hotkey(
'3' | WKC_CTRL | WKC_SHIFT,
"invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
500 Hotkey(
'4' | WKC_CTRL | WKC_SHIFT,
"invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
501 Hotkey(
'5' | WKC_CTRL | WKC_SHIFT,
"invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
502 Hotkey(
'6' | WKC_CTRL | WKC_SHIFT,
"invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
503 Hotkey(
'7' | WKC_CTRL | WKC_SHIFT,
"invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
504 Hotkey(
'8' | WKC_CTRL | WKC_SHIFT,
"invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
505 Hotkey(
'X' | WKC_CTRL,
"transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
506 Hotkey(
'X',
"toggle_transparency", GHK_TRANSPARANCY),
507 Hotkey({WKC_RETURN,
'T'},
"chat", GHK_CHAT),
508 Hotkey({WKC_SHIFT | WKC_RETURN, WKC_SHIFT |
'T'},
"chat_all", GHK_CHAT_ALL),
509 Hotkey({WKC_CTRL | WKC_RETURN, WKC_CTRL |
'T'},
"chat_company", GHK_CHAT_COMPANY),
510 Hotkey({WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT |
'T'},
"chat_server", GHK_CHAT_SERVER),
511 Hotkey(WKC_SPACE,
"close_news", GHK_CLOSE_NEWS),
512 Hotkey(WKC_SPACE,
"close_error", GHK_CLOSE_ERROR),
516 static WindowDesc _main_window_desc(__FILE__, __LINE__,
520 std::begin(_nested_main_window_widgets), std::end(_nested_main_window_widgets),
531 int num = MainWindow::hotkeys.
CheckMatch(keycode);
532 return num == GHK_QUIT;
536 void ShowSelectGameWindow();
543 for (uint i = 0; i != 16; i++) {
553 switch (_game_mode) {
554 default: NOT_REACHED();
556 ShowSelectGameWindow();
574 if (_game_mode == GM_EDITOR)
return;
@ ES_HANDLED
The passed event is handled.
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 OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
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.
void RefreshLinkGraph()
Refresh the link-graph overlay.
@ 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.
@ ZOOM_NONE
Hack, used to update the button status.
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
@ SND_15_BEEP
19 == 0x13 GUI button click
IntervalTimer< TimerWindow > refresh_interval
Refresh the link-graph overlay on a regular interval.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
TimeoutTimer< TimerWindow > refresh_timeout
Sometimes when something happened, force an update to the link-graph a bit sooner.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
ZoomLevel
All zoom levels we know.
ClientSettings _settings_client
The current settings for this game.
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
ZoomLevel _gui_zoom
GUI Zoom level.
int virtual_top
Virtual top coordinate.
ZoomLevel zoom_max
maximum zoom out level
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
@ WID_M_VIEWPORT
Main window viewport.
bool Succeeded() const
Did this command succeed?
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
@ Recolour
Recolour sprite.
High level window description.
void Reset()
Reset the timer, so it will fire again after the timeout.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
@ ZOOM_IN
Zoom in (get more detailed view).
bool HideActiveErrorMessage()
Close active error message 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
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.
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
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.
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
bool HasModalProgress()
Check if we are currently in a modal progress state.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
WindowFlags flags
Window flags.
uint32_t CursorID
The number of the cursor (sprite)
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.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
@ WDF_NO_CLOSE
This window can't be interactively closed.
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
WindowNumber window_number
Window number within the window class.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
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.
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
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.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
SwitchMode _switch_mode
The next mainloop command.
bool confirm
Play sound effect on successful constructions or other actions.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
void ShowTransparencyToolbar()
Show the transparency toolbar.
Window * GetMainWindow()
Get the main window, i.e.
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
EventState
State of handling an event.
WindowClass window_class
Window class.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
@ WC_MAIN_WINDOW
Main window; Window numbers:
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
@ SM_MENU
Switch to game intro menu.
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
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.
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.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
bool HideActiveNewsMessage()
Close active news message window.
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.
Commands
List of commands.
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.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
int virtual_height
height << zoom
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
@ 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.
@ CLIENT_ID_SERVER
Servers always have this ID.
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.
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.