OpenTTD Source 20241224-master-gee860a5c8e
error_gui.cpp File Reference

GUI related to errors. More...

#include "stdafx.h"
#include "core/geometry_func.hpp"
#include "core/mem_func.hpp"
#include "landscape.h"
#include "newgrf_text.h"
#include "error.h"
#include "viewport_func.h"
#include "gfx_func.h"
#include "string_func.h"
#include "company_base.h"
#include "company_func.h"
#include "company_manager_face.h"
#include "strings_func.h"
#include "zoom_func.h"
#include "window_func.h"
#include "console_func.h"
#include "window_gui.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "widgets/error_widget.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  ErrmsgWindow
 Window class for displaying an error message window. More...
 

Functions

void ClearErrorMessages ()
 Clear all errors from the queue.
 
void ShowFirstError ()
 Show the first error of the queue.
 
void UnshowCriticalError ()
 Unshow the critical error.
 
void ShowErrorMessage (StringID summary_msg, int x, int y, CommandCost cc)
 Display an error message in a window.
 
void ShowErrorMessage (StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x, int y, const GRFFile *textref_stack_grffile, uint textref_stack_size, const uint32_t *textref_stack, StringID extra_msg)
 Display an error message in a window.
 
bool HideActiveErrorMessage ()
 Close active error message window.
 
void ScheduleErrorMessage (ErrorList &datas)
 Schedule a list of errors.
 
void ScheduleErrorMessage (const ErrorMessageData &data)
 Schedule an error.
 

Variables

static constexpr NWidgetPart _nested_errmsg_widgets []
 
static WindowDesc _errmsg_desc (WDP_MANUAL, nullptr, 0, 0, WC_ERRMSG, WC_NONE, 0, _nested_errmsg_widgets)
 
static constexpr NWidgetPart _nested_errmsg_face_widgets []
 
static WindowDesc _errmsg_face_desc (WDP_MANUAL, nullptr, 0, 0, WC_ERRMSG, WC_NONE, 0, _nested_errmsg_face_widgets)
 
static ErrorList _error_list
 The actual queue with errors.
 
bool _window_system_initialized = false
 Whether the window system is initialized or not.
 

Detailed Description

GUI related to errors.

Definition in file error_gui.cpp.

Function Documentation

◆ ClearErrorMessages()

void ClearErrorMessages ( )

Clear all errors from the queue.

Definition at line 328 of file error_gui.cpp.

References _error_list, and UnshowCriticalError().

Referenced by SaveLoadWindow::OnClick(), and ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE().

◆ HideActiveErrorMessage()

bool HideActiveErrorMessage ( )

Close active error message window.

Returns
true if a window was closed.

Definition at line 439 of file error_gui.cpp.

References ErrmsgWindow::Close(), FindWindowById(), and WC_ERRMSG.

Referenced by MainWindow::OnHotkey().

◆ ScheduleErrorMessage() [1/2]

void ScheduleErrorMessage ( const ErrorMessageData data)

Schedule an error.

Note: This does not try to display the error now. This is useful if the window system is not yet running.

Parameters
dataError message data; cleared afterwards

Definition at line 462 of file error_gui.cpp.

References _error_list.

◆ ScheduleErrorMessage() [2/2]

void ScheduleErrorMessage ( ErrorList datas)

Schedule a list of errors.

Note: This does not try to display the error now. This is useful if the window system is not yet running.

Parameters
datasError message datas; cleared afterwards

Definition at line 452 of file error_gui.cpp.

References _error_list.

Referenced by LoadFromConfig(), openttd_main(), and DriverFactoryBase::SelectDriverImpl().

◆ ShowErrorMessage() [1/2]

void ShowErrorMessage ( StringID  summary_msg,
int  x,
int  y,
CommandCost  cc 
)

Display an error message in a window.

Note: CommandCost errors are always severity level WL_INFO.

Parameters
summary_msgGeneral error message showed in first line. Must be valid.
xWorld X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
yWorld Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
ccCommandCost containing the optional detailed and extra error messages shown in the second and third lines (can be INVALID_STRING_ID) and TextRefStack info.

Definition at line 367 of file error_gui.cpp.

References CommandCost::GetErrorMessage(), CommandCost::GetExtraErrorMessage(), CommandCost::GetTextRefStack(), CommandCost::GetTextRefStackGRF(), CommandCost::GetTextRefStackSize(), ShowErrorMessage(), and WL_INFO.

