OpenTTD Source  20240917-master-g9ab0a47812
error.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef ERROR_H
11 #define ERROR_H
12 
13 #include "strings_type.h"
14 #include "company_type.h"
15 #include "command_type.h"
16 #include "core/geometry_type.hpp"
17 
18 #include <chrono>
19 
20 struct GRFFile;
21 
28 };
29 
32 protected:
33  bool is_critical;
34  std::vector<StringParameterData> params;
37  uint32_t textref_stack[16];
43 
44 public:
46  ErrorMessageData(StringID summary_msg, StringID detailed_msg, bool is_critical = false, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32_t *textref_stack = nullptr, StringID extra_msg = INVALID_STRING_ID);
47 
48  /* Remove the copy assignment, as the default implementation will not do the right thing. */
49  ErrorMessageData &operator=(ErrorMessageData &rhs) = delete;
50 
52  bool HasFace() const { return face != INVALID_COMPANY; }
53 
54  void SetDParam(uint n, uint64_t v);
55  void SetDParamStr(uint n, const char *str);
56  void SetDParamStr(uint n, const std::string &str);
57 
58  void CopyOutDParams();
59 };
60 
62 typedef std::list<ErrorMessageData> ErrorList;
63 
64 void ScheduleErrorMessage(ErrorList &datas);
65 void ScheduleErrorMessage(const ErrorMessageData &data);
66 
67 void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc);
68 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_t *textref_stack = nullptr, StringID extra_msg = INVALID_STRING_ID);
70 
71 void ClearErrorMessages();
72 void ShowFirstError();
73 void UnshowCriticalError();
74 
75 #endif /* ERROR_H */
ErrorMessageData::position
Point position
Position of the error message window.
Definition: error.h:41
ShowFirstError
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:335
ErrorMessageData::textref_stack_grffile
const GRFFile * textref_stack_grffile
NewGRF that filled the TextRefStack for the error message.
Definition: error.h:35
ErrorMessageData::textref_stack_size
uint textref_stack_size
Number of uint32_t values to put on the TextRefStack for the error message.
Definition: error.h:36
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
ErrorMessageData::SetDParamStr
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:146
WarningLevel
WarningLevel
Message severity/type.
Definition: error.h:23
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:25
ScheduleErrorMessage
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
Definition: error_gui.cpp:452
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
ErrorList
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Definition: error.h:62
ErrorMessageData::is_critical
bool is_critical
Whether the error message is critical.
Definition: error.h:33
ErrorMessageData::params
std::vector< StringParameterData > params
Backup of parameters of the message strings.
Definition: error.h:34
ErrorMessageData::CopyOutDParams
void CopyOutDParams()
Copy error parameters from current DParams.
Definition: error_gui.cpp:116
strings_type.h
geometry_type.hpp
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition: error_gui.cpp:439
ClearErrorMessages
void ClearErrorMessages()
Clear all errors from the queue.
Definition: error_gui.cpp:328
ErrorMessageData::SetDParam
void SetDParam(uint n, uint64_t v)
Set a error string parameter.
Definition: error_gui.cpp:135
CommandCost
Common return value for all commands.
Definition: command_type.h:23
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
ErrorMessageData
The data of the error message.
Definition: error.h:31
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
ErrorMessageData::face
CompanyID face
Company belonging to the face being shown. INVALID_COMPANY if no face present.
Definition: error.h:42
command_type.h
ErrorMessageData::HasFace
bool HasFace() const
Check whether error window shall display a company manager face.
Definition: error.h:52
ErrorMessageData::detailed_msg
StringID detailed_msg
Detailed error message showed in second line. Can be INVALID_STRING_ID.
Definition: error.h:39
UnshowCriticalError
void UnshowCriticalError()
Unshow the critical error.
Definition: error_gui.cpp:349
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:26
ErrorMessageData::textref_stack
uint32_t textref_stack[16]
Values to put on the TextRefStack for the error message.
Definition: error.h:37
ErrorMessageData::extra_msg
StringID extra_msg
Extra error message shown in third line. Can be INVALID_STRING_ID.
Definition: error.h:40
company_type.h
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:108
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:27
ErrorMessageData::summary_msg
StringID summary_msg
General error message showed in first line. Must be valid.
Definition: error.h:38
ErrorMessageData::ErrorMessageData
ErrorMessageData(const ErrorMessageData &data)
Copy the given data into our instance.
Definition: error_gui.cpp:77