39 #include "table/strings.h" 43 const NewsItem *_statusbar_news_item = NULL;
80 static const NWidgetPart _nested_normal_news_widgets[] = {
98 _nested_normal_news_widgets,
lengthof(_nested_normal_news_widgets)
102 static const NWidgetPart _nested_vehicle_news_widgets[] = {
125 _nested_vehicle_news_widgets,
lengthof(_nested_vehicle_news_widgets)
129 static const NWidgetPart _nested_company_news_widgets[] = {
153 _nested_company_news_widgets,
lengthof(_nested_company_news_widgets)
157 static const NWidgetPart _nested_thin_news_widgets[] = {
167 NWidget(
WWT_EMPTY, COLOUR_WHITE,
WID_N_MESSAGE),
SetMinimalSize(428, 48),
SetFill(1, 0),
SetPadding(0, 5, 0, 5),
176 _nested_thin_news_widgets,
lengthof(_nested_thin_news_widgets)
180 static const NWidgetPart _nested_small_news_widgets[] = {
190 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_N_VIEWPORT),
SetPadding(1, 1, 1, 1),
SetMinimalSize(274, 47),
SetFill(1, 0),
192 NWidget(
WWT_EMPTY, COLOUR_WHITE,
WID_N_MESSAGE),
SetMinimalSize(275, 20),
SetFill(1, 0),
SetPadding(0, 5, 0, 5),
200 _nested_small_news_widgets,
lengthof(_nested_small_news_widgets)
217 assert(layout <
lengthof(_news_window_layout));
218 return _news_window_layout[layout];
226 NewsTypeData(
"news_display.arrival_player", 60, SND_1D_APPLAUSE ),
227 NewsTypeData(
"news_display.arrival_other", 60, SND_1D_APPLAUSE ),
229 NewsTypeData(
"news_display.company_info", 60, SND_BEGIN ),
233 NewsTypeData(
"news_display.production_player", 30, SND_BEGIN ),
234 NewsTypeData(
"news_display.production_other", 30, SND_BEGIN ),
235 NewsTypeData(
"news_display.production_nobody", 30, SND_BEGIN ),
237 NewsTypeData(
"news_display.new_vehicles", 30, SND_1E_OOOOH ),
238 NewsTypeData(
"news_display.acceptance", 90, SND_BEGIN ),
239 NewsTypeData(
"news_display.subsidies", 180, SND_BEGIN ),
269 this->chat_height = (w != NULL) ? w->
height : 0;
274 this->CreateNestedTree();
277 if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(
WID_N_TITLE)->widget_data = this->ni->
params[0];
279 this->FinishInitNested(0);
296 void DrawNewsBorder(
const Rect &r)
const 308 Point pt = { 0, _screen.height };
321 *size =
maxdim(*size, d2);
335 str = this->GetCompanyMessageString();
340 str = this->GetNewVehicleMessageString(widget);
355 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
356 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
358 d.width += padding.width;
359 d.height += padding.height;
372 DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, STR_NEWS_MESSAGE_CAPTION);
376 this->DrawNewsBorder(r);
466 if (keycode == WKC_SPACE) {
481 if (!gui_scope)
return;
483 int newtop = this->top + this->chat_height - data;
484 this->chat_height = data;
485 this->SetWindowTop(newtop);
491 int newtop =
max(this->top - 4, _screen.height - this->height - this->status_height - this->chat_height);
492 this->SetWindowTop(newtop);
502 if (this->top == newtop)
return;
504 int mintop =
min(newtop, this->top);
505 int maxtop =
max(newtop, this->top);
506 if (this->viewport != NULL) this->viewport->top += newtop - this->top;
509 SetDirtyBlocks(this->left, mintop, this->left + this->width, maxtop + this->height);
512 StringID GetCompanyMessageString()
const 516 return this->ni->
params[1];
519 StringID GetNewVehicleMessageString(
int widget)
const 527 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
531 return STR_NEWS_NEW_VEHICLE_TYPE;
556 _statusbar_news_item = ni;
563 for (
NewsItem *ni = _oldest_news; ni != NULL; ) {
573 _current_news = NULL;
574 _statusbar_news_item = NULL;
585 if (ni == NULL)
return true;
604 _statusbar_news_item = NULL;
607 if (_current_news != _latest_news) {
608 _current_news = (_current_news == NULL) ? _oldest_news : _current_news->
next;
613 if (
_date - _news_type_data[type].
age > ni->date)
return;
616 default: NOT_REACHED();
647 if (_game_mode == GM_MENU)
return;
668 assert(_oldest_news == NULL);
672 assert(_latest_news->
next == NULL);
673 _latest_news->
next = ni;
751 if (ni->
prev != NULL) {
754 assert(_oldest_news == ni);
755 _oldest_news = ni->
next;
758 if (ni->
next != NULL) {
761 assert(_latest_news == ni);
762 _latest_news = ni->
prev;
767 if (_forced_news == ni || _current_news == ni || _statusbar_news_item == ni) {
770 if (_current_news == ni) _current_news = ni->
prev;
854 static void RemoveOldNewsItems()
871 for (
NewsItem *ni = _oldest_news; ni != NULL; ni = ni->
next) {
872 if (ni->reftype1 ==
NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
873 if (ni->reftype2 ==
NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
874 if (ni->flags &
NF_VEHICLE_PARAM0 && ni->params[0] == from_index) ni->params[0] = to_index;
888 static byte _last_clean_month = 0;
891 RemoveOldNewsItems();
909 if (_forced_news != NULL) {
921 }
else if (_forced_news == NULL) {
924 if (_current_news == NULL) {
932 }
else if (_forced_news == _oldest_news) {
937 ni = _forced_news->
prev;
969 char buffer[512], buffer2[512];
975 GetString(buffer, str,
lastof(buffer));
978 const char *ptr = buffer;
979 char *dest = buffer2;
982 WChar c = Utf8Consume(&ptr);
985 if (c ==
'\n' && c_last !=
'\n') {
988 }
else if (c ==
'\r') {
989 dest[0] = dest[1] = dest[2] = dest[3] =
' ';
991 }
else if (IsPrintable(c)) {
1013 this->CreateNestedTree();
1015 this->FinishInitNested();
1016 this->OnInvalidateData(0);
1023 resize->height = this->line_height;
1030 size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing;
1031 size->width =
max(200u, size->width);
1037 this->OnInvalidateData(0);
1038 this->DrawWidgets();
1047 for (
int n = this->vscroll->
GetPosition(); n > 0; n--) {
1049 if (ni == NULL)
return;
1053 int y = r.top + this->top_spacing;
1059 for (
int n = this->vscroll->
GetCapacity(); n > 0; n--) {
1061 DrawString(date_left, date_right, y, STR_SHORT_DATE);
1064 y += this->line_height;
1067 if (ni == NULL)
return;
1078 if (!gui_scope)
return;
1086 if (ni == NULL)
return;
1090 if (ni == NULL)
return;
1106 static const NWidgetPart _nested_message_history[] = {
1116 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_MH_BACKGROUND),
SetMinimalSize(200, 125),
SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP),
SetResize(1, 12),
SetScrollbar(
WID_MH_SCROLLBAR),
1129 _nested_message_history,
lengthof(_nested_message_history)
EventState
State of handling an event.
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
static NewsItem * _latest_news
tail of news items queue
Functions related to OTTD's strings.
void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition of stuff that is very close to a company, like the company struct itself.
static const int top_spacing
Additional spacing at the top of the WID_MH_BACKGROUND widget.
static const uint8 PC_WHITE
White palette colour.
StringID GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted...
Year coloured_news_year
when does newspaper become coloured?
High level window description.
void SetWindowTop(int newtop)
Moves the window so #newtop is new 'top' coordinate.
static uint MIN_NEWS_AMOUNT
preferred minimum amount of news messages
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
static Titem * Get(size_t index)
Returns Titem with given index.
NewsReferenceType reftype2
Type of ref2.
Functions related to dates.
const char *const name
Name.
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
Offset at top to draw the frame rectangular area.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
The passed event is not handled.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Default zoom level for the news messages.
First bit for window layout.
Functions related to vehicles.
static NewsTypeData _news_type_data[]
Per-NewsType data.
void CopyInDParam(int offs, const uint64 *src, int num)
Copy num string parameters from array src into the global string parameter array. ...
void DrawCompanyManagerFace(CompanyManagerFace cmf, int colour, int x, int y)
Draws the face of a company manager's face.
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
uint64 params[10]
Parameters for string resolving.
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
#define lastof(x)
Get the last element of an fixed size array.
static void ShowNewsMessage(const NewsItem *ni)
Do a forced show of a specific message.
Common return value for all commands.
virtual void OnPaint()
The window must be repainted.
NewsReferenceType reftype1
Type of ref1.
static T max(const T a, const T b)
Returns the maximum of two values.
Year _cur_year
Current year, starting at 0.
byte news_message_timeout
how much longer than the news message "age" should we keep the message in the history ...
Functions related to the vehicle's GUIs.
Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour) ...
static NewsItem * _oldest_news
head of news items queue
void * free_data
Data to be freed when the news item has reached its end.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to (drawing on) viewports.
bool news_full
Play sound effects associated to certain news types.
The object is owned by a superuser / goal script.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
SaveLoad save
Internal structure (going to savegame, parts to config)
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Date date
Date of the news.
Functions related to low-level strings.
Only show a reminder in the status bar.
StringID string_id
Message text.
VarType conv
type of the variable to be saved, int
uint32 ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news...
Window class displaying a news item.
int date_width
< Height of a single line in the news history window including spacing.
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
SoundSettings sound
sound effect settings
uint32 VehicleID
The type all our vehicle IDs have.
void ShowMessageHistory()
Display window with news messages history.
DoCommandFlag
List of flags for a command.
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
Get the position a news-reference is referencing.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
abort current news display (active news were deleted)
NewsDisplay
News display options.
ClientSettings _settings_client
The current settings for this game.
Apply a recolour sprite to the screen content.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition of base types and functions in a cross-platform compatible way.
Center both horizontally and vertically.
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Bit value for disabling transparency.
NewsFlag
Various OR-able news-item flags.
Reference tile. Scroll to tile when clicking on the news.
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void CopyOutDParam(uint64 *dst, int offs, int num)
Copy num string parameters from the global string parameter array to the dst array.
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.
Vehicle drawn in preview window, news, ...
show a reminder (dot on the right side of the statusbar)
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
virtual void OnTick()
Called once per (game) tick.
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Normal news item. (Newspaper with text only)
NewsItem * prev
Previous news item.
void ShowLastNewsMessage()
Show previous news item.
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
uint32 ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleteing the news...
uint16 status_height
Height of the status bar window.
const NewsItem * ni
News item to display.
Offset at bottom to draw the frame rectangular area.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
Bit value for coloured news.
static const int bottom_spacing
Additional spacing at the bottom of the WID_MH_BACKGROUND widget.
void SetDirtyBlocks(int left, int top, int right, int bottom)
This function extends the internal _invalid_rect rectangle as it now contains the rectangle defined b...
void InitNewsItemStructs()
Initialize the news-items data structures.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
virtual void OnResize()
Called after the window got resized.
Functions related to sound.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static const uint8 PC_BLACK
Black palette colour.
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
NewsDisplay GetDisplay() const
Return the news display option.
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
Add a new newsitem to be shown.
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Offset of the caption text at the top.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
News history list; Window numbers:
Month _cur_month
Current month (0..11)
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Number of bits for window layout.
static const uint8 PC_GREY
Grey palette colour.
execute the given command
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Functions related to companies.
static void DeleteNewsItem(NewsItem *ni)
Delete a news item from the queue.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Functionality related to the company manager's face.
GUISettings gui
settings related to the GUI
NewsItem * next
Next news item.
Reference town. Scroll to town when clicking on the news.
Base class for all vehicles.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
uint16 EngineID
Unique identification number of an engine.
Offset of the caption text at the bottom.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
TextDirection _current_text_dir
Text direction of the currently selected language.
static void MoveToNextItem()
Move to the next news item.
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new custom news item.
static WindowDesc * _news_window_layout[]
Window layouts for news items.
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.
TileIndex xy
Base tile of the station.
const SoundFx sound
Sound.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static uint duration
Remaining time for showing current news message (may only be accessed while a news item is displayed)...
static const NewsItem * _forced_news
Forced news item.
Functions and types used internally for the settings configurations.
Functions related to the drop down widget.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
NewsFlag flags
NewsFlags bits.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Statusbar (at the bottom of your screen); Window numbers:
Functions related to commands.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
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.
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Window does not do autoscroll,.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
NewsReferenceType
References to objects in news.
size_t Utf8Encode(char *buf, WChar c)
Encode a unicode character and place it in the buffer.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Offset at right to draw the frame rectangular area.
static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
Draw an unformatted news message truncated to a maximum length.
uint16 chat_height
Height of the chat window.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool ReadyForNextItem()
Are we ready to show another news item? Only if nothing is in the newsticker and no newspaper is disp...
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
static uint _total_news
current number of news items
NewsType type
Type of the news.
Specification of a rectangle with absolute coordinates of all edges.
The passed event is handled.
Text is written right-to-left by default.
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Owner
Enum for all companies/owners.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Window functions not directly related to making/drawing windows.
Find a place automatically.
Manually align the window (so no automatic location finding)
GUI functions that shouldn't be here.
Base classes/functions for stations.
Functions, definitions and such used only by the GUI.
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
uint32 WChar
Type for wide characters, i.e.
bool news_ticker
Play a ticker sound when a news item is published.
const byte age
Maximum age of news items (in days)
static void ShowTicker(const NewsItem *ni)
Show news item in the ticker.
Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted...
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
Bit value for enabling shading.
SoundFx
Sound effects from baseset.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Scrollbar * vscroll
< Width needed for the date part.
Information about a single item of news.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
int height
Height of the window (number of pixels down in y direction)
static const NewsItem * _current_news
Current news item (last item shown regularly).
News window; Window numbers:
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.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.