27 #include "table/strings.h" 32 static const NWidgetPart _nested_errmsg_widgets[] = {
46 _nested_errmsg_widgets,
lengthof(_nested_errmsg_widgets)
49 static const NWidgetPart _nested_errmsg_face_widgets[] = {
56 NWidget(
WWT_EMPTY, COLOUR_RED,
WID_EM_FACE),
SetMinimalSize(92, 119),
SetFill(0, 1),
SetPadding(2, 0, 1, 0),
66 _nested_errmsg_face_widgets,
lengthof(_nested_errmsg_face_widgets)
74 duration(data.duration), 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)
81 if (this->
strings[i] !=
nullptr) {
107 textref_stack_grffile(textref_stack_grffile),
108 textref_stack_size(textref_stack_size),
109 summary_msg(summary_msg),
110 detailed_msg(detailed_msg),
119 if (textref_stack_size > 0)
MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
139 if (this->detailed_msg == STR_ERROR_OWNED_BY) {
201 size->height =
max(size->height, panel_height);
206 size->width =
max(size->width, face_size.width);
207 size->height =
max(size->height, face_size.height);
216 if (this->
position.x == 0 && this->position.y == 0) {
217 Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
232 pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20;
236 pt.y = (pt.y < (_screen.height >> 1)) ? scr_bot - sm_height : scr_top;
275 this->summary_msg, TC_FROMSTRING,
SA_CENTER);
277 int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed -
WD_PAR_VSEP_WIDE) / 2;
281 int bottom = top + this->height_summary + extra;
285 top = bottom - this->height_detailed - extra;
308 if (this->
duration == 0)
delete this;
347 _window_system_initialized =
true;
348 if (!_error_list.empty()) {
350 _error_list.pop_front();
362 if (_window_system_initialized && w !=
nullptr) {
363 if (w->
IsCritical()) _error_list.push_front(*w);
364 _window_system_initialized =
false;
382 assert(textref_stack_size == 0 || (textref_stack_grffile !=
nullptr && textref_stack !=
nullptr));
383 if (summary_msg == STR_NULL) summary_msg = STR_EMPTY;
389 if (textref_stack_size > 0)
StartTextRefStackUsage(textref_stack_grffile, textref_stack_size, textref_stack);
391 char *b = GetString(buf, summary_msg,
lastof(buf));
394 GetString(b, detailed_msg,
lastof(buf));
418 _error_list.push_back(data);
434 _error_list.splice(_error_list.end(), datas);
444 _error_list.push_back(data);
EventState
State of handling an event.
Functions related to OTTD's strings.
Owner
Enum for all companies/owners.
void ShowFirstError()
Show the first error of the queue.
Definition of stuff that is very close to a company, like the company struct itself.
int virtual_left
Virtual left coordinate.
uint textref_stack_size
Number of uint32 values to put on the TextRefStack for the error message.
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
High level window description.
static uint64 GetDParamX(const uint64 *s, uint n)
Get the current string parameter at index n from parameter array s.
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
static Titem * Get(size_t index)
Returns Titem with given index.
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...
void OnHundredthTick() override
Called once every 100 (game) ticks.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
bool _right_button_down
Is right mouse button pressed?
ErrorMessageData(const ErrorMessageData &data)
Copy the given data into our instance.
Offset at top to draw the frame rectangular area.
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"...
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
The passed event is not handled.
static int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right...
void SetDParam(uint n, uint64 v)
Set a error string parameter.
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
void CopyInDParam(int offs, const uint64 *src, int num)
Copy num string parameters from array src into the global string parameter array. ...
CompanyID face
Company belonging to the face being shown. INVALID_COMPANY if no face present.
void DrawCompanyManagerFace(CompanyManagerFace cmf, int colour, int x, int y)
Draws the face of a company manager's face.
bool IsCritical()
Check whether the currently shown error message was critical or not.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
byte errmsg_duration
duration of error message
#define lastof(x)
Get the last element of an fixed size array.
static T max(const T a, const T b)
Returns the maximum of two values.
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.
Large amount of vertical space between two paragraphs of text.
void CopyOutDParams()
Copy error parameters from current DParams.
Functions, definitions and such used only by the GUI.
~ErrorMessageData()
Free all the strings.
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Functions related to (drawing on) viewports.
uint32 textref_stack[16]
Values to put on the TextRefStack for the error message.
Data structure for an opened window.
Critical errors, the MessageBox is shown in all cases.
Header of Action 04 "universal holder" structure and functions.
Main window; Window numbers:
Functions related to low-level strings.
Functions related to errors.
Error message; Window numbers:
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
void UnshowCriticalError()
Unshow the critical error.
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means...
Functions related to the gfx engine.
ClientSettings _settings_client
The current settings for this game.
Definition of base types and functions in a cross-platform compatible way.
ErrorList _error_list
The actual queue with errors.
Center both horizontally and vertically.
int GetMainViewTop()
Return the top of the main view available for general use.
A number of safeguards to prevent using unsafe methods.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void CopyOutDParam(uint64 *dst, int offs, int num)
Copy num string parameters from the global string parameter array to the dst array.
StringID detailed_msg
Detailed error message showed in second line. Can be INVALID_STRING_ID.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Console functions used outside of the console code.
bool _window_system_initialized
Whether the window system is initialized or not.
StringID summary_msg
General error message showed in first line. Must be valid.
Offset at bottom to draw the frame rectangular area.
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.
uint height_summary
Height of the summary_msg string in pixels in the WID_EM_MESSAGE widget.
Right offset of the text of the frame.
#define lengthof(x)
Return the length of an fixed size array.
const char * strings[20]
Copies of raw strings that were used.
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Left offset of the text of the frame.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
CompanyManagerFace face
Face description of the president.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
bool HasFace() const
Check whether error window shall display a company manager face.
int left
Screen coordinate left edge of the viewport.
No window, redirects to WC_MAIN_WINDOW.
The data of the error message.
Functionality related to the company manager's face.
GUISettings gui
settings related to the GUI
Data structure for viewport, display of a part of the world.
uint duration
Length of display of the message. 0 means forever,.
void ClearErrorMessages()
Clear all errors from the queue.
Window class for displaying an error message window.
byte colour
Company colour.
void IConsoleError(const char *string)
It is possible to print error information to the console.
Functions related to zooming.
Maximum number of companies.
const GRFFile * textref_stack_grffile
NewGRF that filled the TextRefStack for the error message.
Functions related to OTTD's landscape.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
ZoomLevel zoom
The zoom level of the viewport.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
int virtual_top
Virtual top coordinate.
Specification of a rectangle with absolute coordinates of all edges.
The passed event is handled.
uint64 decode_params[20]
Parameters of the message strings.
Window functions not directly related to making/drawing windows.
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
int top
Screen coordinate top edge of the viewport.
Manually align the window (so no automatic location finding)
ViewportData * viewport
Pointer to viewport data, if present.
uint32 WChar
Type for wide characters, i.e.
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
static const TextColour CC_WARNING
Colour for warning lines.
Dimensions (a width and height) of a rectangle in 2D.
Point position
Position of the error message window.
uint height_detailed
Height of the detailed_msg string in pixels in the WID_EM_MESSAGE widget.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
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.
Dynamic data of a loaded NewGRF.
WarningLevel
Message severity/type.