Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / error.h
blob06440c127c7a330f096853c8ad7f10a5b6c01719
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 */
8 /** @file error.h Functions related to errors. */
10 #ifndef ERROR_H
11 #define ERROR_H
13 #include "strings_type.h"
14 #include "company_type.h"
15 #include "core/geometry_type.hpp"
16 #include "guitimer_func.h"
18 struct GRFFile;
20 /** Message severity/type */
21 enum WarningLevel {
22 WL_INFO, ///< Used for DoCommand-like (and some non-fatal AI GUI) errors/information
23 WL_WARNING, ///< Other information
24 WL_ERROR, ///< Errors (eg. saving/loading failed)
25 WL_CRITICAL, ///< Critical errors, the MessageBox is shown in all cases
28 /** The data of the error message. */
29 class ErrorMessageData {
30 protected:
31 GUITimer display_timer; ///< Timer before closing the message.
32 uint64 decode_params[20]; ///< Parameters of the message strings.
33 const char *strings[20]; ///< Copies of raw strings that were used.
34 const GRFFile *textref_stack_grffile; ///< NewGRF that filled the #TextRefStack for the error message.
35 uint textref_stack_size; ///< Number of uint32 values to put on the #TextRefStack for the error message.
36 uint32 textref_stack[16]; ///< Values to put on the #TextRefStack for the error message.
37 StringID summary_msg; ///< General error message showed in first line. Must be valid.
38 StringID detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID.
39 Point position; ///< Position of the error message window.
40 CompanyID face; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
42 public:
43 ErrorMessageData(const ErrorMessageData &data);
44 ~ErrorMessageData();
45 ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration = 0, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr);
47 /* Remove the copy assignment, as the default implementation will not do the right thing. */
48 ErrorMessageData &operator=(ErrorMessageData &rhs) = delete;
50 /** Check whether error window shall display a company manager face */
51 bool HasFace() const { return face != INVALID_COMPANY; }
53 void SetDParam(uint n, uint64 v);
54 void SetDParamStr(uint n, const char *str);
55 void SetDParamStr(uint n, const std::string &str);
57 void CopyOutDParams();
60 void ScheduleErrorMessage(const ErrorMessageData &data);
62 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);
63 bool HideActiveErrorMessage();
65 void ClearErrorMessages();
66 void ShowFirstError();
67 void UnshowCriticalError();
69 #endif /* ERROR_H */