OpenTTD Source: src/error_gui.cpp Source File

OpenTTD Source 1.11.0-RC1

error_gui.cpp
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 #include "stdafx.h"
11 #include "landscape.h"
12 #include "newgrf_text.h"
13 #include "error.h"
14 #include "viewport_func.h"
15 #include "gfx_func.h"
16 #include "string_func.h"
17 #include "company_base.h"
18 #include "company_manager_face.h"
19 #include "strings_func.h"
20 #include "zoom_func.h"
21 #include "window_func.h"
22 #include "console_func.h"
23 #include "window_gui.h"
24
25 #include "widgets/error_widget.h"
26
27 #include "table/strings.h"
28 #include <list>
29
30 #include "safeguards.h"
31
32 static const NWidgetPart _nested_errmsg_widgets[] = {
33 NWidget(NWID_HORIZONTAL),
34 NWidget(WWT_CLOSEBOX, COLOUR_RED),
35 NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION, STR_NULL),
36 EndContainer(),
37 NWidget(WWT_PANEL, COLOUR_RED),
38 NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_MESSAGE), SetPadding(0, 2, 0, 2), SetMinimalSize(236, 32),
39 EndContainer(),
40 };
41
42 static WindowDesc _errmsg_desc(
43 WDP_MANUAL, "error", 0, 0,
44 WC_ERRMSG, WC_NONE,
45 0,
46 _nested_errmsg_widgets, lengthof(_nested_errmsg_widgets)
47 );
48
49 static const NWidgetPart _nested_errmsg_face_widgets[] = {
50 NWidget(NWID_HORIZONTAL),
51 NWidget(WWT_CLOSEBOX, COLOUR_RED),
52 NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_NULL),
53 EndContainer(),
54 NWidget(WWT_PANEL, COLOUR_RED),
55 NWidget(NWID_HORIZONTAL), SetPIP(2, 1, 2),
56 NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_FACE), SetMinimalSize(92, 119), SetFill(0, 1), SetPadding(2, 0, 1, 0),
57 NWidget(WWT_EMPTY, COLOUR_RED, WID_EM_MESSAGE), SetFill(0, 1), SetMinimalSize(238, 123),
58 EndContainer(),
59 EndContainer(),
60 };
61
62 static WindowDesc _errmsg_face_desc(
63 WDP_MANUAL, "error_face", 0, 0,
64 WC_ERRMSG, WC_NONE,
65 0,
66 _nested_errmsg_face_widgets, lengthof(_nested_errmsg_face_widgets)
67 );
68
73 ErrorMessageData::ErrorMessageData(const ErrorMessageData &data) :
74 display_timer(data.display_timer), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size),
75 summary_msg(data.summary_msg), detailed_msg(data.detailed_msg), position(data.position), face(data.face)
76 {
77 memcpy(this->textref_stack, data.textref_stack, sizeof(this->textref_stack));
78 memcpy(this->decode_params, data.decode_params, sizeof(this->decode_params));
79 memcpy(this->strings, data.strings, sizeof(this->strings));
80 for (size_t i = 0; i < lengthof(this->strings); i++) {
81 if (this->strings[i] != nullptr) {
82 this->strings[i] = stredup(this->strings[i]);
83 this->decode_params[i] = (size_t)this->strings[i];
84 }
85 }
86 }
87
89 ErrorMessageData::~ErrorMessageData()
90 {
91 for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]);
92 }
93
105 ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration, int x, int y, const GRFFile *textref_stack_grffile, uint textref_stack_size, const uint32 *textref_stack) :
106 textref_stack_grffile(textref_stack_grffile),
107 textref_stack_size(textref_stack_size),
108 summary_msg(summary_msg),
109 detailed_msg(detailed_msg),
110 face(INVALID_COMPANY)
111 {
112 this->position.x = x;
113 this->position.y = y;
114
115 memset(this->decode_params, 0, sizeof(this->decode_params));
116 memset(this->strings, 0, sizeof(this->strings));
117
118 if (textref_stack_size > 0) MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
119
120 assert(summary_msg != INVALID_STRING_ID);
121
122 this->display_timer.SetInterval(duration * 3000);
123 }
124
128 void ErrorMessageData::CopyOutDParams()
129 {
130 /* Reset parameters */
131 for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]);
132 memset(this->decode_params, 0, sizeof(this->decode_params));
133 memset(this->strings, 0, sizeof(this->strings));
134
135 /* Get parameters using type information */
136 if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
137 CopyOutDParam(this->decode_params, this->strings, this->detailed_msg == INVALID_STRING_ID ? this->summary_msg : this->detailed_msg, lengthof(this->decode_params));
138 if (this->textref_stack_size > 0) StopTextRefStackUsage();
139
140 if (this->detailed_msg == STR_ERROR_OWNED_BY) {
141 CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2);
142 if (company < MAX_COMPANIES) face = company;
143 }
144 }
145
151 void ErrorMessageData::SetDParam(uint n, uint64 v)
152 {
153 this->decode_params[n] = v;
154 }
155
161 void ErrorMessageData::SetDParamStr(uint n, const char *str)
162 {
163 free(this->strings[n]);
164 this->strings[n] = stredup(str);
165 }
166
168 typedef std::list<ErrorMessageData> ErrorList;
170 ErrorList _error_list;
172 bool _window_system_initialized = false;
173
175 struct ErrmsgWindow : public Window, ErrorMessageData {
176 private:
177 uint height_summary;
178 uint height_detailed;
179
180 public:
181 ErrmsgWindow(const ErrorMessageData &data) : Window(data.HasFace() ? &_errmsg_face_desc : &_errmsg_desc), ErrorMessageData(data)
182 {
183 this->InitNested();
184 }
185
186 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
187 {
188 switch (widget) {
189 case WID_EM_MESSAGE: {
190 CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
191 if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
192
193 int text_width = std::max(0, (int)size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT);
194 this->height_summary = GetStringHeight(this->summary_msg, text_width);
195 this->height_detailed = (this->detailed_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->detailed_msg, text_width);
196
197 if (this->textref_stack_size > 0) StopTextRefStackUsage();
198
199 uint panel_height = WD_FRAMERECT_TOP + this->height_summary + WD_FRAMERECT_BOTTOM;
200 if (this->detailed_msg != INVALID_STRING_ID) panel_height += this->height_detailed + WD_PAR_VSEP_WIDE;
201
202 size->height = std::max(size->height, panel_height);
203 break;
204 }
205 case WID_EM_FACE: {
206 Dimension face_size = GetSpriteSize(SPR_GRADIENT);
207 size->width = std::max(size->width, face_size.width);
208 size->height = std::max(size->height, face_size.height);
209 break;
210 }
211 }
212 }
213
214 Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
215 {
216 /* Position (0, 0) given, center the window. */
217 if (this->position.x == 0 && this->position.y == 0) {
218 Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
219 return pt;
220 }
221
222 /* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
223 * Add a fixed distance 20 to make it less cluttered.
224 */
225 int scr_top = GetMainViewTop() + 20;
226 int scr_bot = GetMainViewBottom() - 20;
227
228 Point pt = RemapCoords(this->position.x, this->position.y, GetSlopePixelZOutsideMap(this->position.x, this->position.y));
229 const Viewport *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
230 if (this->face == INVALID_COMPANY) {
231 /* move x pos to opposite corner */
232 pt.x = UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left;
233 pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20; // Stay 20 pixels away from the edge of the screen.
234
235 /* move y pos to opposite corner */
236 pt.y = UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top;
237 pt.y = (pt.y < (_screen.height >> 1)) ? scr_bot - sm_height : scr_top;
238 } else {
239 pt.x = Clamp(UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left - (sm_width / 2), 0, _screen.width - sm_width);
240 pt.y = Clamp(UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top - (sm_height / 2), scr_top, scr_bot - sm_height);
241 }
242 return pt;
243 }
244
250 void OnInvalidateData(int data = 0, bool gui_scope = true) override
251 {
252 /* If company gets shut down, while displaying an error about it, remove the error message. */
253 if (this->face != INVALID_COMPANY && !Company::IsValidID(this->face)) delete this;
254 }
255
256 void SetStringParameters(int widget) const override
257 {
258 if (widget == WID_EM_CAPTION) CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
259 }
260
261 void DrawWidget(const Rect &r, int widget) const override
262 {
263 switch (widget) {
264 case WID_EM_FACE: {
265 const Company *c = Company::Get(this->face);
266 DrawCompanyManagerFace(c->face, c->colour, r.left, r.top);
267 break;
268 }
269
270 case WID_EM_MESSAGE:
271 CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
272 if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
273
274 if (this->detailed_msg == INVALID_STRING_ID) {
275 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
276 this->summary_msg, TC_FROMSTRING, SA_CENTER);
277 } else {
278 int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2;
279
280 /* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
281 int top = r.top + WD_FRAMERECT_TOP;
282 int bottom = top + this->height_summary + extra;
283 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->summary_msg, TC_WHITE, SA_CENTER);
284
285 bottom = r.bottom - WD_FRAMERECT_BOTTOM;
286 top = bottom - this->height_detailed - extra;
287 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->detailed_msg, TC_WHITE, SA_CENTER);
288 }
289
290 if (this->textref_stack_size > 0) StopTextRefStackUsage();
291 break;
292
293 default:
294 break;
295 }
296 }
297
298 void OnMouseLoop() override
299 {
300 /* Disallow closing the window too easily, if timeout is disabled */
301 if (_right_button_down && !this->display_timer.HasElapsed()) delete this;
302 }
303
304 void OnRealtimeTick(uint delta_ms) override
305 {
306 if (this->display_timer.CountElapsed(delta_ms) == 0) return;
307
308 delete this;
309 }
310
311 ~ErrmsgWindow()
312 {
313 SetRedErrorSquare(INVALID_TILE);
314 if (_window_system_initialized) ShowFirstError();
315 }
316
321 bool IsCritical()
322 {
323 return this->display_timer.HasElapsed();
324 }
325 };
326
330 void ClearErrorMessages()
331 {
332 UnshowCriticalError();
333 _error_list.clear();
334 }
335
337 void ShowFirstError()
338 {
339 _window_system_initialized = true;
340 if (!_error_list.empty()) {
341 new ErrmsgWindow(_error_list.front());
342 _error_list.pop_front();
343 }
344 }
345
351 void UnshowCriticalError()
352 {
353 ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
354 if (_window_system_initialized && w != nullptr) {
355 if (w->IsCritical()) _error_list.push_front(*w);
356 _window_system_initialized = false;
357 delete w;
358 }
359 }
360
372 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 *textref_stack)
373 {
374 assert(textref_stack_size == 0 || (textref_stack_grffile != nullptr && textref_stack != nullptr));
375 if (summary_msg == STR_NULL) summary_msg = STR_EMPTY;
376
377 if (wl != WL_INFO) {
378 /* Print message to console */
379 char buf[DRAW_STRING_BUFFER];
380
381 if (textref_stack_size > 0) StartTextRefStackUsage(textref_stack_grffile, textref_stack_size, textref_stack);
382
383 char *b = GetString(buf, summary_msg, lastof(buf));
384 if (detailed_msg != INVALID_STRING_ID) {
385 b += seprintf(b, lastof(buf), " ");
386 GetString(b, detailed_msg, lastof(buf));
387 }
388
389 if (textref_stack_size > 0) StopTextRefStackUsage();
390
391 switch (wl) {
392 case WL_WARNING: IConsolePrint(CC_WARNING, buf); break;
393 default: IConsoleError(buf); break;
394 }
395 }
396
397 bool no_timeout = wl == WL_CRITICAL;
398
399 if (_game_mode == GM_BOOTSTRAP) return;
400 if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return;
401
402 ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? 0 : _settings_client.gui.errmsg_duration, x, y, textref_stack_grffile, textref_stack_size, textref_stack);
403 data.CopyOutDParams();
404
405 ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
406 if (w != nullptr && w->IsCritical()) {
407 /* A critical error is currently shown. */
408 if (wl == WL_CRITICAL) {
409 /* Push another critical error in the queue of errors,
410 * but do not put other errors in the queue. */
411 _error_list.push_back(data);
412 }
413 } else {
414 /* Nothing or a non-critical error was shown. */
415 delete w;
416 new ErrmsgWindow(data);
417 }
418 }
419
420
425 bool HideActiveErrorMessage() {
426 ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
427 if (w == nullptr) return false;
428 delete w;
429 return true;
430 }
431
437 void ScheduleErrorMessage(ErrorList &datas)
438 {
439 _error_list.splice(_error_list.end(), datas);
440 }
441
447 void ScheduleErrorMessage(const ErrorMessageData &data)
448 {
449 _error_list.push_back(data);
450 }
ErrorMessageData::position
Point position
Position of the error message window.
Definition: error.h:39
ErrorList
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Definition: error_gui.cpp:168
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
ErrmsgWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: error_gui.cpp:250
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
ErrorMessageData::textref_stack_grffile
const GRFFile * textref_stack_grffile
NewGRF that filled the TextRefStack for the error message.
Definition: error.h:34
CopyOutDParam
void CopyOutDParam(uint64 *dst, int offs, int num)
Copy num string parameters from the global string parameter array to the dst array.
Definition: strings.cpp:149
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
ErrorMessageData::textref_stack_size
uint textref_stack_size
Number of uint32 values to put on the TextRefStack for the error message.
Definition: error.h:35
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1045
ErrorMessageData::SetDParamStr
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:161
WarningLevel
WarningLevel
Message severity/type.
Definition: error.h:21
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:23
ErrorMessageData::decode_params
uint64 decode_params[20]
Parameters of the message strings.
Definition: error.h:32
company_base.h
ErrmsgWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: error_gui.cpp:186
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
RemapCoords
static Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition: landscape.h:82
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:326
SetRedErrorSquare
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition: viewport.cpp:2452
company_manager_face.h
GetDParamX
static uint64 GetDParamX(const uint64 *s, uint n)
Get the current string parameter at index n from parameter array s.
Definition: strings_func.h:219
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
ErrmsgWindow::height_summary
uint height_summary
Height of the summary_msg string in pixels in the WID_EM_MESSAGE widget.
Definition: error_gui.cpp:177
zoom_func.h
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:822
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
ErrorMessageData::~ErrorMessageData
~ErrorMessageData()
Free all the strings.
Definition: error_gui.cpp:89
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
CompanyProperties::face
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:64
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:839
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_func.h:106
ErrmsgWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: error_gui.cpp:261
ErrorMessageData::CopyOutDParams
void CopyOutDParams()
Copy error parameters from current DParams.
Definition: error_gui.cpp:128
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:29
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
MemCpyT
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
Definition: mem_func.hpp:23
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:70
UnshowCriticalError
void UnshowCriticalError()
Unshow the critical error.
Definition: error_gui.cpp:351
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:763
ErrmsgWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: error_gui.cpp:256
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:166
window_gui.h
ErrmsgWindow::height_detailed
uint height_detailed
Height of the detailed_msg string in pixels in the WID_EM_MESSAGE widget.
Definition: error_gui.cpp:178
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
CompanyProperties::colour
byte colour
Company colour.
Definition: company_base.h:70
DRAW_STRING_BUFFER
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
Definition: gfx_func.h:85
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
ErrorMessageData::textref_stack
uint32 textref_stack[16]
Values to put on the TextRefStack for the error message.
Definition: error.h:36
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1861
ErrorMessageData::SetDParam
void SetDParam(uint n, uint64 v)
Set a error string parameter.
Definition: error_gui.cpp:151
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:28
Viewport::left
int left
Screen coordinate left edge of the viewport.
Definition: viewport_type.h:23
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
IConsoleError
void IConsoleError(const char *string)
It is possible to print error information to the console.
Definition: console.cpp:168
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2189
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
ShowErrorMessage
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 *textref_stack)
Display an error message in a window.
Definition: error_gui.cpp:372
safeguards.h
_error_list
ErrorList _error_list
The actual queue with errors.
Definition: error_gui.cpp:170
newgrf_text.h
ErrorMessageData
The data of the error message.
Definition: error.h:29
ErrmsgWindow::OnInitialPosition
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
Definition: error_gui.cpp:214
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
UnScaleByZoom
static int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:34
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:71
ErrorMessageData::face
CompanyID face
Company belonging to the face being shown. INVALID_COMPANY if no face present.
Definition: error.h:40
stdafx.h
IConsolePrint
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:85
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
landscape.h
ErrmsgWindow::IsCritical
bool IsCritical()
Check whether the currently shown error message was critical or not.
Definition: error_gui.cpp:321
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
_window_system_initialized
bool _window_system_initialized
Whether the window system is initialized or not.
Definition: error_gui.cpp:172
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:689
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
ErrorMessageData::display_timer
GUITimer display_timer
Timer before closing the message.
Definition: error.h:31
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
strings_func.h
ErrorMessageData::HasFace
bool HasFace() const
Check whether error window shall display a company manager face.
Definition: error.h:48
ErrorMessageData::detailed_msg
StringID detailed_msg
Detailed error message showed in second line. Can be INVALID_STRING_ID.
Definition: error.h:38
WID_EM_MESSAGE
@ WID_EM_MESSAGE
Error message.
Definition: error_widget.h:17
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
error_widget.h
ErrmsgWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: error_gui.cpp:298
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
DrawCompanyManagerFace
void DrawCompanyManagerFace(CompanyManagerFace cmf, int colour, int x, int y)
Draws the face of a company manager's face.
Definition: company_gui.cpp:1113
GUITimer::CountElapsed
uint CountElapsed(uint delta)
Count how many times the interval has elapsed.
Definition: guitimer_func.h:40
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:442
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
ClearErrorMessages
void ClearErrorMessages()
Clear all errors from the queue.
Definition: error_gui.cpp:330
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:318
ErrorMessageData::strings
const char * strings[20]
Copies of raw strings that were used.
Definition: error.h:33
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1075
GetSlopePixelZOutsideMap
int GetSlopePixelZOutsideMap(int x, int y)
Return world z coordinate of a given point of a tile, also for tiles outside the map (virtual "black"...
Definition: landscape.cpp:357
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
HideActiveErrorMessage
bool HideActiveErrorMessage()
Close active error message window.
Definition: error_gui.cpp:425
ShowFirstError
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:337
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:982
Window
Data structure for an opened window.
Definition: window_gui.h:276
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
ErrmsgWindow
Window class for displaying an error message window.
Definition: error_gui.cpp:175
WID_EM_CAPTION
@ WID_EM_CAPTION
Caption of the window.
Definition: error_widget.h:15
console_func.h
WC_ERRMSG
@ WC_ERRMSG
Error message; Window numbers:
Definition: window_type.h:103
CC_WARNING
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:454
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2200
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
Company
Definition: company_base.h:110
GUISettings::errmsg_duration
byte errmsg_duration
duration of error message
Definition: settings_type.h:102
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
WD_PAR_VSEP_WIDE
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:138
WID_EM_FACE
@ WID_EM_FACE
Error title.
Definition: error_widget.h:16
ErrmsgWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: error_gui.cpp:304
ScheduleErrorMessage
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
Definition: error_gui.cpp:437
_right_button_down
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:40
CopyInDParam
void CopyInDParam(int offs, const uint64 *src, int num)
Copy num string parameters from array src into the global string parameter array.
Definition: strings.cpp:138
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:105
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:577
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:25
ErrorMessageData::summary_msg
StringID summary_msg
General error message showed in first line. Must be valid.
Definition: error.h:37
ErrorMessageData::ErrorMessageData
ErrorMessageData(const ErrorMessageData &data)
Copy the given data into our instance.
Definition: error_gui.cpp:73