29 #include "table/strings.h" 34 static const NWidgetPart _nested_errmsg_widgets[] = {
48 _nested_errmsg_widgets,
lengthof(_nested_errmsg_widgets)
51 static const NWidgetPart _nested_errmsg_face_widgets[] = {
58 NWidget(
WWT_EMPTY, COLOUR_RED,
WID_EM_FACE),
SetMinimalSize(92, 119),
SetFill(0, 1),
SetPadding(2, 0, 1, 0),
68 _nested_errmsg_face_widgets,
lengthof(_nested_errmsg_face_widgets)
105 textref_stack_grffile(textref_stack_grffile),
106 textref_stack_size(textref_stack_size),
107 summary_msg(summary_msg),
108 detailed_msg(detailed_msg),
117 if (textref_stack_size > 0)
MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
137 if (this->detailed_msg == STR_ERROR_OWNED_BY) {
199 size->height =
max(size->height, panel_height);
204 size->width =
max(size->width, face_size.width);
205 size->height =
max(size->height, face_size.height);
214 if (this->
position.x == 0 && this->position.y == 0) {
215 Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
230 pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20;
234 pt.y = (pt.y < (_screen.height >> 1)) ? scr_bot - sm_height : scr_top;
273 this->summary_msg, TC_FROMSTRING,
SA_CENTER);
275 int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed -
WD_PAR_VSEP_WIDE) / 2;
279 int bottom = top + this->height_summary + extra;
283 top = bottom - this->height_detailed - extra;
306 if (this->
duration == 0)
delete this;
345 _window_system_initialized =
true;
346 if (!_error_list.empty()) {
348 _error_list.pop_front();
360 if (_window_system_initialized && w != NULL) {
361 if (w->
IsCritical()) _error_list.push_front(*w);
362 _window_system_initialized =
false;
380 assert(textref_stack_size == 0 || (textref_stack_grffile != NULL && textref_stack != NULL));
381 if (summary_msg == STR_NULL) summary_msg = STR_EMPTY;
387 if (textref_stack_size > 0)
StartTextRefStackUsage(textref_stack_grffile, textref_stack_size, textref_stack);
389 char *b = GetString(buf, summary_msg,
lastof(buf));
392 GetString(b, detailed_msg,
lastof(buf));
416 _error_list.push_back(data);
432 _error_list.splice(_error_list.end(), datas);
442 _error_list.push_back(data);
EventState
State of handling an event.
Functions related to OTTD's strings.
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.
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
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.
static Titem * Get(size_t index)
Returns Titem with given index.
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.
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
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 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.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
byte errmsg_duration
duration of error message
#define lastof(x)
Get the last element of an fixed size array.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
static T max(const T a, const T b)
Returns the maximum of two values.
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.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the 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 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.
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.
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.
Maximum number of companies.
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 egde of the viewport.
No window, redirects to WC_MAIN_WINDOW.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
virtual void OnHundredthTick()
Called once every 100 (game) ticks.
Functions related to zooming.
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
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-NULL) 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.
Owner
Enum for all companies/owners.
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 Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap...
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.