40#include "table/strings.h"
66 if (this->vehicle != VehicleID::Invalid()) {
76 default: NOT_REACHED();
78 switch (this->align.
v) {
88struct SelectGameWindow :
public Window {
95 uint mouse_idle_time = 0;
96 Point mouse_idle_pos{};
107 static const std::string sign_language =
"^T\\s*([0-9]+)\\s*([-+A-Z0-9]+)\\s*([0-9]+)";
108 std::regex re(sign_language, std::regex_constants::icase);
111 std::vector<SignID> signs_to_delete;
115 if (!std::regex_search(sign->name, match, re))
continue;
128 vc.
delay = *value * 1000;
134 auto flags = match[2].str();
138 switch (toupper(c)) {
154 signs_to_delete.push_back(sign->index);
161 std::sort(signs_to_delete.begin(), signs_to_delete.end(), [](
SignID a,
SignID b) { return a > b; });
162 for (
SignID sign_id : signs_to_delete) {
182 bool suppress_panning =
true;
183 if (this->mouse_idle_pos.
x != _cursor.pos.x || this->mouse_idle_pos.y != _cursor.pos.y) {
184 this->mouse_idle_pos = _cursor.pos;
185 this->mouse_idle_time = 2000;
186 }
else if (this->mouse_idle_time > delta_ms) {
187 this->mouse_idle_time -= delta_ms;
189 this->mouse_idle_time = 0;
190 suppress_panning =
false;
194 bool changed_command =
false;
197 this->cur_viewport_command_index = 0;
198 changed_command =
true;
201 this->cur_viewport_command_time += delta_ms;
204 this->cur_viewport_command_time = 0;
205 changed_command =
true;
213 if (!changed_command && !vc.
pan_to_next && vc.
vehicle == VehicleID::Invalid())
return;
216 if (!changed_command && suppress_panning)
return;
219 if (changed_command) FixTitleGameZoom(vc.
zoom_adjust);
229 const double t = this->cur_viewport_command_time / (double)vc.
delay;
230 pos.
x = pos.
x + (int)(t * (pos2.
x - pos.
x));
231 pos.
y = pos.
y + (int)(t * (pos2.
y - pos.
y));
268 bool changed =
false;
332static constexpr std::initializer_list<NWidgetPart> _nested_select_game_widgets = {
339 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_GENERATE_GAME),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_LANDSCAPING, STR_INTRO_NEW_GAME, STR_INTRO_TOOLTIP_NEW_GAME),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
340 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_PLAY_HEIGHTMAP),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_SHOW_COUNTOURS, STR_INTRO_PLAY_HEIGHTMAP, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
341 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_PLAY_SCENARIO),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_SUBSIDIES, STR_INTRO_PLAY_SCENARIO, STR_INTRO_TOOLTIP_PLAY_SCENARIO),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
342 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_LOAD_GAME),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_SAVE, STR_INTRO_LOAD_GAME, STR_INTRO_TOOLTIP_LOAD_GAME),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
343 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_HIGHSCORE),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_COMPANY_LEAGUE, STR_INTRO_HIGHSCORE, STR_INTRO_TOOLTIP_HIGHSCORE),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
348 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_PLAY_NETWORK),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_COMPANY_GENERAL, STR_INTRO_MULTIPLAYER, STR_INTRO_TOOLTIP_MULTIPLAYER),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
365 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_OPTIONS),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_SETTINGS, STR_INTRO_GAME_OPTIONS, STR_INTRO_TOOLTIP_GAME_OPTIONS),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
366 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_CONTENT_DOWNLOAD),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_SHOW_VEHICLES, STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
367 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_EDIT_SCENARIO),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_SMALLMAP, STR_INTRO_SCENARIO_EDITOR, STR_INTRO_TOOLTIP_SCENARIO_EDITOR),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
368 NWidget(
WWT_PUSHIMGTEXTBTN,
Colours::Orange,
WID_SGI_HELP),
SetToolbarMinimalSize(1),
SetSpriteStringTip(
SPR_IMG_QUERY, STR_INTRO_HELP, STR_INTRO_TOOLTIP_HELP),
SetAlignment({
AlignmentH::Start,
AlignmentV::Middle}),
SetFill(1, 0),
381 WindowClass::SelectGame, WindowClass::None,
383 _nested_select_game_widgets
386void ShowSelectGameWindow()
391static void AskExitGameCallback(
Window *,
bool confirmed)
411static void AskExitToGameMenuCallback(
Window *,
bool confirmed)
419void AskExitToGameMenu()
425 AskExitToGameMenuCallback,
Window for configuring the AIs.
@ Exit
User is exiting the application.
Parse data from a string / buffer.
char32_t ReadUtf8(char32_t def='?')
Read UTF-8 character, and advance reader.
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
T ReadIntegerBase(int base, T def=0, bool clamp=false)
Read and parse an integer in number 'base', and advance the reader.
Functions related to errors.
void ClearErrorMessages()
Clear all errors from the queue.
@ Error
Errors (eg. saving/loading failed).
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
@ Load
File is being loaded.
@ Savegame
old or new savegame
@ Scenario
old or new scenario
@ Heightmap
heightmap file
Declarations for savegames operations.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Window for configuring GS.
Functions related to world/map generation.
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
void StartScenarioEditor()
Start with a scenario editor.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
void ShowGenerateLandscape()
Start with a normal game.
@ ForceRight
Force align to the right.
@ Centre
Align to the centre.
@ Start
Align to the start, LTR/RTL aware.
@ ForceLeft
Force align to the left.
@ Bottom
Align to the bottom.
@ Middle
Align to the middle.
bool _ctrl_pressed
Is Ctrl pressed?
SwitchMode _switch_mode
The next mainloop command.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Functions related to the gfx engine.
@ FromString
Marker for telling to use the colour from the string.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
GUI functions that shouldn't be here.
void ShowGameOptions()
Open the game options window.
GUI to access manuals and related.
Declaration of functions and types defined in highscore.h and highscore_gui.h.
void ShowHighscoreTable(int difficulty=SP_CUSTOM, int8_t rank=-1)
Show the highscore table for a given difficulty.
static WindowDesc _select_game_desc(WindowPosition::Center, {}, 0, 0, WindowClass::SelectGame, WindowClass::None, WindowDefaultFlag::NoClose, _nested_select_game_widgets)
Window definition for the select game window.
Functions related to OTTD's landscape.
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.
Types related to the landscape.
Information about languages and their files.
const LanguageMetadata * _current_language
The currently loaded language.
#define Point
Macro that prevents name conflicts between included headers.
void ShowQuery(EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
bool _is_network_server
Does this client wants to be a network-server?
bool _network_available
is network mode available?
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=ContentType::End, ContentType type2=ContentType::End)
Show the content list window with a given set of content.
void ShowNetworkGameWindow()
Show the server list window.
GUIs related to networking.
NetworkSurveyHandler _survey
The handler for sending surveys for statistics.
Part of the network protocol handling opt-in survey.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
@ Editor
In the scenario editor.
@ Menu
Switch to game intro menu.
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
PoolID< uint16_t, struct SignIDTag, 64000, 0xFFFF > SignID
The type of the IDs of signs.
This file contains all sprite-related enums and defines.
static const SpriteID SPR_IMG_COMPANY_GENERAL
static const SpriteID SPR_IMG_SAVE
static const SpriteID SPR_IMG_SHOW_VEHICLES
static const SpriteID SPR_IMG_SHOW_COUNTOURS
static const SpriteID SPR_IMG_SUBSIDIES
static const SpriteID SPR_IMG_SETTINGS
static const SpriteID SPR_IMG_COMPANY_LEAGUE
static const SpriteID SPR_IMG_QUERY
static const SpriteID SPR_IMG_SMALLMAP
static const SpriteID SPR_IMG_LANDSCAPING
Definition of base types and functions in a cross-platform compatible way.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
Horizontal and vertical alignment.
AlignmentH ResolveRTL() const
Resolve horizontal alignment for the current text direction.
AlignmentV v
Vertical alignment.
AlignmentH h
Horizontal alignment.
A viewport command for the main menu background (intro game).
int zoom_adjust
Adjustment to zoom level from base zoom level.
Point PositionForViewport(const Viewport &vp)
Calculate effective position.
uint delay
Delay until next command.
Alignment align
Alignment.
VehicleID vehicle
Vehicle to follow, or VehicleID::Invalid() if not following a vehicle.
bool pan_to_next
If true, do a smooth pan from this position to the next.
int command_index
Sequence number of the command (order they are performed in).
Point position
Calculated world coordinate to position viewport top-left at.
static Pool::IterateWrapper< Sign > Iterate(size_t from=0)
static Vehicle * Get(auto index)
Specification of a rectangle with absolute coordinates of all edges.
std::vector< IntroGameViewportCommand > intro_viewport_commands
Vector of viewport commands parsed.
void OnResize() override
Called after the window got resized.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
size_t cur_viewport_command_index
Index of currently active viewport command.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
uint cur_viewport_command_time
Time spent (milliseconds) on current viewport command.
void OnInit() override
Notification that the nested widget tree gets initialized.
void ReadIntroGameViewportCommand()
Find and parse all viewport command signs.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int32_t z_pos
z coordinate.
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
Data structure for viewport, display of a part of the world.
int virtual_width
width << zoom
int virtual_height
height << zoom
High level window description.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
WindowFlags flags
Window flags.
Stuff related to the text buffer GUI.
Base class for all vehicles.
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
Functions related to (drawing on) viewports.
Window * GetMainWindow()
Get the main window, i.e.
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ NoClose
This window can't be interactively closed.
@ Centred
Window is centered and shall stay centered after ReInit.
@ Center
Center the window.