File diff r23123:aa31147b532e → r23124:8fa6d269005b
src/news_gui.cpp
Show inline comments
 
@@ -251,29 +251,31 @@ NewsDisplay NewsTypeData::GetDisplay() c
 
	uint index;
 
	const SettingDesc *sd = GetSettingFromName(this->name, &index);
 
	assert(sd != NULL);
 
	void *ptr = GetVariableAddress(NULL, &sd->save);
 
	return (NewsDisplay)ReadValue(ptr, sd->save.conv);
 
}
 

	
 
/** 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
 
	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).
 
	static int duration;  ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
 

	
 
	uint timer;
 

	
 
	NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
 
	{
 
		NewsWindow::duration = 555;
 
		NewsWindow::duration = 16650;
 
		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->flags |= WF_DISABLE_VP_SCROLL;
 

	
 
		this->CreateNestedTree();
 

	
 
		/* For company news with a face we have a separate headline in param[0] */
 
		if (desc == &_company_news_desc) this->GetWidget<NWidgetCore>(WID_N_TITLE)->widget_data = this->ni->params[0];
 

	
 
		this->FinishInitNested(0);
 
@@ -476,29 +478,36 @@ struct NewsWindow : Window {
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (!gui_scope) return;
 
		/* The chatbar has notified us that is was either created or closed */
 
		int newtop = this->top + this->chat_height - data;
 
		this->chat_height = data;
 
		this->SetWindowTop(newtop);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		/* Scroll up newsmessages from the bottom in steps of 4 pixels */
 
		int newtop = max(this->top - 4, _screen.height - this->height - this->status_height - this->chat_height);
 
		this->SetWindowTop(newtop);
 
		int count = CountIntervalElapsed(this->timer, delta_ms, 15);
 
		if (count > 0) {
 
			/* Scroll up newsmessages from the bottom */
 
			int newtop = max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
 
			this->SetWindowTop(newtop);
 
		}
 

	
 
		/* Decrement the news timer. We don't need to action an elapsed event here,
 
		 * so no need to use TimerElapsed(). */
 
		if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
 
	}
 

	
 
private:
 
	/**
 
	 * Moves the window to a new #top coordinate. Makes screen dirty where needed.
 
	 * @param newtop new top coordinate
 
	 */
 
	void SetWindowTop(int newtop)
 
	{
 
		if (this->top == newtop) return;
 

	
 
		int mintop = min(newtop, this->top);
 
@@ -527,25 +536,25 @@ private:
 
				return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
 

	
 
			case WID_N_VEH_NAME:
 
				SetDParam(0, engine);
 
				return STR_NEWS_NEW_VEHICLE_TYPE;
 

	
 
			default:
 
				NOT_REACHED();
 
		}
 
	}
 
};
 

	
 
/* static */ uint NewsWindow::duration = 0; // Instance creation.
 
/* static */ int NewsWindow::duration = 0; // Instance creation.
 

	
 

	
 
/** Open up an own newspaper window for the news item */
 
static void ShowNewspaper(const NewsItem *ni)
 
{
 
	SoundFx sound = _news_type_data[ni->type].sound;
 
	if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
 

	
 
	new NewsWindow(GetNewsWindowLayout(ni->flags), ni);
 
}
 

	
 
/** Show news item in the ticker */
 
@@ -579,29 +588,26 @@ void InitNewsItemStructs()
 
 * Are we ready to show another news item?
 
 * Only if nothing is in the newsticker and no newspaper is displayed
 
 */
 
static bool ReadyForNextItem()
 
{
 
	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);
 
	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
 
	_forced_news = NULL;
 
	_statusbar_news_item = NULL;
 

	
 
	/* if we're not at the last item, then move on */
 
	if (_current_news != _latest_news) {