46 #include "table/strings.h" 50 static int _rename_id = 1;
51 static int _rename_what = -1;
61 GetString(msg, STR_COMPANY_NAME,
lastof(msg));
71 void HandleOnEditText(
const char *str)
73 switch (_rename_what) {
87 default: NOT_REACHED();
90 _rename_id = _rename_what = -1;
126 #ifdef ENABLE_NETWORK 127 void ShowNetworkGiveMoneyWindow(
CompanyID company)
129 _rename_id = company;
190 void ZoomInOrOutToCursorWindow(
bool in,
Window *w)
194 if (_game_mode != GM_MENU) {
198 Point pt = GetTileZoomCenterWindow(in, w);
207 static const struct NWidgetPart _nested_main_window_widgets[] = {
219 GHK_RESET_OBJECT_TO_PLACE,
221 GHK_DELETE_NONVITAL_WINDOWS,
226 GHK_TOGGLE_TRANSPARENCY,
227 GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
228 GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
240 static const uint LINKGRAPH_REFRESH_PERIOD = 0xff;
241 static const uint LINKGRAPH_DELAY = 0xf;
253 this->refresh = LINKGRAPH_DELAY;
258 if (--this->refresh > 0)
return;
260 this->refresh = LINKGRAPH_REFRESH_PERIOD;
274 if (_game_mode == GM_MENU) {
275 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};
276 static const uint LETTER_SPACING = 10;
277 int name_width = (
lengthof(title_sprites) - 1) * LETTER_SPACING;
279 for (uint i = 0; i <
lengthof(title_sprites); i++) {
282 int off_x = (this->
width - name_width) / 2;
284 for (uint i = 0; i <
lengthof(title_sprites); i++) {
285 DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
286 off_x +=
GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
293 if (hotkey == GHK_QUIT) {
294 HandleExitGameRequest();
320 case GHK_BOUNDING_BOXES:
324 case GHK_DIRTY_BLOCKS:
333 case GHK_CENTER_ZOOM: {
334 Point pt = GetTileBelowCursor();
349 *(
volatile byte *)0 = 0;
357 case GHK_UPDATE_COORDS:
361 case GHK_TOGGLE_TRANSPARENCY:
362 case GHK_TOGGLE_TRANSPARENCY + 1:
363 case GHK_TOGGLE_TRANSPARENCY + 2:
364 case GHK_TOGGLE_TRANSPARENCY + 3:
365 case GHK_TOGGLE_TRANSPARENCY + 4:
366 case GHK_TOGGLE_TRANSPARENCY + 5:
367 case GHK_TOGGLE_TRANSPARENCY + 6:
368 case GHK_TOGGLE_TRANSPARENCY + 7:
369 case GHK_TOGGLE_TRANSPARENCY + 8:
375 case GHK_TOGGLE_INVISIBILITY:
376 case GHK_TOGGLE_INVISIBILITY + 1:
377 case GHK_TOGGLE_INVISIBILITY + 2:
378 case GHK_TOGGLE_INVISIBILITY + 3:
379 case GHK_TOGGLE_INVISIBILITY + 4:
380 case GHK_TOGGLE_INVISIBILITY + 5:
381 case GHK_TOGGLE_INVISIBILITY + 6:
382 case GHK_TOGGLE_INVISIBILITY + 7:
388 case GHK_TRANSPARENCY_TOOLBAR:
392 case GHK_TRANSPARANCY:
396 #ifdef ENABLE_NETWORK 400 if (cio == NULL)
break;
410 case GHK_CHAT_COMPANY:
413 if (cio == NULL)
break;
419 case GHK_CHAT_SERVER:
437 this->refresh = LINKGRAPH_DELAY;
443 ZoomInOrOutToCursorWindow(wheel < 0,
this);
452 this->refresh = LINKGRAPH_DELAY;
463 if (!gui_scope)
return;
471 const uint16 _ghk_quit_keys[] = {
'Q' | WKC_CTRL,
'Q' | WKC_META, 0};
472 const uint16 _ghk_abandon_keys[] = {
'W' | WKC_CTRL,
'W' | WKC_META, 0};
473 const uint16 _ghk_chat_keys[] = {WKC_RETURN,
'T', 0};
474 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT |
'T', 0};
475 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL |
'T', 0};
476 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT |
'T', 0};
478 static Hotkey global_hotkeys[] = {
479 Hotkey(_ghk_quit_keys,
"quit", GHK_QUIT),
480 Hotkey(_ghk_abandon_keys,
"abandon", GHK_ABANDON),
481 Hotkey(WKC_BACKQUOTE,
"console", GHK_CONSOLE),
482 Hotkey(
'B' | WKC_CTRL,
"bounding_boxes", GHK_BOUNDING_BOXES),
483 Hotkey(
'I' | WKC_CTRL,
"dirty_blocks", GHK_DIRTY_BLOCKS),
484 Hotkey(
'C',
"center", GHK_CENTER),
485 Hotkey(
'Z',
"center_zoom", GHK_CENTER_ZOOM),
486 Hotkey(WKC_ESC,
"reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
487 Hotkey(WKC_DELETE,
"delete_windows", GHK_DELETE_WINDOWS),
488 Hotkey(WKC_DELETE | WKC_SHIFT,
"delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
489 Hotkey(
'R' | WKC_CTRL,
"refresh_screen", GHK_REFRESH_SCREEN),
491 Hotkey(
'0' | WKC_ALT,
"crash_game", GHK_CRASH),
492 Hotkey(
'1' | WKC_ALT,
"money", GHK_MONEY),
493 Hotkey(
'2' | WKC_ALT,
"update_coordinates", GHK_UPDATE_COORDS),
495 Hotkey(
'1' | WKC_CTRL,
"transparency_signs", GHK_TOGGLE_TRANSPARENCY),
496 Hotkey(
'2' | WKC_CTRL,
"transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
497 Hotkey(
'3' | WKC_CTRL,
"transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
498 Hotkey(
'4' | WKC_CTRL,
"transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
499 Hotkey(
'5' | WKC_CTRL,
"transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
500 Hotkey(
'6' | WKC_CTRL,
"transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
501 Hotkey(
'7' | WKC_CTRL,
"transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
502 Hotkey(
'8' | WKC_CTRL,
"transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
503 Hotkey(
'9' | WKC_CTRL,
"transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
504 Hotkey(
'1' | WKC_CTRL | WKC_SHIFT,
"invisibility_signs", GHK_TOGGLE_INVISIBILITY),
505 Hotkey(
'2' | WKC_CTRL | WKC_SHIFT,
"invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
506 Hotkey(
'3' | WKC_CTRL | WKC_SHIFT,
"invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
507 Hotkey(
'4' | WKC_CTRL | WKC_SHIFT,
"invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
508 Hotkey(
'5' | WKC_CTRL | WKC_SHIFT,
"invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
509 Hotkey(
'6' | WKC_CTRL | WKC_SHIFT,
"invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
510 Hotkey(
'7' | WKC_CTRL | WKC_SHIFT,
"invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
511 Hotkey(
'8' | WKC_CTRL | WKC_SHIFT,
"invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
512 Hotkey(
'X' | WKC_CTRL,
"transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
513 Hotkey(
'X',
"toggle_transparency", GHK_TRANSPARANCY),
514 #ifdef ENABLE_NETWORK 515 Hotkey(_ghk_chat_keys,
"chat", GHK_CHAT),
516 Hotkey(_ghk_chat_all_keys,
"chat_all", GHK_CHAT_ALL),
517 Hotkey(_ghk_chat_company_keys,
"chat_company", GHK_CHAT_COMPANY),
518 Hotkey(_ghk_chat_server_keys,
"chat_server", GHK_CHAT_SERVER),
522 HotkeyList MainWindow::hotkeys(
"global", global_hotkeys);
528 _nested_main_window_widgets,
lengthof(_nested_main_window_widgets),
539 int num = MainWindow::hotkeys.
CheckMatch(keycode);
540 return num == GHK_QUIT;
544 void ShowSelectGameWindow();
551 for (uint i = 0; i != 16; i++) {
561 switch (_game_mode) {
562 default: NOT_REACHED();
564 ShowSelectGameWindow();
582 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.
Send message/notice to all clients (All)
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?
virtual void OnResize()
Called after the window got resized.
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...
ZoomLevelByte zoom_max
maximum zoom out level
All data for a single hotkey.
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
High level window description.
uint32 GetCargoMask()
Get a bitmask of the currently shown cargoes.
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.
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.
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
virtual void OnTick()
Called once per (game) tick.
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.
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...
void RebuildCache()
Rebuild the cache and recalculate which links and stations to be shown.
Functions related to maps.
Functions, definitions and such used only by the GUI.
Servers always have this ID.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
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.
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.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
Default zoom level for viewports.
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
virtual void OnMouseWheel(int wheel)
The mouse wheel has been turned.
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.
ZoomLevelByte zoom_min
minimum zoom out level
void DeleteNonVitalWindows()
Try to delete a non-vital window.
ZoomLevel
All zoom levels we know.
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Functions related to companies.
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.
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.
SwitchMode _switch_mode
The next mainloop command.
bool confirm
Play sound effect on succesful 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.
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.
int virtual_top
Virtual top coordinate.
#define CMD_MSG(x)
Used to combine a StringID with the command.
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.
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Manually align the window (so no automatic location finding)
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.
Window white border counter bit mask.
void ShowVitalWindows()
Show the vital in-game windows.
virtual void OnPaint()
The window must be repainted.
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.
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.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
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.
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.