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"
|
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"
|
2019-07-22 20:16:41 +00:00
|
|
|
#include "roadveh.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"
|
2011-12-19 21:01:03 +00:00
|
|
|
#include "command_func.h"
|
|
|
|
#include "company_base.h"
|
2012-12-23 21:07:12 +00:00
|
|
|
#include "settings_internal.h"
|
2018-05-20 08:58:36 +00:00
|
|
|
#include "guitimer_func.h"
|
2019-07-22 20:16:41 +00:00
|
|
|
#include "group_gui.h"
|
2021-02-13 21:18:03 +00:00
|
|
|
#include "zoom_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/news_widget.h"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
const NewsItem *_statusbar_news_item = nullptr;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
2019-04-25 21:55:16 +00:00
|
|
|
static uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages
|
2020-02-16 22:03:12 +00:00
|
|
|
static uint MAX_NEWS_AMOUNT = 1 << 10; ///< Do not exceed this number of news messages
|
2019-04-25 21:55:16 +00:00
|
|
|
static uint _total_news = 0; ///< current number of news items
|
|
|
|
static NewsItem *_oldest_news = nullptr; ///< head of news items queue
|
|
|
|
NewsItem *_latest_news = nullptr; ///< 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
|
2019-04-10 21:07:06 +00:00
|
|
|
* in _forced_news. Otherwise, \a _forced_news variable is nullptr.
|
2010-08-01 19:44:49 +00:00
|
|
|
*/
|
2019-04-25 21:55:16 +00:00
|
|
|
static const NewsItem *_forced_news = nullptr;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
/** Current news item (last item shown regularly). */
|
2019-04-10 21:07:06 +00:00
|
|
|
static const NewsItem *_current_news = nullptr;
|
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:39:40 +00:00
|
|
|
/* Normal news items. */
|
2009-09-02 20:21:30 +00:00
|
|
|
static const NWidgetPart _nested_normal_news_widgets[] = {
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
|
2009-09-02 20:52:58 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
2014-10-05 21:18:37 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), 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),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_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(),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 154), SetPadding(0, 5, 1, 5),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _normal_news_desc(
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_MANUAL, nullptr, 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[] = {
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
|
2009-09-02 20:55:55 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2014-10-05 21:18:37 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), 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(),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL),
|
2009-09-02 20:55:55 +00:00
|
|
|
EndContainer(),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_VEH_BKGND), SetPadding(0, 25, 1, 25),
|
2009-09-02 20:55:55 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_NAME), SetMinimalSize(369, 33), SetFill(1, 0),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_SPR), SetMinimalSize(369, 32), SetFill(1, 0),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_VEH_INFO), SetMinimalSize(369, 46), SetFill(1, 0),
|
2009-09-02 20:55:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _vehicle_news_desc(
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_MANUAL, nullptr, 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[] = {
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
|
2009-09-02 20:54:27 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2014-10-05 21:18:37 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), 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(),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_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),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_FACE), SetMinimalSize(93, 119), SetPadding(2, 6, 2, 1),
|
2014-10-04 18:13:10 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MGR_NAME), SetMinimalSize(93, 24), 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(),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_COMPANY_MSG), SetFill(1, 1), SetMinimalSize(328, 150),
|
2009-09-02 20:54:27 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _company_news_desc(
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_MANUAL, nullptr, 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[] = {
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL),
|
2009-09-02 20:52:58 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1),
|
2014-10-05 21:18:37 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_WHITE, WID_N_CLOSEBOX), 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),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_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(),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(428, 48), SetFill(1, 0), SetPadding(0, 5, 0, 5),
|
|
|
|
NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(426, 70), SetPadding(1, 2, 2, 2),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _thin_news_desc(
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_MANUAL, nullptr, 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),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
|
|
|
|
NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_N_CAPTION), SetFill(1, 0),
|
2019-07-22 20:16:41 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP), SetMinimalSize(14, 11), SetResize(1, 0),
|
|
|
|
SetDataTip(STR_NULL /* filled in later */, STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
|
|
|
|
/* Main part */
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
|
|
|
|
NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
|
2021-05-08 20:01:16 +00:00
|
|
|
NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(274, 47), SetFill(1, 0),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
|
2009-09-02 20:21:30 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _small_news_desc(
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_MANUAL, nullptr, 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
|
|
|
/**
|
2012-05-26 14:16:03 +00:00
|
|
|
* Window layouts for news items.
|
2008-05-15 13:39:36 +00:00
|
|
|
*/
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc* _news_window_layout[] = {
|
2012-05-26 14:16:03 +00:00
|
|
|
&_thin_news_desc, ///< NF_THIN
|
|
|
|
&_small_news_desc, ///< NF_SMALL
|
|
|
|
&_normal_news_desc, ///< NF_NORMAL
|
|
|
|
&_vehicle_news_desc, ///< NF_VEHICLE
|
|
|
|
&_company_news_desc, ///< NF_COMPANY
|
2008-05-15 13:39:36 +00:00
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
WindowDesc* GetNewsWindowLayout(NewsFlag flags)
|
2012-05-26 14:16:03 +00:00
|
|
|
{
|
|
|
|
uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT);
|
|
|
|
assert(layout < lengthof(_news_window_layout));
|
|
|
|
return _news_window_layout[layout];
|
|
|
|
}
|
2009-03-23 11:48:05 +00:00
|
|
|
|
2008-05-28 20:13:28 +00:00
|
|
|
/**
|
|
|
|
* Per-NewsType data
|
|
|
|
*/
|
2012-12-23 21:07:12 +00:00
|
|
|
static NewsTypeData _news_type_data[] = {
|
|
|
|
/* name, age, sound, */
|
|
|
|
NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_COMPANY
|
|
|
|
NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ), ///< NT_ARRIVAL_OTHER
|
|
|
|
NewsTypeData("news_display.accident", 90, SND_BEGIN ), ///< NT_ACCIDENT
|
2021-11-07 18:54:50 +00:00
|
|
|
NewsTypeData("news_display.accident_other", 90, SND_BEGIN ), ///< NT_ACCIDENT_OTHER
|
2012-12-23 21:07:12 +00:00
|
|
|
NewsTypeData("news_display.company_info", 60, SND_BEGIN ), ///< NT_COMPANY_INFO
|
|
|
|
NewsTypeData("news_display.open", 90, SND_BEGIN ), ///< NT_INDUSTRY_OPEN
|
|
|
|
NewsTypeData("news_display.close", 90, SND_BEGIN ), ///< NT_INDUSTRY_CLOSE
|
|
|
|
NewsTypeData("news_display.economy", 30, SND_BEGIN ), ///< NT_ECONOMY
|
|
|
|
NewsTypeData("news_display.production_player", 30, SND_BEGIN ), ///< NT_INDUSTRY_COMPANY
|
|
|
|
NewsTypeData("news_display.production_other", 30, SND_BEGIN ), ///< NT_INDUSTRY_OTHER
|
|
|
|
NewsTypeData("news_display.production_nobody", 30, SND_BEGIN ), ///< NT_INDUSTRY_NOBODY
|
|
|
|
NewsTypeData("news_display.advice", 150, SND_BEGIN ), ///< NT_ADVICE
|
2021-02-20 18:01:04 +00:00
|
|
|
NewsTypeData("news_display.new_vehicles", 30, SND_1E_NEW_ENGINE), ///< NT_NEW_VEHICLES
|
2012-12-23 21:07:12 +00:00
|
|
|
NewsTypeData("news_display.acceptance", 90, SND_BEGIN ), ///< NT_ACCEPTANCE
|
|
|
|
NewsTypeData("news_display.subsidies", 180, SND_BEGIN ), ///< NT_SUBSIDIES
|
|
|
|
NewsTypeData("news_display.general", 60, SND_BEGIN ), ///< NT_GENERAL
|
2008-05-28 20:13:28 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2020-12-27 10:44:22 +00:00
|
|
|
static_assert(lengthof(_news_type_data) == NT_END);
|
2009-03-23 11:48:05 +00:00
|
|
|
|
2012-12-23 21:07:12 +00:00
|
|
|
/**
|
|
|
|
* Return the news display option.
|
|
|
|
* @return display options
|
|
|
|
*/
|
|
|
|
NewsDisplay NewsTypeData::GetDisplay() const
|
|
|
|
{
|
2021-05-18 18:57:44 +00:00
|
|
|
const SettingDesc *sd = GetSettingFromName(this->name);
|
2021-05-31 08:56:06 +00:00
|
|
|
assert(sd != nullptr && sd->IsIntSetting());
|
|
|
|
return (NewsDisplay)sd->AsIntSetting()->Read(nullptr);
|
2012-12-23 21:07:12 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2018-05-04 20:29:22 +00:00
|
|
|
static int duration; ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
|
|
|
|
|
2018-05-20 08:58:36 +00:00
|
|
|
GUITimer timer;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
2018-05-04 20:29:22 +00:00
|
|
|
NewsWindow::duration = 16650;
|
2009-11-29 00:41:08 +00:00
|
|
|
const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
|
2019-04-10 21:07:06 +00:00
|
|
|
this->chat_height = (w != nullptr) ? 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
|
|
|
|
2011-12-15 19:54:23 +00:00
|
|
|
this->flags |= WF_DISABLE_VP_SCROLL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2018-05-20 08:58:36 +00:00
|
|
|
this->timer.SetInterval(15);
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
2009-09-02 20:54:27 +00:00
|
|
|
|
2012-05-26 14:15:41 +00:00
|
|
|
/* 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];
|
2009-09-02 20:54:27 +00:00
|
|
|
|
2019-07-22 20:16:41 +00:00
|
|
|
NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
|
|
|
|
if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) {
|
|
|
|
const Vehicle *v = Vehicle::Get(ni->ref1);
|
|
|
|
switch (v->type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
nwid->widget_data = STR_TRAIN;
|
|
|
|
break;
|
|
|
|
case VEH_ROAD:
|
|
|
|
nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY;
|
|
|
|
break;
|
|
|
|
case VEH_SHIP:
|
|
|
|
nwid->widget_data = STR_SHIP;
|
|
|
|
break;
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
nwid->widget_data = STR_PLANE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break; // Do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(0);
|
2009-08-16 16:06:06 +00:00
|
|
|
|
2009-09-02 20:52:58 +00:00
|
|
|
/* Initialize viewport if it exists. */
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_N_VIEWPORT);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (nvp != nullptr) {
|
2009-09-02 20:52:58 +00:00
|
|
|
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
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
|
2009-11-28 13:54:28 +00:00
|
|
|
{
|
2010-11-18 19:24:40 +00:00
|
|
|
Point pt = { 0, _screen.height };
|
2009-11-28 13:54:28 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
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) {
|
2017-03-31 23:09:50 +00:00
|
|
|
case WID_N_CAPTION: {
|
|
|
|
/* Caption is not a real caption (so that the window cannot be moved)
|
|
|
|
* thus it doesn't get the default sizing of a caption. */
|
|
|
|
Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION);
|
|
|
|
d2.height += WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM;
|
|
|
|
*size = maxdim(*size, d2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-04 18:13:10 +00:00
|
|
|
case WID_N_MGR_FACE:
|
|
|
|
*size = maxdim(*size, GetSpriteSize(SPR_GRADIENT));
|
|
|
|
break;
|
|
|
|
|
2019-04-23 19:39:41 +00:00
|
|
|
case WID_N_MGR_NAME:
|
2021-06-17 14:38:34 +00:00
|
|
|
SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data.get())->president_name);
|
2019-04-23 19:39:41 +00:00
|
|
|
str = STR_JUST_RAW_STRING;
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_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
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_COMPANY_MSG:
|
2009-09-02 20:54:27 +00:00
|
|
|
str = this->GetCompanyMessageString();
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VEH_NAME:
|
|
|
|
case WID_N_VEH_TITLE:
|
2009-09-02 20:55:55 +00:00
|
|
|
str = this->GetNewVehicleMessageString(widget);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VEH_INFO: {
|
2009-09-02 20:55:55 +00:00
|
|
|
assert(this->ni->reftype1 == NR_ENGINE);
|
|
|
|
EngineID engine = this->ni->ref1;
|
|
|
|
str = GetEngineInfoString(engine);
|
|
|
|
break;
|
|
|
|
}
|
2019-07-22 20:16:41 +00:00
|
|
|
|
|
|
|
case WID_N_SHOW_GROUP:
|
|
|
|
if (this->ni->reftype1 == NR_VEHICLE) {
|
|
|
|
Dimension d2 = GetStringBoundingBox(this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP)->widget_data);
|
|
|
|
d2.height += WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM;
|
|
|
|
d2.width += WD_CAPTIONTEXT_LEFT + WD_CAPTIONTEXT_RIGHT;
|
|
|
|
*size = d2;
|
|
|
|
} else {
|
|
|
|
/* Hide 'Show group window' button if this news is not about a vehicle. */
|
|
|
|
size->width = 0;
|
|
|
|
size->height = 0;
|
|
|
|
resize->width = 0;
|
|
|
|
resize->height = 0;
|
|
|
|
fill->width = 0;
|
|
|
|
fill->height = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void SetStringParameters(int widget) const override
|
2009-09-02 20:52:58 +00:00
|
|
|
{
|
2011-12-16 18:32:57 +00:00
|
|
|
if (widget == WID_N_DATE) SetDParam(0, this->ni->date);
|
2009-09-02 20:52:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void DrawWidget(const Rect &r, int widget) const override
|
2009-09-02 20:46:42 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_CAPTION:
|
2021-05-12 16:43:35 +00:00
|
|
|
DrawCaption(r, COLOUR_LIGHT_BLUE, this->owner, TC_FROMSTRING, STR_NEWS_MESSAGE_CAPTION, SA_CENTER);
|
2010-06-07 19:56:32 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_PANEL:
|
2009-09-02 20:52:58 +00:00
|
|
|
this->DrawNewsBorder(r);
|
2010-06-07 19:56:32 +00:00
|
|
|
break;
|
2009-09-02 20:52:58 +00:00
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_MESSAGE:
|
2009-09-02 20:46:42 +00:00
|
|
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
2011-12-13 18:27:04 +00:00
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
|
2009-09-02 20:46:42 +00:00
|
|
|
break;
|
2009-09-02 20:54:27 +00:00
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_MGR_FACE: {
|
2021-06-17 14:38:34 +00:00
|
|
|
const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
|
2009-09-02 20:54:27 +00:00
|
|
|
DrawCompanyManagerFace(cni->face, cni->colour, r.left, r.top);
|
2014-10-04 18:13:10 +00:00
|
|
|
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
|
2009-09-02 20:54:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_MGR_NAME: {
|
2021-06-17 14:38:34 +00:00
|
|
|
const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
|
2009-09-02 20:54:27 +00:00
|
|
|
SetDParamStr(0, cni->president_name);
|
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
|
|
|
}
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_COMPANY_MSG:
|
2009-09-02 20:54:27 +00:00
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetCompanyMessageString(), TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
2009-09-02 20:55:55 +00:00
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_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;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VEH_NAME:
|
|
|
|
case WID_N_VEH_TITLE:
|
2009-09-02 20:55:55 +00:00
|
|
|
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VEH_SPR: {
|
2009-09-02 20:55:55 +00:00
|
|
|
assert(this->ni->reftype1 == NR_ENGINE);
|
|
|
|
EngineID engine = this->ni->ref1;
|
2011-11-01 16:51:47 +00:00
|
|
|
DrawVehicleEngine(r.left, r.right, (r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
|
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;
|
|
|
|
}
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VEH_INFO: {
|
2009-09-02 20:55:55 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnClick(Point pt, int widget, int click_count) override
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_CLOSEBOX:
|
2008-05-30 20:57:19 +00:00
|
|
|
NewsWindow::duration = 0;
|
2021-05-15 21:12:25 +00:00
|
|
|
this->Close();
|
2019-04-10 21:07:06 +00:00
|
|
|
_forced_news = nullptr;
|
2008-05-15 13:47:55 +00:00
|
|
|
break;
|
2008-05-05 11:24:58 +00:00
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_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;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VIEWPORT:
|
2009-09-02 20:44:36 +00:00
|
|
|
break; // Ignore clicks
|
|
|
|
|
2019-07-22 20:16:41 +00:00
|
|
|
case WID_N_SHOW_GROUP:
|
|
|
|
if (this->ni->reftype1 == NR_VEHICLE) {
|
|
|
|
const Vehicle *v = Vehicle::Get(this->ni->ref1);
|
|
|
|
ShowCompanyGroupForVehicle(v);
|
|
|
|
}
|
|
|
|
break;
|
2009-09-02 20:44:36 +00:00
|
|
|
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) {
|
2020-06-29 01:38:29 +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
|
|
|
|
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.
|
|
|
|
*/
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
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
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnRealtimeTick(uint delta_ms) override
|
2008-05-15 13:47:55 +00:00
|
|
|
{
|
2018-05-20 08:58:36 +00:00
|
|
|
int count = this->timer.CountElapsed(delta_ms);
|
2018-05-04 20:29:22 +00:00
|
|
|
if (count > 0) {
|
|
|
|
/* Scroll up newsmessages from the bottom */
|
2021-01-08 10:16:18 +00:00
|
|
|
int newtop = std::max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
|
2018-05-04 20:29:22 +00:00
|
|
|
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;
|
2010-06-04 09:47:55 +00:00
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2010-06-04 09:47:55 +00:00
|
|
|
private:
|
|
|
|
/**
|
2018-10-28 02:17:36 +00:00
|
|
|
* Moves the window to a new #top coordinate. Makes screen dirty where needed.
|
2010-06-04 09:47:55 +00:00
|
|
|
* @param newtop new top coordinate
|
|
|
|
*/
|
|
|
|
void SetWindowTop(int newtop)
|
|
|
|
{
|
|
|
|
if (this->top == newtop) return;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2021-01-08 10:16:18 +00:00
|
|
|
int mintop = std::min(newtop, this->top);
|
|
|
|
int maxtop = std::max(newtop, this->top);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (this->viewport != nullptr) this->viewport->top += newtop - this->top;
|
2010-06-04 09:47:55 +00:00
|
|
|
this->top = newtop;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2020-06-07 22:38:06 +00:00
|
|
|
AddDirtyBlock(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
|
|
|
|
{
|
2012-05-26 14:15:41 +00:00
|
|
|
/* Company news with a face have a separate headline, so the normal message is shifted by two params */
|
|
|
|
CopyInDParam(0, this->ni->params + 2, lengthof(this->ni->params) - 2);
|
|
|
|
return this->ni->params[1];
|
2009-09-02 20:54:27 +00:00
|
|
|
}
|
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) {
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VEH_TITLE:
|
2009-09-02 20:55:55 +00:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
|
|
|
return STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE;
|
|
|
|
|
2011-12-16 18:32:57 +00:00
|
|
|
case WID_N_VEH_NAME:
|
2009-09-02 20:55:55 +00:00
|
|
|
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
|
|
|
|
2018-05-04 20:29:22 +00:00
|
|
|
/* static */ int NewsWindow::duration = 0; // Instance creation.
|
2008-05-30 20:57:19 +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
|
|
|
{
|
2012-05-26 14:16:03 +00:00
|
|
|
SoundFx sound = _news_type_data[ni->type].sound;
|
2012-12-23 21:09:09 +00:00
|
|
|
if (sound != 0 && _settings_client.sound.news_full) SndPlayFx(sound);
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2012-05-26 14:16:03 +00:00
|
|
|
new NewsWindow(GetNewsWindowLayout(ni->flags), 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
|
|
|
{
|
2021-02-20 18:01:04 +00:00
|
|
|
if (_settings_client.sound.news_ticker) SndPlayFx(SND_16_NEWS_TICKER);
|
2005-04-13 23:03:31 +00:00
|
|
|
|
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()
|
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
for (NewsItem *ni = _oldest_news; ni != nullptr; ) {
|
2008-05-28 21:36:16 +00:00
|
|
|
NewsItem *next = ni->next;
|
|
|
|
delete ni;
|
|
|
|
ni = next;
|
|
|
|
}
|
|
|
|
|
2008-05-28 20:13:28 +00:00
|
|
|
_total_news = 0;
|
2019-04-10 21:07:06 +00:00
|
|
|
_oldest_news = nullptr;
|
|
|
|
_latest_news = nullptr;
|
|
|
|
_forced_news = nullptr;
|
|
|
|
_current_news = nullptr;
|
|
|
|
_statusbar_news_item = nullptr;
|
2009-08-16 08:59:56 +00:00
|
|
|
NewsWindow::duration = 0;
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-29 22:11:20 +00:00
|
|
|
* Are we ready to show another ticker item?
|
|
|
|
* Only if nothing is in the newsticker is displayed
|
2008-05-28 20:13:28 +00:00
|
|
|
*/
|
2019-05-29 22:11:20 +00:00
|
|
|
static bool ReadyForNextTickerItem()
|
2008-05-28 20:13:28 +00:00
|
|
|
{
|
2019-05-29 22:11:20 +00:00
|
|
|
const NewsItem *ni = _statusbar_news_item;
|
2019-04-10 21:07:06 +00:00
|
|
|
if (ni == nullptr) return true;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
/* Ticker message
|
|
|
|
* Check if the status bar message is still being displayed? */
|
2021-06-16 21:21:21 +00:00
|
|
|
return !IsNewsTickerShown();
|
2019-05-29 22:11:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Are we ready to show another news item?
|
|
|
|
* Only if no newspaper is displayed
|
|
|
|
*/
|
|
|
|
static bool ReadyForNextNewsItem()
|
|
|
|
{
|
|
|
|
const NewsItem *ni = _forced_news == nullptr ? _current_news : _forced_news;
|
|
|
|
if (ni == nullptr) return true;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
/* neither newsticker nor newspaper are running */
|
2019-04-10 21:07:06 +00:00
|
|
|
return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr);
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-29 22:11:20 +00:00
|
|
|
/** Move to the next ticker item */
|
|
|
|
static void MoveToNextTickerItem()
|
2008-05-28 20:13:28 +00:00
|
|
|
{
|
2020-06-27 13:14:21 +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) == nullptr) return;
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
/* if we're not at the last item, then move on */
|
2019-05-29 22:11:20 +00:00
|
|
|
while (_statusbar_news_item != _latest_news) {
|
|
|
|
_statusbar_news_item = (_statusbar_news_item == nullptr) ? _oldest_news : _statusbar_news_item->next;
|
|
|
|
const NewsItem *ni = _statusbar_news_item;
|
2012-05-26 14:16:03 +00:00
|
|
|
const NewsType type = ni->type;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
|
|
|
/* check the date, don't show too old items */
|
2019-05-29 22:11:20 +00:00
|
|
|
if (_date - _news_type_data[type].age > ni->date) continue;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
2012-12-23 21:07:12 +00:00
|
|
|
switch (_news_type_data[type].GetDisplay()) {
|
2008-05-28 21:36:16 +00:00
|
|
|
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
|
|
|
|
2019-05-29 22:11:20 +00:00
|
|
|
case ND_FULL: // Full - show newspaper, skipped here
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Move to the next news item */
|
|
|
|
static void MoveToNextNewsItem()
|
|
|
|
{
|
2020-06-27 13:14:21 +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) == nullptr) return;
|
|
|
|
|
2021-05-17 13:46:38 +00:00
|
|
|
CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown
|
2019-05-29 22:11:20 +00:00
|
|
|
_forced_news = nullptr;
|
|
|
|
|
|
|
|
/* if we're not at the last item, then move on */
|
|
|
|
while (_current_news != _latest_news) {
|
|
|
|
_current_news = (_current_news == nullptr) ? _oldest_news : _current_news->next;
|
|
|
|
const NewsItem *ni = _current_news;
|
|
|
|
const NewsType type = ni->type;
|
|
|
|
|
|
|
|
/* check the date, don't show too old items */
|
|
|
|
if (_date - _news_type_data[type].age > ni->date) continue;
|
|
|
|
|
|
|
|
switch (_news_type_data[type].GetDisplay()) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case ND_SUMMARY: // Summary - show ticker, skipped here
|
|
|
|
continue;
|
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
case ND_FULL: // Full - show newspaper
|
|
|
|
ShowNewspaper(ni);
|
|
|
|
break;
|
|
|
|
}
|
2019-09-12 19:46:48 +00:00
|
|
|
return;
|
2008-05-28 21:36:16 +00:00
|
|
|
}
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 22:03:12 +00:00
|
|
|
/** Delete a news item from the queue */
|
|
|
|
static void DeleteNewsItem(NewsItem *ni)
|
|
|
|
{
|
|
|
|
/* Delete the news from the news queue. */
|
|
|
|
if (ni->prev != nullptr) {
|
|
|
|
ni->prev->next = ni->next;
|
|
|
|
} else {
|
|
|
|
assert(_oldest_news == ni);
|
|
|
|
_oldest_news = ni->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ni->next != nullptr) {
|
|
|
|
ni->next->prev = ni->prev;
|
|
|
|
} else {
|
|
|
|
assert(_latest_news == ni);
|
|
|
|
_latest_news = ni->prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
_total_news--;
|
|
|
|
|
|
|
|
if (_forced_news == ni || _current_news == 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) */
|
|
|
|
MoveToNextNewsItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_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. */
|
|
|
|
_statusbar_news_item = ni->prev;
|
|
|
|
|
|
|
|
/* About to remove the currently displayed item (ticker, or just a reminder) */
|
2021-02-18 11:17:51 +00:00
|
|
|
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
|
2020-02-16 22:03:12 +00:00
|
|
|
MoveToNextTickerItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete ni;
|
|
|
|
|
|
|
|
SetWindowDirty(WC_MESSAGE_HISTORY, 0);
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:38:34 +00:00
|
|
|
/**
|
|
|
|
* Create a new newsitem to be shown.
|
|
|
|
* @param string_id String to display.
|
|
|
|
* @param type The type of news.
|
|
|
|
* @param flags Flags related to how to display the news.
|
|
|
|
* @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 deleting 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 deleting the news when the object is deleted.
|
|
|
|
* @param data Pointer to data that must be released once the news message is cleared.
|
|
|
|
*
|
|
|
|
* @see NewsSubtype
|
|
|
|
*/
|
|
|
|
NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, const NewsAllocatedData *data) :
|
|
|
|
string_id(string_id), date(_date), type(type), flags(flags), reftype1(reftype1), reftype2(reftype2), ref1(ref1), ref2(ref2), data(data)
|
|
|
|
{
|
|
|
|
/* show this news message in colour? */
|
|
|
|
if (_cur_year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR;
|
|
|
|
CopyOutDParam(this->params, 0, lengthof(this->params));
|
|
|
|
}
|
|
|
|
|
2008-05-28 20:13:28 +00:00
|
|
|
/**
|
|
|
|
* Add a new newsitem to be shown.
|
|
|
|
* @param string String to display
|
2012-05-26 14:16:03 +00:00
|
|
|
* @param type news category
|
|
|
|
* @param flags display flags for the news
|
2009-05-24 16:52:42 +00:00
|
|
|
* @param reftype1 Type of ref1
|
2019-09-29 20:27:32 +00:00
|
|
|
* @param 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.
|
2009-05-24 16:52:42 +00:00
|
|
|
* @param reftype2 Type of ref2
|
2019-09-29 20:27:32 +00:00
|
|
|
* @param ref2 Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
|
2021-06-17 14:38:34 +00:00
|
|
|
* @param data Pointer to data that must be released 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
|
|
|
*/
|
2021-06-16 15:50:18 +00:00
|
|
|
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, const NewsAllocatedData *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 */
|
2021-06-17 14:38:34 +00:00
|
|
|
NewsItem *ni = new NewsItem(string, type, flags, reftype1, ref1, reftype2, ref2, data);
|
2008-05-28 20:13:28 +00:00
|
|
|
|
2008-05-28 21:36:16 +00:00
|
|
|
if (_total_news++ == 0) {
|
2019-04-10 21:07:06 +00:00
|
|
|
assert(_oldest_news == nullptr);
|
2008-05-28 21:36:16 +00:00
|
|
|
_oldest_news = ni;
|
2019-04-10 21:07:06 +00:00
|
|
|
ni->prev = nullptr;
|
2008-05-28 21:36:16 +00:00
|
|
|
} else {
|
2019-04-10 21:07:06 +00:00
|
|
|
assert(_latest_news->next == nullptr);
|
2008-05-28 21:36:16 +00:00
|
|
|
_latest_news->next = ni;
|
|
|
|
ni->prev = _latest_news;
|
|
|
|
}
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
ni->next = nullptr;
|
2008-05-28 21:36:16 +00:00
|
|
|
_latest_news = ni;
|
|
|
|
|
2020-02-16 22:03:12 +00:00
|
|
|
/* Keep the number of stored news items to a managable number */
|
|
|
|
if (_total_news > MAX_NEWS_AMOUNT) {
|
|
|
|
DeleteNewsItem(_oldest_news);
|
|
|
|
}
|
|
|
|
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowDirty(WC_MESSAGE_HISTORY, 0);
|
2008-05-28 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:01:03 +00:00
|
|
|
/**
|
|
|
|
* Create a new custom news item.
|
|
|
|
* @param tile unused
|
|
|
|
* @param flags type of operation
|
|
|
|
* @param p1 various bitstuffed elements
|
2012-05-26 14:16:03 +00:00
|
|
|
* - p1 = (bit 0 - 7) - NewsType of the message.
|
2011-12-19 21:01:03 +00:00
|
|
|
* - p1 = (bit 8 - 15) - NewsReferenceType of first reference.
|
|
|
|
* - p1 = (bit 16 - 23) - Company this news message is for.
|
|
|
|
* @param p2 First reference of the news message.
|
|
|
|
* @param text The text of the news message.
|
|
|
|
* @return the cost of this operation or an error
|
|
|
|
*/
|
2021-05-29 14:09:25 +00:00
|
|
|
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
|
2011-12-19 21:01:03 +00:00
|
|
|
{
|
|
|
|
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
|
|
|
|
2012-05-26 14:16:03 +00:00
|
|
|
NewsType type = (NewsType)GB(p1, 0, 8);
|
2011-12-19 21:01:03 +00:00
|
|
|
NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8);
|
|
|
|
CompanyID company = (CompanyID)GB(p1, 16, 8);
|
|
|
|
|
|
|
|
if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
|
2012-05-26 14:16:03 +00:00
|
|
|
if (type >= NT_END) return CMD_ERROR;
|
2021-05-29 14:09:25 +00:00
|
|
|
if (text.empty()) return CMD_ERROR;
|
2011-12-19 21:01:03 +00:00
|
|
|
|
|
|
|
switch (reftype1) {
|
|
|
|
case NR_NONE: break;
|
|
|
|
case NR_TILE:
|
|
|
|
if (!IsValidTile(p2)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NR_VEHICLE:
|
|
|
|
if (!Vehicle::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NR_STATION:
|
|
|
|
if (!Station::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NR_INDUSTRY:
|
|
|
|
if (!Industry::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NR_TOWN:
|
|
|
|
if (!Town::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NR_ENGINE:
|
|
|
|
if (!Engine::IsValidID(p2)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (company != INVALID_OWNER && company != _local_company) return CommandCost();
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2021-06-16 15:50:18 +00:00
|
|
|
NewsStringData *news = new NewsStringData(text);
|
|
|
|
SetDParamStr(0, news->string);
|
2012-05-26 14:16:03 +00:00
|
|
|
AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news);
|
2011-12-19 21:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CommandCost();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
while (ni != nullptr) {
|
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;
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
while (ni != nullptr) {
|
2008-09-13 10:19:51 +00:00
|
|
|
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;
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
while (ni != nullptr) {
|
2009-05-24 16:52:42 +00:00
|
|
|
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;
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
while (ni != nullptr) {
|
2011-02-05 20:41:13 +00:00
|
|
|
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;
|
2019-04-10 21:07:06 +00:00
|
|
|
for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != nullptr; cur = next) {
|
2008-05-28 21:36:16 +00:00
|
|
|
next = cur->next;
|
2012-05-26 14:16:03 +00:00
|
|
|
if (_date - _news_type_data[cur->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)
|
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
for (NewsItem *ni = _oldest_news; ni != nullptr; ni = ni->next) {
|
2009-08-10 20:06:39 +00:00
|
|
|
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;
|
2012-05-26 14:16:07 +00:00
|
|
|
if (ni->flags & NF_VEHICLE_PARAM0 && ni->params[0] == from_index) ni->params[0] = to_index;
|
2009-08-10 20:06:39 +00:00
|
|
|
}
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-29 22:11:20 +00:00
|
|
|
if (ReadyForNextTickerItem()) MoveToNextTickerItem();
|
|
|
|
if (ReadyForNextNewsItem()) MoveToNextNewsItem();
|
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 */
|
2021-05-17 13:46:38 +00:00
|
|
|
CloseWindowById(WC_NEWS_WINDOW, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (_forced_news != nullptr) {
|
2021-05-17 13:46:38 +00:00
|
|
|
CloseWindowById(WC_NEWS_WINDOW, 0);
|
2004-08-18 23:38:53 +00:00
|
|
|
ShowNewspaper(ni);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 18:18:35 +00:00
|
|
|
/**
|
|
|
|
* Close active news message window
|
|
|
|
* @return true if a window was closed.
|
|
|
|
*/
|
|
|
|
bool HideActiveNewsMessage() {
|
|
|
|
NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0);
|
|
|
|
if (w == nullptr) return false;
|
2021-05-15 21:12:25 +00:00
|
|
|
w->Close();
|
2020-07-05 18:18:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
const NewsItem *ni = nullptr;
|
2008-05-28 21:36:16 +00:00
|
|
|
if (_total_news == 0) {
|
|
|
|
return;
|
2019-04-10 21:07:06 +00:00
|
|
|
} else if (_forced_news == nullptr) {
|
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 */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (_current_news == nullptr) {
|
2013-03-17 14:41:09 +00:00
|
|
|
/* No news were shown yet resp. the last shown one was already deleted.
|
|
|
|
* Threat this as if _forced_news reached _oldest_news; so, wrap around and start anew with the latest. */
|
|
|
|
ni = _latest_news;
|
|
|
|
} else {
|
|
|
|
const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
|
2019-04-10 21:07:06 +00:00
|
|
|
ni = (w == nullptr || (_current_news == _oldest_news)) ? _current_news : _current_news->prev;
|
2013-03-17 14:41:09 +00:00
|
|
|
}
|
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 */
|
2012-12-08 17:19:09 +00:00
|
|
|
ni = _latest_news;
|
2007-01-11 01:21:55 +00:00
|
|
|
} else {
|
|
|
|
/* 'Scrolling' through news history show each one in turn */
|
2012-12-08 17:19:09 +00:00
|
|
|
ni = _forced_news->prev;
|
|
|
|
}
|
|
|
|
bool wrap = false;
|
|
|
|
for (;;) {
|
2012-12-23 21:07:12 +00:00
|
|
|
if (_news_type_data[ni->type].GetDisplay() != ND_OFF) {
|
2012-12-08 17:19:09 +00:00
|
|
|
ShowNewsMessage(ni);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ni = ni->prev;
|
2019-04-10 21:07:06 +00:00
|
|
|
if (ni == nullptr) {
|
2012-12-08 17:19:09 +00:00
|
|
|
if (wrap) break;
|
|
|
|
/* We have reached the oldest news, start anew with the latest */
|
|
|
|
ni = _latest_news;
|
|
|
|
wrap = true;
|
|
|
|
}
|
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
|
|
|
|
*/
|
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';
|
2013-01-08 22:46:42 +00:00
|
|
|
/* Truncate and show string; postfixed by '...' if necessary */
|
2009-11-19 11:10:32 +00:00
|
|
|
DrawString(left, right, y, buffer2, colour);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-18 08:50:51 +00:00
|
|
|
struct MessageHistoryWindow : Window {
|
2011-12-16 18:32:57 +00:00
|
|
|
static const int top_spacing; ///< Additional spacing at the top of the #WID_MH_BACKGROUND widget.
|
|
|
|
static const int bottom_spacing; ///< Additional spacing at the bottom of the #WID_MH_BACKGROUND widget.
|
2009-08-08 20:06:38 +00:00
|
|
|
|
2013-01-08 22:46:42 +00:00
|
|
|
int line_height; /// < Height of a single line in the news history window including spacing.
|
2009-08-08 20:06:38 +00:00
|
|
|
int date_width; /// < Width needed for the date part.
|
|
|
|
|
2010-08-12 08:37:01 +00:00
|
|
|
Scrollbar *vscroll;
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
MessageHistoryWindow(WindowDesc *desc) : Window(desc)
|
2008-05-18 08:50:51 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
2011-12-16 18:32:57 +00:00
|
|
|
this->vscroll = this->GetScrollbar(WID_MH_SCROLLBAR);
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(); // 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
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
2009-08-08 20:06:38 +00:00
|
|
|
{
|
2011-12-16 18:32:57 +00:00
|
|
|
if (widget == WID_MH_BACKGROUND) {
|
2009-08-08 20:06:38 +00:00
|
|
|
this->line_height = FONT_HEIGHT_NORMAL + 2;
|
|
|
|
resize->height = this->line_height;
|
|
|
|
|
2011-12-20 19:57:03 +00:00
|
|
|
/* Months are off-by-one, so it's actually 8. Not using
|
|
|
|
* month 12 because the 1 is usually less wide. */
|
|
|
|
SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 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.
|
2021-01-08 10:16:18 +00:00
|
|
|
size->width = std::max(200u, size->width); // At least 200 pixels wide.
|
2009-08-08 20:06:38 +00:00
|
|
|
}
|
2008-05-18 08:50:51 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnPaint() override
|
2008-05-18 08:50:51 +00:00
|
|
|
{
|
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
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void DrawWidget(const Rect &r, int widget) const override
|
2009-08-08 20:06:38 +00:00
|
|
|
{
|
2011-12-16 18:32:57 +00:00
|
|
|
if (widget != WID_MH_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;
|
2019-04-10 21:07:06 +00:00
|
|
|
if (ni == nullptr) return;
|
2008-05-28 21:36:16 +00:00
|
|
|
}
|
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;
|
2021-02-13 21:18:03 +00:00
|
|
|
uint news_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->date_width + WD_FRAMERECT_RIGHT + ScaleFontTrad(5);
|
|
|
|
uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT - ScaleFontTrad(5) : 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;
|
2019-04-10 21:07:06 +00:00
|
|
|
if (ni == nullptr) 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.
|
|
|
|
*/
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
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
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnClick(Point pt, int widget, int click_count) override
|
2008-05-18 08:50:51 +00:00
|
|
|
{
|
2011-12-16 18:32:57 +00:00
|
|
|
if (widget == WID_MH_BACKGROUND) {
|
2008-05-28 21:36:16 +00:00
|
|
|
NewsItem *ni = _latest_news;
|
2019-04-10 21:07:06 +00:00
|
|
|
if (ni == nullptr) return;
|
2008-05-28 21:36:16 +00:00
|
|
|
|
2021-04-21 14:22:45 +00:00
|
|
|
for (int n = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_MH_BACKGROUND, WD_FRAMERECT_TOP); n > 0; n--) {
|
2008-05-28 21:36:16 +00:00
|
|
|
ni = ni->prev;
|
2019-04-10 21:07:06 +00:00
|
|
|
if (ni == nullptr) return;
|
2008-05-28 21:36:16 +00:00
|
|
|
}
|
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
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnResize() override
|
2008-05-18 08:50:51 +00:00
|
|
|
{
|
2013-06-30 14:33:32 +00:00
|
|
|
this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND);
|
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),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, 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),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, WID_MH_BACKGROUND), SetMinimalSize(200, 125), SetDataTip(0x0, STR_MESSAGE_HISTORY_TOOLTIP), SetResize(1, 12), SetScrollbar(WID_MH_SCROLLBAR),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2011-12-16 18:32:57 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_MH_SCROLLBAR),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _message_history_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "list_news", 400, 140,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_MESSAGE_HISTORY, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
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
|
|
|
{
|
2021-05-17 13:46:38 +00:00
|
|
|
CloseWindowById(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
|
|
|
}
|