OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
41 #include "table/strings.h"
45 const NewsItem *_statusbar_news_item =
nullptr;
83 static const NWidgetPart _nested_normal_news_widgets[] = {
101 _nested_normal_news_widgets,
lengthof(_nested_normal_news_widgets)
105 static const NWidgetPart _nested_vehicle_news_widgets[] = {
128 _nested_vehicle_news_widgets,
lengthof(_nested_vehicle_news_widgets)
132 static const NWidgetPart _nested_company_news_widgets[] = {
156 _nested_company_news_widgets,
lengthof(_nested_company_news_widgets)
160 static const NWidgetPart _nested_thin_news_widgets[] = {
170 NWidget(
WWT_EMPTY, COLOUR_WHITE,
WID_N_MESSAGE),
SetMinimalSize(428, 48),
SetFill(1, 0),
SetPadding(0, 5, 0, 5),
179 _nested_thin_news_widgets,
lengthof(_nested_thin_news_widgets)
183 static const NWidgetPart _nested_small_news_widgets[] = {
189 SetDataTip(STR_NULL , STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
195 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_N_VIEWPORT),
SetPadding(1, 1, 1, 1),
SetMinimalSize(274, 47),
SetFill(1, 0),
197 NWidget(
WWT_EMPTY, COLOUR_WHITE,
WID_N_MESSAGE),
SetMinimalSize(275, 20),
SetFill(1, 0),
SetPadding(0, 5, 0, 5),
205 _nested_small_news_widgets,
lengthof(_nested_small_news_widgets)
234 NewsTypeData(
"news_display.company_info", 60, SND_BEGIN ),
238 NewsTypeData(
"news_display.production_player", 30, SND_BEGIN ),
239 NewsTypeData(
"news_display.production_other", 30, SND_BEGIN ),
240 NewsTypeData(
"news_display.production_nobody", 30, SND_BEGIN ),
243 NewsTypeData(
"news_display.acceptance", 90, SND_BEGIN ),
244 NewsTypeData(
"news_display.subsidies", 180, SND_BEGIN ),
258 assert(sd !=
nullptr);
276 this->chat_height = (w !=
nullptr) ? w->
height : 0;
281 this->timer.SetInterval(15);
286 if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(
WID_N_TITLE)->widget_data = this->ni->
params[0];
313 if (nvp !=
nullptr) {
326 void DrawNewsBorder(
const Rect &r)
const
338 Point pt = { 0, _screen.height };
351 *size =
maxdim(*size, d2);
361 str = STR_JUST_RAW_STRING;
370 str = this->GetCompanyMessageString();
375 str = this->GetNewVehicleMessageString(widget);
408 d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
409 d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
411 d.width += padding.width;
412 d.height += padding.height;
429 this->DrawNewsBorder(r);
530 if (!gui_scope)
return;
532 int newtop = this->
top + this->chat_height - data;
533 this->chat_height = data;
542 int newtop = std::max(this->
top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
558 if (this->
top == newtop)
return;
560 int mintop = std::min(newtop, this->
top);
561 int maxtop = std::max(newtop, this->
top);
568 StringID GetCompanyMessageString()
const
572 return this->ni->
params[1];
575 StringID GetNewVehicleMessageString(
int widget)
const
583 return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
587 return STR_NEWS_NEW_VEHICLE_TYPE;
611 _statusbar_news_item = ni;
629 _statusbar_news_item =
nullptr;
639 const NewsItem *ni = _statusbar_news_item;
640 if (ni ==
nullptr)
return true;
655 if (ni ==
nullptr)
return true;
671 _statusbar_news_item = (_statusbar_news_item ==
nullptr) ?
_oldest_news : _statusbar_news_item->
next;
672 const NewsItem *ni = _statusbar_news_item;
679 default: NOT_REACHED();
716 default: NOT_REACHED();
735 if (ni->
prev !=
nullptr) {
742 if (ni->
next !=
nullptr) {
761 if (_statusbar_news_item == ni) {
764 _statusbar_news_item = ni->
prev;
791 if (_game_mode == GM_MENU)
return;
906 while (ni !=
nullptr) {
925 while (ni !=
nullptr) {
942 while (ni !=
nullptr) {
958 while (ni !=
nullptr) {
968 static void RemoveOldNewsItems()
997 static byte _last_clean_month = 0;
1000 RemoveOldNewsItems();
1031 if (w ==
nullptr)
return false;
1068 if (ni ==
nullptr) {
1089 char buffer[512], buffer2[512];
1095 GetString(buffer, str,
lastof(buffer));
1098 const char *ptr = buffer;
1099 char *dest = buffer2;
1100 WChar c_last =
'\0';
1102 WChar c = Utf8Consume(&ptr);
1105 if (c ==
'\n' && c_last !=
'\n') {
1108 }
else if (c ==
'\r') {
1109 dest[0] = dest[1] = dest[2] = dest[3] =
' ';
1111 }
else if (IsPrintable(c)) {
1143 resize->height = this->line_height;
1151 size->width = std::max(200u, size->width);
1167 for (
int n = this->vscroll->
GetPosition(); n > 0; n--) {
1169 if (ni ==
nullptr)
return;
1179 for (
int n = this->vscroll->
GetCapacity(); n > 0; n--) {
1181 DrawString(date_left, date_right, y, STR_SHORT_DATE);
1184 y += this->line_height;
1187 if (ni ==
nullptr)
return;
1198 if (!gui_scope)
return;
1206 if (ni ==
nullptr)
return;
1210 if (ni ==
nullptr)
return;
1226 static const NWidgetPart _nested_message_history[] = {
1236 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_MH_BACKGROUND),
SetMinimalSize(200, 125),
SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP),
SetResize(1, 12),
SetScrollbar(
WID_MH_SCROLLBAR),
1249 _nested_message_history,
lengthof(_nested_message_history)
@ VEH_AIRCRAFT
Aircraft vehicle type.
StringID GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
static const uint8 PC_WHITE
White palette colour.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
uint16 chat_height
Height of the chat window.
uint32 TileIndex
The index/ID of a Tile.
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-...
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
char32_t WChar
Type for wide characters, i.e.
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
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.
void CopyOutDParam(uint64 *dst, int offs, int num)
Copy num string parameters from the global string parameter array to the dst array.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static int duration
Remaining time for showing the current news message (may only be access while a news item is displaye...
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
Dimensions (a width and height) of a rectangle in 2D.
static const int bottom_spacing
Additional spacing at the bottom of the WID_MH_BACKGROUND widget.
static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
Draw an unformatted news message truncated to a maximum length.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
static WindowDesc * _news_window_layout[]
Window layouts for news items.
Information about a single item of news.
Year _cur_year
Current year, starting at 0.
uint32 ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news ...
@ NR_STATION
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
ViewportData * viewport
Pointer to viewport data, if present.
SaveLoad save
Internal structure (going to savegame, parts to config)
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
int top
Screen coordinate top edge of the viewport.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
bool _ctrl_pressed
Is Ctrl pressed?
size_t Utf8Encode(T buf, WChar c)
Encode a unicode character and place it in the buffer.
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
void ShowMessageHistory()
Display window with news messages history.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
static Station * Get(size_t index)
Gets station with given index.
ClientSettings _settings_client
The current settings for this game.
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.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
@ NFB_WINDOW_LAYOUT
First bit for window layout.
NewsReferenceType reftype2
Type of ref2.
@ NF_VEHICLE_PARAM0
Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour)
void OnResize() override
Called after the window got resized.
void SetWindowTop(int newtop)
Moves the window to a new top coordinate.
@ SA_CENTER
Center both horizontally and vertically.
@ VEH_ROAD
Road vehicle type.
VarType conv
type of the variable to be saved, int
bool IsNewsTickerShown()
Checks whether the news ticker is currently being used.
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
DoCommandFlag
List of flags for a command.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
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 OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
@ SND_1E_NEW_ENGINE
28 == 0x1C News: new engine available
Scrollbar * vscroll
< Width needed for the date part.
NewsFlag flags
NewsFlags bits.
@ NF_NO_TRANSPARENT
Bit value for disabling transparency.
const byte age
Maximum age of news items (in days)
const SoundFx sound
Sound.
High level window description.
static uint _total_news
current number of news items
Window class displaying a news item.
NewsType type
Type of the news.
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
uint16 EngineID
Unique identification number of an engine.
@ WDP_AUTO
Find a place automatically.
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
ResizeInfo resize
Resize information.
Common return value for all commands.
Date _date
Current date in days (day counter)
SoundSettings sound
sound effect settings
@ NF_INCOLOUR
Bit value for coloured news.
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
int height
Height of the window (number of pixels down in y direction)
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
@ SBI_NEWS_DELETED
abort current news display (active news were deleted)
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
@ INVALID_OWNER
An invalid owner.
static uint MIN_NEWS_AMOUNT
preferred minimum amount of news messages
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
const char *const name
Name.
bool news_full
Play sound effects associated to certain news types.
static void DeleteNewsItem(NewsItem *ni)
Delete a news item from the queue.
void OnPaint() override
The window must be repainted.
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
static void MoveToNextTickerItem()
Move to the next ticker item.
static uint MAX_NEWS_AMOUNT
Do not exceed this number of news messages.
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
NewsDisplay GetDisplay() const
Return the news display option.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static void ShowTicker(const NewsItem *ni)
Show news item in the ticker.
int left
x position of left edge of the window
uint16 status_height
Height of the status bar window.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
StringID string_id
Message text.
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
NewsItem * prev
Previous news item.
@ ND_OFF
Only show a reminder in the status bar.
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Coordinates of a point in 2D.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
static const NewsItem * _forced_news
Forced news item.
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.
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
NewsItem * next
Next news item.
@ NR_NONE
Empty reference.
static const int top_spacing
Additional spacing at the top of the WID_MH_BACKGROUND widget.
static const uint8 PC_BLACK
Black palette colour.
WindowNumber window_number
Window number within the window class.
@ SBI_SHOW_REMINDER
show a reminder (dot on the right side of the statusbar)
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.
SoundFx
Sound effects from baseset.
@ NF_NORMAL
Normal news item. (Newspaper with text only)
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
NewsDisplay
News display options.
static const uint8 PC_GREY
Grey palette colour.
void * free_data
Data to be freed when the news item has reached its end.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
NewsReferenceType
References to objects in news.
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
@ NR_TILE
Reference tile. Scroll to tile when clicking on the news.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
CompanyID _current_company
Company currently doing an action.
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
Get the position a news-reference is referencing.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
const NewsItem * ni
News item to display.
static void ShowNewsMessage(const NewsItem *ni)
Do a forced show of a specific message.
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
@ WD_CAPTIONTEXT_TOP
Offset of the caption text at the top.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
static void ShowNewspaper(const NewsItem *ni)
Open up an own newspaper window for the news item.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void ShowLastNewsMessage()
Show previous news item.
void DrawCompanyManagerFace(CompanyManagerFace cmf, int colour, int x, int y)
Draws the face of a company manager's face.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
int date_width
< Height of a single line in the news history window including spacing.
@ NFB_WINDOW_LAYOUT_COUNT
Number of bits for window layout.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
uint CountElapsed(uint delta)
Count how many times the interval has elapsed.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
static const NewsItem * _current_news
Current news item (last item shown regularly).
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
TileIndex xy
Base tile of the station.
byte news_message_timeout
how much longer than the news message "age" should we keep the message in the history
int top
y position of top edge of the window
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
@ NR_VEHICLE
Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
uint32 VehicleID
The type all our vehicle IDs have.
Date date
Date of the news.
bool news_ticker
Play a ticker sound when a news item is published.
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
NewsItem * _latest_news
tail of news items queue
@ WD_CAPTIONTEXT_BOTTOM
Offset of the caption text at the bottom.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
static bool ReadyForNextNewsItem()
Are we ready to show another news item? Only if no newspaper is displayed.
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.
@ ZOOM_LVL_NEWS
Default zoom level for the news messages.
@ NF_SHADE
Bit value for enabling shading.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
bool IsBus() const
Check whether a roadvehicle is a bus.
uint64 params[10]
Parameters for string resolving.
bool HideActiveNewsMessage()
Close active news message window.
static void MoveToNextNewsItem()
Move to the next news item.
NewsFlag
Various OR-able news-item flags.
static NewsItem * _oldest_news
head of news items queue
static NewsTypeData _news_type_data[]
Per-NewsType data.
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Data structure for an opened window.
@ WD_CAPTIONTEXT_LEFT
Offset of the caption text at the left.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
VehicleType type
Type of vehicle.
void DeleteInvalidEngineNews()
Remove engine announcements for invalid engines.
void DrawWidgets() const
Paint all widgets of a window.
@ WC_NEWS_WINDOW
News window; Window numbers:
void InitNewsItemStructs()
Initialize the news-items data structures.
@ VEH_SHIP
Ship vehicle type.
uint32 ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news,...
@ NR_INDUSTRY
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
Specification of a rectangle with absolute coordinates of all edges.
Month _cur_month
Current month (0..11)
@ NT_END
end-of-array marker
@ SND_1D_APPLAUSE
27 == 0x1B News: first vehicle at station
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
#define lastof(x)
Get the last element of an fixed size array.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
@ SBI_SHOW_TICKER
start scrolling news
void CopyInDParam(int offs, const uint64 *src, int num)
Copy num string parameters from array src into the global string parameter array.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
@ NR_ENGINE
Reference engine.
Year coloured_news_year
when does newspaper become coloured?
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new custom news item.
GUISettings gui
settings related to the GUI
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
NewsReferenceType reftype1
Type of ref1.
@ SND_16_NEWS_TICKER
20 == 0x14 News ticker
@ WD_CAPTIONTEXT_RIGHT
Offset of the caption text at the right.
static bool ReadyForNextTickerItem()
Are we ready to show another ticker item? Only if nothing is in the newsticker is displayed.