OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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 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)
81 if (this->
strings[i] !=
nullptr) {
106 textref_stack_grffile(textref_stack_grffile),
107 textref_stack_size(textref_stack_size),
108 summary_msg(summary_msg),
109 detailed_msg(detailed_msg),
140 if (this->detailed_msg == STR_ERROR_OWNED_BY) {
202 size->height = std::max(size->height, panel_height);
207 size->width = std::max(size->width, face_size.width);
208 size->height = std::max(size->height, face_size.height);
217 if (this->
position.x == 0 && this->position.y == 0) {
218 Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
233 pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20;
237 pt.y = (pt.y < (_screen.height >> 1)) ? scr_bot - sm_height : scr_top;
276 this->summary_msg, TC_FROMSTRING,
SA_CENTER);
278 int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed -
WD_PAR_VSEP_WIDE) / 2;
282 int bottom =
top + this->height_summary + extra;
286 top = bottom - this->height_detailed - extra;
374 assert(textref_stack_size == 0 || (textref_stack_grffile !=
nullptr && textref_stack !=
nullptr));
375 if (summary_msg == STR_NULL) summary_msg = STR_EMPTY;
381 if (textref_stack_size > 0)
StartTextRefStackUsage(textref_stack_grffile, textref_stack_size, textref_stack);
383 char *b = GetString(buf, summary_msg,
lastof(buf));
386 GetString(b, detailed_msg,
lastof(buf));
426 if (w ==
nullptr)
return false;
Point position
Position of the error message window.
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static Titem * Get(size_t index)
Returns Titem with given index.
const GRFFile * textref_stack_grffile
NewGRF that filled the TextRefStack for the error message.
void CopyOutDParam(uint64 *dst, int offs, int num)
Copy num string parameters from the global string parameter array to the dst array.
Dimensions (a width and height) of a rectangle in 2D.
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.
WarningLevel
Message severity/type.
@ WL_WARNING
Other information.
uint64 decode_params[20]
Parameters of the message strings.
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.
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.
ViewportData * viewport
Pointer to viewport data, if present.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
static uint64 GetDParamX(const uint64 *s, uint n)
Get the current string parameter at index n from parameter array s.
int top
Screen coordinate top edge of the viewport.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
uint height_summary
Height of the summary_msg string in pixels in the WID_EM_MESSAGE widget.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
ClientSettings _settings_client
The current settings for this game.
~ErrorMessageData()
Free all the strings.
CompanyManagerFace face
Face description of the president.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
@ SA_CENTER
Center both horizontally and vertically.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void CopyOutDParams()
Copy error parameters from current DParams.
int virtual_top
Virtual top coordinate.
Owner
Enum for all companies/owners.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
void UnshowCriticalError()
Unshow the critical error.
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.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
High level window description.
uint height_detailed
Height of the detailed_msg string in pixels in the WID_EM_MESSAGE widget.
Data structure for viewport, display of a part of the world.
byte colour
Company colour.
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
ResizeInfo resize
Resize information.
uint32 textref_stack[16]
Values to put on the TextRefStack for the error message.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void SetDParam(uint n, uint64 v)
Set a error string parameter.
int virtual_left
Virtual left coordinate.
int left
Screen coordinate left edge of the viewport.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
void IConsoleError(const char *string)
It is possible to print error information to the console.
int GetMainViewTop()
Return the top of the main view available for general use.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ MAX_COMPANIES
Maximum number of companies.
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.
ErrorList _error_list
The actual queue with errors.
The data of the error message.
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
Coordinates of a point in 2D.
static int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
CompanyID face
Company belonging to the face being shown. INVALID_COMPANY if no face present.
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means.
WindowNumber window_number
Window number within the window class.
bool IsCritical()
Check whether the currently shown error message was critical or not.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
bool _window_system_initialized
Whether the window system is initialized or not.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
GUITimer display_timer
Timer before closing the message.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
bool HasFace() const
Check whether error window shall display a company manager face.
StringID detailed_msg
Detailed error message showed in second line. Can be INVALID_STRING_ID.
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
void DrawCompanyManagerFace(CompanyManagerFace cmf, int colour, int x, int y)
Draws the face of a company manager's face.
uint CountElapsed(uint delta)
Count how many times the interval has elapsed.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
@ WC_MAIN_WINDOW
Main window; Window numbers:
void ClearErrorMessages()
Clear all errors from the queue.
int top
y position of top edge of the window
const char * strings[20]
Copies of raw strings that were used.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
#define lengthof(x)
Return the length of an fixed size array.
ZoomLevel zoom
The zoom level of the viewport.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
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"...
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
@ INVALID_COMPANY
An invalid company.
bool HideActiveErrorMessage()
Close active error message window.
void ShowFirstError()
Show the first error of the queue.
Data structure for an opened window.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Window class for displaying an error message window.
@ WC_ERRMSG
Error message; Window numbers:
static const TextColour CC_WARNING
Colour for warning lines.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Specification of a rectangle with absolute coordinates of all edges.
byte errmsg_duration
duration of error message
#define lastof(x)
Get the last element of an fixed size array.
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
bool _right_button_down
Is right mouse button pressed?
void CopyInDParam(int offs, const uint64 *src, int num)
Copy num string parameters from array src into the global string parameter array.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
StringID summary_msg
General error message showed in first line. Must be valid.
ErrorMessageData(const ErrorMessageData &data)
Copy the given data into our instance.