2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file news_gui.cpp GUI functions related to news messages. */
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2006-03-06 23:01:35 +00:00
|
|
|
#include "gui.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "news_type.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_base.h"
|
2009-09-02 20:55:55 +00:00
|
|
|
#include "vehicle_func.h"
|
2010-06-07 20:00:21 +00:00
|
|
|
#include "vehicle_gui.h"
|
2009-05-24 16:52:42 +00:00
|
|
|
#include "station_base.h"
|
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-01-14 16:10:58 +00:00
|
|
|
#include "widgets/dropdown_func.h"
|
2008-05-16 07:08:04 +00:00
|
|
|
#include "statusbar_gui.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_manager_face.h"
|
2009-09-02 20:55:55 +00:00
|
|
|
#include "company_func.h"
|
2011-02-05 20:41:13 +00:00
|
|
|
#include "engine_base.h"
|
2009-09-02 20:55:55 +00:00
|
|
|
#include "engine_gui.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2009-12-21 21:14:40 +00:00
|
|
|
const NewsItem *_statusbar_news_item = NULL;
|
2009-08-14 18:41:03 +00:00
|
|
|
bool _news_ticker_sound; ///< Make a ticker sound when a news item is published.
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
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
|
2007-09-17 17:07:24 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Forced news item.
|
2007-09-17 17:07:24 +00:00
|
|
|
* Users can force an item by accessing the history or "last message".
|
2008-05-28 21:36:16 +00:00
|
|
|
* If the message being shown was forced by the user, a pointer is stored
|
2010-08-01 19:44:49 +00:00
|
|
|
* in _forced_news. Otherwise, \a _forced_news variable is NULL.
|
|
|
|
*/
|
2009-12-21 21:14:40 +00:00
|
|
|
static const NewsItem *_forced_news = NULL; ///< item the user has asked for
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
/** Current news item (last item shown regularly). */
|
2009-12-21 21:14:40 +00:00
|
|
|
static const NewsItem *_current_news = NULL;
|
2008-05-15 13:47:55 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-24 16:52:42 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
case NR_STATION: return Station::Get((StationID)ref)->xy;
|
2010-01-04 18:21:07 +00:00
|
|
|
case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1);
|
2009-05-24 16:52:42 +00:00
|
|
|
case NR_TOWN: return Town::Get((TownID)ref)->xy;
|
|
|
|
default: return INVALID_TILE;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-02 20:21:30 +00:00
|
|
|
/** Widget numbers of the news display windows. */
|
|
|
|
enum NewsTypeWidgets {
|
2009-09-02 20:54:27 +00:00
|
|
|
NTW_PANEL, ///< The news item background panel.
|
|
|
|
NTW_TITLE, ///< Title of the company news.
|
|
|
|
NTW_HEADLINE, ///< The news headline.
|
|
|
|
NTW_CLOSEBOX, ///< Close the window.
|
|
|
|
NTW_DATE, ///< Date of the news item.
|
|
|
|
NTW_CAPTION, ///< Title bar of the window. Only used in small news items.
|
|
|
|
NTW_INSET, ///< Inset around the viewport in the window. Only used in small news items.
|
|
|
|
NTW_VIEWPORT, ///< Viewport in the window.
|
|
|
|
NTW_COMPANY_MSG, ///< Message in company news items.
|
|
|
|
NTW_MESSAGE, ///< Space for displaying the message. Only used in small news items.
|
|
|
|
NTW_MGR_FACE, ///< Face of the manager.
|
|
|
|
NTW_MGR_NAME, ///< Name of the manager.
|
2009-09-02 20:55:55 +00:00
|
|
|
NTW_VEH_TITLE, ///< Vehicle new title.
|
|
|
|
NTW_VEH_BKGND, ///< Dark background of new vehicle news.
|
|
|
|
NTW_VEH_NAME, ///< Name of the new vehicle.
|
|
|
|
NTW_VEH_SPR, ///< Graphical display of the new vehicle.
|
|
|
|
NTW_VEH_INFO, ///< Some technical data of the new vehicle.
|
2009-09-02 20:21:30 +00:00
|
|
|
};
|
|
|
|
|
2009-09-02 20:39:40 +00:00
|
|
|
/* Normal news items. */
|
2009-09-02 20:21:30 +00:00
|
|
|
static const NWidgetPart _nested_normal_news_widgets[] = {
|
2009-09-02 20:52:58 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_PANEL),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_WHITE, NTW_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-09-02 20:59:30 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, NTW_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-09-02 20:59:30 +00:00
|
|
|
EndContainer(),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
2009-09-02 20:59:30 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, NTW_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 1, 1, 1),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-11-28 13:54:28 +00:00
|
|
|
static const WindowDesc _normal_news_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2009-09-02 20:21:30 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_normal_news_widgets, lengthof(_nested_normal_news_widgets)
|
2009-09-02 20:21:30 +00:00
|
|
|
);
|
|
|
|
|
2009-09-02 20:55:55 +00:00
|
|
|
/* New vehicles news items. */
|
|
|
|
static const NWidgetPart _nested_vehicle_news_widgets[] = {
|
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_PANEL),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_WHITE, NTW_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-09-02 20:55:55 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, NTW_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
|
2009-09-02 20:55:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_VEH_BKGND), SetPadding(0, 25, 1, 25),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, NTW_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, NTW_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, NTW_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
|
2009-09-02 20:55:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-11-28 13:54:28 +00:00
|
|
|
static const WindowDesc _vehicle_news_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2009-09-02 20:55:55 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_vehicle_news_widgets, lengthof(_nested_vehicle_news_widgets)
|
2009-09-02 20:55:55 +00:00
|
|
|
);
|
|
|
|
|
2009-09-02 20:54:27 +00:00
|
|
|
/* Company news items. */
|
|
|
|
static const NWidgetPart _nested_company_news_widgets[] = {
|
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_PANEL),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_WHITE, NTW_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-09-02 20:54:27 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, NTW_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL),
|
2009-09-02 20:54:27 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(0, 1, 1, 1),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, NTW_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, NTW_MGR_NAME), SetMinimalSize(93, 24), SetPadding(0, 0, 0, 1),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-09-02 20:54:27 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-09-02 20:54:27 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, NTW_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
|
2009-09-02 20:54:27 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-11-28 13:54:28 +00:00
|
|
|
static const WindowDesc _company_news_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2009-09-02 20:54:27 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_company_news_widgets, lengthof(_nested_company_news_widgets)
|
2009-09-02 20:54:27 +00:00
|
|
|
);
|
|
|
|
|
2009-09-02 20:39:40 +00:00
|
|
|
/* Thin news items. */
|
2009-09-02 20:21:30 +00:00
|
|
|
static const NWidgetPart _nested_thin_news_widgets[] = {
|
2009-09-02 20:52:58 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, NTW_PANEL),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_WHITE, NTW_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-09-02 20:52:58 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, NTW_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-09-02 20:52:58 +00:00
|
|
|
EndContainer(),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, NTW_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 1, 0, 1),
|
2009-09-02 20:52:58 +00:00
|
|
|
NWidget(NWID_VIEWPORT, INVALID_COLOUR, NTW_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-11-28 13:54:28 +00:00
|
|
|
static const WindowDesc _thin_news_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2009-09-02 20:21:30 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_thin_news_widgets, lengthof(_nested_thin_news_widgets)
|
2009-09-02 20:21:30 +00:00
|
|
|
);
|
|
|
|
|
2009-09-02 20:39:40 +00:00
|
|
|
/* Small news items. */
|
2009-11-28 13:54:28 +00:00
|
|
|
static const NWidgetPart _nested_small_news_widgets[] = {
|
2010-06-07 19:56:32 +00:00
|
|
|
/* Caption + close box. The caption is no WWT_CAPTION as the window shall not be moveable and so on. */
|
2009-09-02 20:21:30 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 11:20:12 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, NTW_CLOSEBOX),
|
2010-06-07 19:56:32 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, NTW_CAPTION), SetFill(1, 0),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
|
|
|
|
/* Main part */
|
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, NTW_HEADLINE),
|
2009-09-02 20:46:42 +00:00
|
|
|
NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, NTW_INSET), SetPadding(2, 2, 2, 2),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_VIEWPORT, INVALID_COLOUR, NTW_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(1, 0),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, NTW_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-11-28 13:54:28 +00:00
|
|
|
static const WindowDesc _small_news_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2009-09-02 20:21:30 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_small_news_widgets, lengthof(_nested_small_news_widgets)
|
2009-09-02 20:21:30 +00:00
|
|
|
);
|
|
|
|
|
2008-05-15 13:39:36 +00:00
|
|
|
/**
|
|
|
|
* Data common to all news items of a given subtype (structure)
|
|
|
|
*/
|
|
|
|
struct NewsSubtypeData {
|
2009-11-28 13:54:28 +00:00
|
|
|
NewsType type; ///< News category @see NewsType
|
|
|
|
NewsFlag flags; ///< Initial NewsFlags bits @see NewsFlag
|
|
|
|
const WindowDesc *desc; ///< Window description for displaying this news.
|
2008-05-15 13:39:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data common to all news items of a given subtype (actual data)
|
|
|
|
*/
|
2009-03-23 11:48:05 +00:00
|
|
|
static const NewsSubtypeData _news_subtype_data[] = {
|
2009-09-02 20:52:58 +00:00
|
|
|
/* type, display_mode, flags, window description, callback */
|
2009-09-02 20:59:30 +00:00
|
|
|
{ NT_ARRIVAL_COMPANY, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ARRIVAL_COMPANY
|
|
|
|
{ NT_ARRIVAL_OTHER, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ARRIVAL_OTHER
|
|
|
|
{ NT_ACCIDENT, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ACCIDENT
|
|
|
|
{ NT_COMPANY_INFO, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_TROUBLE
|
|
|
|
{ NT_COMPANY_INFO, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_MERGER
|
|
|
|
{ NT_COMPANY_INFO, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_BANKRUPT
|
|
|
|
{ NT_COMPANY_INFO, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_NEW
|
|
|
|
{ NT_INDUSTRY_OPEN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_OPEN
|
|
|
|
{ NT_INDUSTRY_CLOSE, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_CLOSE
|
|
|
|
{ NT_ECONOMY, NF_NONE, &_normal_news_desc }, ///< NS_ECONOMY
|
|
|
|
{ NT_INDUSTRY_COMPANY, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_COMPANY
|
|
|
|
{ NT_INDUSTRY_OTHER, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_OTHER
|
|
|
|
{ NT_INDUSTRY_NOBODY, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_NOBODY
|
|
|
|
{ NT_ADVICE, NF_INCOLOUR, &_small_news_desc }, ///< NS_ADVICE
|
|
|
|
{ NT_NEW_VEHICLES, NF_NONE, &_vehicle_news_desc }, ///< NS_NEW_VEHICLES
|
|
|
|
{ NT_ACCEPTANCE, NF_INCOLOUR, &_small_news_desc }, ///< NS_ACCEPTANCE
|
|
|
|
{ NT_SUBSIDIES, NF_NONE, &_normal_news_desc }, ///< NS_SUBSIDIES
|
|
|
|
{ NT_GENERAL, NF_NONE, &_normal_news_desc }, ///< NS_GENERAL
|
2008-05-15 13:39:36 +00:00
|
|
|
};
|
|
|
|
|
2009-03-23 11:48:05 +00:00
|
|
|
assert_compile(lengthof(_news_subtype_data) == NS_END);
|
|
|
|
|
2008-05-28 20:13:28 +00:00
|
|
|
/**
|
|
|
|
* Per-NewsType data
|
|
|
|
*/
|
2009-03-23 11:48:05 +00:00
|
|
|
NewsTypeData _news_type_data[] = {
|
2011-09-05 21:55:05 +00:00
|
|
|
/* name, age, sound, display, description */
|
|
|
|
NewsTypeData("arrival_player", 60, SND_1D_APPLAUSE, ND_FULL, STR_NEWS_MESSAGE_TYPE_ARRIVAL_OF_FIRST_VEHICLE_OWN ), ///< NT_ARRIVAL_COMPANY
|
|
|
|
NewsTypeData("arrival_other", 60, SND_1D_APPLAUSE, ND_SUMMARY, STR_NEWS_MESSAGE_TYPE_ARRIVAL_OF_FIRST_VEHICLE_OTHER ), ///< NT_ARRIVAL_OTHER
|
|
|
|
NewsTypeData("accident", 90, SND_BEGIN, ND_FULL, STR_NEWS_MESSAGE_TYPE_ACCIDENTS_DISASTERS ), ///< NT_ACCIDENT
|
|
|
|
NewsTypeData("company_info", 60, SND_BEGIN, ND_FULL, STR_NEWS_MESSAGE_TYPE_COMPANY_INFORMATION ), ///< NT_COMPANY_INFO
|
|
|
|
NewsTypeData("open", 90, SND_BEGIN, ND_SUMMARY, STR_NEWS_MESSAGE_TYPE_INDUSTRY_OPEN ), ///< NT_INDUSTRY_OPEN
|
|
|
|
NewsTypeData("close", 90, SND_BEGIN, ND_SUMMARY, STR_NEWS_MESSAGE_TYPE_INDUSTRY_CLOSE ), ///< NT_INDUSTRY_CLOSE
|
|
|
|
NewsTypeData("economy", 30, SND_BEGIN, ND_FULL, STR_NEWS_MESSAGE_TYPE_ECONOMY_CHANGES ), ///< NT_ECONOMY
|
|
|
|
NewsTypeData("production_player", 30, SND_BEGIN, ND_SUMMARY, STR_NEWS_MESSAGE_TYPE_INDUSTRY_CHANGES_SERVED_BY_COMPANY ), ///< NT_INDUSTRY_COMPANY
|
|
|
|
NewsTypeData("production_other", 30, SND_BEGIN, ND_OFF, STR_NEWS_MESSAGE_TYPE_INDUSTRY_CHANGES_SERVED_BY_OTHER ), ///< NT_INDUSTRY_OTHER
|
|
|
|
NewsTypeData("production_nobody", 30, SND_BEGIN, ND_OFF, STR_NEWS_MESSAGE_TYPE_INDUSTRY_CHANGES_UNSERVED ), ///< NT_INDUSTRY_NOBODY
|
|
|
|
NewsTypeData("advice", 150, SND_BEGIN, ND_FULL, STR_NEWS_MESSAGE_TYPE_ADVICE_INFORMATION_ON_COMPANY ), ///< NT_ADVICE
|
|
|
|
NewsTypeData("new_vehicles", 30, SND_1E_OOOOH, ND_FULL, STR_NEWS_MESSAGE_TYPE_NEW_VEHICLES ), ///< NT_NEW_VEHICLES
|
|
|
|
NewsTypeData("acceptance", 90, SND_BEGIN, ND_FULL, STR_NEWS_MESSAGE_TYPE_CHANGES_OF_CARGO_ACCEPTANCE ), ///< NT_ACCEPTANCE
|
|
|
|
NewsTypeData("subsidies", 180, SND_BEGIN, ND_SUMMARY, STR_NEWS_MESSAGE_TYPE_SUBSIDIES ), ///< NT_SUBSIDIES
|
|
|
|
NewsTypeData("general", 60, SND_BEGIN, ND_FULL, STR_NEWS_MESSAGE_TYPE_GENERAL_INFORMATION ), ///< NT_GENERAL
|
2008-05-28 20:13:28 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-23 11:48:05 +00:00
|
|
|
assert_compile(lengthof(_news_type_data) == NT_END);
|
|
|
|
|
2009-08-16 08:59:56 +00:00
|
|
|
/** Window class displaying a news item. */
|
2008-05-15 13:47:55 +00:00
|
|
|
struct NewsWindow : Window {
|
2009-08-16 08:59:56 +00:00
|
|
|
uint16 chat_height; ///< Height of the chat window.
|
2009-11-02 10:15:48 +00:00
|
|
|
uint16 status_height; ///< Height of the status bar window
|
2009-12-21 21:14:40 +00:00
|
|
|
const NewsItem *ni; ///< News item to display.
|
2009-08-16 08:59:56 +00:00
|
|
|
static uint duration; ///< Remaining time for showing current news message (may only be accessed while a news item is displayed).
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-12-21 21:14:40 +00:00
|
|
|
NewsWindow(const WindowDesc *desc, const NewsItem *ni) : Window(), ni(ni)
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
2008-05-30 20:57:19 +00:00
|
|
|
NewsWindow::duration = 555;
|
2009-11-29 00:41:08 +00:00
|
|
|
const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
|
2008-05-15 13:47:55 +00:00
|
|
|
this->chat_height = (w != NULL) ? w->height : 0;
|
2009-11-02 10:15:48 +00:00
|
|
|
this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-02 20:54:27 +00:00
|
|
|
this->CreateNestedTree(desc);
|
|
|
|
switch (this->ni->subtype) {
|
|
|
|
case NS_COMPANY_TROUBLE:
|
2009-09-19 11:31:12 +00:00
|
|
|
this->GetWidget<NWidgetCore>(NTW_TITLE)->widget_data = STR_NEWS_COMPANY_IN_TROUBLE_TITLE;
|
2009-09-02 20:54:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_COMPANY_MERGER:
|
2009-09-19 11:31:12 +00:00
|
|
|
this->GetWidget<NWidgetCore>(NTW_TITLE)->widget_data = STR_NEWS_COMPANY_MERGER_TITLE;
|
2009-09-02 20:54:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_COMPANY_BANKRUPT:
|
2009-09-19 11:31:12 +00:00
|
|
|
this->GetWidget<NWidgetCore>(NTW_TITLE)->widget_data = STR_NEWS_COMPANY_BANKRUPT_TITLE;
|
2009-09-02 20:54:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_COMPANY_NEW:
|
2009-09-19 11:31:12 +00:00
|
|
|
this->GetWidget<NWidgetCore>(NTW_TITLE)->widget_data = STR_NEWS_COMPANY_LAUNCH_TITLE;
|
2009-09-02 20:54:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->FinishInitNested(desc, 0);
|
2009-08-16 16:06:06 +00:00
|
|
|
|
2009-09-02 20:52:58 +00:00
|
|
|
/* Initialize viewport if it exists. */
|
2009-09-19 11:31:12 +00:00
|
|
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(NTW_VIEWPORT);
|
2009-09-02 20:52:58 +00:00
|
|
|
if (nvp != NULL) {
|
|
|
|
nvp->InitializeViewport(this, ni->reftype1 == NR_VEHICLE ? 0x80000000 | ni->ref1 : GetReferenceTile(ni->reftype1, ni->ref1), ZOOM_LVL_NEWS);
|
|
|
|
if (this->ni->flags & NF_NO_TRANSPARENT) nvp->disp_flags |= ND_NO_TRANSPARENCY;
|
|
|
|
if ((this->ni->flags & NF_INCOLOUR) == 0) {
|
|
|
|
nvp->disp_flags |= ND_SHADE_GREY;
|
|
|
|
} else if (this->ni->flags & NF_SHADE) {
|
|
|
|
nvp->disp_flags |= ND_SHADE_DIMMED;
|
2009-09-02 20:46:42 +00:00
|
|
|
}
|
2009-08-16 16:06:06 +00:00
|
|
|
}
|
2010-11-18 19:24:40 +00:00
|
|
|
|
|
|
|
PositionNewsMessage(this);
|
2008-05-15 13:47:55 +00:00
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2009-09-02 20:52:58 +00:00
|
|
|
void DrawNewsBorder(const Rect &r) const
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left, r.top, r.right, r.bottom, PC_WHITE);
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left, r.top, r.left, r.bottom, PC_BLACK);
|
|
|
|
GfxFillRect(r.right, r.top, r.right, r.bottom, PC_BLACK);
|
|
|
|
GfxFillRect(r.left, r.top, r.right, r.top, PC_BLACK);
|
|
|
|
GfxFillRect(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
|
2008-05-15 13:47:55 +00:00
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2009-11-28 13:54:28 +00:00
|
|
|
virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
|
|
|
|
{
|
2010-11-18 19:24:40 +00:00
|
|
|
Point pt = { 0, _screen.height };
|
2009-11-28 13:54:28 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-09-02 20:46:42 +00:00
|
|
|
{
|
2009-09-02 20:54:27 +00:00
|
|
|
StringID str = STR_NULL;
|
2009-09-02 20:46:42 +00:00
|
|
|
switch (widget) {
|
2009-09-02 20:54:27 +00:00
|
|
|
case NTW_MESSAGE:
|
2009-09-02 20:46:42 +00:00
|
|
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
2009-09-02 20:54:27 +00:00
|
|
|
str = this->ni->string_id;
|
2009-09-02 20:46:42 +00:00
|
|
|
break;
|
2009-09-02 20:54:27 +00:00
|
|
|
|
|
|
|
case NTW_COMPANY_MSG:
|
|
|
|
str = this->GetCompanyMessageString();
|
|
|
|
break;
|
|
|
|
|
2009-09-02 20:55:55 +00:00
|
|
|
case NTW_VEH_NAME:
|
|
|
|
case NTW_VEH_TITLE:
|
|
|
|
str = this->GetNewVehicleMessageString(widget);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NTW_VEH_INFO: {
|
|
|
|
assert(this->ni->reftype1 == NR_ENGINE);
|
|
|
|
EngineID engine = this->ni->ref1;
|
|
|
|
str = GetEngineInfoString(engine);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-02 20:54:27 +00:00
|
|
|
default:
|
|
|
|
return; // Do nothing
|
2009-09-02 20:46:42 +00:00
|
|
|
}
|
2009-09-02 20:54:27 +00:00
|
|
|
|
|
|
|
/* Update minimal size with length of the multi-line string. */
|
|
|
|
Dimension d = *size;
|
|
|
|
d.width = (d.width >= padding.width) ? d.width - padding.width : 0;
|
|
|
|
d.height = (d.height >= padding.height) ? d.height - padding.height : 0;
|
|
|
|
d = GetStringMultiLineBoundingBox(str, d);
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
2009-09-02 20:46:42 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 20:52:58 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
if (widget == NTW_DATE) SetDParam(0, this->ni->date);
|
|
|
|
}
|
|
|
|
|
2009-09-02 20:46:42 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2010-06-07 19:56:32 +00:00
|
|
|
case NTW_CAPTION:
|
|
|
|
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, STR_NEWS_MESSAGE_CAPTION);
|
|
|
|
break;
|
|
|
|
|
2009-09-02 20:52:58 +00:00
|
|
|
case NTW_PANEL:
|
|
|
|
this->DrawNewsBorder(r);
|
2010-06-07 19:56:32 +00:00
|
|
|
break;
|
2009-09-02 20:52:58 +00:00
|
|
|
|
2009-09-02 20:46:42 +00:00
|
|
|
case NTW_MESSAGE:
|
|
|
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
|
|
|
DrawStringMultiLine(r.left + 2, r.right - 2, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
2009-09-02 20:54:27 +00:00
|
|
|
|
|
|
|
case NTW_MGR_FACE: {
|
|
|
|
const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
|
|
|
|
DrawCompanyManagerFace(cni->face, cni->colour, r.left, r.top);
|
2011-04-29 20:47:36 +00:00
|
|
|
GfxFillRect(r.left + 1, r.top, r.left + 1 + 91, r.top + 118, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
|
2009-09-02 20:54:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NTW_MGR_NAME: {
|
|
|
|
const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
|
|
|
|
SetDParamStr(0, cni->president_name);
|
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NTW_COMPANY_MSG:
|
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
2009-09-02 20:55:55 +00:00
|
|
|
|
|
|
|
case NTW_VEH_BKGND:
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left, r.top, r.right, r.bottom, PC_GREY);
|
2009-09-02 20:55:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NTW_VEH_NAME:
|
|
|
|
case NTW_VEH_TITLE:
|
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NTW_VEH_SPR: {
|
|
|
|
assert(this->ni->reftype1 == NR_ENGINE);
|
|
|
|
EngineID engine = this->ni->ref1;
|
2009-11-16 17:15:42 +00:00
|
|
|
DrawVehicleEngine(r.left, r.right, (r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company));
|
2011-04-29 20:47:36 +00:00
|
|
|
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
|
2009-09-02 20:55:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NTW_VEH_INFO: {
|
|
|
|
assert(this->ni->reftype1 == NR_ENGINE);
|
|
|
|
EngineID engine = this->ni->ref1;
|
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-02 20:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2009-05-31 20:18:47 +00:00
|
|
|
case NTW_CLOSEBOX:
|
2008-05-30 20:57:19 +00:00
|
|
|
NewsWindow::duration = 0;
|
2008-05-15 13:47:55 +00:00
|
|
|
delete this;
|
2008-05-28 21:36:16 +00:00
|
|
|
_forced_news = NULL;
|
2008-05-15 13:47:55 +00:00
|
|
|
break;
|
2008-05-05 11:24:58 +00:00
|
|
|
|
2009-09-02 20:44:36 +00:00
|
|
|
case NTW_CAPTION:
|
2010-06-07 20:00:21 +00:00
|
|
|
if (this->ni->reftype1 == NR_VEHICLE) {
|
|
|
|
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
|
|
|
ShowVehicleViewWindow(v);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-02 20:44:36 +00:00
|
|
|
case NTW_VIEWPORT:
|
|
|
|
break; // Ignore clicks
|
|
|
|
|
|
|
|
default:
|
2009-05-24 16:52:42 +00:00
|
|
|
if (this->ni->reftype1 == NR_VEHICLE) {
|
|
|
|
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
2009-03-15 15:25:18 +00:00
|
|
|
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
|
2009-05-24 16:52:42 +00:00
|
|
|
} else {
|
|
|
|
TileIndex tile1 = GetReferenceTile(this->ni->reftype1, this->ni->ref1);
|
|
|
|
TileIndex tile2 = GetReferenceTile(this->ni->reftype2, this->ni->ref2);
|
2008-05-15 13:47:55 +00:00
|
|
|
if (_ctrl_pressed) {
|
2009-05-24 16:52:42 +00:00
|
|
|
if (tile1 != INVALID_TILE) ShowExtraViewPortWindow(tile1);
|
|
|
|
if (tile2 != INVALID_TILE) ShowExtraViewPortWindow(tile2);
|
2008-05-15 13:47:55 +00:00
|
|
|
} else {
|
2009-09-02 19:57:22 +00:00
|
|
|
if ((tile1 == INVALID_TILE || !ScrollMainWindowToTile(tile1)) && tile2 != INVALID_TILE) {
|
2009-05-24 16:52:42 +00:00
|
|
|
ScrollMainWindowToTile(tile2);
|
2008-05-05 11:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
}
|
2008-05-15 13:47:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-17 23:11:06 +00:00
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
|
|
|
if (keycode == WKC_SPACE) {
|
|
|
|
/* Don't continue. */
|
|
|
|
delete this;
|
2008-05-17 23:11:06 +00:00
|
|
|
return ES_HANDLED;
|
2008-05-15 13:47:55 +00:00
|
|
|
}
|
2008-05-17 23:11:06 +00:00
|
|
|
return ES_NOT_HANDLED;
|
2008-05-15 13:47:55 +00:00
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @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)
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2008-05-15 13:47:55 +00:00
|
|
|
/* The chatbar has notified us that is was either created or closed */
|
2010-06-04 09:47:55 +00:00
|
|
|
int newtop = this->top + this->chat_height - data;
|
2008-05-15 13:47:55 +00:00
|
|
|
this->chat_height = data;
|
2010-06-04 09:47:55 +00:00
|
|
|
this->SetWindowTop(newtop);
|
2008-05-15 13:47:55 +00:00
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
virtual void OnTick()
|
|
|
|
{
|
|
|
|
/* Scroll up newsmessages from the bottom in steps of 4 pixels */
|
2010-06-04 09:47:55 +00:00
|
|
|
int newtop = max(this->top - 4, _screen.height - this->height - this->status_height - this->chat_height);
|
|
|
|
this->SetWindowTop(newtop);
|
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2010-06-04 09:47:55 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Moves the window so #newtop is new 'top' coordinate. Makes screen dirty where needed.
|
|
|
|
* @param newtop new top coordinate
|
|
|
|
*/
|
|
|
|
void SetWindowTop(int newtop)
|
|
|
|
{
|
|
|
|
if (this->top == newtop) return;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2010-06-04 09:47:55 +00:00
|
|
|
int mintop = min(newtop, this->top);
|
|
|
|
int maxtop = max(newtop, this->top);
|
|
|
|
if (this->viewport != NULL) this->viewport->top += newtop - this->top;
|
|
|
|
this->top = newtop;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2010-06-04 09:47:55 +00:00
|
|
|
SetDirtyBlocks(this->left, mintop, this->left + this->width, maxtop + this->height);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-09-02 20:54:27 +00:00
|
|
|
|
|
|
|
StringID GetCompanyMessageString() const
|
|
|
|
{
|
|
|
|
switch (this->ni->subtype) {
|
|
|
|
case NS_COMPANY_TROUBLE:
|
|
|
|
SetDParam(0, this->ni->params[2]);
|
|
|
|
return STR_NEWS_COMPANY_IN_TROUBLE_DESCRIPTION;
|
|
|
|
|
|
|
|
case NS_COMPANY_MERGER:
|
|
|
|
SetDParam(0, this->ni->params[2]);
|
|
|
|
SetDParam(1, this->ni->params[3]);
|
|
|
|
SetDParam(2, this->ni->params[4]);
|
|
|
|
return this->ni->params[4] == 0 ? STR_NEWS_MERGER_TAKEOVER_TITLE : STR_NEWS_COMPANY_MERGER_DESCRIPTION;
|
|
|
|
|
|
|
|
case NS_COMPANY_BANKRUPT:
|
|
|
|
SetDParam(0, this->ni->params[2]);
|
|
|
|
return STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION;
|
|
|
|
|
|
|
|
case NS_COMPANY_NEW:
|
|
|
|
SetDParam(0, this->ni->params[2]);
|
|
|
|
SetDParam(1, this->ni->params[3]);
|
|
|
|
return STR_NEWS_COMPANY_LAUNCH_DESCRIPTION;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
2009-09-02 20:55:55 +00:00
|
|
|
|
|
|
|
StringID GetNewVehicleMessageString(int widget) const
|
|
|
|
{
|
|
|
|
assert(this->ni->reftype1 == NR_ENGINE);
|
|
|
|
EngineID engine = this->ni->ref1;
|
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case NTW_VEH_TITLE:
|
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
|
|
|
return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
|
|
|
|
|
|
|
|
case NTW_VEH_NAME:
|
|
|
|
SetDParam(0, engine);
|
|
|
|
return STR_NEWS_NEW_VEHICLE_TYPE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
2008-05-15 13:47:55 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-08-16 08:59:56 +00:00
|
|
|
/* static */ uint NewsWindow::duration = 0; // Instance creation.
|
2008-05-30 20:57:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** Open up an own newspaper window for the news item */
|
2009-12-21 21:14:40 +00:00
|
|
|
static void ShowNewspaper(const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-15 13:39:36 +00:00
|
|
|
SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (sound != 0) SndPlayFx(sound);
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2009-11-28 13:54:28 +00:00
|
|
|
new NewsWindow(_news_subtype_data[ni->subtype].desc, ni);
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** Show news item in the ticker */
|
2004-11-15 12:05:01 +00:00
|
|
|
static void ShowTicker(const NewsItem *ni)
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2005-04-13 23:03:31 +00:00
|
|
|
if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
|
|
|
|
|
2009-12-21 21:14:40 +00:00
|
|
|
_statusbar_news_item = ni;
|
2008-05-16 07:08:04 +00:00
|
|
|
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 20:13:28 +00:00
|
|
|
/** Initialize the news-items data structures */
|
|
|
|
void InitNewsItemStructs()
|
|
|
|
{
|
2008-05-28 21:36:16 +00:00
|
|
|
for (NewsItem *ni = _oldest_news; ni != NULL; ) {
|
|
|
|
NewsItem *next = ni->next;
|
|
|
|
delete ni;
|
|
|
|
ni = next;
|
|
|
|
}
|
|
|
|
|
2008-05-28 20:13:28 +00:00
|
|
|
_total_news = 0;
|
2008-05-28 21:36:16 +00:00
|
|
|
_oldest_news = NULL;
|
|
|
|
_latest_news = NULL;
|
|
|
|
_forced_news = NULL;
|
|
|
|
_current_news = NULL;
|
2009-12-21 21:14:40 +00:00
|
|
|
_statusbar_news_item = NULL;
|
2009-08-16 08:59:56 +00:00
|
|
|
NewsWindow::duration = 0;
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-05-28 21:36:16 +00:00
|
|
|
* Are we ready to show another news item?
|
|
|
|
* Only if nothing is in the newsticker and no newspaper is displayed
|
2008-05-28 20:13:28 +00:00
|
|
|
*/
|
2008-05-28 21:36:16 +00:00
|
|
|
static bool ReadyForNextItem()
|
2008-05-28 20:13:28 +00:00
|
|
|
{
|
2009-12-21 21:14:40 +00:00
|
|
|
const NewsItem *ni = _forced_news == NULL ? _current_news : _forced_news;
|
2008-05-28 21:36:16 +00:00
|
|
|
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 */
|
2008-05-30 20:57:19 +00:00
|
|
|
if (NewsWindow::duration != 0) NewsWindow::duration--;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
/* neither newsticker nor newspaper are running */
|
2008-05-30 20:57:19 +00:00
|
|
|
return (NewsWindow::duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
/** Move to the next news item */
|
|
|
|
static void MoveToNextItem()
|
2008-05-28 20:13:28 +00:00
|
|
|
{
|
2009-01-09 20:42:17 +00:00
|
|
|
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
|
|
|
|
DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
|
2008-05-28 21:36:16 +00:00
|
|
|
_forced_news = NULL;
|
2009-12-21 21:14:40 +00:00
|
|
|
_statusbar_news_item = NULL;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
/* 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;
|
2009-12-21 21:14:40 +00:00
|
|
|
const NewsItem *ni = _current_news;
|
2008-05-28 21:36:16 +00:00
|
|
|
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;
|
|
|
|
|
2008-06-01 10:11:31 +00:00
|
|
|
case ND_SUMMARY: // Summary - show ticker
|
|
|
|
ShowTicker(ni);
|
|
|
|
break;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
case ND_FULL: // Full - show newspaper
|
|
|
|
ShowNewspaper(ni);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new newsitem to be shown.
|
|
|
|
* @param string String to display
|
|
|
|
* @param subtype news category, any of the NewsSubtype enums (NS_)
|
2009-05-24 16:52:42 +00:00
|
|
|
* @param reftype1 Type of ref1
|
|
|
|
* @param ref1 Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleteing the news when the object is deleted.
|
|
|
|
* @param reftype2 Type of ref2
|
|
|
|
* @param ref2 Reference 2 to some object: Used for scrolling after clicking on the news, and for deleteing the news when the object is deleted.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param free_data Pointer to data that must be freed once the news message is cleared
|
2008-05-28 20:13:28 +00:00
|
|
|
*
|
2009-12-13 21:12:36 +00:00
|
|
|
* @see NewsSubtype
|
2008-05-28 20:13:28 +00:00
|
|
|
*/
|
2009-05-24 16:52:42 +00:00
|
|
|
void AddNewsItem(StringID string, NewsSubtype subtype, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
|
2008-05-28 20:13:28 +00:00
|
|
|
{
|
|
|
|
if (_game_mode == GM_MENU) return;
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
/* Create new news item node */
|
|
|
|
NewsItem *ni = new NewsItem;
|
2008-05-28 20:13:28 +00:00
|
|
|
|
|
|
|
ni->string_id = string;
|
|
|
|
ni->subtype = subtype;
|
|
|
|
ni->flags = _news_subtype_data[subtype].flags;
|
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
/* show this news message in colour? */
|
|
|
|
if (_cur_year >= _settings_client.gui.coloured_news_year) ni->flags |= NF_INCOLOUR;
|
2008-05-28 20:13:28 +00:00
|
|
|
|
2009-05-24 16:52:42 +00:00
|
|
|
ni->reftype1 = reftype1;
|
|
|
|
ni->reftype2 = reftype2;
|
|
|
|
ni->ref1 = ref1;
|
|
|
|
ni->ref2 = ref2;
|
2008-07-18 16:26:51 +00:00
|
|
|
ni->free_data = free_data;
|
2008-05-28 20:13:28 +00:00
|
|
|
ni->date = _date;
|
|
|
|
CopyOutDParam(ni->params, 0, lengthof(ni->params));
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
if (_total_news++ == 0) {
|
|
|
|
assert(_oldest_news == NULL);
|
|
|
|
_oldest_news = ni;
|
|
|
|
ni->prev = NULL;
|
|
|
|
} else {
|
|
|
|
assert(_latest_news->next == NULL);
|
|
|
|
_latest_news->next = ni;
|
|
|
|
ni->prev = _latest_news;
|
|
|
|
}
|
|
|
|
|
|
|
|
ni->next = NULL;
|
|
|
|
_latest_news = ni;
|
|
|
|
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowDirty(WC_MESSAGE_HISTORY, 0);
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
/** Delete a news item from the queue */
|
|
|
|
static void DeleteNewsItem(NewsItem *ni)
|
2008-05-28 20:13:28 +00:00
|
|
|
{
|
2010-12-10 22:39:01 +00:00
|
|
|
/* Delete the news from the news queue. */
|
2008-05-28 21:36:16 +00:00
|
|
|
if (ni->prev != NULL) {
|
|
|
|
ni->prev->next = ni->next;
|
|
|
|
} else {
|
|
|
|
assert(_oldest_news == ni);
|
|
|
|
_oldest_news = ni->next;
|
|
|
|
}
|
2008-05-28 20:13:28 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
if (ni->next != NULL) {
|
|
|
|
ni->next->prev = ni->prev;
|
|
|
|
} else {
|
|
|
|
assert(_latest_news == ni);
|
|
|
|
_latest_news = ni->prev;
|
|
|
|
}
|
2008-05-28 20:13:28 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
_total_news--;
|
2010-12-10 22:39:01 +00:00
|
|
|
|
|
|
|
if (_forced_news == ni || _current_news == ni || _statusbar_news_item == ni) {
|
|
|
|
/* When we're the current news, go to the previous item first;
|
|
|
|
* we just possibly made that the last news item. */
|
|
|
|
if (_current_news == ni) _current_news = ni->prev;
|
|
|
|
|
|
|
|
/* About to remove the currently forced item (shown as newspapers) ||
|
|
|
|
* about to remove the currently displayed item (newspapers, ticker, or just a reminder) */
|
|
|
|
MoveToNextItem();
|
|
|
|
}
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
delete ni;
|
2008-05-28 20:13:28 +00:00
|
|
|
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowDirty(WC_MESSAGE_HISTORY, 0);
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2011-01-22 09:53:15 +00:00
|
|
|
/**
|
|
|
|
* Delete a news item type about a vehicle.
|
|
|
|
* When the news item type is INVALID_STRING_ID all news about the vehicle gets deleted.
|
|
|
|
* @param vid The vehicle to remove the news for.
|
|
|
|
* @param news The news type to remove.
|
|
|
|
*/
|
2008-05-28 21:36:16 +00:00
|
|
|
void DeleteVehicleNews(VehicleID vid, StringID news)
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2008-05-28 21:36:16 +00:00
|
|
|
NewsItem *ni = _oldest_news;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
while (ni != NULL) {
|
2009-05-24 16:52:42 +00:00
|
|
|
NewsItem *next = ni->next;
|
|
|
|
if (((ni->reftype1 == NR_VEHICLE && ni->ref1 == vid) || (ni->reftype2 == NR_VEHICLE && ni->ref2 == vid)) &&
|
2008-05-28 21:36:16 +00:00
|
|
|
(news == INVALID_STRING_ID || ni->string_id == news)) {
|
|
|
|
DeleteNewsItem(ni);
|
|
|
|
}
|
2009-05-24 16:52:42 +00:00
|
|
|
ni = next;
|
2008-05-28 21:36:16 +00:00
|
|
|
}
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Remove news regarding given station so there are no 'unknown station now accepts Mail'
|
2008-09-13 10:19:51 +00:00
|
|
|
* or 'First train arrived at unknown station' news items.
|
|
|
|
* @param sid station to remove news about
|
|
|
|
*/
|
|
|
|
void DeleteStationNews(StationID sid)
|
|
|
|
{
|
|
|
|
NewsItem *ni = _oldest_news;
|
|
|
|
|
|
|
|
while (ni != NULL) {
|
|
|
|
NewsItem *next = ni->next;
|
2009-05-24 16:52:42 +00:00
|
|
|
if ((ni->reftype1 == NR_STATION && ni->ref1 == sid) || (ni->reftype2 == NR_STATION && ni->ref2 == sid)) {
|
|
|
|
DeleteNewsItem(ni);
|
|
|
|
}
|
|
|
|
ni = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Remove news regarding given industry
|
2009-05-24 16:52:42 +00:00
|
|
|
* @param iid industry to remove news about
|
|
|
|
*/
|
|
|
|
void DeleteIndustryNews(IndustryID iid)
|
|
|
|
{
|
|
|
|
NewsItem *ni = _oldest_news;
|
|
|
|
|
|
|
|
while (ni != NULL) {
|
|
|
|
NewsItem *next = ni->next;
|
|
|
|
if ((ni->reftype1 == NR_INDUSTRY && ni->ref1 == iid) || (ni->reftype2 == NR_INDUSTRY && ni->ref2 == iid)) {
|
|
|
|
DeleteNewsItem(ni);
|
2008-09-13 10:19:51 +00:00
|
|
|
}
|
|
|
|
ni = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 20:41:13 +00:00
|
|
|
/**
|
|
|
|
* Remove engine announcements for invalid engines.
|
|
|
|
*/
|
|
|
|
void DeleteInvalidEngineNews()
|
|
|
|
{
|
|
|
|
NewsItem *ni = _oldest_news;
|
|
|
|
|
|
|
|
while (ni != NULL) {
|
|
|
|
NewsItem *next = ni->next;
|
|
|
|
if ((ni->reftype1 == NR_ENGINE && (!Engine::IsValidID(ni->ref1) || !Engine::Get(ni->ref1)->IsEnabled())) ||
|
|
|
|
(ni->reftype2 == NR_ENGINE && (!Engine::IsValidID(ni->ref2) || !Engine::Get(ni->ref2)->IsEnabled()))) {
|
|
|
|
DeleteNewsItem(ni);
|
|
|
|
}
|
|
|
|
ni = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 10:40:33 +00:00
|
|
|
static void RemoveOldNewsItems()
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2008-05-28 21:36:16 +00:00
|
|
|
NewsItem *next;
|
|
|
|
for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != NULL; cur = next) {
|
|
|
|
next = cur->next;
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_date - _news_type_data[_news_subtype_data[cur->subtype].type].age * _settings_client.gui.news_message_timeout > cur->date) DeleteNewsItem(cur);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-08-10 20:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
|
|
|
|
* @note Viewports of currently displayed news is changed via #ChangeVehicleViewports
|
|
|
|
* @param from_index the old vehicle ID
|
|
|
|
* @param to_index the new vehicle ID
|
|
|
|
*/
|
|
|
|
void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
|
|
|
|
{
|
|
|
|
for (NewsItem *ni = _oldest_news; ni != NULL; ni = ni->next) {
|
|
|
|
if (ni->reftype1 == NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
|
|
|
|
if (ni->reftype2 == NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
|
|
|
|
|
|
|
|
/* Oh noes :(
|
|
|
|
* Autoreplace is breaking the whole news-reference concept here, as we want to keep the news,
|
|
|
|
* but do not know which DParams to change.
|
|
|
|
*
|
|
|
|
* Currently only NS_ADVICE news have vehicle IDs in their DParams.
|
|
|
|
* And all NS_ADVICE news have the ID in param 0.
|
|
|
|
*/
|
|
|
|
if (ni->subtype == NS_ADVICE && ni->params[0] == from_index) ni->params[0] = to_index;
|
|
|
|
}
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void NewsLoop()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-21 03:06:21 +00:00
|
|
|
/* no news item yet */
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_total_news == 0) return;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2009-11-23 13:01:12 +00:00
|
|
|
/* There is no status bar, so no reason to show news;
|
|
|
|
* especially important with the end game screen when
|
|
|
|
* there is no status bar but possible news. */
|
|
|
|
if (FindWindowById(WC_STATUS_BAR, 0) == NULL) return;
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
static byte _last_clean_month = 0;
|
|
|
|
|
|
|
|
if (_last_clean_month != _cur_month) {
|
|
|
|
RemoveOldNewsItems();
|
|
|
|
_last_clean_month = _cur_month;
|
|
|
|
}
|
|
|
|
|
2006-12-05 22:31:10 +00:00
|
|
|
if (ReadyForNextItem()) MoveToNextItem();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** Do a forced show of a specific message */
|
2009-12-21 21:14:40 +00:00
|
|
|
static void ShowNewsMessage(const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-28 21:36:16 +00:00
|
|
|
assert(_total_news != 0);
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Delete the news window */
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindowById(WC_NEWS_WINDOW, 0);
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* setup forced news item */
|
2008-05-28 21:36:16 +00:00
|
|
|
_forced_news = ni;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
if (_forced_news != NULL) {
|
2004-08-18 23:38:53 +00:00
|
|
|
DeleteWindowById(WC_NEWS_WINDOW, 0);
|
|
|
|
ShowNewspaper(ni);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** Show previous news item */
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowLastNewsMessage()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-28 21:36:16 +00:00
|
|
|
if (_total_news == 0) {
|
|
|
|
return;
|
|
|
|
} else if (_forced_news == NULL) {
|
2007-01-11 01:21:55 +00:00
|
|
|
/* Not forced any news yet, show the current one, unless a news window is
|
|
|
|
* open (which can only be the current one), then show the previous item */
|
|
|
|
const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
|
2008-05-28 21:36:16 +00:00
|
|
|
ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : _current_news->prev);
|
2007-01-11 01:21:55 +00:00
|
|
|
} else if (_forced_news == _oldest_news) {
|
|
|
|
/* We have reached the oldest news, start anew with the latest */
|
|
|
|
ShowNewsMessage(_latest_news);
|
|
|
|
} else {
|
|
|
|
/* 'Scrolling' through news history show each one in turn */
|
2008-05-28 21:36:16 +00:00
|
|
|
ShowNewsMessage(_forced_news->prev);
|
2004-08-19 13:39:50 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/**
|
|
|
|
* Draw an unformatted news message truncated to a maximum length. If
|
2005-07-17 16:02:17 +00:00
|
|
|
* length exceeds maximum length it will be postfixed by '...'
|
2009-11-19 11:10:32 +00:00
|
|
|
* @param left the left most location for the string
|
|
|
|
* @param right the right most location for the string
|
|
|
|
* @param y position of the string
|
2009-02-09 02:09:47 +00:00
|
|
|
* @param colour the colour the string will be shown in
|
2005-07-17 16:02:17 +00:00
|
|
|
* @param *ni NewsItem being printed
|
|
|
|
* @param maxw maximum width of string in pixels
|
|
|
|
*/
|
2009-11-19 11:10:32 +00:00
|
|
|
static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-17 16:02:17 +00:00
|
|
|
char buffer[512], buffer2[512];
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-13 10:17:04 +00:00
|
|
|
CopyInDParam(0, ni->params, lengthof(ni->params));
|
|
|
|
str = ni->string_id;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, str, lastof(buffer));
|
2005-07-17 16:02:17 +00:00
|
|
|
/* Copy the just gotten string to another buffer to remove any formatting
|
|
|
|
* from it such as big fonts, etc. */
|
2008-03-28 16:45:20 +00:00
|
|
|
const char *ptr = buffer;
|
|
|
|
char *dest = buffer2;
|
2007-04-28 10:41:00 +00:00
|
|
|
WChar c_last = '\0';
|
2006-11-16 22:05:33 +00:00
|
|
|
for (;;) {
|
|
|
|
WChar c = Utf8Consume(&ptr);
|
|
|
|
if (c == 0) break;
|
2007-04-28 10:41:00 +00:00
|
|
|
/* Make a space from a newline, but ignore multiple newlines */
|
|
|
|
if (c == '\n' && c_last != '\n') {
|
|
|
|
dest[0] = ' ';
|
|
|
|
dest++;
|
|
|
|
} else if (c == '\r') {
|
2005-07-17 16:02:17 +00:00
|
|
|
dest[0] = dest[1] = dest[2] = dest[3] = ' ';
|
|
|
|
dest += 4;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (IsPrintable(c)) {
|
|
|
|
dest += Utf8Encode(dest, c);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-04-28 10:41:00 +00:00
|
|
|
c_last = c;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-17 16:02:17 +00:00
|
|
|
|
|
|
|
*dest = '\0';
|
|
|
|
/* Truncate and show string; postfixed by '...' if neccessary */
|
2009-11-19 11:10:32 +00:00
|
|
|
DrawString(left, right, y, buffer2, colour);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-31 20:18:47 +00:00
|
|
|
/** Widget numbers of the message history window. */
|
|
|
|
enum MessageHistoryWidgets {
|
|
|
|
MHW_STICKYBOX,
|
|
|
|
MHW_BACKGROUND,
|
|
|
|
MHW_SCROLLBAR,
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:50:51 +00:00
|
|
|
struct MessageHistoryWindow : Window {
|
2009-08-08 20:06:38 +00:00
|
|
|
static const int top_spacing; ///< Additional spacing at the top of the #MHW_BACKGROUND widget.
|
|
|
|
static const int bottom_spacing; ///< Additional spacing at the bottom of the #MHW_BACKGROUND widget.
|
|
|
|
|
|
|
|
int line_height; /// < Height of a single line in the news histoy window including spacing.
|
|
|
|
int date_width; /// < Width needed for the date part.
|
|
|
|
|
2010-08-12 08:37:01 +00:00
|
|
|
Scrollbar *vscroll;
|
|
|
|
|
2009-08-08 20:06:38 +00:00
|
|
|
MessageHistoryWindow(const WindowDesc *desc) : Window()
|
2008-05-18 08:50:51 +00:00
|
|
|
{
|
2010-08-12 08:37:01 +00:00
|
|
|
this->CreateNestedTree(desc);
|
|
|
|
this->vscroll = this->GetScrollbar(MHW_SCROLLBAR);
|
|
|
|
this->FinishInitNested(desc); // Initializes 'this->line_height' and 'this->date_width'.
|
2009-08-08 20:39:45 +00:00
|
|
|
this->OnInvalidateData(0);
|
2009-08-08 20:06:38 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-08-08 20:06:38 +00:00
|
|
|
{
|
|
|
|
if (widget == MHW_BACKGROUND) {
|
|
|
|
this->line_height = FONT_HEIGHT_NORMAL + 2;
|
|
|
|
resize->height = this->line_height;
|
|
|
|
|
2009-11-19 11:10:32 +00:00
|
|
|
SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 12, 30));
|
2009-08-08 20:06:38 +00:00
|
|
|
this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width;
|
|
|
|
|
|
|
|
size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing; // At least 4 lines are visible.
|
|
|
|
size->width = max(200u, size->width); // At least 200 pixels wide.
|
|
|
|
}
|
2008-05-18 08:50:51 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:50:51 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2009-08-08 20:39:45 +00:00
|
|
|
this->OnInvalidateData(0);
|
2008-05-18 08:50:51 +00:00
|
|
|
this->DrawWidgets();
|
2009-08-08 20:06:38 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-08-08 20:06:38 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (widget != MHW_BACKGROUND || _total_news == 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-08-08 20:06:38 +00:00
|
|
|
/* Find the first news item to display. */
|
2008-05-28 21:36:16 +00:00
|
|
|
NewsItem *ni = _latest_news;
|
2010-08-12 08:37:01 +00:00
|
|
|
for (int n = this->vscroll->GetPosition(); n > 0; n--) {
|
2008-05-28 21:36:16 +00:00
|
|
|
ni = ni->prev;
|
|
|
|
if (ni == NULL) return;
|
|
|
|
}
|
2008-05-18 08:50:51 +00:00
|
|
|
|
2009-08-08 20:06:38 +00:00
|
|
|
/* Fill the widget with news items. */
|
|
|
|
int y = r.top + this->top_spacing;
|
2010-11-13 09:56:25 +00:00
|
|
|
bool rtl = _current_text_dir == TD_RTL;
|
2009-11-19 11:10:32 +00:00
|
|
|
uint date_left = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width : r.left + WD_FRAMERECT_LEFT;
|
|
|
|
uint date_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->date_width;
|
|
|
|
uint news_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->date_width + WD_FRAMERECT_RIGHT;
|
|
|
|
uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT : r.right - WD_FRAMERECT_RIGHT;
|
2010-08-12 08:37:01 +00:00
|
|
|
for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
|
2008-05-18 08:50:51 +00:00
|
|
|
SetDParam(0, ni->date);
|
2009-11-19 11:10:32 +00:00
|
|
|
DrawString(date_left, date_right, y, STR_SHORT_DATE);
|
2008-05-18 08:50:51 +00:00
|
|
|
|
2009-11-19 11:10:32 +00:00
|
|
|
DrawNewsString(news_left, news_right, y, TC_WHITE, ni);
|
2009-08-08 20:06:38 +00:00
|
|
|
y += this->line_height;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
ni = ni->prev;
|
|
|
|
if (ni == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 08:50:51 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @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)
|
2009-08-08 20:06:38 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->SetCount(_total_news);
|
2009-08-08 20:06:38 +00:00
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-18 08:50:51 +00:00
|
|
|
{
|
2009-05-31 20:18:47 +00:00
|
|
|
if (widget == MHW_BACKGROUND) {
|
2008-05-28 21:36:16 +00:00
|
|
|
NewsItem *ni = _latest_news;
|
|
|
|
if (ni == NULL) return;
|
|
|
|
|
2010-08-12 08:37:01 +00:00
|
|
|
for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, MHW_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
|
2008-05-28 21:36:16 +00:00
|
|
|
ni = ni->prev;
|
|
|
|
if (ni == NULL) return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
ShowNewsMessage(ni);
|
2008-05-18 08:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-22 23:13:20 +00:00
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2008-05-18 08:50:51 +00:00
|
|
|
{
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->SetCapacity(this->GetWidget<NWidgetBase>(MHW_BACKGROUND)->current_y / this->line_height);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 08:50:51 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-08-08 20:06:38 +00:00
|
|
|
const int MessageHistoryWindow::top_spacing = WD_FRAMERECT_TOP + 4;
|
|
|
|
const int MessageHistoryWindow::bottom_spacing = WD_FRAMERECT_BOTTOM;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-22 21:16:57 +00:00
|
|
|
static const NWidgetPart _nested_message_history[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MESSAGE_HISTORY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2010-08-12 06:44:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, MHW_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(MHW_SCROLLBAR),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2010-08-12 09:16:43 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, MHW_SCROLLBAR),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _message_history_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_AUTO, 400, 140,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_MESSAGE_HISTORY, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_message_history, lengthof(_nested_message_history)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** Display window with news messages history */
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowMessageHistory()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_MESSAGE_HISTORY, 0);
|
2008-05-18 08:50:51 +00:00
|
|
|
new MessageHistoryWindow(&_message_history_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-14 22:01:44 +00:00
|
|
|
/** Constants in the message options window. */
|
|
|
|
enum MessageOptionsSpace {
|
|
|
|
MOS_WIDG_PER_SETTING = 4, ///< Number of widgets needed for each news category, starting at widget #WIDGET_NEWSOPT_START_OPTION.
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2009-08-14 22:01:44 +00:00
|
|
|
MOS_LEFT_EDGE = 6, ///< Number of pixels between left edge of the window and the options buttons column.
|
|
|
|
MOS_COLUMN_SPACING = 4, ///< Number of pixels between the buttons and the description columns.
|
|
|
|
MOS_RIGHT_EDGE = 6, ///< Number of pixels between right edge of the window and the options descriptions column.
|
|
|
|
MOS_BUTTON_SPACE = 10, ///< Additional space in the button with the option value (for better looks).
|
|
|
|
|
|
|
|
MOS_ABOVE_GLOBAL_SETTINGS = 6, ///< Number of vertical pixels between the categories and the global options.
|
|
|
|
MOS_BOTTOM_EDGE = 6, ///< Number of pixels between bottom edge of the window and bottom of the global options.
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Message options widget numbers. */
|
|
|
|
enum MessageOptionWidgets {
|
2009-05-02 16:52:21 +00:00
|
|
|
WIDGET_NEWSOPT_BACKGROUND, ///< Background widget.
|
|
|
|
WIDGET_NEWSOPT_LABEL, ///< Top label.
|
|
|
|
WIDGET_NEWSOPT_DROP_SUMMARY, ///< Dropdown that adjusts at once the level for all settings.
|
|
|
|
WIDGET_NEWSOPT_LABEL_SUMMARY, ///< Label of the summary drop down.
|
|
|
|
WIDGET_NEWSOPT_SOUNDTICKER, ///< Button for (de)activating sound on events.
|
|
|
|
WIDGET_NEWSOPT_SOUNDTICKER_LABEL, ///< Label of the soundticker button,
|
|
|
|
|
2009-08-14 22:01:44 +00:00
|
|
|
WIDGET_NEWSOPT_START_OPTION, ///< First widget that is part of a group [<][label][>] [description]
|
|
|
|
WIDGET_NEWSOPT_END_OPTION = WIDGET_NEWSOPT_START_OPTION + NT_END * MOS_WIDG_PER_SETTING, ///< First widget after the groups.
|
2007-03-10 03:33:43 +00:00
|
|
|
};
|
|
|
|
|
2008-05-16 07:15:32 +00:00
|
|
|
struct MessageOptionsWindow : Window {
|
2009-08-14 19:02:20 +00:00
|
|
|
static const StringID message_opt[]; ///< Message report options, 'off', 'summary', or 'full'.
|
2009-11-29 21:17:37 +00:00
|
|
|
int state; ///< Option value for setting all categories at once.
|
|
|
|
Dimension dim_message_opt; ///< Amount of space needed for a label such that all labels will fit.
|
2005-04-13 23:03:31 +00:00
|
|
|
|
2009-08-14 22:01:44 +00:00
|
|
|
MessageOptionsWindow(const WindowDesc *desc) : Window()
|
2008-05-16 07:15:32 +00:00
|
|
|
{
|
2009-08-14 22:01:44 +00:00
|
|
|
this->InitNested(desc);
|
2008-05-16 07:15:32 +00:00
|
|
|
/* Set up the initial disabled buttons in the case of 'off' or 'full' */
|
2009-08-14 22:01:44 +00:00
|
|
|
NewsDisplay all_val = _news_type_data[0].display;
|
2008-05-16 07:15:32 +00:00
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
this->SetMessageButtonStates(_news_type_data[i].display, i);
|
|
|
|
/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
|
|
|
|
if (_news_type_data[i].display != all_val) all_val = ND_OFF;
|
2008-05-05 11:24:58 +00:00
|
|
|
}
|
2008-05-16 07:15:32 +00:00
|
|
|
/* If all values are the same value, the ALL-button will take over this value */
|
|
|
|
this->state = all_val;
|
2009-08-14 21:33:30 +00:00
|
|
|
this->OnInvalidateData(0);
|
2008-05-16 07:15:32 +00:00
|
|
|
}
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2008-05-16 07:15:32 +00:00
|
|
|
/**
|
|
|
|
* Setup the disabled/enabled buttons in the message window
|
|
|
|
* If the value is 'off' disable the [<] widget, and enable the [>] one
|
|
|
|
* Same-wise for all the others. Starting value of 4 is the first widget
|
|
|
|
* group. These are grouped as [<][>] .. [<][>], etc.
|
|
|
|
* @param value to set in the widget
|
|
|
|
* @param element index of the group of widget to set
|
|
|
|
*/
|
|
|
|
void SetMessageButtonStates(byte value, int element)
|
|
|
|
{
|
2009-08-14 22:01:44 +00:00
|
|
|
element *= MOS_WIDG_PER_SETTING;
|
2008-01-17 20:00:13 +00:00
|
|
|
|
2008-05-16 07:15:32 +00:00
|
|
|
this->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION, value == 0);
|
|
|
|
this->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION + 2, value == 2);
|
|
|
|
}
|
2005-04-13 23:03:31 +00:00
|
|
|
|
2009-08-14 22:01:44 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (widget >= WIDGET_NEWSOPT_START_OPTION && widget < WIDGET_NEWSOPT_END_OPTION && (widget - WIDGET_NEWSOPT_START_OPTION) % MOS_WIDG_PER_SETTING == 1) {
|
|
|
|
/* Draw the string of each setting on each button. */
|
|
|
|
int i = (widget - WIDGET_NEWSOPT_START_OPTION) / MOS_WIDG_PER_SETTING;
|
2010-07-02 13:53:05 +00:00
|
|
|
DrawString(r.left, r.right, r.top + 2, this->message_opt[_news_type_data[i].display], TC_BLACK, SA_HOR_CENTER);
|
2009-08-14 22:01:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-29 21:17:37 +00:00
|
|
|
virtual void OnInit()
|
|
|
|
{
|
2009-11-29 21:40:51 +00:00
|
|
|
this->dim_message_opt.width = 0;
|
|
|
|
this->dim_message_opt.height = 0;
|
2009-11-29 21:17:37 +00:00
|
|
|
for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) this->dim_message_opt = maxdim(this->dim_message_opt, GetStringBoundingBox(*str));
|
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-08-14 22:01:44 +00:00
|
|
|
{
|
|
|
|
if (widget >= WIDGET_NEWSOPT_START_OPTION && widget < WIDGET_NEWSOPT_END_OPTION) {
|
|
|
|
/* Height is the biggest widget height in a row. */
|
|
|
|
size->height = FONT_HEIGHT_NORMAL + max(WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
|
|
|
|
|
|
|
|
/* Compute width for the label widget only. */
|
|
|
|
if ((widget - WIDGET_NEWSOPT_START_OPTION) % MOS_WIDG_PER_SETTING == 1) {
|
2009-11-29 21:17:37 +00:00
|
|
|
size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
|
2009-08-14 22:01:44 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Size computations for global message options. */
|
|
|
|
if (widget == WIDGET_NEWSOPT_DROP_SUMMARY || widget == WIDGET_NEWSOPT_LABEL_SUMMARY || widget == WIDGET_NEWSOPT_SOUNDTICKER || widget == WIDGET_NEWSOPT_SOUNDTICKER_LABEL) {
|
|
|
|
/* Height is the biggest widget height in a row. */
|
|
|
|
size->height = FONT_HEIGHT_NORMAL + max(WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM);
|
|
|
|
|
|
|
|
if (widget == WIDGET_NEWSOPT_DROP_SUMMARY) {
|
2009-11-29 21:17:37 +00:00
|
|
|
size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
|
2009-08-20 10:23:39 +00:00
|
|
|
} else if (widget == WIDGET_NEWSOPT_SOUNDTICKER) {
|
2009-08-14 22:01:44 +00:00
|
|
|
size->width += MOS_BUTTON_SPACE; // A bit extra for better looks.
|
|
|
|
}
|
|
|
|
return;
|
2008-05-16 07:15:32 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @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)
|
2009-08-14 21:33:30 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2009-08-14 21:33:30 +00:00
|
|
|
/* Update the dropdown value for 'set all categories'. */
|
2009-09-19 11:31:12 +00:00
|
|
|
this->GetWidget<NWidgetCore>(WIDGET_NEWSOPT_DROP_SUMMARY)->widget_data = this->message_opt[this->state];
|
2009-08-14 22:01:44 +00:00
|
|
|
|
2009-08-14 21:33:30 +00:00
|
|
|
/* Update widget to reflect the value of the #_news_ticker_sound variable. */
|
|
|
|
this->SetWidgetLoweredState(WIDGET_NEWSOPT_SOUNDTICKER, _news_ticker_sound);
|
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-16 07:15:32 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WIDGET_NEWSOPT_DROP_SUMMARY: // Dropdown menu for all settings
|
2009-08-14 19:02:20 +00:00
|
|
|
ShowDropDownMenu(this, this->message_opt, this->state, WIDGET_NEWSOPT_DROP_SUMMARY, 0, 0);
|
2008-05-16 07:15:32 +00:00
|
|
|
break;
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2008-05-16 07:15:32 +00:00
|
|
|
case WIDGET_NEWSOPT_SOUNDTICKER: // Change ticker sound on/off
|
|
|
|
_news_ticker_sound ^= 1;
|
2009-09-30 21:07:54 +00:00
|
|
|
this->InvalidateData();
|
2008-05-16 07:15:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: { // Clicked on the [<] .. [>] widgets
|
2009-08-14 22:01:44 +00:00
|
|
|
if (widget >= WIDGET_NEWSOPT_START_OPTION && widget < WIDGET_NEWSOPT_END_OPTION) {
|
|
|
|
int wid = widget - WIDGET_NEWSOPT_START_OPTION;
|
|
|
|
int element = wid / MOS_WIDG_PER_SETTING;
|
|
|
|
byte val = (_news_type_data[element].display + ((wid % MOS_WIDG_PER_SETTING) ? 1 : -1)) % 3;
|
2008-05-16 07:15:32 +00:00
|
|
|
|
|
|
|
this->SetMessageButtonStates(val, element);
|
|
|
|
_news_type_data[element].display = (NewsDisplay)val;
|
|
|
|
this->SetDirty();
|
2008-05-05 11:24:58 +00:00
|
|
|
}
|
2008-05-16 07:15:32 +00:00
|
|
|
break;
|
2008-03-28 16:45:20 +00:00
|
|
|
}
|
2008-05-16 07:15:32 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2008-05-16 07:15:32 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
|
|
|
this->state = index;
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2008-05-16 07:15:32 +00:00
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
this->SetMessageButtonStates(index, i);
|
|
|
|
_news_type_data[i].display = (NewsDisplay)index;
|
|
|
|
}
|
2009-09-30 21:07:54 +00:00
|
|
|
this->InvalidateData();
|
2004-08-20 13:58:25 +00:00
|
|
|
}
|
2008-05-16 07:15:32 +00:00
|
|
|
};
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2009-08-14 19:02:20 +00:00
|
|
|
const StringID MessageOptionsWindow::message_opt[] = {STR_NEWS_MESSAGES_OFF, STR_NEWS_MESSAGES_SUMMARY, STR_NEWS_MESSAGES_FULL, INVALID_STRING_ID};
|
2007-11-15 22:20:33 +00:00
|
|
|
|
2009-08-14 21:21:56 +00:00
|
|
|
/** Make a column with the buttons for changing each news category setting, and the global settings. */
|
|
|
|
static NWidgetBase *MakeButtonsColumn(int *biggest_index)
|
2009-05-02 17:00:56 +00:00
|
|
|
{
|
2009-08-14 21:21:56 +00:00
|
|
|
NWidgetVertical *vert_buttons = new NWidgetVertical;
|
2009-05-02 17:00:56 +00:00
|
|
|
|
2009-08-14 21:21:56 +00:00
|
|
|
/* Top-part of the column, one row for each new category. */
|
2009-05-02 17:00:56 +00:00
|
|
|
int widnum = WIDGET_NEWSOPT_START_OPTION;
|
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
NWidgetHorizontal *hor = new NWidgetHorizontal;
|
|
|
|
/* [<] button. */
|
2010-08-12 16:44:51 +00:00
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum, AWV_DECREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
|
2009-11-22 18:26:01 +00:00
|
|
|
leaf->SetFill(1, 1);
|
2009-05-02 17:00:56 +00:00
|
|
|
hor->Add(leaf);
|
|
|
|
/* Label. */
|
2009-08-14 21:21:56 +00:00
|
|
|
leaf = new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_YELLOW, widnum + 1, STR_EMPTY, STR_NULL);
|
2009-11-22 18:26:01 +00:00
|
|
|
leaf->SetFill(1, 1);
|
2009-05-02 17:00:56 +00:00
|
|
|
hor->Add(leaf);
|
|
|
|
/* [>] button. */
|
2010-08-12 16:44:51 +00:00
|
|
|
leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum + 2, AWV_INCREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
|
2009-11-22 18:26:01 +00:00
|
|
|
leaf->SetFill(1, 1);
|
2009-05-02 17:00:56 +00:00
|
|
|
hor->Add(leaf);
|
2009-08-14 21:21:56 +00:00
|
|
|
vert_buttons->Add(hor);
|
|
|
|
|
2009-08-14 22:01:44 +00:00
|
|
|
widnum += MOS_WIDG_PER_SETTING;
|
2009-08-14 21:21:56 +00:00
|
|
|
}
|
2009-08-14 22:01:44 +00:00
|
|
|
*biggest_index = widnum - MOS_WIDG_PER_SETTING + 2;
|
2009-08-14 21:21:56 +00:00
|
|
|
|
|
|
|
/* Space between the category buttons and the global settings buttons. */
|
2009-08-14 22:01:44 +00:00
|
|
|
NWidgetSpacer *spacer = new NWidgetSpacer(0, MOS_ABOVE_GLOBAL_SETTINGS);
|
2009-08-14 21:21:56 +00:00
|
|
|
vert_buttons->Add(spacer);
|
|
|
|
|
|
|
|
/* Bottom part of the column with buttons for global changes. */
|
2009-08-14 22:01:44 +00:00
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_DROPDOWN, COLOUR_YELLOW, WIDGET_NEWSOPT_DROP_SUMMARY, STR_EMPTY, STR_NULL);
|
2009-11-22 18:26:01 +00:00
|
|
|
leaf->SetFill(1, 1);
|
2009-08-14 21:21:56 +00:00
|
|
|
vert_buttons->Add(leaf);
|
|
|
|
|
|
|
|
leaf = new NWidgetLeaf(WWT_TEXTBTN_2, COLOUR_YELLOW, WIDGET_NEWSOPT_SOUNDTICKER, STR_STATION_BUILD_COVERAGE_OFF, STR_NULL);
|
2009-11-22 18:26:01 +00:00
|
|
|
leaf->SetFill(1, 1);
|
2009-08-14 21:21:56 +00:00
|
|
|
vert_buttons->Add(leaf);
|
|
|
|
|
|
|
|
*biggest_index = max(*biggest_index, max<int>(WIDGET_NEWSOPT_DROP_SUMMARY, WIDGET_NEWSOPT_SOUNDTICKER));
|
|
|
|
return vert_buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Make a column with descriptions for each news category and the global settings. */
|
|
|
|
static NWidgetBase *MakeDescriptionColumn(int *biggest_index)
|
|
|
|
{
|
|
|
|
NWidgetVertical *vert_desc = new NWidgetVertical;
|
|
|
|
|
|
|
|
/* Top-part of the column, one row for each new category. */
|
|
|
|
int widnum = WIDGET_NEWSOPT_START_OPTION;
|
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
NWidgetHorizontal *hor = new NWidgetHorizontal;
|
|
|
|
|
2009-05-02 17:00:56 +00:00
|
|
|
/* Descriptive text. */
|
2009-08-14 21:21:56 +00:00
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, widnum + 3, _news_type_data[i].description, STR_NULL);
|
2009-05-02 17:00:56 +00:00
|
|
|
hor->Add(leaf);
|
2009-08-14 21:21:56 +00:00
|
|
|
/* Filling empty space to push text to the left. */
|
|
|
|
NWidgetSpacer *spacer = new NWidgetSpacer(0, 0);
|
2009-11-22 18:26:01 +00:00
|
|
|
spacer->SetFill(1, 0);
|
2009-08-14 21:21:56 +00:00
|
|
|
hor->Add(spacer);
|
|
|
|
vert_desc->Add(hor);
|
2009-05-02 17:00:56 +00:00
|
|
|
|
2009-08-14 22:01:44 +00:00
|
|
|
widnum += MOS_WIDG_PER_SETTING;
|
2009-05-02 17:00:56 +00:00
|
|
|
}
|
2009-08-14 22:01:44 +00:00
|
|
|
*biggest_index = widnum - MOS_WIDG_PER_SETTING + 3;
|
2009-08-14 21:21:56 +00:00
|
|
|
|
|
|
|
/* Space between the category descriptions and the global settings descriptions. */
|
2009-08-14 22:01:44 +00:00
|
|
|
NWidgetSpacer *spacer = new NWidgetSpacer(0, MOS_ABOVE_GLOBAL_SETTINGS);
|
2009-08-14 21:21:56 +00:00
|
|
|
vert_desc->Add(spacer);
|
|
|
|
|
|
|
|
/* Bottom part of the column with descriptions of global changes. */
|
|
|
|
NWidgetHorizontal *hor = new NWidgetHorizontal;
|
|
|
|
NWidgetLeaf *leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, WIDGET_NEWSOPT_LABEL_SUMMARY, STR_NEWS_MESSAGES_ALL, STR_NULL);
|
|
|
|
hor->Add(leaf);
|
|
|
|
/* Filling empty space to push text to the left. */
|
|
|
|
spacer = new NWidgetSpacer(0, 0);
|
2009-11-22 18:26:01 +00:00
|
|
|
spacer->SetFill(1, 0);
|
2009-08-14 21:21:56 +00:00
|
|
|
hor->Add(spacer);
|
|
|
|
vert_desc->Add(hor);
|
|
|
|
|
|
|
|
hor = new NWidgetHorizontal;
|
|
|
|
leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, WIDGET_NEWSOPT_SOUNDTICKER_LABEL, STR_NEWS_MESSAGES_SOUND, STR_NULL);
|
|
|
|
hor->Add(leaf);
|
|
|
|
/* Filling empty space to push text to the left. */
|
|
|
|
spacer = new NWidgetSpacer(0, 0);
|
2009-11-22 18:26:01 +00:00
|
|
|
leaf->SetFill(1, 0);
|
2009-08-14 21:21:56 +00:00
|
|
|
hor->Add(spacer);
|
|
|
|
vert_desc->Add(hor);
|
|
|
|
|
|
|
|
*biggest_index = max(*biggest_index, max<int>(WIDGET_NEWSOPT_LABEL_SUMMARY, WIDGET_NEWSOPT_SOUNDTICKER_LABEL));
|
|
|
|
return vert_desc;
|
2009-05-02 17:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const NWidgetPart _nested_message_options_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_NEWS_MESSAGE_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-05-02 17:00:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, WIDGET_NEWSOPT_BACKGROUND),
|
2009-08-14 21:21:56 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-08-14 22:01:44 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_BROWN, WIDGET_NEWSOPT_LABEL), SetMinimalSize(0, 14), SetDataTip(STR_NEWS_MESSAGE_TYPES, STR_NULL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-08-14 22:01:44 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(MOS_LEFT_EDGE, 0),
|
2009-08-14 21:21:56 +00:00
|
|
|
NWidgetFunction(MakeButtonsColumn),
|
2009-08-14 22:01:44 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(MOS_COLUMN_SPACING, 0),
|
2009-08-14 21:21:56 +00:00
|
|
|
NWidgetFunction(MakeDescriptionColumn),
|
2009-08-14 22:01:44 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(MOS_RIGHT_EDGE, 0),
|
2009-05-02 17:00:56 +00:00
|
|
|
EndContainer(),
|
2009-08-14 22:01:44 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, MOS_BOTTOM_EDGE),
|
2009-05-02 17:00:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _message_options_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_AUTO, 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_message_options_widgets, lengthof(_nested_message_options_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2011-05-02 16:14:23 +00:00
|
|
|
/**
|
|
|
|
* Show the settings window for news messages.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowMessageOptions()
|
2004-08-20 13:58:25 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
2008-05-16 07:15:32 +00:00
|
|
|
new MessageOptionsWindow(&_message_options_desc);
|
2004-08-20 13:58:25 +00:00
|
|
|
}
|