|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
32 #include "table/strings.h"
36 static constexpr
NWidgetPart _nested_errmsg_widgets[] = {
46 static WindowDesc _errmsg_desc(__FILE__, __LINE__,
50 std::begin(_nested_errmsg_widgets), std::end(_nested_errmsg_widgets)
53 static constexpr
NWidgetPart _nested_errmsg_face_widgets[] = {
60 NWidget(
WWT_EMPTY, COLOUR_RED,
WID_EM_FACE),
SetPadding(2, 0, 2, 2),
SetFill(0, 1),
SetMinimalSize(92, 119),
66 static WindowDesc _errmsg_face_desc(__FILE__, __LINE__,
70 std::begin(_nested_errmsg_face_widgets), std::end(_nested_errmsg_face_widgets)
78 is_critical(data.is_critical), params(data.params), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size),
79 summary_msg(data.summary_msg), detailed_msg(data.detailed_msg), extra_msg(data.extra_msg), position(data.position), face(data.face)
97 is_critical(is_critical),
98 textref_stack_grffile(textref_stack_grffile),
99 textref_stack_size(textref_stack_size),
100 summary_msg(summary_msg),
101 detailed_msg(detailed_msg),
102 extra_msg(extra_msg),
137 if (n >= this->
params.size()) this->
params.resize(n + 1);
148 if (n >= this->
params.size()) this->
params.resize(n + 1);
159 if (n >= this->
params.size()) this->
params.resize(n + 1);
180 display_timeout(std::chrono::seconds(3 *
_settings_client.gui.errmsg_duration), [this]() {
188 this->display_timeout.
Reset();
209 size->height = std::max(size->height, panel_height);
218 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]]
int window_number)
override
221 if (this->
position.x == 0 && this->position.y == 0) {
222 Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
226 constexpr
int distance_to_cursor = 200;
232 pt.x = _cursor.
pos.x - sm_width / 2;
233 pt.y = _cursor.
pos.y - (distance_to_cursor + sm_height);
237 pt.y = _cursor.
pos.y + distance_to_cursor;
248 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
254 void SetStringParameters(
WidgetID widget)
const override
259 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
286 Rect top_section = r.
WithHeight(this->height_summary + extra,
false);
287 Rect bottom_section = r.
WithHeight(this->height_extra + extra,
true);
288 Rect middle_section = { top_section.left, top_section.bottom, top_section.right, bottom_section.top };
308 void Close([[maybe_unused]]
int data = 0)
override
386 assert(textref_stack_size == 0 || (textref_stack_grffile !=
nullptr && textref_stack !=
nullptr));
387 if (summary_msg == STR_NULL) summary_msg = STR_EMPTY;
392 if (textref_stack_size > 0)
StartTextRefStackUsage(textref_stack_grffile, textref_stack_size, textref_stack);
394 std::string message =
GetString(summary_msg);
411 if (_game_mode == GM_BOOTSTRAP)
return;
414 ErrorMessageData data(summary_msg, detailed_msg, is_critical, x, y, textref_stack_grffile, textref_stack_size, textref_stack, extra_msg);
442 if (w ==
nullptr)
return false;
Point position
Position of the error message window.
void CopyInDParam(const std::span< const StringParameterBackup > backup)
Copy the parameters from the backup into the global string parameter array.
int Height() const
Get height of Rect.
static Titem * Get(size_t index)
Returns Titem with given index.
const GRFFile * textref_stack_grffile
NewGRF that filled the TextRefStack for the error message.
Dimensions (a width and height) of a rectangle in 2D.
uint textref_stack_size
Number of uint32_t values to put on the TextRefStack for the error message.
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
WarningLevel
Message severity/type.
@ WL_WARNING
Other information.
std::vector< StringParameterBackup > params
Backup of parameters of the message strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
uint height_summary
Height of the summary_msg string in pixels in the WID_EM_MESSAGE widget.
ClientSettings _settings_client
The current settings for this game.
bool is_critical
Whether the error message is critical.
CompanyManagerFace face
Face description of the president.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
void CopyOutDParams()
Copy error parameters from current DParams.
Owner
Enum for all companies/owners.
void UnshowCriticalError()
Unshow the critical error.
StringID GetErrorMessage() const
Returns the error message of a command.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
High level window description.
void Reset()
Reset the timer, so it will fire again after the timeout.
void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
uint height_detailed
Height of the detailed_msg string in pixels in the WID_EM_MESSAGE widget.
ResizeInfo resize
Resize information.
void SetDParam(uint n, uint64_t v)
Set a error string parameter.
Common return value for all commands.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
uint GetTextRefStackSize() const
Returns the number of uint32_t values for the TextRefStack of the error message.
Colours colour
Company colour.
const uint32_t * GetTextRefStack() const
Returns a pointer to the values for the TextRefStack of the error message.
const GRFFile * GetTextRefStackGRF() const
Returns the NewGRF providing the TextRefStack of the error message.
int GetMainViewTop()
Return the top of the main view available for general use.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ MAX_COMPANIES
Maximum number of companies.
void CopyOutDParam(std::vector< StringParameterBackup > &backup, size_t num)
Copy num string parameters from the global string parameter array to the backup.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
static ErrorList _error_list
The actual queue with errors.
StringID GetExtraErrorMessage() const
Returns the extra error message of a command.
uint64_t GetDParam(size_t n)
Get the current string parameter at index n from the global string parameter array.
The data of the error message.
Coordinates of a point in 2D.
CompanyID face
Company belonging to the face being shown. INVALID_COMPANY if no face present.
WindowNumber window_number
Window number within the window class.
bool IsCritical()
Check whether the currently shown error message was critical or not.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
bool _window_system_initialized
Whether the window system is initialized or not.
uint height_extra
Height of the extra_msg string in pixels in the WID_EM_MESSAGE widget.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
bool HasFace() const
Check whether error window shall display a company manager face.
StringID detailed_msg
Detailed error message showed in second line. Can be INVALID_STRING_ID.
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
void ClearErrorMessages()
Clear all errors from the queue.
static const TextColour CC_ERROR
Colour for error lines.
void DrawCompanyManagerFace(CompanyManagerFace cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
@ SA_CENTER
Center both horizontally and vertically.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
@ INVALID_COMPANY
An invalid company.
bool HideActiveErrorMessage()
Close active error message window.
void ShowFirstError()
Show the first error of the queue.
uint32_t textref_stack[16]
Values to put on the TextRefStack for the error message.
Data structure for an opened window.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Window class for displaying an error message window.
@ WC_ERRMSG
Error message; Window numbers:
static const TextColour CC_WARNING
Colour for warning lines.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Specification of a rectangle with absolute coordinates of all edges.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Point pos
logical mouse position
byte errmsg_duration
duration of error message
StringID extra_msg
Extra error message shown in third line. Can be INVALID_STRING_ID.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
static const int OWNED_BY_OWNER_IN_PARAMETERS_OFFSET
The index in the parameters for the owner information.
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
bool _right_button_down
Is right mouse button pressed?
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
StringID summary_msg
General error message showed in first line. Must be valid.
ErrorMessageData(const ErrorMessageData &data)
Copy the given data into our instance.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.