Go to the documentation of this file.
38 #include "table/strings.h"
84 switch (this->align_h) {
85 case LEFT: p.x = this->
position.x;
break;
89 switch (this->align_v) {
90 case TOP: p.y = this->
position.y;
break;
106 uint mouse_idle_time;
107 Point mouse_idle_pos;
118 const char *sign_langauge =
"^T\\s*([0-9]+)\\s*([-+A-Z0-9]+)\\s*([0-9]+)";
119 std::regex re(sign_langauge, std::regex_constants::icase);
122 std::vector<SignID> signs_to_delete;
126 if (std::regex_search(sign->name, match, re)) {
133 vc.
delay = std::stoi(match[3].str()) * 1000;
139 for (
char c : match[2].str()) {
141 if (id_type == ID_VEHICLE) {
146 switch (toupper(c)) {
149 case 'T': vc.
align_v = IntroGameViewportCommand::TOP;
break;
150 case 'M': vc.
align_v = IntroGameViewportCommand::MIDDLE;
break;
151 case 'B': vc.
align_v = IntroGameViewportCommand::BOTTOM;
break;
152 case 'L': vc.
align_h = IntroGameViewportCommand::LEFT;
break;
153 case 'C': vc.
align_h = IntroGameViewportCommand::CENTRE;
break;
154 case 'R': vc.
align_h = IntroGameViewportCommand::RIGHT;
break;
156 case 'V': id_type = ID_VEHICLE; vc.
vehicle = 0;
break;
163 signs_to_delete.push_back(sign->index);
171 std::sort(signs_to_delete.begin(), signs_to_delete.end(), [](
SignID a,
SignID b) { return a > b; });
172 for (
SignID sign_id : signs_to_delete) {
185 this->cur_viewport_command_index = (size_t)-1;
186 this->cur_viewport_command_time = 0;
187 this->mouse_idle_time = 0;
188 this->mouse_idle_pos = _cursor.
pos;
197 bool suppress_panning =
true;
198 if (this->mouse_idle_pos.x != _cursor.
pos.x || this->mouse_idle_pos.y != _cursor.
pos.y) {
199 this->mouse_idle_pos = _cursor.
pos;
200 this->mouse_idle_time = 2000;
201 }
else if (this->mouse_idle_time > delta_ms) {
202 this->mouse_idle_time -= delta_ms;
204 this->mouse_idle_time = 0;
205 suppress_panning =
false;
209 bool changed_command =
false;
212 this->cur_viewport_command_index = 0;
213 changed_command =
true;
216 this->cur_viewport_command_time += delta_ms;
219 this->cur_viewport_command_time = 0;
220 changed_command =
true;
232 if (!changed_command && suppress_panning)
return;
235 if (changed_command) FixTitleGameZoom(vc.
zoom_adjust);
245 const double t = this->cur_viewport_command_time / (double)vc.
delay;
246 pos.x = pos.x + (
int)(t * (pos2.x - pos.x));
247 pos.y = pos.y + (int)(t * (pos2.y - pos.y));
267 if (!gui_scope)
return;
304 str = STR_INTRO_BASESET;
309 str = STR_INTRO_TRANSLATION;
319 textdim.width -= textdim.width / 2;
320 *size =
maxdim(*size, textdim);
322 size->height =
height + padding.height;
351 ShowNetworkGameWindow();
378 static const NWidgetPart _nested_select_game_widgets[] = {
417 SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
420 SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
423 SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
426 SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
433 NWidget(
WWT_EMPTY, COLOUR_ORANGE,
WID_SGI_BASESET),
SetMinimalSize(316, 12),
SetFill(1, 0),
SetPadding(0, 10, 7, 10),
438 NWidget(
WWT_EMPTY, COLOUR_ORANGE,
WID_SGI_TRANSLATION),
SetMinimalSize(316, 12),
SetFill(1, 0),
SetPadding(0, 10, 7, 10),
484 SetDataTip(STR_INTRO_QUIT, STR_INTRO_TOOLTIP_QUIT),
497 _nested_select_game_widgets,
lengthof(_nested_select_game_widgets)
500 void ShowSelectGameWindow()
505 static void AskExitGameCallback(
Window *w,
bool confirmed)
507 if (confirmed) _exit_game =
true;
514 STR_QUIT_ARE_YOU_SURE_YOU_WANT_TO_EXIT_OPENTTD,
521 static void AskExitToGameMenuCallback(
Window *w,
bool confirmed)
529 void AskExitToGameMenu()
532 STR_ABANDON_GAME_CAPTION,
533 (_game_mode != GM_EDITOR) ? STR_ABANDON_GAME_QUERY : STR_ABANDON_SCENARIO_QUERY,
535 AskExitToGameMenuCallback
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
VehicleID vehicle
Vehicle to follow, or INVALID_VEHICLE if not following a vehicle.
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
@ FT_SCENARIO
old or new scenario
static Titem * Get(size_t index)
Returns Titem with given index.
bool pan_to_next
If true, do a smooth pan from this position to the next.
int zoom_adjust
Adjustment to zoom level from base zoom level.
Dimensions (a width and height) of a rectangle in 2D.
byte landscape
the landscape we're currently in
uint delay
Delay until next command.
@ WC_SELECT_GAME
Select game window; Window numbers:
static Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
ViewportData * viewport
Pointer to viewport data, if present.
int command_index
Sequence number of the command (order they are performed in).
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
bool _ctrl_pressed
Is Ctrl pressed?
void ShowGameOptions()
Open the game options window.
uint cur_viewport_command_time
Time spent (milliseconds) on current viewport command.
void ShowGameSettings()
Open advanced settings window.
ClientSettings _settings_client
The current settings for this game.
void StartScenarioEditor()
Start with a scenario editor.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
GameCreationSettings game_creation
settings used during the creation of a game (map)
High level window description.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Data structure for viewport, display of a part of the world.
void ClearErrorMessages()
Clear all errors from the queue.
@ SLO_LOAD
File is being loaded.
ResizeInfo resize
Resize information.
void ShowGenerateLandscape()
Start with a normal game.
A viewport command for the main menu background (intro game).
int height
Height of the window (number of pixels down in y direction)
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Point position
Calculated world coordinate to position viewport top-left at.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
byte missing_strings_threshold
the number of missing strings before showing the warning
void ReadIntroGameViewportCommands()
Find and parse all viewport command signs.
const LanguageMetadata * _current_language
The currently loaded language.
int virtual_width
width << zoom
Coordinates of a point in 2D.
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
@ FT_SAVEGAME
old or new savegame
void ShowGSConfigWindow()
Open the GS config window.
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
void ShowHighscoreTable(int difficulty=SP_CUSTOM, int8 rank=-1)
Show the highscore table for a given difficulty.
SwitchMode _switch_mode
The next mainloop command.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
size_t cur_viewport_command_index
Index of currently active viewport command.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
AlignmentV align_v
Vertical alignment.
void SetNewLandscapeType(byte landscape)
Changes landscape type and sets genworld window dirty.
void UpdateViewportPosition(Window *w)
Update the viewport position being displayed.
AlignmentH
Horizontal alignment value.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
AlignmentH align_h
Horizontal alignment.
@ FT_HEIGHTMAP
heightmap file
@ WC_MAIN_WINDOW
Main window; Window numbers:
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
@ WL_ERROR
Errors (eg. saving/loading failed)
@ SM_MENU
Switch to game intro menu.
AlignmentV
Vertical alignment value.
uint32 VehicleID
The type all our vehicle IDs have.
Point PositionForViewport(const Viewport *vp)
Calculate effective position.
@ SA_CENTER
Center both horizontally and vertically.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
#define lengthof(x)
Return the length of an fixed size array.
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Data structure for an opened window.
int virtual_height
height << zoom
bool _network_available
is network mode available?
void ShowAIConfigWindow()
Open the AI config window.
Specification of a rectangle with absolute coordinates of all edges.
Point pos
logical mouse position
void OnInit() override
Notification that the nested widget tree gets initialized.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
@ WDP_CENTER
Center the window.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
bool _is_network_server
Does this client wants to be a network-server?
std::vector< IntroGameViewportCommand > intro_viewport_commands
Vector of viewport commands parsed.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
uint16 SignID
The type of the IDs of signs.
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.