2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-06 23:01:35 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
2008-03-28 08:53:36 +00:00
|
|
|
#include "news_func.h"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.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"
|
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-04-22 21:18:55 +00:00
|
|
|
#include "map_func.h"
|
2008-05-16 07:08:04 +00:00
|
|
|
#include "statusbar_gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** @file news_gui.cpp
|
|
|
|
*
|
2006-09-04 20:40:33 +00:00
|
|
|
* News system is realized as a FIFO queue (in an array)
|
|
|
|
* The positions in the queue can't be rearranged, we only access
|
|
|
|
* the array elements through pointers to the elements. Once the
|
2007-09-17 17:07:24 +00:00
|
|
|
* array is full, the oldest entry (\a _oldest_news) is being overwritten
|
|
|
|
* by the newest (\a _latest_news).
|
2006-09-04 20:40:33 +00:00
|
|
|
*
|
2007-09-17 17:07:24 +00:00
|
|
|
* \verbatim
|
2006-09-04 20:40:33 +00:00
|
|
|
* oldest current lastest
|
|
|
|
* | | |
|
|
|
|
* [O------------F-------------C---------L ]
|
|
|
|
* |
|
|
|
|
* forced
|
2007-09-17 17:07:24 +00:00
|
|
|
* \endverbatim
|
2006-12-05 22:35:25 +00:00
|
|
|
*
|
|
|
|
* Of course by using an array we can have situations like
|
|
|
|
*
|
2007-09-17 17:07:24 +00:00
|
|
|
* \verbatim
|
2006-12-05 22:35:25 +00:00
|
|
|
* [----L O-----F---------C-----------------]
|
|
|
|
* This is where we have wrapped around the array and have
|
|
|
|
* (MAX_NEWS - O) + L news items
|
2007-09-17 17:07:24 +00:00
|
|
|
* \endverbatim
|
2006-09-04 20:40:33 +00:00
|
|
|
*/
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2007-03-10 03:33:43 +00:00
|
|
|
#define NB_WIDG_PER_SETTING 4
|
2004-11-15 12:05:01 +00:00
|
|
|
|
2006-12-05 12:17:31 +00:00
|
|
|
typedef byte NewsID;
|
2004-11-15 12:05:01 +00:00
|
|
|
#define INVALID_NEWS 255
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2008-01-13 13:36:01 +00:00
|
|
|
NewsItem _statusbar_news_item;
|
2008-01-13 14:37:30 +00:00
|
|
|
bool _news_ticker_sound;
|
2008-04-22 21:18:55 +00:00
|
|
|
static NewsItem *_news_items = NULL; ///< The news FIFO queue
|
|
|
|
static uint _max_news_items = 0; ///< size of news FIFO queue
|
2007-09-17 17:07:24 +00:00
|
|
|
static NewsID _current_news = INVALID_NEWS; ///< points to news item that should be shown next
|
|
|
|
static NewsID _oldest_news = 0; ///< points to first item in fifo queue
|
|
|
|
static NewsID _latest_news = INVALID_NEWS; ///< points to last item in fifo queue
|
|
|
|
|
|
|
|
/** Forced news item.
|
|
|
|
* Users can force an item by accessing the history or "last message".
|
|
|
|
* If the message being shown was forced by the user, its index is stored in
|
|
|
|
* _forced_news. Otherwise, \a _forced_news variable is INVALID_NEWS. */
|
2006-12-05 12:17:31 +00:00
|
|
|
static NewsID _forced_news = INVALID_NEWS;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2008-04-22 21:18:55 +00:00
|
|
|
static uint _total_news = 0; ///< Number of news items in FIFO queue @see _news_items
|
2008-05-15 13:47:55 +00:00
|
|
|
static void MoveToNextItem();
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
typedef void DrawNewsCallbackProc(struct Window *w, const NewsItem *ni);
|
2008-03-28 08:53:36 +00:00
|
|
|
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni);
|
|
|
|
void DrawNewsBankrupcy(Window *w, const NewsItem *ni);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static DrawNewsCallbackProc * const _draw_news_callback[] = {
|
2007-09-17 17:07:24 +00:00
|
|
|
DrawNewsNewVehicleAvail, ///< DNC_VEHICLEAVAIL
|
|
|
|
DrawNewsBankrupcy, ///< DNC_BANKRUPCY
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2008-05-15 13:39:36 +00:00
|
|
|
/**
|
|
|
|
* Data common to all news items of a given subtype (structure)
|
|
|
|
*/
|
|
|
|
struct NewsSubtypeData {
|
|
|
|
NewsType type; ///< News category @see NewsType
|
|
|
|
NewsMode display_mode; ///< Display mode value @see NewsMode
|
|
|
|
NewsFlag flags; ///< Initial NewsFlags bits @see NewsFlag
|
|
|
|
NewsCallback callback; ///< Call-back function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data common to all news items of a given subtype (actual data)
|
|
|
|
*/
|
|
|
|
static const struct NewsSubtypeData _news_subtype_data[NS_END] = {
|
|
|
|
/* type, display_mode, flags, callback */
|
|
|
|
{ NT_ARRIVAL_PLAYER, NM_THIN, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ARRIVAL_PLAYER
|
|
|
|
{ NT_ARRIVAL_OTHER, NM_THIN, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ARRIVAL_OTHER
|
|
|
|
{ NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_ACCIDENT_TILE
|
|
|
|
{ NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ACCIDENT_VEHICLE
|
|
|
|
{ NT_COMPANY_INFO, NM_CALLBACK, NF_NONE, DNC_BANKRUPCY }, ///< NS_COMPANY_TROUBLE
|
|
|
|
{ NT_COMPANY_INFO, NM_CALLBACK, NF_NONE, DNC_BANKRUPCY }, ///< NS_COMPANY_MERGER
|
|
|
|
{ NT_COMPANY_INFO, NM_CALLBACK, NF_NONE, DNC_BANKRUPCY }, ///< NS_COMPANY_BANKRUPT
|
|
|
|
{ NT_COMPANY_INFO, NM_CALLBACK, NF_TILE, DNC_BANKRUPCY }, ///< NS_COMPANY_NEW
|
|
|
|
{ NT_OPENCLOSE, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_OPENCLOSE
|
|
|
|
{ NT_ECONOMY, NM_NORMAL, NF_NONE, DNC_NONE }, ///< NS_ECONOMY
|
|
|
|
{ NT_INDUSTRY_PLAYER, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_INDUSTRY_PLAYER
|
|
|
|
{ NT_INDUSTRY_OTHER, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_INDUSTRY_OTHER
|
|
|
|
{ NT_INDUSTRY_NOBODY, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_INDUSTRY_NOBODY
|
|
|
|
{ NT_ADVICE, NM_SMALL, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ADVICE
|
|
|
|
{ NT_NEW_VEHICLES, NM_CALLBACK, NF_NONE, DNC_VEHICLEAVAIL }, ///< NS_NEW_VEHICLES
|
|
|
|
{ NT_ACCEPTANCE, NM_SMALL, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_ACCEPTANCE
|
|
|
|
{ NT_SUBSIDIES, NM_NORMAL, NF_TILE|NF_TILE2, DNC_NONE }, ///< NS_SUBSIDIES
|
|
|
|
{ NT_GENERAL, NM_NORMAL, NF_TILE, DNC_NONE }, ///< NS_GENERAL
|
|
|
|
};
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** Initialize the news-items data structures */
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitNewsItemStructs()
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2008-04-22 21:18:55 +00:00
|
|
|
free(_news_items);
|
|
|
|
_max_news_items = max(ScaleByMapSize(30), 30U);
|
|
|
|
_news_items = CallocT<NewsItem>(_max_news_items);
|
2004-11-15 12:05:01 +00:00
|
|
|
_current_news = INVALID_NEWS;
|
2004-08-20 13:58:25 +00:00
|
|
|
_oldest_news = 0;
|
2004-11-15 12:05:01 +00:00
|
|
|
_latest_news = INVALID_NEWS;
|
|
|
|
_forced_news = INVALID_NEWS;
|
2004-08-20 13:58:25 +00:00
|
|
|
_total_news = 0;
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
struct NewsWindow : Window {
|
|
|
|
uint16 chat_height;
|
|
|
|
NewsItem *ni;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
NewsWindow(const WindowDesc *desc, NewsItem *ni) : Window(desc), ni(ni)
|
|
|
|
{
|
|
|
|
const Window *w = FindWindowById(WC_SEND_NETWORK_MSG, 0);
|
|
|
|
this->chat_height = (w != NULL) ? w->height : 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
this->ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news];
|
|
|
|
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
void DrawNewsBorder()
|
|
|
|
{
|
|
|
|
int left = 0;
|
|
|
|
int right = this->width - 1;
|
|
|
|
int top = 0;
|
|
|
|
int bottom = this->height - 1;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
GfxFillRect(left, top, right, bottom, 0xF);
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
GfxFillRect(left, top, left, bottom, 0xD7);
|
|
|
|
GfxFillRect(right, top, right, bottom, 0xD7);
|
|
|
|
GfxFillRect(left, top, right, top, 0xD7);
|
|
|
|
GfxFillRect(left, bottom, right, bottom, 0xD7);
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
DrawString(left + 2, top + 1, STR_00C6, TC_FROMSTRING);
|
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
const NewsMode display_mode = _news_subtype_data[this->ni->subtype].display_mode;
|
|
|
|
|
|
|
|
switch (display_mode) {
|
|
|
|
case NM_NORMAL:
|
|
|
|
case NM_THIN: {
|
|
|
|
this->DrawNewsBorder();
|
|
|
|
|
|
|
|
DrawString(2, 1, STR_00C6, TC_FROMSTRING);
|
|
|
|
|
|
|
|
SetDParam(0, this->ni->date);
|
|
|
|
DrawStringRightAligned(428, 1, STR_01FF, TC_FROMSTRING);
|
|
|
|
|
|
|
|
if (!(this->ni->flags & NF_VIEWPORT)) {
|
|
|
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
|
|
|
DrawStringMultiCenter(215, display_mode == NM_NORMAL ? 76 : 56,
|
|
|
|
this->ni->string_id, this->width - 4);
|
|
|
|
} else {
|
|
|
|
/* Back up transparency options to draw news view */
|
|
|
|
TransparencyOptionBits to_backup = _transparency_opt;
|
|
|
|
_transparency_opt = 0;
|
|
|
|
DrawWindowViewport(this);
|
|
|
|
_transparency_opt = to_backup;
|
|
|
|
|
|
|
|
/* Shade the viewport into gray, or color*/
|
|
|
|
ViewPort *vp = this->viewport;
|
|
|
|
GfxFillRect(vp->left - this->left, vp->top - this->top,
|
|
|
|
vp->left - this->left + vp->width - 1, vp->top - this->top + vp->height - 1,
|
|
|
|
(this->ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY) | (1 << USE_COLORTABLE)
|
|
|
|
);
|
|
|
|
|
|
|
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
|
|
|
DrawStringMultiCenter(this->width / 2, 20, this->ni->string_id, this->width - 4);
|
2004-11-15 12:05:01 +00:00
|
|
|
}
|
2008-05-15 13:47:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
case NM_CALLBACK:
|
|
|
|
this->DrawNewsBorder();
|
|
|
|
_draw_news_callback[_news_subtype_data[this->ni->subtype].callback](this, ni);
|
|
|
|
break;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
default:
|
|
|
|
DrawWindowWidgets(this);
|
|
|
|
if (!(this->ni->flags & NF_VIEWPORT)) {
|
|
|
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
|
|
|
DrawStringMultiCenter(140, 38, this->ni->string_id, 276);
|
|
|
|
} else {
|
|
|
|
DrawWindowViewport(this);
|
|
|
|
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
|
|
|
|
DrawStringMultiCenter(this->width / 2, this->height - 16, this->ni->string_id, this->width - 4);
|
|
|
|
}
|
|
|
|
break;
|
2008-05-05 11:24:58 +00:00
|
|
|
}
|
2008-05-15 13:47:55 +00:00
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case 1:
|
|
|
|
this->ni->duration = 0;
|
|
|
|
delete this;
|
|
|
|
_forced_news = INVALID_NEWS;
|
|
|
|
break;
|
2008-05-05 11:24:58 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
case 0:
|
|
|
|
if (this->ni->flags & NF_VEHICLE) {
|
|
|
|
Vehicle *v = GetVehicle(this->ni->data_a);
|
|
|
|
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
|
|
|
} else if (this->ni->flags & NF_TILE) {
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
ShowExtraViewPortWindow(this->ni->data_a);
|
|
|
|
if (this->ni->flags & NF_TILE2) {
|
|
|
|
ShowExtraViewPortWindow(this->ni->data_b);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ScrollMainWindowToTile(this->ni->data_a) && this->ni->flags & NF_TILE2) {
|
|
|
|
ScrollMainWindowToTile(this->ni->data_b);
|
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-15 13:47:55 +00:00
|
|
|
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
|
|
|
{
|
|
|
|
if (keycode == WKC_SPACE) {
|
|
|
|
/* Don't continue. */
|
|
|
|
delete this;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
|
|
|
/* The chatbar has notified us that is was either created or closed */
|
|
|
|
this->chat_height = data;
|
|
|
|
}
|
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 */
|
|
|
|
int y = max(this->top - 4, _screen.height - this->height - 12 - this->chat_height);
|
|
|
|
if (y == this->top) return;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
if (this->viewport != NULL) this->viewport->top += y - this->top;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
int diff = Delta(this->top, y);
|
|
|
|
this->top = y;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
2008-05-15 13:47:55 +00:00
|
|
|
SetDirtyBlocks(this->left, this->top - diff, this->left + this->width, this->top + this->height);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-15 13:47:55 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/**
|
|
|
|
* Return the correct index in the pseudo-fifo
|
|
|
|
* queue and deals with overflows when increasing the index
|
|
|
|
*/
|
2008-03-28 16:45:20 +00:00
|
|
|
static inline NewsID IncreaseIndex(NewsID i)
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2006-12-05 23:37:04 +00:00
|
|
|
assert(i != INVALID_NEWS);
|
2008-04-22 21:18:55 +00:00
|
|
|
return (i + 1) % _max_news_items;
|
2006-12-05 11:59:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/**
|
|
|
|
* Return the correct index in the pseudo-fifo
|
|
|
|
* queue and deals with overflows when decreasing the index
|
|
|
|
*/
|
2008-03-28 16:45:20 +00:00
|
|
|
static inline NewsID DecreaseIndex(NewsID i)
|
2006-12-05 11:59:28 +00:00
|
|
|
{
|
|
|
|
assert(i != INVALID_NEWS);
|
2008-04-22 21:18:55 +00:00
|
|
|
return (i + _max_news_items - 1) % _max_news_items;
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/**
|
|
|
|
* Add a new newsitem to be shown.
|
2008-05-15 20:53:44 +00:00
|
|
|
* @param string String to display
|
|
|
|
* @param subtype news category, any of the NewsSubtype enums (NS_)
|
2006-10-17 17:59:41 +00:00
|
|
|
* @param data_a news-specific value based on news type
|
|
|
|
* @param data_b news-specific value based on news type
|
2007-09-17 17:07:24 +00:00
|
|
|
*
|
2008-05-15 20:53:44 +00:00
|
|
|
* @see NewsSubype
|
2007-09-17 17:07:24 +00:00
|
|
|
*/
|
2008-05-15 13:39:36 +00:00
|
|
|
void AddNewsItem(StringID string, NewsSubtype subtype, uint data_a, uint data_b)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-06-10 08:37:41 +00:00
|
|
|
if (_game_mode == GM_MENU) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* check the rare case that the oldest (to be overwritten) news item is open */
|
2008-04-22 21:18:55 +00:00
|
|
|
if (_total_news == _max_news_items && (_oldest_news == _current_news || _oldest_news == _forced_news)) {
|
2006-12-05 22:31:10 +00:00
|
|
|
MoveToNextItem();
|
2008-03-28 16:45:20 +00:00
|
|
|
}
|
2004-08-21 22:04:25 +00:00
|
|
|
|
2008-04-22 21:18:55 +00:00
|
|
|
if (_total_news < _max_news_items) _total_news++;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-12-05 23:37:04 +00:00
|
|
|
/* Increase _latest_news. If we have no news yet, use _oldest news as an
|
|
|
|
* index. We cannot use 0 as _oldest_news can jump around due to
|
|
|
|
* DeleteVehicleNews */
|
2008-03-28 16:45:20 +00:00
|
|
|
NewsID l_news = _latest_news;
|
|
|
|
_latest_news = (_latest_news == INVALID_NEWS) ? _oldest_news : IncreaseIndex(_latest_news);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-05 11:51:23 +00:00
|
|
|
/* If the fifo-buffer is full, overwrite the oldest entry */
|
2006-12-05 11:59:28 +00:00
|
|
|
if (l_news != INVALID_NEWS && _latest_news == _oldest_news) {
|
2008-04-22 21:18:55 +00:00
|
|
|
assert(_total_news == _max_news_items);
|
2008-03-28 16:45:20 +00:00
|
|
|
_oldest_news = IncreaseIndex(_oldest_news);
|
2006-12-05 11:59:28 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 01:21:55 +00:00
|
|
|
/*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d",
|
|
|
|
_current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
|
2007-01-04 17:23:55 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Add news to _latest_news */
|
2008-03-28 08:53:36 +00:00
|
|
|
NewsItem *ni = &_news_items[_latest_news];
|
|
|
|
memset(ni, 0, sizeof(*ni));
|
|
|
|
|
|
|
|
ni->string_id = string;
|
2008-05-15 13:39:36 +00:00
|
|
|
ni->subtype = subtype;
|
|
|
|
ni->flags = _news_subtype_data[subtype].flags;
|
2008-03-28 08:53:36 +00:00
|
|
|
|
|
|
|
/* show this news message in color? */
|
|
|
|
if (_cur_year >= _patches.colored_news_year) ni->flags |= NF_INCOLOR;
|
|
|
|
|
|
|
|
ni->data_a = data_a;
|
|
|
|
ni->data_b = data_b;
|
|
|
|
ni->date = _date;
|
|
|
|
CopyOutDParam(ni->params, 0, lengthof(ni->params));
|
|
|
|
|
|
|
|
Window *w = FindWindowById(WC_MESSAGE_HISTORY, 0);
|
|
|
|
if (w == NULL) return;
|
2008-05-06 22:08:18 +00:00
|
|
|
w->SetDirty();
|
2008-03-28 08:53:36 +00:00
|
|
|
w->vscroll.count = _total_news;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-19 09:39:19 +00:00
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/**
|
2008-04-19 12:50:02 +00:00
|
|
|
* Per-NewsType data
|
2007-09-17 17:07:24 +00:00
|
|
|
*/
|
2008-04-20 11:40:33 +00:00
|
|
|
NewsTypeData _news_type_data[NT_END] = {
|
|
|
|
/* name, age, sound, display */
|
|
|
|
{ "arrival_player", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_PLAYER
|
|
|
|
{ "arrival_other", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_OTHER
|
|
|
|
{ "accident", 90, SND_BEGIN, ND_FULL }, ///< NT_ACCIDENT
|
|
|
|
{ "company_info", 60, SND_BEGIN, ND_FULL }, ///< NT_COMPANY_INFO
|
|
|
|
{ "openclose", 90, SND_BEGIN, ND_FULL }, ///< NT_OPENCLOSE
|
|
|
|
{ "economy", 30, SND_BEGIN, ND_FULL }, ///< NT_ECONOMY
|
|
|
|
{ "production_player", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_PLAYER
|
|
|
|
{ "production_other", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_OTHER
|
|
|
|
{ "production_nobody", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_NOBODY
|
|
|
|
{ "advice", 150, SND_BEGIN, ND_FULL }, ///< NT_ADVICE
|
|
|
|
{ "new_vehicles", 30, SND_1E_OOOOH, ND_FULL }, ///< NT_NEW_VEHICLES
|
|
|
|
{ "acceptance", 90, SND_BEGIN, ND_FULL }, ///< NT_ACCEPTANCE
|
|
|
|
{ "subsidies", 180, SND_BEGIN, ND_FULL }, ///< NT_SUBSIDIES
|
|
|
|
{ "general", 60, SND_BEGIN, ND_FULL }, ///< NT_GENERAL
|
2007-09-17 17:07:24 +00:00
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static const Widget _news_type13_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 15, 0, 429, 0, 169, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 15, 0, 10, 0, 11, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static WindowDesc _news_type13_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, 476, 430, 170, 430, 170,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_DEF_WIDGET,
|
|
|
|
_news_type13_widgets,
|
2008-05-15 13:47:55 +00:00
|
|
|
NULL
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _news_type2_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 15, 0, 429, 0, 129, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 15, 0, 10, 0, 11, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static WindowDesc _news_type2_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, 476, 430, 130, 430, 130,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_DEF_WIDGET,
|
|
|
|
_news_type2_widgets,
|
2008-05-15 13:47:55 +00:00
|
|
|
NULL
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _news_type0_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 5, 0, 279, 14, 86, 0x0, STR_NULL},
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 279, 0, 13, STR_012C_MESSAGE, STR_NULL},
|
2006-10-24 16:27:18 +00:00
|
|
|
{ WWT_INSET, RESIZE_NONE, 5, 2, 277, 16, 64, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static WindowDesc _news_type0_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, 476, 280, 87, 280, 87,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_NEWS_WINDOW, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_DEF_WIDGET,
|
|
|
|
_news_type0_widgets,
|
2008-05-15 13:47:55 +00:00
|
|
|
NULL
|
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 */
|
2004-08-18 23:38:53 +00:00
|
|
|
static void ShowNewspaper(NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-17 18:15:35 +00:00
|
|
|
ni->flags &= ~NF_FORCE_BIG;
|
2004-08-18 23:38:53 +00:00
|
|
|
ni->duration = 555;
|
|
|
|
|
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
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
int top = _screen.height;
|
|
|
|
Window *w;
|
2008-05-15 13:39:36 +00:00
|
|
|
switch (_news_subtype_data[ni->subtype].display_mode) {
|
2004-11-15 12:05:01 +00:00
|
|
|
case NM_NORMAL:
|
2008-03-28 16:45:20 +00:00
|
|
|
case NM_CALLBACK:
|
2004-11-15 12:05:01 +00:00
|
|
|
_news_type13_desc.top = top;
|
2008-05-15 13:47:55 +00:00
|
|
|
w = new NewsWindow(&_news_type13_desc, ni);
|
2008-03-28 16:45:20 +00:00
|
|
|
if (ni->flags & NF_VIEWPORT) {
|
2008-04-19 13:17:19 +00:00
|
|
|
InitializeWindowViewport(w, 2, 58, 426, 110,
|
2007-05-15 14:08:39 +00:00
|
|
|
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
|
2008-03-28 16:45:20 +00:00
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
case NM_THIN:
|
2004-11-15 12:05:01 +00:00
|
|
|
_news_type2_desc.top = top;
|
2008-05-15 13:47:55 +00:00
|
|
|
w = new NewsWindow(&_news_type2_desc, ni);
|
2008-03-28 16:45:20 +00:00
|
|
|
if (ni->flags & NF_VIEWPORT) {
|
2008-04-19 13:17:19 +00:00
|
|
|
InitializeWindowViewport(w, 2, 58, 426, 70,
|
2007-05-15 14:08:39 +00:00
|
|
|
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
|
2008-03-28 16:45:20 +00:00
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
default:
|
2004-11-15 12:05:01 +00:00
|
|
|
_news_type0_desc.top = top;
|
2008-05-15 13:47:55 +00:00
|
|
|
w = new NewsWindow(&_news_type0_desc, ni);
|
2008-03-28 16:45:20 +00:00
|
|
|
if (ni->flags & NF_VIEWPORT) {
|
2008-04-19 13:17:19 +00:00
|
|
|
InitializeWindowViewport(w, 3, 17, 274, 47,
|
2007-05-15 14:08:39 +00:00
|
|
|
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
|
2008-03-28 16:45:20 +00:00
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
break;
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
2007-01-04 17:23:55 +00:00
|
|
|
|
2007-01-11 01:21:55 +00:00
|
|
|
/*DEBUG(misc, 0, " cur %3d, old %2d, lat %3d, for %3d, tot %2d",
|
|
|
|
_current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
|
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);
|
|
|
|
|
2004-08-18 23:38:53 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/**
|
|
|
|
* Are we ready to show another news item?
|
|
|
|
* Only if nothing is in the newsticker and no newspaper is displayed
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static bool ReadyForNextItem()
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2006-12-05 12:17:31 +00:00
|
|
|
NewsID item = (_forced_news == INVALID_NEWS) ? _current_news : _forced_news;
|
2004-08-20 15:37:44 +00:00
|
|
|
|
2008-04-22 21:18:55 +00:00
|
|
|
if (item >= _max_news_items) return true;
|
2008-03-28 16:45:20 +00:00
|
|
|
NewsItem *ni = &_news_items[item];
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Ticker message
|
|
|
|
* Check if the status bar message is still being displayed? */
|
2008-05-16 07:08:04 +00:00
|
|
|
if (IsNewsTickerShown()) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Newspaper message, decrement duration counter */
|
2006-12-06 17:28:14 +00:00
|
|
|
if (ni->duration != 0) ni->duration--;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* neither newsticker nor newspaper are running */
|
2006-12-06 17:28:14 +00:00
|
|
|
return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/** Move to the next news item */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void MoveToNextItem()
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_NEWS_WINDOW, 0);
|
2004-11-15 12:05:01 +00:00
|
|
|
_forced_news = INVALID_NEWS;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* if we're not at the last item, then move on */
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_current_news != _latest_news) {
|
2008-03-28 16:45:20 +00:00
|
|
|
_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : IncreaseIndex(_current_news);
|
|
|
|
NewsItem *ni = &_news_items[_current_news];
|
2008-05-15 13:39:36 +00:00
|
|
|
const NewsType type = _news_subtype_data[ni->subtype].type;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* check the date, don't show too old items */
|
2008-05-15 13:39:36 +00:00
|
|
|
if (_date - _news_type_data[type].age > ni->date) return;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2008-05-15 13:39:36 +00:00
|
|
|
switch (_news_type_data[type].display) {
|
2007-09-17 17:07:24 +00:00
|
|
|
default: NOT_REACHED();
|
2008-05-16 07:08:04 +00:00
|
|
|
case ND_OFF: // Off - show nothing only a small reminder in the status bar
|
|
|
|
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
|
|
|
|
2008-04-20 11:40:33 +00:00
|
|
|
case ND_SUMMARY: // Summary - show ticker, but if forced big, cascade to full
|
2007-09-17 17:07:24 +00:00
|
|
|
if (!(ni->flags & NF_FORCE_BIG)) {
|
|
|
|
ShowTicker(ni);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fallthrough */
|
|
|
|
|
2008-04-20 11:40:33 +00:00
|
|
|
case ND_FULL: // Full - show newspaper
|
2007-09-17 17:07:24 +00:00
|
|
|
ShowNewspaper(ni);
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +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
|
|
|
|
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 */
|
2006-12-05 12:17:31 +00:00
|
|
|
static void ShowNewsMessage(NewsID i)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_total_news == 0) return;
|
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 */
|
2004-08-18 23:38:53 +00:00
|
|
|
_forced_news = i;
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_forced_news != INVALID_NEWS) {
|
2004-08-18 23:38:53 +00:00
|
|
|
NewsItem *ni = &_news_items[_forced_news];
|
|
|
|
ni->duration = 555;
|
2006-10-17 18:15:35 +00:00
|
|
|
ni->flags |= NF_FORCE_BIG;
|
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
|
|
|
{
|
2007-01-11 01:21:55 +00:00
|
|
|
if (_forced_news == INVALID_NEWS) {
|
|
|
|
/* 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-03-28 16:45:20 +00:00
|
|
|
ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : DecreaseIndex(_current_news));
|
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-03-28 16:45:20 +00:00
|
|
|
ShowNewsMessage(DecreaseIndex(_forced_news));
|
2004-08-19 13:39:50 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
|
|
|
|
/* return news by number, with 0 being the most
|
2006-09-04 20:40:33 +00:00
|
|
|
* recent news. Returns INVALID_NEWS if end of queue reached. */
|
2006-12-05 12:17:31 +00:00
|
|
|
static NewsID getNews(NewsID i)
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
if (i >= _total_news) return INVALID_NEWS;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_latest_news < i) {
|
2008-04-22 21:18:55 +00:00
|
|
|
i = _latest_news + _max_news_items - i;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2004-08-20 13:58:25 +00:00
|
|
|
i = _latest_news - i;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2008-04-22 21:18:55 +00:00
|
|
|
i %= _max_news_items;
|
2004-08-18 23:38:53 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
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 '...'
|
|
|
|
* @param x,y position of the string
|
|
|
|
* @param color the color the string will be shown in
|
|
|
|
* @param *ni NewsItem being printed
|
|
|
|
* @param maxw maximum width of string in pixels
|
|
|
|
*/
|
|
|
|
static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint maxw)
|
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 */
|
|
|
|
DoDrawStringTruncated(buffer2, x, y, color, maxw);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void MessageHistoryWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (e->event) {
|
2008-03-28 16:45:20 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
int y = 19;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
SetVScrollCount(w, _total_news);
|
|
|
|
DrawWindowWidgets(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
if (_total_news == 0) break;
|
|
|
|
NewsID show = min(_total_news, w->vscroll.cap);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
for (NewsID p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
|
|
|
|
/* get news in correct order */
|
|
|
|
const NewsItem *ni = &_news_items[getNews(p)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
SetDParam(0, ni->date);
|
|
|
|
DrawString(4, y, STR_SHORT_DATE, TC_WHITE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
DrawNewsString(82, y, TC_WHITE, ni, w->width - 95);
|
|
|
|
y += 12;
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
case WE_CLICK:
|
|
|
|
if (e->we.click.widget == 3) {
|
|
|
|
int y = (e->we.click.pt.y - 19) / 12;
|
|
|
|
NewsID p = getNews(y + w->vscroll.pos);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
if (p != INVALID_NEWS) ShowNewsMessage(p);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-01-22 23:13:20 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
case WE_RESIZE:
|
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 12;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _message_history_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 13, 11, 387, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 13, 388, 399, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RB, 13, 0, 387, 14, 139, 0x0, STR_MESSAGE_HISTORY_TIP},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 13, 388, 399, 14, 127, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 13, 388, 399, 128, 139, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _message_history_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
240, 22, 400, 140, 400, 140,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_MESSAGE_HISTORY, WC_NONE,
|
2005-01-22 23:13:20 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_message_history_widgets,
|
|
|
|
MessageHistoryWndProc
|
|
|
|
};
|
|
|
|
|
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-08 11:31:41 +00:00
|
|
|
Window *w = new Window(&_message_history_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-05 11:24:58 +00:00
|
|
|
if (w == NULL) return;
|
|
|
|
|
|
|
|
w->vscroll.cap = 10;
|
|
|
|
w->vscroll.count = _total_news;
|
|
|
|
w->resize.step_height = 12;
|
|
|
|
w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
|
|
|
|
w->resize.step_width = 1;
|
|
|
|
w->resize.width = 200; // can't make window any smaller than 200 pixel
|
2008-05-06 22:08:18 +00:00
|
|
|
w->SetDirty();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2007-11-15 22:20:33 +00:00
|
|
|
/** News settings window widget offset constants */
|
2007-03-10 03:33:43 +00:00
|
|
|
enum {
|
2008-01-17 20:00:13 +00:00
|
|
|
WIDGET_NEWSOPT_DROP_SUMMARY = 4, ///< Dropdown that adjusts at once the level for all settings
|
|
|
|
WIDGET_NEWSOPT_SOUNDTICKER = 6, ///< Button activating sound on events
|
|
|
|
WIDGET_NEWSOPT_START_OPTION = 8, ///< First widget that is part of a group [<] .. [.]
|
2007-03-10 03:33:43 +00:00
|
|
|
};
|
|
|
|
|
2007-09-17 17:07:24 +00:00
|
|
|
/**
|
|
|
|
* Setup the disabled/enabled buttons in the message window
|
2005-04-13 23:03:31 +00:00
|
|
|
* If the value is 'off' disable the [<] widget, and enable the [>] one
|
2007-03-10 03:33:43 +00:00
|
|
|
* Same-wise for all the others. Starting value of 4 is the first widget
|
2005-04-13 23:03:31 +00:00
|
|
|
* group. These are grouped as [<][>] .. [<][>], etc.
|
2007-03-10 03:33:43 +00:00
|
|
|
* @param w Window been used
|
|
|
|
* @param value to set in the widget
|
|
|
|
* @param element index of the group of widget to set
|
2005-04-13 23:03:31 +00:00
|
|
|
*/
|
|
|
|
static void SetMessageButtonStates(Window *w, byte value, int element)
|
|
|
|
{
|
2007-03-10 03:33:43 +00:00
|
|
|
element *= NB_WIDG_PER_SETTING;
|
2006-10-03 02:08:15 +00:00
|
|
|
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION, value == 0);
|
|
|
|
w->SetWidgetDisabledState(element + WIDGET_NEWSOPT_START_OPTION + 2, value == 2);
|
2005-04-13 23:03:31 +00:00
|
|
|
}
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2007-03-10 03:33:43 +00:00
|
|
|
/**
|
|
|
|
* Event handler of the Message Options window
|
|
|
|
* @param w window pointer
|
|
|
|
* @param e event been triggered
|
|
|
|
*/
|
2004-08-20 13:58:25 +00:00
|
|
|
static void MessageOptionsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-04-13 23:03:31 +00:00
|
|
|
static const StringID message_opt[] = {STR_OFF, STR_SUMMARY, STR_FULL, INVALID_STRING_ID};
|
|
|
|
|
2007-03-10 03:33:43 +00:00
|
|
|
/* WP(w, def_d).data_1 stores state of the ALL on/off/summary button */
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (e->event) {
|
2007-03-10 03:33:43 +00:00
|
|
|
case WE_CREATE: {
|
2008-04-20 11:40:33 +00:00
|
|
|
NewsDisplay all_val;
|
2005-04-13 23:03:31 +00:00
|
|
|
|
2007-03-10 03:33:43 +00:00
|
|
|
/* Set up the initial disabled buttons in the case of 'off' or 'full' */
|
2008-04-20 11:40:33 +00:00
|
|
|
all_val = _news_type_data[0].display;
|
|
|
|
for (int i = 0; i < NT_END; i++) {
|
|
|
|
SetMessageButtonStates(w, _news_type_data[i].display, i);
|
2007-03-13 12:05:41 +00:00
|
|
|
/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
|
2008-04-20 11:40:33 +00:00
|
|
|
if (_news_type_data[i].display != all_val) all_val = ND_OFF;
|
2007-03-13 12:05:41 +00:00
|
|
|
}
|
|
|
|
/* If all values are the same value, the ALL-button will take over this value */
|
|
|
|
WP(w, def_d).data_1 = all_val;
|
2008-05-05 11:24:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2008-05-05 11:24:58 +00:00
|
|
|
case WE_PAINT:
|
2007-12-02 14:29:48 +00:00
|
|
|
if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
|
2008-01-17 20:00:13 +00:00
|
|
|
|
|
|
|
w->widget[WIDGET_NEWSOPT_DROP_SUMMARY].data = message_opt[WP(w, def_d).data_1];
|
2007-03-10 03:33:43 +00:00
|
|
|
DrawWindowWidgets(w);
|
2005-04-13 23:03:31 +00:00
|
|
|
|
2007-03-10 03:33:43 +00:00
|
|
|
/* Draw the string of each setting on each button. */
|
2008-04-20 11:40:33 +00:00
|
|
|
for (int i = 0, y = 26; i < NT_END; i++, y += 12) {
|
2007-03-10 03:33:43 +00:00
|
|
|
/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
|
|
|
|
* which will give centered position */
|
2008-04-20 11:40:33 +00:00
|
|
|
DrawStringCentered(51, y + 1, message_opt[_news_type_data[i].display], TC_BLACK);
|
2007-03-10 03:33:43 +00:00
|
|
|
}
|
2008-05-05 11:24:58 +00:00
|
|
|
break;
|
2005-04-13 23:03:31 +00:00
|
|
|
|
2007-03-10 03:33:43 +00:00
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
case WIDGET_NEWSOPT_DROP_SUMMARY: // Dropdown menu for all settings
|
|
|
|
ShowDropDownMenu(w, message_opt, WP(w, def_d).data_1, WIDGET_NEWSOPT_DROP_SUMMARY, 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WIDGET_NEWSOPT_SOUNDTICKER: // Change ticker sound on/off
|
|
|
|
_news_ticker_sound ^= 1;
|
2007-12-02 14:29:48 +00:00
|
|
|
w->ToggleWidgetLoweredState(e->we.click.widget);
|
2007-12-07 18:05:49 +00:00
|
|
|
w->InvalidateWidget(e->we.click.widget);
|
2007-03-10 03:33:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: { // Clicked on the [<] .. [>] widgets
|
|
|
|
int wid = e->we.click.widget - WIDGET_NEWSOPT_START_OPTION;
|
|
|
|
if (wid >= 0 && wid < (NB_WIDG_PER_SETTING * NT_END)) {
|
|
|
|
int element = wid / NB_WIDG_PER_SETTING;
|
2008-04-20 11:40:33 +00:00
|
|
|
byte val = (_news_type_data[element].display + ((wid % NB_WIDG_PER_SETTING) ? 1 : -1)) % 3;
|
2007-03-10 03:33:43 +00:00
|
|
|
|
|
|
|
SetMessageButtonStates(w, val, element);
|
2008-04-20 11:40:33 +00:00
|
|
|
_news_type_data[element].display = (NewsDisplay)val;
|
2008-05-06 22:08:18 +00:00
|
|
|
w->SetDirty();
|
2007-03-10 03:33:43 +00:00
|
|
|
}
|
2008-05-05 11:24:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-28 16:45:20 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-03-10 03:33:43 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
case WE_DROPDOWN_SELECT: // Select all settings for newsmessages
|
2007-03-10 03:33:43 +00:00
|
|
|
WP(w, def_d).data_1 = e->we.dropdown.index;
|
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
for (int i = 0; i < NT_END; i++) {
|
2007-03-10 03:33:43 +00:00
|
|
|
SetMessageButtonStates(w, e->we.dropdown.index, i);
|
2008-04-20 11:40:33 +00:00
|
|
|
_news_type_data[i].display = (NewsDisplay)e->we.dropdown.index;
|
2005-04-13 23:03:31 +00:00
|
|
|
}
|
2008-05-06 22:08:18 +00:00
|
|
|
w->SetDirty();
|
2008-03-28 16:45:20 +00:00
|
|
|
break;
|
2004-08-20 13:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-15 22:20:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The news settings window widgets
|
|
|
|
*
|
|
|
|
* Main part of the window is a list of news-setting lines, one for each news category.
|
|
|
|
* Each line is constructed by an expansion of the \c NEWS_SETTINGS_LINE macro
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Macro to construct one news-setting line in the news-settings window.
|
|
|
|
* One line consists of four widgets, namely
|
|
|
|
* - A [<] button
|
|
|
|
* - A [...] label
|
|
|
|
* - A [>] button
|
|
|
|
* - A text label describing the news category
|
|
|
|
* Horizontal positions of the widgets are hard-coded, vertical start position is (\a basey + \a linenum * \c NEWS_SETTING_BASELINE_SKIP).
|
|
|
|
* Height of one line is 12, with the text label shifted 1 pixel down.
|
|
|
|
*
|
|
|
|
* First line should be widget number WIDGET_NEWSOPT_START_OPTION
|
|
|
|
*
|
|
|
|
* @param basey: Base Y coordinate
|
|
|
|
* @param linenum: Count, news-setting is the \a linenum-th line
|
|
|
|
* @param text: StringID for the text label to display
|
|
|
|
*/
|
|
|
|
#define NEWS_SETTINGS_LINE(basey, linenum, text) \
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, COLOUR_YELLOW, \
|
|
|
|
4, 12, basey + linenum * NEWS_SETTING_BASELINE_SKIP, basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
|
|
|
|
SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST}, \
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, \
|
|
|
|
13, 89, basey + linenum * NEWS_SETTING_BASELINE_SKIP, basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
|
|
|
|
STR_EMPTY, STR_NULL}, \
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, COLOUR_YELLOW, \
|
|
|
|
90, 98, basey + linenum * NEWS_SETTING_BASELINE_SKIP, basey + 11 + linenum * NEWS_SETTING_BASELINE_SKIP, \
|
|
|
|
SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST}, \
|
|
|
|
{ WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW, \
|
|
|
|
103, 409, basey + 1 + linenum * NEWS_SETTING_BASELINE_SKIP, basey + 13 + linenum * NEWS_SETTING_BASELINE_SKIP, \
|
|
|
|
text, STR_NULL}
|
|
|
|
|
|
|
|
static const int NEWS_SETTING_BASELINE_SKIP = 12; ///< Distance between two news-setting lines, should be at least 12
|
|
|
|
|
|
|
|
|
2004-08-20 13:58:25 +00:00
|
|
|
static const Widget _message_options_widgets[] = {
|
2007-11-15 22:20:33 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13,
|
|
|
|
STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_BROWN, 11, 409, 0, 13,
|
|
|
|
STR_0204_MESSAGE_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_BROWN, 0, 409, 14, 64 + NT_END * NEWS_SETTING_BASELINE_SKIP,
|
|
|
|
0x0, STR_NULL},
|
2007-03-10 03:33:43 +00:00
|
|
|
|
|
|
|
/* Text at the top of the main panel, in black */
|
2007-11-15 22:20:33 +00:00
|
|
|
{ WWT_LABEL, RESIZE_NONE, COLOUR_BROWN,
|
|
|
|
0, 409, 13, 26,
|
|
|
|
STR_0205_MESSAGE_TYPES, STR_NULL},
|
|
|
|
|
|
|
|
/* General drop down and sound button, widgets WIDGET_NEWSOPT_BTN_SUMMARY and WIDGET_NEWSOPT_DROP_SUMMARY */
|
2008-01-17 20:00:13 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_YELLOW,
|
|
|
|
4, 98, 34 + NT_END * NEWS_SETTING_BASELINE_SKIP, 45 + NT_END * NEWS_SETTING_BASELINE_SKIP,
|
2007-11-15 22:20:33 +00:00
|
|
|
0x0, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW,
|
|
|
|
103, 409, 35 + NT_END * NEWS_SETTING_BASELINE_SKIP, 47 + NT_END * NEWS_SETTING_BASELINE_SKIP,
|
|
|
|
STR_MESSAGES_ALL, STR_NULL},
|
|
|
|
|
|
|
|
/* Below is widget WIDGET_NEWSOPT_SOUNDTICKER */
|
|
|
|
{ WWT_TEXTBTN_2, RESIZE_NONE, COLOUR_YELLOW,
|
|
|
|
4, 98, 46 + NT_END * NEWS_SETTING_BASELINE_SKIP, 57 + NT_END * NEWS_SETTING_BASELINE_SKIP,
|
|
|
|
STR_02DB_OFF, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_TEXT, RESIZE_NONE, COLOUR_YELLOW,
|
|
|
|
103, 409, 47 + NT_END * NEWS_SETTING_BASELINE_SKIP, 59 + NT_END * NEWS_SETTING_BASELINE_SKIP,
|
|
|
|
STR_MESSAGE_SOUND, STR_NULL},
|
|
|
|
|
|
|
|
/* List of news-setting lines (4 widgets for each line).
|
|
|
|
* First widget must be number WIDGET_NEWSOPT_START_OPTION
|
|
|
|
*/
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_PLAYER, STR_0206_ARRIVAL_OF_FIRST_VEHICLE),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_OTHER, STR_0207_ARRIVAL_OF_FIRST_VEHICLE),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_ACCIDENT, STR_0208_ACCIDENTS_DISASTERS),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_COMPANY_INFO, STR_0209_COMPANY_INFORMATION),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_OPENCLOSE, STR_NEWS_OPEN_CLOSE),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_ECONOMY, STR_020A_ECONOMY_CHANGES),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_PLAYER, STR_INDUSTRY_CHANGES_SERVED_BY_PLAYER),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_OTHER, STR_INDUSTRY_CHANGES_SERVED_BY_OTHER),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_NOBODY, STR_OTHER_INDUSTRY_PRODUCTION_CHANGES),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_ADVICE, STR_020B_ADVICE_INFORMATION_ON_PLAYER),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_NEW_VEHICLES, STR_020C_NEW_VEHICLES),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_ACCEPTANCE, STR_020D_CHANGES_OF_CARGO_ACCEPTANCE),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_SUBSIDIES, STR_020E_SUBSIDIES),
|
|
|
|
NEWS_SETTINGS_LINE(26, NT_GENERAL, STR_020F_GENERAL_INFORMATION),
|
2004-09-07 21:48:09 +00:00
|
|
|
|
|
|
|
{ WIDGETS_END},
|
2004-08-20 13:58:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _message_options_desc = {
|
2007-11-15 22:20:33 +00:00
|
|
|
270, 22, 410, 65 + NT_END * NEWS_SETTING_BASELINE_SKIP,
|
|
|
|
410, 65 + NT_END * NEWS_SETTING_BASELINE_SKIP,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2004-08-20 13:58:25 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_message_options_widgets,
|
|
|
|
MessageOptionsWndProc
|
|
|
|
};
|
|
|
|
|
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-08 11:31:41 +00:00
|
|
|
new Window(&_message_options_desc);
|
2004-08-20 13:58:25 +00:00
|
|
|
}
|
2006-03-04 11:01:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DeleteVehicleNews(VehicleID vid, StringID news)
|
|
|
|
{
|
2008-03-28 16:45:20 +00:00
|
|
|
for (NewsID n = _oldest_news; _latest_news != INVALID_NEWS; n = IncreaseIndex(n)) {
|
2006-12-05 11:59:28 +00:00
|
|
|
const NewsItem *ni = &_news_items[n];
|
2006-03-04 11:01:35 +00:00
|
|
|
|
|
|
|
if (ni->flags & NF_VEHICLE &&
|
|
|
|
ni->data_a == vid &&
|
|
|
|
(news == INVALID_STRING_ID || ni->string_id == news)) {
|
2007-01-11 01:21:55 +00:00
|
|
|
/* If we delete a forced news and it is just before the current news
|
|
|
|
* then we need to advance to the next news (if any) */
|
|
|
|
if (_forced_news == n) MoveToNextItem();
|
|
|
|
if (_forced_news == INVALID_NEWS && _current_news == n) MoveToNextItem();
|
2006-12-05 22:35:25 +00:00
|
|
|
_total_news--;
|
2006-03-04 11:01:35 +00:00
|
|
|
|
2007-01-04 17:23:55 +00:00
|
|
|
/* If this is the last news item, invalidate _latest_news */
|
|
|
|
if (_total_news == 0) {
|
|
|
|
assert(_latest_news == _oldest_news);
|
2006-12-05 22:35:25 +00:00
|
|
|
_latest_news = INVALID_NEWS;
|
2008-04-13 11:15:48 +00:00
|
|
|
_current_news = INVALID_NEWS;
|
2006-12-05 22:35:25 +00:00
|
|
|
}
|
2006-03-04 11:01:35 +00:00
|
|
|
|
2006-12-05 22:35:25 +00:00
|
|
|
/* Since we only imitate a FIFO removing an arbitrary element does need
|
|
|
|
* some magic. Remove the item by shifting head towards the tail. eg
|
|
|
|
* oldest remove last
|
|
|
|
* | | |
|
|
|
|
* [------O--------n-----L--]
|
|
|
|
* will become (change dramatized to make clear)
|
|
|
|
* [---------O-----------L--]
|
2007-01-04 17:23:55 +00:00
|
|
|
* We also need an update of the current, forced and visible (open window)
|
|
|
|
* news's as this shifting could change the items they were pointing to */
|
2006-12-05 22:35:25 +00:00
|
|
|
if (_total_news != 0) {
|
2008-05-15 13:47:55 +00:00
|
|
|
NewsWindow *w = dynamic_cast<NewsWindow*>(FindWindowById(WC_NEWS_WINDOW, 0));
|
|
|
|
NewsID visible_news = (w != NULL) ? (NewsID)(w->ni - _news_items) : INVALID_NEWS;
|
2007-01-04 17:23:55 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
for (NewsID i = n;; i = DecreaseIndex(i)) {
|
|
|
|
_news_items[i] = _news_items[DecreaseIndex(i)];
|
2006-12-05 22:35:25 +00:00
|
|
|
|
2007-01-26 00:25:39 +00:00
|
|
|
if (i != _latest_news) {
|
2008-03-28 16:45:20 +00:00
|
|
|
if (i == _current_news) _current_news = IncreaseIndex(_current_news);
|
|
|
|
if (i == _forced_news) _forced_news = IncreaseIndex(_forced_news);
|
2008-05-15 13:47:55 +00:00
|
|
|
if (i == visible_news) w->ni = &_news_items[IncreaseIndex(visible_news)];
|
2007-01-26 00:25:39 +00:00
|
|
|
}
|
2007-01-04 17:23:55 +00:00
|
|
|
|
2007-01-05 11:41:11 +00:00
|
|
|
if (i == _oldest_news) break;
|
|
|
|
}
|
2008-03-28 16:45:20 +00:00
|
|
|
_oldest_news = IncreaseIndex(_oldest_news);
|
2006-03-04 11:01:35 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 01:21:55 +00:00
|
|
|
/*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
|
|
|
|
_current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
|
2007-01-04 17:23:55 +00:00
|
|
|
|
2008-03-28 16:45:20 +00:00
|
|
|
Window *w = FindWindowById(WC_MESSAGE_HISTORY, 0);
|
2006-03-04 17:18:13 +00:00
|
|
|
if (w != NULL) {
|
2008-05-06 22:08:18 +00:00
|
|
|
w->SetDirty();
|
2006-03-04 17:18:13 +00:00
|
|
|
w->vscroll.count = _total_news;
|
|
|
|
}
|
2006-03-04 11:01:35 +00:00
|
|
|
}
|
2006-12-05 22:35:25 +00:00
|
|
|
|
|
|
|
if (n == _latest_news) break;
|
2006-03-04 11:01:35 +00:00
|
|
|
}
|
|
|
|
}
|