OpenTTD Source: src/error.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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
20struct GRFFile;
21
23 enum WarningLevel : uint8_t {
24 WL_INFO,
25 WL_WARNING,
26 WL_ERROR,
27 WL_CRITICAL,
28};
29
31 class ErrorMessageData {
32protected:
33 bool is_critical;
34 EncodedString summary_msg;
35 EncodedString detailed_msg;
36 EncodedString extra_msg;
37 Point position;
38 CompanyID company;
39
40public:
41 ErrorMessageData(EncodedString &&summary_msg, EncodedString &&detailed_msg, bool is_critical = false, int x = 0, int y = 0, EncodedString &&extra_msg = {}, CompanyID company = CompanyID::Invalid());
42
44 bool HasFace() const { return company != CompanyID::Invalid(); }
45};
46
48 typedef std::list<ErrorMessageData> ErrorList;
49
50void ScheduleErrorMessage(ErrorList &datas);
51void ScheduleErrorMessage(const ErrorMessageData &data);
52
53void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc);
54void ShowErrorMessage(EncodedString &&summary_msg, EncodedString &&detailed_msg, WarningLevel wl, int x = 0, int y = 0, EncodedString &&extra_msg = {}, CompanyID company = CompanyID::Invalid());
55bool HideActiveErrorMessage();
56
57void ClearErrorMessages();
58void ShowFirstError();
59void UnshowCriticalError();
60
61#endif /* ERROR_H */
CommandCost
Common return value for all commands.
Definition command_type.h:24
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
ErrorMessageData
The data of the error message.
Definition error.h:31
ErrorMessageData::HasFace
bool HasFace() const
Check whether error window shall display a company manager face.
Definition error.h:44
ErrorMessageData::company
CompanyID company
Company belonging to the face being shown. CompanyID::Invalid() if no face present.
Definition error.h:38
ErrorMessageData::position
Point position
Position of the error message window.
Definition error.h:37
ErrorMessageData::detailed_msg
EncodedString detailed_msg
Detailed error message showed in second line. Can be INVALID_STRING_ID.
Definition error.h:35
ErrorMessageData::extra_msg
EncodedString extra_msg
Extra error message shown in third line. Can be INVALID_STRING_ID.
Definition error.h:36
ErrorMessageData::summary_msg
EncodedString summary_msg
General error message showed in first line. Must be valid.
Definition error.h:34
ErrorMessageData::is_critical
bool is_critical
Whether the error message is critical.
Definition error.h:33
command_type.h
Types related to commands.
company_type.h
Types related to companies.
UnshowCriticalError
void UnshowCriticalError()
Unshow the critical error.
Definition error_gui.cpp:278
ClearErrorMessages
void ClearErrorMessages()
Clear all errors from the queue.
Definition error_gui.cpp:257
ErrorList
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Definition error.h:48
ScheduleErrorMessage
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
Definition error_gui.cpp:374
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition error_gui.cpp:361
WarningLevel
WarningLevel
Message severity/type.
Definition error.h:23
WL_WARNING
@ WL_WARNING
Other information.
Definition error.h:25
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition error.h:27
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:24
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:296
ShowFirstError
void ShowFirstError()
Show the first error of the queue.
Definition error_gui.cpp:264
geometry_type.hpp
All geometry types in OpenTTD.
strings_type.h
Types related to strings.
Coord2D< int >
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >