@@ -37,25 +37,25 @@ static inline void AddVehicleNewsItem(St
{
AddNewsItem(string, subtype, NR_VEHICLE, vehicle, station == INVALID_STATION ? NR_NONE : NR_STATION, station);
}
static inline void AddIndustryNewsItem(StringID string, NewsSubtype subtype, IndustryID industry)
AddNewsItem(string, subtype, NR_INDUSTRY, industry);
void NewsLoop();
void InitNewsItemStructs();
extern NewsItem _statusbar_news_item;
extern const NewsItem *_statusbar_news_item;
extern bool _news_ticker_sound;
extern NewsTypeData _news_type_data[];
/**
* Delete a news item type about a vehicle
* if the news item type is INVALID_STRING_ID all news about the vehicle get
* deleted
*/
void DeleteVehicleNews(VehicleID vid, StringID news);
/** Delete news associated with given station */
@@ -25,40 +25,40 @@
#include "industry.h"
#include "town.h"
#include "sound_func.h"
#include "string_func.h"
#include "widgets/dropdown_func.h"
#include "statusbar_gui.h"
#include "company_manager_face.h"
#include "company_func.h"
#include "engine_gui.h"
#include "table/strings.h"
NewsItem _statusbar_news_item;
const NewsItem *_statusbar_news_item = NULL;
bool _news_ticker_sound; ///< Make a ticker sound when a news item is published.
static uint MIN_NEWS_AMOUNT = 30; ///< prefered minimum amount of news messages
static uint _total_news = 0; ///< current number of news items
static NewsItem *_oldest_news = NULL; ///< head of news items queue
static NewsItem *_latest_news = NULL; ///< tail of news items queue
/** 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, a pointer is stored
* in _forced_news. Otherwise, \a _forced_news variable is NULL. */
static NewsItem *_forced_news = NULL; ///< item the user has asked for
static const NewsItem *_forced_news = NULL; ///< item the user has asked for
/** Current news item (last item shown regularly). */
static NewsItem *_current_news = NULL;
static const NewsItem *_current_news = NULL;
* Get the position a news-reference is referencing.
* @param reftype The type of reference.
* @param ref The reference.
* @return A tile for the referenced object, or INVALID_TILE if none.
static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref)
switch (reftype) {
case NR_TILE: return (TileIndex)ref;
@@ -272,28 +272,28 @@ NewsTypeData _news_type_data[] = {
NewsTypeData("new_vehicles", 30, SND_1E_OOOOH, STR_NEWS_MESSAGE_TYPE_NEW_VEHICLES ), ///< NT_NEW_VEHICLES
NewsTypeData("acceptance", 90, SND_BEGIN, STR_NEWS_MESSAGE_TYPE_CHANGES_OF_CARGO_ACCEPTANCE ), ///< NT_ACCEPTANCE
NewsTypeData("subsidies", 180, SND_BEGIN, STR_NEWS_MESSAGE_TYPE_SUBSIDIES ), ///< NT_SUBSIDIES
NewsTypeData("general", 60, SND_BEGIN, STR_NEWS_MESSAGE_TYPE_GENERAL_INFORMATION ), ///< NT_GENERAL
};
assert_compile(lengthof(_news_type_data) == NT_END);
/** Window class displaying a news item. */
struct NewsWindow : Window {
uint16 chat_height; ///< Height of the chat window.
uint16 status_height; ///< Height of the status bar window
NewsItem *ni; ///< News item to display.
const NewsItem *ni; ///< News item to display.
static uint duration; ///< Remaining time for showing current news message (may only be accessed while a news item is displayed).
NewsWindow(const WindowDesc *desc, NewsItem *ni) : Window(), ni(ni)
NewsWindow(const WindowDesc *desc, const NewsItem *ni) : Window(), ni(ni)
NewsWindow::duration = 555;
const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
this->chat_height = (w != NULL) ? w->height : 0;
this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
this->flags4 |= WF_DISABLE_VP_SCROLL;
this->CreateNestedTree(desc);
switch (this->ni->subtype) {
case NS_COMPANY_TROUBLE:
this->GetWidget<NWidgetCore>(NTW_TITLE)->widget_data = STR_NEWS_COMPANY_IN_TROUBLE_TITLE;
@@ -552,89 +552,91 @@ private:
return STR_NEWS_NEW_VEHICLE_TYPE;
default:
NOT_REACHED();
/* static */ uint NewsWindow::duration = 0; // Instance creation.
/** Open up an own newspaper window for the news item */
static void ShowNewspaper(NewsItem *ni)
static void ShowNewspaper(const NewsItem *ni)
SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound;
if (sound != 0) SndPlayFx(sound);
new NewsWindow(_news_subtype_data[ni->subtype].desc, ni);
/** Show news item in the ticker */
static void ShowTicker(const NewsItem *ni)
if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
_statusbar_news_item = *ni;
_statusbar_news_item = ni;
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
/** Initialize the news-items data structures */
void InitNewsItemStructs()
for (NewsItem *ni = _oldest_news; ni != NULL; ) {
NewsItem *next = ni->next;
delete ni;
ni = next;
_total_news = 0;
_oldest_news = NULL;
_latest_news = NULL;
_forced_news = NULL;
_current_news = NULL;
_statusbar_news_item = NULL;
NewsWindow::duration = 0;
* Are we ready to show another news item?
* Only if nothing is in the newsticker and no newspaper is displayed
static bool ReadyForNextItem()
NewsItem *ni = _forced_news == NULL ? _current_news : _forced_news;
const NewsItem *ni = _forced_news == NULL ? _current_news : _forced_news;
if (ni == NULL) return true;
/* Ticker message
* Check if the status bar message is still being displayed? */
if (IsNewsTickerShown()) return false;
/* Newspaper message, decrement duration counter */
if (NewsWindow::duration != 0) NewsWindow::duration--;
/* neither newsticker nor newspaper are running */
return (NewsWindow::duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
/** Move to the next news item */
static void MoveToNextItem()
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
/* if we're not at the last item, then move on */
if (_current_news != _latest_news) {
_current_news = (_current_news == NULL) ? _oldest_news : _current_news->next;
NewsItem *ni = _current_news;
const NewsItem *ni = _current_news;
const NewsType type = _news_subtype_data[ni->subtype].type;
/* check the date, don't show too old items */
if (_date - _news_type_data[type].age > ni->date) return;
switch (_news_type_data[type].display) {
default: NOT_REACHED();
case ND_OFF: // Off - show nothing only a small reminder in the status bar
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
break;
case ND_SUMMARY: // Summary - show ticker
@@ -823,25 +825,25 @@ void NewsLoop()
static byte _last_clean_month = 0;
if (_last_clean_month != _cur_month) {
RemoveOldNewsItems();
_last_clean_month = _cur_month;
if (ReadyForNextItem()) MoveToNextItem();
/** Do a forced show of a specific message */
static void ShowNewsMessage(NewsItem *ni)
static void ShowNewsMessage(const NewsItem *ni)
assert(_total_news != 0);
/* Delete the news window */
DeleteWindowById(WC_NEWS_WINDOW, 0);
/* setup forced news item */
_forced_news = ni;
if (_forced_news != NULL) {
ShowNewspaper(ni);
@@ -152,27 +152,27 @@ struct StatusBarWindow : Window {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_COMPANY_MONEY, TC_FROMSTRING, SA_CENTER);
} break;
case SBW_MIDDLE:
/* Draw status bar */
if (this->saving) { // true when saving is active
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_SAVING_GAME, TC_FROMSTRING, SA_CENTER);
} else if (_do_autosave) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_CENTER);
} else if (_pause_mode != PM_UNPAUSED) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_PAUSED, TC_FROMSTRING, SA_CENTER);
} else if (this->ticker_scroll < TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item.string_id != 0) {
} else if (this->ticker_scroll < TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == NULL && _statusbar_news_item != NULL && _statusbar_news_item->string_id != 0) {
/* Draw the scrolling news text */
if (!DrawScrollingStatusText(&_statusbar_news_item, this->ticker_scroll, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) {
if (!DrawScrollingStatusText(_statusbar_news_item, this->ticker_scroll, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) {
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED);
if (Company::IsValidID(_local_company)) {
/* This is the default text */
SetDParam(0, _local_company);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_CENTER);
} else {
Status change: