OpenTTD Source 20250205-master-gfd85ab1e2c
|
GUI functions related to news messages. More...
#include "stdafx.h"
#include "gui.h"
#include "viewport_func.h"
#include "strings_func.h"
#include "window_func.h"
#include "vehicle_base.h"
#include "vehicle_func.h"
#include "vehicle_gui.h"
#include "roadveh.h"
#include "station_base.h"
#include "industry.h"
#include "town.h"
#include "sound_func.h"
#include "string_func.h"
#include "statusbar_gui.h"
#include "company_manager_face.h"
#include "company_func.h"
#include "engine_base.h"
#include "engine_gui.h"
#include "core/geometry_func.hpp"
#include "command_func.h"
#include "company_base.h"
#include "settings_internal.h"
#include "group_gui.h"
#include "zoom_func.h"
#include "news_cmd.h"
#include "news_func.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "timer/timer_game_calendar.h"
#include "widgets/news_widget.h"
#include "table/strings.h"
#include "safeguards.h"
Go to the source code of this file.
Data Structures | |
struct | NewsWindow |
Window class displaying a news item. More... | |
struct | MessageHistoryWindow |
Functions | |
const NewsItem * | GetStatusbarNews () |
Get pointer to the current status bar news item. | |
const NewsContainer & | GetNews () |
Get read-only reference to all news items. | |
static TileIndex | GetReferenceTile (NewsReferenceType reftype, uint32_t ref) |
Get the position a news-reference is referencing. | |
WindowDesc & | GetNewsWindowLayout (NewsFlag flags) |
static void | ShowNewspaper (const NewsItem *ni) |
Open up an own newspaper window for the news item. | |
static void | ShowTicker (NewsIterator ni) |
Show news item in the ticker. | |
void | InitNewsItemStructs () |
Initialize the news-items data structures. | |
static bool | ReadyForNextTickerItem () |
Are we ready to show another ticker item? Only if nothing is in the newsticker is displayed. | |
static bool | ReadyForNextNewsItem () |
Are we ready to show another news item? Only if no newspaper is displayed. | |
static void | MoveToNextTickerItem () |
Move to the next ticker item. | |
static void | MoveToNextNewsItem () |
Move to the next news item. | |
static std::list< NewsItem >::iterator | DeleteNewsItem (std::list< NewsItem >::iterator ni) |
Delete a news item from the queue. | |
void | AddNewsItem (StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, std::unique_ptr< NewsAllocatedData > &&data, AdviceType advice_type) |
Add a new newsitem to be shown. | |
CommandCost | CmdCustomNewsItem (DoCommandFlag flags, NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string &text) |
Create a new custom news item. | |
template<size_t Tmin = 0, class Tpredicate > | |
void | DeleteNews (Tpredicate predicate) |
Delete news items by predicate, and invalidate the message history if necessary. | |
void | DeleteVehicleNews (VehicleID vid, AdviceType advice_type) |
Delete news with a given advice type about a vehicle. | |
void | DeleteStationNews (StationID sid) |
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First train arrived at unknown station' news items. | |
void | DeleteIndustryNews (IndustryID iid) |
Remove news regarding given industry. | |
void | DeleteInvalidEngineNews () |
Remove engine announcements for invalid engines. | |
static void | RemoveOldNewsItems () |
void | ChangeVehicleNews (VehicleID from_index, VehicleID to_index) |
Report a change in vehicle IDs (due to autoreplace) to affected vehicle news. | |
void | NewsLoop () |
static void | ShowNewsMessage (NewsIterator ni) |
Do a forced show of a specific message. | |
bool | HideActiveNewsMessage () |
Close active news message window. | |
void | ShowLastNewsMessage () |
Show previous news item. | |
static void | DrawNewsString (uint left, uint right, int y, TextColour colour, const NewsItem *ni) |
Draw an unformatted news message truncated to a maximum length. | |
void | ShowMessageHistory () |
Display window with news messages history. | |
Variables | |
static const uint | MIN_NEWS_AMOUNT = 30 |
preferred minimum amount of news messages. | |
static const uint | MAX_NEWS_AMOUNT = 1U << 10 |
Do not exceed this number of news messages. | |
static NewsContainer | _news |
List of news, with newest items at the start. | |
static NewsIterator | _forced_news = std::end(_news) |
Forced news item. | |
static NewsIterator | _current_news = std::end(_news) |
Current news item (last item shown regularly). | |
static NewsIterator | _statusbar_news = std::end(_news) |
Current status bar news item. | |
static constexpr NWidgetPart | _nested_normal_news_widgets [] |
static WindowDesc | _normal_news_desc (WDP_MANUAL, nullptr, 0, 0, WC_NEWS_WINDOW, WC_NONE, {}, _nested_normal_news_widgets) |
static constexpr NWidgetPart | _nested_vehicle_news_widgets [] |
static WindowDesc | _vehicle_news_desc (WDP_MANUAL, nullptr, 0, 0, WC_NEWS_WINDOW, WC_NONE, {}, _nested_vehicle_news_widgets) |
static constexpr NWidgetPart | _nested_company_news_widgets [] |
static WindowDesc | _company_news_desc (WDP_MANUAL, nullptr, 0, 0, WC_NEWS_WINDOW, WC_NONE, {}, _nested_company_news_widgets) |
static constexpr NWidgetPart | _nested_thin_news_widgets [] |
static WindowDesc | _thin_news_desc (WDP_MANUAL, nullptr, 0, 0, WC_NEWS_WINDOW, WC_NONE, {}, _nested_thin_news_widgets) |
static constexpr NWidgetPart | _nested_small_news_widgets [] |
static WindowDesc | _small_news_desc (WDP_MANUAL, nullptr, 0, 0, WC_NEWS_WINDOW, WC_NONE, {}, _nested_small_news_widgets) |
static WindowDesc * | _news_window_layout [] |
Window layouts for news items. | |
static NewsTypeData | _news_type_data [] |
Per-NewsType data. | |
static constexpr NWidgetPart | _nested_message_history [] |
static WindowDesc | _message_history_desc (WDP_AUTO, "list_news", 400, 140, WC_MESSAGE_HISTORY, WC_NONE, {}, _nested_message_history) |
GUI functions related to news messages.
Definition in file news_gui.cpp.
void AddNewsItem | ( | StringID | string, |
NewsType | type, | ||
NewsFlag | flags, | ||
NewsReferenceType | reftype1, | ||
uint32_t | ref1, | ||
NewsReferenceType | reftype2, | ||
uint32_t | ref2, | ||
std::unique_ptr< NewsAllocatedData > && | data, | ||
AdviceType | advice_type | ||
) |
Add a new newsitem to be shown.
string | String to display |
type | news category |
flags | display flags for the news |
reftype1 | Type of ref1 |
ref1 | Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleting the news when the object is deleted. |
reftype2 | Type of ref2 |
ref2 | Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted. |
data | Pointer to data that must be released once the news message is cleared. |
advice_type | Sub-type in case the news type is NT_ADVICE. |
Definition at line 899 of file news_gui.cpp.
References _news, DeleteNewsItem(), InvalidateWindowData(), MAX_NEWS_AMOUNT, and WC_MESSAGE_HISTORY.
Referenced by AddVehicleAdviceNewsItem(), AddVehicleNewsItem(), Subsidy::AwardTo(), CmdCustomNewsItem(), CreateSubsidy(), GenerateCompanyName(), NewVehicleAvailable(), ShowRejectOrAcceptNews(), TownActionBuyRights(), and TownActionRoadRebuild().
Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
from_index | the old vehicle ID |
to_index | the new vehicle ID |
Definition at line 1054 of file news_gui.cpp.
References _news, NewsItem::flags, NF_VEHICLE_PARAM0, NR_VEHICLE, NewsItem::params, NewsItem::ref1, NewsItem::ref2, NewsItem::reftype1, and NewsItem::reftype2.
Referenced by CopyHeadSpecificThings().
CommandCost CmdCustomNewsItem | ( | DoCommandFlag | flags, |
NewsType | type, | ||
NewsReferenceType | reftype1, | ||
CompanyID | company, | ||
uint32_t | reference, | ||
const std::string & | text | ||
) |
Create a new custom news item.
flags | type of operation @aram type NewsType of the message. |
reftype1 | NewsReferenceType of first reference. |
company | Company this news message is for. |
reference | First reference of the news message. |
text | The text of the news message. |
Definition at line 924 of file news_gui.cpp.
References _current_company, _local_company, AddNewsItem(), CMD_ERROR, DC_EXEC, INVALID_OWNER, SpecializedStation< Station, false >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), IsValidTile(), NF_NORMAL, NR_ENGINE, NR_INDUSTRY, NR_NONE, NR_STATION, NR_TILE, NR_TOWN, NR_VEHICLE, NT_END, OWNER_DEITY, and SetDParamStr().
void DeleteIndustryNews | ( | IndustryID | iid | ) |
Remove news regarding given industry.
iid | industry to remove news about |
Definition at line 1023 of file news_gui.cpp.
References DeleteNews(), NR_INDUSTRY, NewsItem::ref1, NewsItem::ref2, NewsItem::reftype1, and NewsItem::reftype2.
void DeleteInvalidEngineNews | ( | ) |
Remove engine announcements for invalid engines.
Definition at line 1033 of file news_gui.cpp.
References DeleteNews(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::IsValidID(), NR_ENGINE, NewsItem::ref1, NewsItem::ref2, NewsItem::reftype1, and NewsItem::reftype2.
Referenced by ReloadNewGRFData().
void DeleteNews | ( | Tpredicate | predicate | ) |
Delete news items by predicate, and invalidate the message history if necessary.
Tmin | Stop if the number of news items remaining reaches min items. |
Tpredicate | Condition for a news item to be deleted. |
Definition at line 977 of file news_gui.cpp.
References _news, DeleteNewsItem(), InvalidateWindowData(), and WC_MESSAGE_HISTORY.
Referenced by DeleteIndustryNews(), DeleteInvalidEngineNews(), DeleteStationNews(), and DeleteVehicleNews().
Delete a news item from the queue.
Definition at line 827 of file news_gui.cpp.
References _current_news, _forced_news, _news, _statusbar_news, InvalidateWindowData(), MoveToNextNewsItem(), MoveToNextTickerItem(), SBI_NEWS_DELETED, and WC_STATUS_BAR.
Referenced by AddNewsItem(), and DeleteNews().
void DeleteStationNews | ( | StationID | sid | ) |
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First train arrived at unknown station' news items.
sid | station to remove news about |
Definition at line 1012 of file news_gui.cpp.
References DeleteNews(), NR_STATION, NewsItem::ref1, NewsItem::ref2, NewsItem::reftype1, and NewsItem::reftype2.
Referenced by Station::~Station().
void DeleteVehicleNews | ( | VehicleID | vid, |
AdviceType | advice_type | ||
) |
Delete news with a given advice type about a vehicle.
When the advice_type is AdviceType::Invalid all news about the vehicle gets deleted.
vid | The vehicle to remove the news for. |
advice_type | The advice type to remove for. |
Definition at line 1000 of file news_gui.cpp.
References NewsItem::advice_type, DeleteNews(), NR_VEHICLE, NewsItem::ref1, NewsItem::ref2, NewsItem::reftype1, and NewsItem::reftype2.
Referenced by AircraftHandleDestTooFar(), CmdStartStopVehicle(), DeleteOrderWarnings(), Vehicle::HandlePathfindingResult(), and Vehicle::~Vehicle().
|
static |
Draw an unformatted news message truncated to a maximum length.
If length exceeds maximum length it will be postfixed by '...'
left | the left most location for the string |
right | the right most location for the string |
y | position of the string |
colour | the colour the string will be shown in |
*ni | NewsItem being printed |
Definition at line 1159 of file news_gui.cpp.
References CopyInDParam(), DrawString(), GetString(), NewsItem::params, NewsItem::string_id, StrMakeValid(), and SVS_REPLACE_TAB_CR_NL_WITH_SPACE.
Referenced by MessageHistoryWindow::DrawWidget().
const NewsContainer & GetNews | ( | ) |
Get read-only reference to all news items.
Definition at line 79 of file news_gui.cpp.
References _news.
Referenced by SurveyRecentNews().
WindowDesc & GetNewsWindowLayout | ( | NewsFlag | flags | ) |
Definition at line 304 of file news_gui.cpp.
|
static |
Get the position a news-reference is referencing.
reftype | The type of reference. |
ref | The reference. |
Definition at line 90 of file news_gui.cpp.
References SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), INVALID_TILE, NR_INDUSTRY, NR_STATION, NR_TILE, NR_TOWN, TileDiffXY(), and BaseStation::xy.
Referenced by NewsWindow::OnClick(), and NewsWindow::OnResize().
const NewsItem * GetStatusbarNews | ( | ) |
Get pointer to the current status bar news item.
Definition at line 70 of file news_gui.cpp.
References _news, and _statusbar_news.
Referenced by StatusBarWindow::DrawWidget(), and ReadyForNextTickerItem().
bool HideActiveNewsMessage | ( | ) |
Close active news message window.
Definition at line 1100 of file news_gui.cpp.
References Window::Close(), FindWindowById(), and WC_NEWS_WINDOW.
Referenced by MainWindow::OnHotkey().
void InitNewsItemStructs | ( | ) |
Initialize the news-items data structures.
Definition at line 719 of file news_gui.cpp.
References _current_news, _forced_news, _news, _statusbar_news, and NewsWindow::duration.
Referenced by DeleteAllMessages().
|
static |
Move to the next news item.
Definition at line 790 of file news_gui.cpp.
References _current_news, _forced_news, _news, _news_type_data, CloseWindowById(), TimerGameEconomy::date, FindWindowById(), ND_FULL, ND_OFF, ND_SUMMARY, ShowNewspaper(), WC_NEWS_WINDOW, and WC_STATUS_BAR.
Referenced by DeleteNewsItem().
|
static |
Move to the next ticker item.
Definition at line 755 of file news_gui.cpp.
References _news, _news_type_data, _statusbar_news, TimerGameEconomy::date, FindWindowById(), InvalidateWindowData(), ND_FULL, ND_OFF, ND_SUMMARY, SBI_SHOW_REMINDER, ShowTicker(), and WC_STATUS_BAR.
Referenced by DeleteNewsItem().
void NewsLoop | ( | ) |
Definition at line 1063 of file news_gui.cpp.
|
static |
Are we ready to show another news item? Only if no newspaper is displayed.
Definition at line 746 of file news_gui.cpp.
References _current_news, _forced_news, _news, NewsWindow::duration, FindWindowById(), and WC_NEWS_WINDOW.
|
static |
Are we ready to show another ticker item? Only if nothing is in the newsticker is displayed.
Definition at line 732 of file news_gui.cpp.
References GetStatusbarNews(), and IsNewsTickerShown().
|
static |
Definition at line 1041 of file news_gui.cpp.
void ShowLastNewsMessage | ( | ) |
Show previous news item.
Definition at line 1109 of file news_gui.cpp.
References _current_news, _forced_news, _news, _news_type_data, FindWindowById(), NewsTypeData::GetDisplay(), ND_OFF, ShowNewsMessage(), and WC_NEWS_WINDOW.
Referenced by MenuClickNewspaper(), and StatusBarWindow::OnClick().
void ShowMessageHistory | ( | ) |
Display window with news messages history.
Definition at line 1278 of file news_gui.cpp.
References CloseWindowById(), and WC_MESSAGE_HISTORY.
Referenced by MenuClickNewspaper().
|
static |
Do a forced show of a specific message.
Definition at line 1080 of file news_gui.cpp.
References _forced_news, _news, CloseWindowById(), ShowNewspaper(), and WC_NEWS_WINDOW.
Referenced by MessageHistoryWindow::OnClick(), and ShowLastNewsMessage().
|
static |
Open up an own newspaper window for the news item.
Definition at line 701 of file news_gui.cpp.
References _news_type_data, _settings_client, NewsItem::flags, SoundSettings::news_full, NewsTypeData::sound, ClientSettings::sound, and NewsItem::type.
Referenced by MoveToNextNewsItem(), and ShowNewsMessage().
|
static |
Show news item in the ticker.
Definition at line 710 of file news_gui.cpp.
References _settings_client, _statusbar_news, InvalidateWindowData(), SoundSettings::news_ticker, SBI_SHOW_TICKER, SND_16_NEWS_TICKER, ClientSettings::sound, and WC_STATUS_BAR.
Referenced by MoveToNextTickerItem().
|
static |
Current news item (last item shown regularly).
Definition at line 61 of file news_gui.cpp.
Referenced by DeleteNewsItem(), InitNewsItemStructs(), MoveToNextNewsItem(), ReadyForNextNewsItem(), and ShowLastNewsMessage().
|
static |
Forced news item.
Users can force an item by accessing the history or "last message". If the message being shown was forced by the user, an iterater is stored in _forced_news. Otherwise, _forced_news variable is the end of _news.
Definition at line 58 of file news_gui.cpp.
Referenced by DeleteNewsItem(), InitNewsItemStructs(), MoveToNextNewsItem(), NewsWindow::OnClick(), ReadyForNextNewsItem(), ShowLastNewsMessage(), and ShowNewsMessage().
|
staticconstexpr |
Definition at line 181 of file news_gui.cpp.
|
staticconstexpr |
Definition at line 1251 of file news_gui.cpp.
|
staticconstexpr |
Definition at line 102 of file news_gui.cpp.
|
staticconstexpr |
Definition at line 259 of file news_gui.cpp.
|
staticconstexpr |
Definition at line 225 of file news_gui.cpp.
|
staticconstexpr |
Definition at line 134 of file news_gui.cpp.
|
static |
List of news, with newest items at the start.
Definition at line 50 of file news_gui.cpp.
Referenced by AddNewsItem(), ChangeVehicleNews(), DeleteNews(), DeleteNewsItem(), MessageHistoryWindow::DrawWidget(), GetNews(), GetStatusbarNews(), InitNewsItemStructs(), MoveToNextNewsItem(), MoveToNextTickerItem(), NewsWindow::OnClick(), MessageHistoryWindow::OnClick(), MessageHistoryWindow::OnInvalidateData(), ReadyForNextNewsItem(), ShowLastNewsMessage(), and ShowNewsMessage().
|
static |
Per-NewsType data.
Definition at line 314 of file news_gui.cpp.
Referenced by MoveToNextNewsItem(), MoveToNextTickerItem(), ShowLastNewsMessage(), and ShowNewspaper().
|
static |
Window layouts for news items.
Definition at line 296 of file news_gui.cpp.
|
static |
Current status bar news item.
Definition at line 64 of file news_gui.cpp.
Referenced by DeleteNewsItem(), GetStatusbarNews(), InitNewsItemStructs(), MoveToNextTickerItem(), and ShowTicker().
|
static |
Do not exceed this number of news messages.
Definition at line 48 of file news_gui.cpp.
Referenced by AddNewsItem().
|
static |
preferred minimum amount of news messages.
Definition at line 47 of file news_gui.cpp.