45 #include "table/strings.h" 49 static int _rename_id = 1;
50 static int _rename_what = -1;
59 GetString(msg, STR_COMPANY_NAME,
lastof(msg));
68 void HandleOnEditText(
const char *str)
70 switch (_rename_what) {
73 if (c ==
nullptr)
break;
82 default: NOT_REACHED();
85 _rename_id = _rename_what = -1;
116 void CcPlaySound_EXPLOSION(
const CommandCost &result,
TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
121 void ShowNetworkGiveMoneyWindow(
CompanyID company)
123 _rename_id = company;
140 assert(w !=
nullptr);
183 void ZoomInOrOutToCursorWindow(
bool in,
Window *w)
185 assert(w !=
nullptr);
187 if (_game_mode != GM_MENU) {
191 Point pt = GetTileZoomCenterWindow(in, w);
200 void FixTitleGameZoom()
202 if (_game_mode != GM_MENU)
return;
210 static const struct NWidgetPart _nested_main_window_widgets[] = {
222 GHK_RESET_OBJECT_TO_PLACE,
224 GHK_DELETE_NONVITAL_WINDOWS,
225 GHK_DELETE_ALL_MESSAGES,
230 GHK_TOGGLE_TRANSPARENCY,
231 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
232 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
245 static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
246 static const uint LINKGRAPH_DELAY = 450;
258 this->refresh.SetInterval(LINKGRAPH_DELAY);
263 if (!this->refresh.
Elapsed(delta_ms))
return;
265 this->refresh.SetInterval(LINKGRAPH_REFRESH_PERIOD);
279 if (_game_mode == GM_MENU) {
280 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};
281 static const uint LETTER_SPACING = 10;
282 int name_width = (
lengthof(title_sprites) - 1) * LETTER_SPACING;
284 for (uint i = 0; i <
lengthof(title_sprites); i++) {
287 int off_x = (this->
width - name_width) / 2;
289 for (uint i = 0; i <
lengthof(title_sprites); i++) {
290 DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
291 off_x +=
GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
298 if (hotkey == GHK_QUIT) {
299 HandleExitGameRequest();
325 case GHK_BOUNDING_BOXES:
329 case GHK_DIRTY_BLOCKS:
338 case GHK_CENTER_ZOOM: {
339 Point pt = GetTileBelowCursor();
355 *(
volatile byte *)0 = 0;
363 case GHK_UPDATE_COORDS:
367 case GHK_TOGGLE_TRANSPARENCY:
368 case GHK_TOGGLE_TRANSPARENCY + 1:
369 case GHK_TOGGLE_TRANSPARENCY + 2:
370 case GHK_TOGGLE_TRANSPARENCY + 3:
371 case GHK_TOGGLE_TRANSPARENCY + 4:
372 case GHK_TOGGLE_TRANSPARENCY + 5:
373 case GHK_TOGGLE_TRANSPARENCY + 6:
374 case GHK_TOGGLE_TRANSPARENCY + 7:
375 case GHK_TOGGLE_TRANSPARENCY + 8:
381 case GHK_TOGGLE_INVISIBILITY:
382 case GHK_TOGGLE_INVISIBILITY + 1:
383 case GHK_TOGGLE_INVISIBILITY + 2:
384 case GHK_TOGGLE_INVISIBILITY + 3:
385 case GHK_TOGGLE_INVISIBILITY + 4:
386 case GHK_TOGGLE_INVISIBILITY + 5:
387 case GHK_TOGGLE_INVISIBILITY + 6:
388 case GHK_TOGGLE_INVISIBILITY + 7:
394 case GHK_TRANSPARENCY_TOOLBAR:
398 case GHK_TRANSPARANCY:
405 if (cio ==
nullptr)
break;
415 case GHK_CHAT_COMPANY:
418 if (cio ==
nullptr)
break;
424 case GHK_CHAT_SERVER:
441 this->refresh.SetInterval(LINKGRAPH_DELAY);
447 ZoomInOrOutToCursorWindow(wheel < 0,
this);
456 this->refresh.SetInterval(LINKGRAPH_DELAY);
467 if (!gui_scope)
return;
475 const uint16 _ghk_quit_keys[] = {
'Q' | WKC_CTRL,
'Q' | WKC_META, 0};
476 const uint16 _ghk_abandon_keys[] = {
'W' | WKC_CTRL,
'W' | WKC_META, 0};
477 const uint16 _ghk_chat_keys[] = {WKC_RETURN,
'T', 0};
478 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT |
'T', 0};
479 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL |
'T', 0};
480 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT |
'T', 0};
482 static Hotkey global_hotkeys[] = {
483 Hotkey(_ghk_quit_keys,
"quit", GHK_QUIT),
484 Hotkey(_ghk_abandon_keys,
"abandon", GHK_ABANDON),
485 Hotkey(WKC_BACKQUOTE,
"console", GHK_CONSOLE),
486 Hotkey(
'B' | WKC_CTRL,
"bounding_boxes", GHK_BOUNDING_BOXES),
487 Hotkey(
'I' | WKC_CTRL,
"dirty_blocks", GHK_DIRTY_BLOCKS),
488 Hotkey(
'C',
"center", GHK_CENTER),
489 Hotkey(
'Z',
"center_zoom", GHK_CENTER_ZOOM),
490 Hotkey(WKC_ESC,
"reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
491 Hotkey(WKC_DELETE,
"delete_windows", GHK_DELETE_WINDOWS),
492 Hotkey(WKC_DELETE | WKC_SHIFT,
"delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
493 Hotkey(WKC_DELETE | WKC_CTRL,
"delete_all_messages", GHK_DELETE_ALL_MESSAGES),
494 Hotkey(
'R' | WKC_CTRL,
"refresh_screen", GHK_REFRESH_SCREEN),
496 Hotkey(
'0' | WKC_ALT,
"crash_game", GHK_CRASH),
497 Hotkey(
'1' | WKC_ALT,
"money", GHK_MONEY),
498 Hotkey(
'2' | WKC_ALT,
"update_coordinates", GHK_UPDATE_COORDS),
500 Hotkey(
'1' | WKC_CTRL,
"transparency_signs", GHK_TOGGLE_TRANSPARENCY),
501 Hotkey(
'2' | WKC_CTRL,
"transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
502 Hotkey(
'3' | WKC_CTRL,
"transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
503 Hotkey(
'4' | WKC_CTRL,
"transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
504 Hotkey(
'5' | WKC_CTRL,
"transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
505 Hotkey(
'6' | WKC_CTRL,
"transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
506 Hotkey(
'7' | WKC_CTRL,
"transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
507 Hotkey(
'8' | WKC_CTRL,
"transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
508 Hotkey(
'9' | WKC_CTRL,
"transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
509 Hotkey(
'1' | WKC_CTRL | WKC_SHIFT,
"invisibility_signs", GHK_TOGGLE_INVISIBILITY),
510 Hotkey(
'2' | WKC_CTRL | WKC_SHIFT,
"invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
511 Hotkey(
'3' | WKC_CTRL | WKC_SHIFT,
"invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
512 Hotkey(
'4' | WKC_CTRL | WKC_SHIFT,
"invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
513 Hotkey(
'5' | WKC_CTRL | WKC_SHIFT,
"invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
514 Hotkey(
'6' | WKC_CTRL | WKC_SHIFT,
"invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
515 Hotkey(
'7' | WKC_CTRL | WKC_SHIFT,
"invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
516 Hotkey(
'8' | WKC_CTRL | WKC_SHIFT,
"invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
517 Hotkey(
'X' | WKC_CTRL,
"transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
518 Hotkey(
'X',
"toggle_transparency", GHK_TRANSPARANCY),
519 Hotkey(_ghk_chat_keys,
"chat", GHK_CHAT),
520 Hotkey(_ghk_chat_all_keys,
"chat_all", GHK_CHAT_ALL),
521 Hotkey(_ghk_chat_company_keys,
"chat_company", GHK_CHAT_COMPANY),
522 Hotkey(_ghk_chat_server_keys,
"chat_server", GHK_CHAT_SERVER),
525 HotkeyList MainWindow::hotkeys(
"global", global_hotkeys);
531 _nested_main_window_widgets,
lengthof(_nested_main_window_widgets),
542 int num = MainWindow::hotkeys.
CheckMatch(keycode);
543 return num == GHK_QUIT;
547 void ShowSelectGameWindow();
554 for (uint i = 0; i != 16; i++) {
564 switch (_game_mode) {
565 default: NOT_REACHED();
567 ShowSelectGameWindow();
585 if (_game_mode == GM_EDITOR)
return;
EventState
State of handling an event.
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows. ...
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Functions related to OTTD's strings.
Owner
Enum for all companies/owners.
Send message/notice to all clients (All)
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
bool _networking
are we in networking mode?
int virtual_left
Virtual left coordinate.
Container for all information known about a client.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
All data for a single hotkey.
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
High level window description.
EconomySettings economy
settings to change the economy
WindowFlags flags
Window flags.
Zoom out (get helicopter view).
void DrawWidgets() const
Paint all widgets of a window.
int height
Screen height of the viewport.
Switch to game intro menu.
Hotkey related functions.
GUIs related to networking.
Functions to handle different currencies.
bool IsQuitKey(uint16 keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
The passed event is not handled.
bool Elapsed(uint delta)
Test if a timer has elapsed.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
int virtual_height
height << zoom
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right...
bool give_money
allow giving other companies money
Send message/notice to only a certain client (Private)
Dimension _cur_resolution
The current resolution.
Zoom in (get more detailed view).
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat message.
#define lastof(x)
Get the last element of an fixed size array.
Stuff related to the text buffer GUI.
Base core network types and some helper functions to access them.
#define CLRBITS(x, y)
Clears several bits in a variable.
void DeleteAllMessages()
Delete all messages and their corresponding window (if any).
Common return value for all commands.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
void DeleteAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Functions related to maps.
void OnPaint() override
The window must be repainted.
Functions, definitions and such used only by the GUI.
Functions related to (drawing on) viewports.
static void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Declaration of linkgraph overlay GUI.
Data structure for an opened window.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Main window; Window numbers:
Functions/types related to saving and loading games.
CompanyID client_playas
As which company is this client playing (CompanyID)
Types related to the main widgets.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
SoundSettings sound
sound effect settings
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Money current_loan
Amount of money borrowed from the bank.
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
ClientID _network_own_client_id
Our client identifier.
ClientSettings _settings_client
The current settings for this game.
uint8 scrollwheel_scrolling
scrolling using the scroll wheel?
Functions related to modal progress.
bool Succeeded() const
Did this command succeed?
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
List of hotkeys for a window.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
GUI functions related to transparency.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
GUI related functions in the console.
ZoomLevel zoom_max
maximum zoom out level
int virtual_width
width << zoom
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?"
Money money
Money owned by the company.
Basic functions/variables used all over the place.
give money to another company
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
static void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
#define lengthof(x)
Return the length of an fixed size array.
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
static T min(const T a, const T b)
Returns the minimum of two values.
Functions related to sound.
Functions to cache sprites in memory.
bool Failed() const
Did this command fail?
static void MaxZoomInOut(ZoomStateChange how, Window *w)
Zoom a viewport as far as possible in the given direction.
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members where he/she can chat to.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
No window, redirects to WC_MAIN_WINDOW.
void DeleteNonVitalWindows()
Try to delete a non-vital window.
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Functions related to companies.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
GUISettings gui
settings related to the GUI
Data structure for viewport, display of a part of the world.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Default zoom level for viewports.
uint32 TileIndex
The index/ID of a Tile.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
void GameSizeChanged()
Size of the application screen changed.
Functions related to transparency.
Functions related to zooming.
ZoomLevel _gui_zoom
GUI Zoom level.
SwitchMode _switch_mode
The next mainloop command.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
bool confirm
Play sound effect on successful constructions or other actions.
Functions related to commands.
Network functions used by other parts of OpenTTD.
bool _network_server
network-server is active
uint32 CursorID
The number of the cursor (sprite)
Main toolbar (the long bar at the top); Window numbers:
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a 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...
HighLightStyle
Highlighting draw styles.
int CheckMatch(uint16 keycode, bool global_only=false) const
Check if a keycode is bound to something.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
ZoomLevel zoom
The zoom level of the viewport.
ZoomStateChange
Directions of zooming.
int width
width of the window (number of pixels to the right in x direction)
void ShowStatusBar()
Show our status bar.
void OnResize() override
Called after the window got resized.
ZoomLevel
All zoom levels we know.
int virtual_top
Virtual top coordinate.
#define CMD_MSG(x)
Used to combine a StringID with the command.
Servers always have this ID.
WindowClass window_class
Window class.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
The passed event is handled.
WindowNumber window_number
Window number within the window class.
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Manually align the window (so no automatic location finding)
ZoomLevel zoom_min
minimum zoom out level
ViewportData * viewport
Pointer to viewport data, if present.
Functions, definitions and such used only by the GUI.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
Window white border counter bit mask.
void ShowVitalWindows()
Show the vital in-game windows.
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Send message/notice to everyone playing the same company (Team)
static void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Hack, used to update the button status.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
bool click_beep
Beep on a random selection of buttons.
void ShowTransparencyToolbar()
Show the transparency toolbar.
This file contains all sprite-related enums and defines.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Handles drawing of links into some window.
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
static bool HasModalProgress()
Check if we are currently in a modal progress state.
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-...
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
int width
Screen width of the viewport.