Referenced by NewGRFWindow::AddGRFToActive(), ClientNetworkContentSocketHandler::AfterDownload(), AfterLoadGame(), ClientNetworkContentSocketHandler::BeforeDownload(), CcBuildIndustry(), ClientNetworkGameSocketHandler::CheckConnection(), CheckDynamicEngines(), CheckEngines(), CheckForMissingGlyphs(), CheckIndustries(), CheckTownRoadTypes(), CheckTrainsLengths(), ClickChangeMaxHlCheat(), NetworkGameSocketHandler::CloseConnection(), CmdBuildIndustry(), AIInstance::Died(), GameInstance::Died(), DoAutoOrNetsave(), ErrorUnknownCallbackResult(), GenerateTowns(), GetOrderCmdFromTile(), GetSavegameFormat(), GraphicsSetLoadConfig(), GRFLoadConfig(), IndustryProductionCallback(), CommandHelperBase::InternalPostBefore(), CommandHelperBase::InternalPostResult(), LoadTownData(), NetworkValidateClientName(), NetworkValidateServerName(), AIConfigWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), SaveLoadWindow::OnClick(), GSConfigWindow::OnClick(), SelectGameWindow::OnClick(), NewGRFWindow::OnClick(), GameOptionsWindow::OnClick(), FoundTownWindow::OnClick(), NetworkContentListWindow::OnConnect(), GameOptionsWindow::OnDropdownSelect(), BuildIndustryWindow::OnPlaceObject(), SelectCompanyManagerFaceWindow::OnQueryTextFinished(), SaveLoadWindow::OnTimeout(), DepotWindow::OnVehicleSelect(), OrdersWindow::OnVehicleSelect(), ReadHeightmapBMP(), ReadHeightmapPNG(), RealMakeScreenshot(), ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(), ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(), ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(), ClientNetworkGameSocketHandler::Receive_SERVER_FULL(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(), ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(), SaveFileError(), SaveOrLoad(), ShowBuildBridgeWindow(), ShowErrorMessage(), ShowEstimatedCostOrIncome(), ShowNetworkContentListWindow(), ShowNewGRFError(), ShowNewGrfVehicleError(), ShowScriptDebugWindow(), TownActionBribe(), and WarnCorruptSprite().

◆ ShowErrorMessage() [2/2]

void ShowErrorMessage ( StringID  summary_msg,
StringID  detailed_msg,
WarningLevel  wl,
int  x,
int  y,
const GRFFile textref_stack_grffile,
uint  textref_stack_size,
const uint32_t *  textref_stack,
StringID  extra_msg 
)

Display an error message in a window.

Parameters
summary_msgGeneral error message showed in first line. Must be valid.
detailed_msgDetailed error message showed in second line. Can be INVALID_STRING_ID.
wlMessage severity.
xWorld X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
yWorld Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
textref_stack_grffileNewGRF providing the TextRefStack for the error message.
textref_stack_sizeNumber of uint32_t values to put on the TextRefStack for the error message; 0 if the TextRefStack shall not be used.
textref_stackValues to put on the TextRefStack.
extra_msgExtra error message shown in third line. Can be INVALID_STRING_ID.

Definition at line 384 of file error_gui.cpp.

References _error_list, _settings_client, AppendStringInPlace(), CC_ERROR, CC_WARNING, ErrmsgWindow::Close(), ErrorMessageData::CopyOutDParams(), GUISettings::errmsg_duration, FindWindowById(), GetString(), ClientSettings::gui, IConsolePrint(), INVALID_STRING_ID, ErrmsgWindow::IsCritical(), StartTextRefStackUsage(), StopTextRefStackUsage(), WC_ERRMSG, WL_CRITICAL, WL_INFO, and WL_WARNING.

◆ ShowFirstError()

void ShowFirstError ( )

Show the first error of the queue.

Definition at line 335 of file error_gui.cpp.

References _error_list, and _window_system_initialized.

Referenced by CleanupGeneration(), ErrmsgWindow::Close(), InitWindowSystem(), and LoadFromConfig().

◆ UnshowCriticalError()

void UnshowCriticalError ( )

Unshow the critical error.

This has to happen when a critical error is shown and we uninitialise the window system, i.e. remove all the windows.

Definition at line 349 of file error_gui.cpp.

References _error_list, _window_system_initialized, ErrmsgWindow::Close(), FindWindowById(), ErrmsgWindow::IsCritical(), and WC_ERRMSG.

Referenced by ClearErrorMessages(), GenerateWorld(), and UnInitWindowSystem().

Variable Documentation

◆ _error_list

ErrorList _error_list
static

The actual queue with errors.

Definition at line 164 of file error_gui.cpp.

Referenced by ClearErrorMessages(), ScheduleErrorMessage(), ScheduleErrorMessage(), ShowErrorMessage(), ShowFirstError(), and UnshowCriticalError().

◆ _nested_errmsg_face_widgets

constexpr NWidgetPart _nested_errmsg_face_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_RED),
NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_NULL),
NWidget(WWT_PANEL, COLOUR_RED),
NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_FACE), SetPadding(2, 0, 2, 2), SetFill(0, 1), SetMinimalSize(92, 119),
}
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
@ WID_EM_CAPTION
Caption of the window.
@ WID_EM_MESSAGE
Error message.
@ WID_EM_FACE
Error title.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:48

Definition at line 53 of file error_gui.cpp.

◆ _nested_errmsg_widgets

constexpr NWidgetPart _nested_errmsg_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_RED),
NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION, STR_NULL),
NWidget(WWT_PANEL, COLOUR_RED),
}

Definition at line 36 of file error_gui.cpp.

◆ _window_system_initialized

bool _window_system_initialized = false

Whether the window system is initialized or not.

Definition at line 166 of file error_gui.cpp.

Referenced by ErrmsgWindow::Close(), ShowFirstError(), and UnshowCriticalError().