2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.h"
|
2005-04-13 23:03:31 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "news.h"
|
|
|
|
#include "vehicle.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
/* News system
|
|
|
|
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
|
2004-09-10 19:02:27 +00:00
|
|
|
array is full, the oldest entry (_oldest_news) is being overwritten
|
2004-08-18 23:38:53 +00:00
|
|
|
by the newest (_latest news).
|
|
|
|
|
|
|
|
oldest current lastest
|
|
|
|
| | |
|
|
|
|
[O------------F-------------C---------L ]
|
|
|
|
|
|
|
|
|
forced
|
|
|
|
*/
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
#define MAX_NEWS 30
|
|
|
|
|
|
|
|
#define INVALID_NEWS 255
|
2004-08-18 23:38:53 +00:00
|
|
|
|
|
|
|
static NewsItem _news_items[MAX_NEWS];
|
2004-11-15 12:05:01 +00:00
|
|
|
static byte _current_news = INVALID_NEWS; // points to news item that should be shown next
|
2004-08-18 23:38:53 +00:00
|
|
|
static byte _oldest_news = 0; // points to first item in fifo queue
|
2004-11-15 12:05:01 +00:00
|
|
|
static byte _latest_news = INVALID_NEWS; // points to last item in fifo queue
|
|
|
|
/* if the message being shown was forced by the user, its index is stored in
|
|
|
|
* _forced_news. forced_news is INVALID_NEWS otherwise.
|
|
|
|
* (Users can force messages through history or "last message") */
|
|
|
|
static byte _forced_news = INVALID_NEWS;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
|
|
|
static byte _total_news = 0; // total news count
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
void DrawNewsNewTrainAvail(Window *w);
|
|
|
|
void DrawNewsNewRoadVehAvail(Window *w);
|
|
|
|
void DrawNewsNewShipAvail(Window *w);
|
|
|
|
void DrawNewsNewAircraftAvail(Window *w);
|
|
|
|
void DrawNewsBankrupcy(Window *w);
|
2004-11-15 12:05:01 +00:00
|
|
|
static void MoveToNexItem(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 16:02:17 +00:00
|
|
|
StringID GetNewsStringNewTrainAvail(const NewsItem *ni);
|
|
|
|
StringID GetNewsStringNewRoadVehAvail(const NewsItem *ni);
|
|
|
|
StringID GetNewsStringNewShipAvail(const NewsItem *ni);
|
|
|
|
StringID GetNewsStringNewAircraftAvail(const NewsItem *ni);
|
|
|
|
StringID GetNewsStringBankrupcy(const NewsItem *ni);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static DrawNewsCallbackProc * const _draw_news_callback[] = {
|
2004-11-15 12:05:01 +00:00
|
|
|
DrawNewsNewTrainAvail, /* DNC_TRAINAVAIL */
|
|
|
|
DrawNewsNewRoadVehAvail, /* DNC_ROADAVAIL */
|
|
|
|
DrawNewsNewShipAvail, /* DNC_SHIPAVAIL */
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawNewsNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
|
2004-11-15 12:05:01 +00:00
|
|
|
DrawNewsBankrupcy, /* DNC_BANKRUPCY */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GetNewsStringCallbackProc * const _get_news_string_callback[] = {
|
2004-11-15 12:05:01 +00:00
|
|
|
GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */
|
|
|
|
GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */
|
|
|
|
GetNewsStringNewShipAvail, /* DNC_SHIPAVAIL */
|
2004-08-09 17:04:08 +00:00
|
|
|
GetNewsStringNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
|
2004-11-15 12:05:01 +00:00
|
|
|
GetNewsStringBankrupcy, /* DNC_BANKRUPCY */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
void InitNewsItemStructs(void)
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
memset(_news_items, 0, sizeof(_news_items));
|
|
|
|
_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
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
void DrawNewsBorder(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int left = 0;
|
|
|
|
int right = w->width - 1;
|
|
|
|
int top = 0;
|
|
|
|
int bottom = w->height - 1;
|
|
|
|
|
|
|
|
GfxFillRect(left, top, right, bottom, 0xF);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +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);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
|
|
|
DrawString(left + 2, top + 1, STR_00C6, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void NewsWindowProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (e->event) {
|
2005-04-05 21:03:30 +00:00
|
|
|
case WE_CREATE: { /* If chatbar is open at creation time, we need to go above it */
|
|
|
|
const Window *w1 = FindWindowById(WC_SEND_NETWORK_MSG, 0);
|
|
|
|
w->message.msg = (w1 != NULL) ? w1->height : 0;
|
|
|
|
} break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2004-11-15 12:05:01 +00:00
|
|
|
const NewsItem *ni = WP(w, news_d).ni;
|
2004-08-09 17:04:08 +00:00
|
|
|
ViewPort *vp;
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (ni->display_mode) {
|
|
|
|
case NM_NORMAL:
|
|
|
|
case NM_THIN: {
|
|
|
|
DrawNewsBorder(w);
|
|
|
|
|
|
|
|
DrawString(2, 1, STR_00C6, 0);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, ni->date);
|
2004-11-15 12:05:01 +00:00
|
|
|
DrawStringRightAligned(428, 1, STR_01FF, 0);
|
|
|
|
|
|
|
|
if (!(ni->flags & NF_VIEWPORT)) {
|
|
|
|
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
|
|
DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56,
|
|
|
|
ni->string_id, 426);
|
|
|
|
} else {
|
|
|
|
byte bk = _display_opt;
|
2004-11-23 22:36:11 +00:00
|
|
|
_display_opt &= ~DO_TRANS_BUILDINGS;
|
2004-11-15 12:05:01 +00:00
|
|
|
DrawWindowViewport(w);
|
|
|
|
_display_opt = bk;
|
|
|
|
|
|
|
|
/* Shade the viewport into gray, or color*/
|
|
|
|
vp = w->viewport;
|
|
|
|
GfxFillRect(vp->left - w->left, vp->top - w->top,
|
|
|
|
vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1,
|
|
|
|
ni->flags & NF_INCOLOR ? 0x4322 : 0x4323
|
|
|
|
);
|
|
|
|
|
|
|
|
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
|
|
DrawStringMultiCenter(w->width / 2, 20, ni->string_id, 428);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
case NM_CALLBACK: {
|
|
|
|
_draw_news_callback[ni->callback](w);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
|
|
|
|
default: {
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
if (!(ni->flags & NF_VIEWPORT)) {
|
|
|
|
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
|
|
DrawStringMultiCenter(140, 38, ni->string_id, 276);
|
|
|
|
} else {
|
|
|
|
DrawWindowViewport(w);
|
|
|
|
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
|
|
|
DrawStringMultiCenter(w->width / 2, w->height - 16, ni->string_id, 276);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (e->click.widget) {
|
2004-08-18 23:38:53 +00:00
|
|
|
case 1: {
|
2004-11-15 12:05:01 +00:00
|
|
|
NewsItem *ni = WP(w, news_d).ni;
|
2004-08-19 09:03:35 +00:00
|
|
|
DeleteWindow(w);
|
2004-08-18 23:38:53 +00:00
|
|
|
ni->duration = 0;
|
2004-11-15 12:05:01 +00:00
|
|
|
_forced_news = INVALID_NEWS;
|
2004-08-18 23:38:53 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0: {
|
2004-11-15 12:05:01 +00:00
|
|
|
NewsItem *ni = WP(w, news_d).ni;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ni->flags & NF_VEHICLE) {
|
2005-01-06 22:31:58 +00:00
|
|
|
Vehicle *v = GetVehicle(ni->data_a);
|
2004-08-09 17:04:08 +00:00
|
|
|
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
|
|
|
} else if (ni->flags & NF_TILE) {
|
|
|
|
if (!ScrollMainWindowToTile(ni->data_a) && ni->data_b != 0)
|
|
|
|
ScrollMainWindowToTile(ni->data_b);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_KEYPRESS:
|
|
|
|
if (e->keypress.keycode == WKC_SPACE) {
|
|
|
|
// Don't continue.
|
|
|
|
e->keypress.cont = false;
|
|
|
|
DeleteWindow(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
case WE_MESSAGE: /* The chatbar has notified us that is was either created or closed */
|
|
|
|
switch (e->message.msg) {
|
|
|
|
case WE_CREATE: w->message.msg = e->message.wparam; break;
|
|
|
|
case WE_DESTROY: w->message.msg = 0; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_TICK: { /* Scroll up newsmessages from the bottom in steps of 4 pixels */
|
|
|
|
int diff;
|
|
|
|
int y = max(w->top - 4, _screen.height - w->height - 12 - w->message.msg);
|
|
|
|
if (y == w->top) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (w->viewport != NULL)
|
|
|
|
w->viewport->top += y - w->top;
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
diff = abs(w->top - y);
|
2004-08-09 17:04:08 +00:00
|
|
|
w->top = y;
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
SetDirtyBlocks(w->left, w->top - diff, w->left + w->width, w->top + w->height);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// returns the correct index in the array
|
|
|
|
// (to deal with overflows)
|
2005-01-22 22:47:58 +00:00
|
|
|
static byte increaseIndex(byte i)
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
if (i == INVALID_NEWS)
|
2004-08-19 13:39:50 +00:00
|
|
|
return 0;
|
|
|
|
i++;
|
2004-11-15 12:05:01 +00:00
|
|
|
if (i >= MAX_NEWS)
|
2004-08-19 13:39:50 +00:00
|
|
|
i = i % MAX_NEWS;
|
2004-08-18 23:38:53 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
|
|
|
|
{
|
|
|
|
NewsItem *ni;
|
2004-08-18 23:38:53 +00:00
|
|
|
Window *w;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (_game_mode == GM_MENU)
|
|
|
|
return;
|
|
|
|
|
2004-08-21 22:04:25 +00:00
|
|
|
// check the rare case that the oldest (to be overwritten) news item is open
|
2005-01-08 09:09:11 +00:00
|
|
|
if (_total_news==MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news))
|
2004-08-21 22:04:25 +00:00
|
|
|
MoveToNexItem();
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
_forced_news = INVALID_NEWS;
|
|
|
|
if (_total_news < MAX_NEWS) _total_news++;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// make sure our pointer isn't overflowing
|
2004-08-19 13:39:50 +00:00
|
|
|
_latest_news = increaseIndex(_latest_news);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// overwrite oldest news entry
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_oldest_news == _latest_news && _news_items[_oldest_news].string_id != 0)
|
2004-08-19 13:39:50 +00:00
|
|
|
_oldest_news = increaseIndex(_oldest_news); // but make sure we're not overflowing here
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// add news to _latest_news
|
|
|
|
ni = &_news_items[_latest_news];
|
2004-12-21 16:54:46 +00:00
|
|
|
memset(ni, 0, sizeof(*ni));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
ni->string_id = string;
|
|
|
|
ni->display_mode = (byte)flags;
|
|
|
|
ni->flags = (byte)(flags >> 8) | NF_NOEXPIRE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// show this news message in color?
|
|
|
|
if (_date >= ConvertIntDate(_patches.colored_news_date))
|
|
|
|
ni->flags |= NF_INCOLOR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
ni->type = (byte)(flags >> 16);
|
|
|
|
ni->callback = (byte)(flags >> 24);
|
|
|
|
ni->data_a = data_a;
|
|
|
|
ni->data_b = data_b;
|
|
|
|
ni->date = _date;
|
|
|
|
COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params));
|
|
|
|
|
|
|
|
w = FindWindowById(WC_MESSAGE_HISTORY, 0);
|
2004-11-15 12:05:01 +00:00
|
|
|
if (w == NULL) return;
|
2004-08-18 23:38:53 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
w->vscroll.count = _total_news;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-19 09:39:19 +00:00
|
|
|
/* To add a news item with an attached validation function. This validation function
|
|
|
|
* makes sure that the news item is not outdated when the newspaper pops up. */
|
2004-12-19 13:06:20 +00:00
|
|
|
void AddValidatedNewsItem(StringID string, uint32 flags, uint data_a, uint data_b, ValidationProc *validation)
|
2004-12-19 09:39:19 +00:00
|
|
|
{
|
|
|
|
AddNewsItem(string, flags, data_a, data_b);
|
|
|
|
_news_items[_latest_news].isValid = validation;
|
|
|
|
}
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// don't show item if it's older than x days
|
2004-08-09 17:04:08 +00:00
|
|
|
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
WDP_CENTER, 476, 430, 170,
|
2004-11-15 12:05:01 +00:00
|
|
|
WC_NEWS_WINDOW, 0,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_DEF_WIDGET,
|
|
|
|
_news_type13_widgets,
|
|
|
|
NewsWindowProc
|
|
|
|
};
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
WDP_CENTER, 476, 430, 130,
|
2004-11-15 12:05:01 +00:00
|
|
|
WC_NEWS_WINDOW, 0,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_DEF_WIDGET,
|
|
|
|
_news_type2_widgets,
|
|
|
|
NewsWindowProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _news_type0_widgets[] = {
|
2005-01-03 19:45:18 +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_NULL},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 279, 0, 13, STR_012C_MESSAGE, STR_NULL},
|
|
|
|
{ WWT_6, 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 = {
|
|
|
|
WDP_CENTER, 476, 280, 87,
|
2004-11-15 12:05:01 +00:00
|
|
|
WC_NEWS_WINDOW, 0,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_DEF_WIDGET,
|
|
|
|
_news_type0_widgets,
|
|
|
|
NewsWindowProc
|
|
|
|
};
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
static const SoundFx _news_sounds[] = {
|
|
|
|
SND_1D_APPLAUSE,
|
|
|
|
SND_1D_APPLAUSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
SND_1E_OOOOH,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-13 23:03:31 +00:00
|
|
|
/** Get the value of an item of the news-display settings. This is
|
|
|
|
* a little tricky since on/off/summary must use 2 bits to store the value
|
|
|
|
* @param item the item whose value is requested
|
|
|
|
* @return return the found value which is between 0-2
|
|
|
|
*/
|
|
|
|
static inline byte GetNewsDisplayValue(byte item)
|
|
|
|
{
|
|
|
|
assert(item < 10 && ((_news_display_opt >> (item * 2)) & 0x3) <= 2);
|
|
|
|
return (_news_display_opt >> (item * 2)) & 0x3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the value of an item in the news-display settings. This is
|
|
|
|
* a little tricky since on/off/summary must use 2 bits to store the value
|
|
|
|
* @param item the item whose value is being set
|
|
|
|
* @param val new value
|
|
|
|
*/
|
|
|
|
static inline void SetNewsDisplayValue(byte item, byte val)
|
|
|
|
{
|
|
|
|
assert(item < 10 && val <= 2);
|
|
|
|
item *= 2;
|
|
|
|
CLRBIT(_news_display_opt, item);
|
|
|
|
CLRBIT(_news_display_opt, item + 1);
|
|
|
|
_news_display_opt |= val << item;
|
|
|
|
}
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// open up an own newspaper window for the news item
|
|
|
|
static void ShowNewspaper(NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
int sound;
|
2004-08-18 23:38:53 +00:00
|
|
|
int top;
|
2004-11-15 12:05:01 +00:00
|
|
|
ni->flags &= ~(NF_NOEXPIRE | NF_FORCE_BIG);
|
2004-08-18 23:38:53 +00:00
|
|
|
ni->duration = 555;
|
|
|
|
|
|
|
|
sound = _news_sounds[ni->type];
|
|
|
|
if (sound != 0)
|
|
|
|
SndPlayFx(sound);
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
top = _screen.height;
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (ni->display_mode) {
|
|
|
|
case NM_NORMAL:
|
|
|
|
case NM_CALLBACK: {
|
|
|
|
_news_type13_desc.top = top;
|
|
|
|
w = AllocateWindowDesc(&_news_type13_desc);
|
|
|
|
if (ni->flags & NF_VIEWPORT)
|
|
|
|
AssignWindowViewport(w, 2, 58, 0x1AA, 0x6E,
|
|
|
|
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
|
|
|
|
break;
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
|
|
|
|
case NM_THIN: {
|
|
|
|
_news_type2_desc.top = top;
|
|
|
|
w = AllocateWindowDesc(&_news_type2_desc);
|
|
|
|
if (ni->flags & NF_VIEWPORT)
|
|
|
|
AssignWindowViewport(w, 2, 58, 0x1AA, 0x46,
|
|
|
|
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
|
|
|
|
break;
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
|
|
|
|
default: {
|
|
|
|
_news_type0_desc.top = top;
|
|
|
|
w = AllocateWindowDesc(&_news_type0_desc);
|
|
|
|
if (ni->flags & NF_VIEWPORT)
|
|
|
|
AssignWindowViewport(w, 3, 17, 0x112, 0x2F,
|
|
|
|
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
|
|
|
|
break;
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-15 12:05:01 +00:00
|
|
|
WP(w, news_d).ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news];
|
2004-08-18 23:38:53 +00:00
|
|
|
w->flags4 |= WF_DISABLE_VP_SCROLL;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +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
|
|
|
{
|
|
|
|
Window *w;
|
2004-08-09 17:04:08 +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;
|
|
|
|
w = FindWindowById(WC_STATUS_BAR, 0);
|
2004-11-15 12:05:01 +00:00
|
|
|
if (w != NULL)
|
|
|
|
WP(w, def_d).data_1 = 360;
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Are we ready to show another news item?
|
|
|
|
// Only if nothing is in the newsticker and no newspaper is displayed
|
2004-11-15 12:05:01 +00:00
|
|
|
static bool ReadyForNextItem(void)
|
2004-08-18 23:38:53 +00:00
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
const Window *w;
|
|
|
|
byte item = _forced_news == INVALID_NEWS ? _current_news : _forced_news;
|
2004-08-20 15:37:44 +00:00
|
|
|
NewsItem *ni;
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
if (item >= MAX_NEWS) return true;
|
2004-08-20 15:37:44 +00:00
|
|
|
ni = &_news_items[item];
|
2004-08-18 23:38:53 +00:00
|
|
|
|
|
|
|
// Ticker message
|
|
|
|
// Check if the status bar message is still being displayed?
|
|
|
|
w = FindWindowById(WC_STATUS_BAR, 0);
|
2004-11-15 12:05:01 +00:00
|
|
|
if (w != NULL && WP(w, def_d).data_1 > -1280)
|
2004-08-18 23:38:53 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// Newspaper message
|
|
|
|
// Wait until duration reaches 0
|
|
|
|
if (ni->duration != 0) {
|
|
|
|
ni->duration--;
|
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// neither newsticker nor newspaper are running
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
static void MoveToNexItem(void)
|
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
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// if we're not at the last item, than move on
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_current_news != _latest_news) {
|
2004-08-18 23:38:53 +00:00
|
|
|
NewsItem *ni;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-19 13:39:50 +00:00
|
|
|
_current_news = increaseIndex(_current_news);
|
2004-08-18 23:38:53 +00:00
|
|
|
ni = &_news_items[_current_news];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// check the date, don't show too old items
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_date - _news_items_age[ni->type] > ni->date)
|
2004-08-18 23:38:53 +00:00
|
|
|
return;
|
|
|
|
|
2004-12-19 09:39:19 +00:00
|
|
|
// execute the validation function to see if this item is still valid
|
|
|
|
if ( ni->isValid != NULL && !ni->isValid(ni->data_a, ni->data_b) )
|
|
|
|
return;
|
|
|
|
|
2005-04-13 23:03:31 +00:00
|
|
|
switch (GetNewsDisplayValue(ni->type)) {
|
|
|
|
case 0: { /* Off - show nothing only a small reminder in the status bar */
|
|
|
|
Window *w = FindWindowById(WC_STATUS_BAR, 0);
|
|
|
|
if (w != NULL) {
|
|
|
|
WP(w, def_d).data_2 = 91;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 1: /* Summary - show ticker, but if forced big, cascade to full */
|
|
|
|
if (!(ni->flags & NF_FORCE_BIG)) {
|
|
|
|
ShowTicker(ni);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fallthrough */
|
|
|
|
case 2: /* Full - show newspaper*/
|
|
|
|
ShowNewspaper(ni);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-08-18 23:38:53 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
void NewsLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-08-18 23:38:53 +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
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
if (ReadyForNextItem())
|
2004-08-18 23:38:53 +00:00
|
|
|
MoveToNexItem();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
/* Do a forced show of a specific message */
|
2005-01-22 22:47:58 +00:00
|
|
|
static void ShowNewsMessage(byte 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
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Delete the news window
|
|
|
|
DeleteWindowById(WC_NEWS_WINDOW, 0);
|
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
// setup forced news item
|
|
|
|
_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;
|
|
|
|
ni->flags |= NF_NOEXPIRE | NF_FORCE_BIG;
|
|
|
|
DeleteWindowById(WC_NEWS_WINDOW, 0);
|
|
|
|
ShowNewspaper(ni);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
void ShowLastNewsMessage(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_forced_news == INVALID_NEWS)
|
2004-08-18 23:38:53 +00:00
|
|
|
ShowNewsMessage(_current_news);
|
2004-11-15 12:05:01 +00:00
|
|
|
else if (_forced_news != 0)
|
|
|
|
ShowNewsMessage(_forced_news - 1);
|
2004-08-19 13:39:50 +00:00
|
|
|
else {
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_total_news != MAX_NEWS)
|
2004-08-19 13:39:50 +00:00
|
|
|
ShowNewsMessage(_latest_news);
|
|
|
|
else
|
2004-11-15 12:05:01 +00:00
|
|
|
ShowNewsMessage(MAX_NEWS - 1);
|
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
|
2004-11-15 12:05:01 +00:00
|
|
|
recent news. Returns INVALID_NEWS if end of queue reached. */
|
2004-08-18 23:38:53 +00:00
|
|
|
static byte getNews(byte i)
|
|
|
|
{
|
2004-11-15 12:05:01 +00:00
|
|
|
if (i >= _total_news)
|
|
|
|
return INVALID_NEWS;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_latest_news < i)
|
2004-08-20 13:58:25 +00:00
|
|
|
i = _latest_news + MAX_NEWS - i;
|
|
|
|
else
|
|
|
|
i = _latest_news - i;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
i %= MAX_NEWS;
|
2004-08-18 23:38:53 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2005-07-17 16:02:17 +00:00
|
|
|
/** Draw an unformatted news message truncated to a maximum length. If
|
|
|
|
* 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];
|
|
|
|
char *ptr, *dest;
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ni->display_mode == 3) {
|
|
|
|
str = _get_news_string_callback[ni->callback](ni);
|
|
|
|
} else {
|
|
|
|
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
|
2004-09-10 19:02:27 +00:00
|
|
|
str = ni->string_id;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-17 16:02:17 +00:00
|
|
|
GetString(buffer, str);
|
|
|
|
/* Copy the just gotten string to another buffer to remove any formatting
|
|
|
|
* from it such as big fonts, etc. */
|
|
|
|
for (ptr = buffer, dest = buffer2; *ptr != '\0'; ptr++) {
|
2005-07-21 06:31:02 +00:00
|
|
|
if (*ptr == '\r') {
|
2005-07-17 16:02:17 +00:00
|
|
|
dest[0] = dest[1] = dest[2] = dest[3] = ' ';
|
|
|
|
dest += 4;
|
|
|
|
} else if ((byte)*ptr >= ' ' && ((byte)*ptr < 0x88 || (byte)*ptr >= 0x99)) {
|
|
|
|
*dest++ = *ptr;
|
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) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2004-11-15 12:05:01 +00:00
|
|
|
int y = 19;
|
2004-08-18 23:38:53 +00:00
|
|
|
byte p, show;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_total_news == 0) break;
|
2005-01-22 23:13:20 +00:00
|
|
|
show = min(_total_news, w->vscroll.cap);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
|
2004-08-18 23:38:53 +00:00
|
|
|
// get news in correct order
|
2005-07-17 16:02:17 +00:00
|
|
|
const NewsItem *ni = &_news_items[getNews(p)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, ni->date);
|
2005-07-17 16:02:17 +00:00
|
|
|
DrawString(4, y, STR_SHORT_DATE, 12);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 16:02:17 +00:00
|
|
|
DrawNewsString(82, y, 12, ni, w->width - 95);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 12;
|
|
|
|
}
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (e->click.widget) {
|
2005-01-22 23:13:20 +00:00
|
|
|
case 3: {
|
2004-08-18 23:38:53 +00:00
|
|
|
int y = (e->click.pt.y - 19) / 12;
|
|
|
|
byte p, q;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
#if 0 // === DEBUG code only
|
|
|
|
for (p = 0; p < _total_news; p++)
|
2004-08-20 13:58:25 +00:00
|
|
|
{
|
|
|
|
NewsItem *ni;
|
|
|
|
byte buffer[256];
|
2004-11-15 12:05:01 +00:00
|
|
|
ni = &_news_items[p];
|
2004-08-20 13:58:25 +00:00
|
|
|
GetNewsString(ni, buffer);
|
|
|
|
printf("%i\t%i\t%s\n", p, ni->date, buffer);
|
|
|
|
}
|
|
|
|
printf("=========================\n");
|
2004-11-15 12:05:01 +00:00
|
|
|
#endif
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2004-08-18 23:38:53 +00:00
|
|
|
p = y + w->vscroll.pos;
|
2004-11-15 12:05:01 +00:00
|
|
|
if (p > _total_news - 1) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
if (_latest_news >= p)
|
|
|
|
q = _latest_news - p;
|
|
|
|
else
|
|
|
|
q = _latest_news + MAX_NEWS - p;
|
2004-08-18 23:38:53 +00:00
|
|
|
ShowNewsMessage(q);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-01-22 23:13:20 +00:00
|
|
|
|
|
|
|
case WE_RESIZE:
|
|
|
|
w->vscroll.cap += e->sizing.diff.y / 12;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _message_history_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-22 23:13:20 +00:00
|
|
|
{ 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},
|
|
|
|
{ WWT_IMGBTN, RESIZE_RB, 13, 0, 387, 14, 139, 0x0, STR_MESSAGE_HISTORY_TIP},
|
|
|
|
{ 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 = {
|
2004-08-18 23:38:53 +00:00
|
|
|
240, 22, 400, 140,
|
2004-11-15 12:05:01 +00:00
|
|
|
WC_MESSAGE_HISTORY, 0,
|
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
|
|
|
|
};
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
void ShowMessageHistory(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
2004-08-18 23:38:53 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindowById(WC_MESSAGE_HISTORY, 0);
|
|
|
|
w = AllocateWindowDesc(&_message_history_desc);
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
if (w != NULL) {
|
2004-08-18 23:38:53 +00:00
|
|
|
w->vscroll.cap = 10;
|
|
|
|
w->vscroll.count = _total_news;
|
2005-01-22 23:13:20 +00:00
|
|
|
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
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 23:03:31 +00:00
|
|
|
/** Setup the disabled/enabled buttons in the message window
|
|
|
|
* If the value is 'off' disable the [<] widget, and enable the [>] one
|
|
|
|
* Same-wise for all the others. Starting value of 3 is the first widget
|
|
|
|
* group. These are grouped as [<][>] .. [<][>], etc.
|
|
|
|
*/
|
|
|
|
static void SetMessageButtonStates(Window *w, byte value, int element)
|
|
|
|
{
|
|
|
|
element *= 2;
|
|
|
|
switch (value) {
|
|
|
|
case 0: /* Off */
|
|
|
|
SETBIT(w->disabled_state, element + 3);
|
|
|
|
CLRBIT(w->disabled_state, element + 3 + 1);
|
|
|
|
break;
|
|
|
|
case 1: /* Summary */
|
|
|
|
CLRBIT(w->disabled_state, element + 3);
|
|
|
|
CLRBIT(w->disabled_state, element + 3 + 1);
|
|
|
|
break;
|
|
|
|
case 2: /* Full */
|
|
|
|
SETBIT(w->disabled_state, element + 3 + 1);
|
|
|
|
CLRBIT(w->disabled_state, element + 3);
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
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};
|
|
|
|
static const uint32 message_val[] = {0x0, 0x55555555, 0xAAAAAAAA}; // 0x555.. = 01010101010101010101 (all summary), 286.. 1010... (full)
|
|
|
|
static const uint32 message_dis[] = {
|
|
|
|
(1 << 3) | (1 << 5) | (1 << 7) | (1 << 9) | (1 << 11) | (1 << 13) | (1 << 15) | (1 << 17) | (1 << 19) | (1 << 21),
|
|
|
|
0,
|
|
|
|
(1 << 4) | (1 << 6) | (1 << 8) | (1 << 10) | (1 << 12) | (1 << 14) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 22),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* WP(w, def_d).data_1 are stores the clicked state of the fake widgets
|
|
|
|
* WP(w, def_d).data_2 stores state of the ALL on/off/summary button */
|
2004-11-15 12:05:01 +00:00
|
|
|
switch (e->event) {
|
2005-04-13 23:03:31 +00:00
|
|
|
case WE_CREATE: {
|
|
|
|
uint32 val = _news_display_opt;
|
|
|
|
int i;
|
|
|
|
WP(w, def_d).data_1 = WP(w, def_d).data_2 = 0;
|
|
|
|
|
|
|
|
// Set up the initial disabled buttons in the case of 'off' or 'full'
|
|
|
|
for (i = 0; i != 10; i++, val >>= 2) SetMessageButtonStates(w, val & 0x3, i);
|
|
|
|
} break;
|
|
|
|
|
2004-08-20 13:58:25 +00:00
|
|
|
case WE_PAINT: {
|
2005-04-13 23:03:31 +00:00
|
|
|
uint32 val = _news_display_opt;
|
|
|
|
int click_state = WP(w, def_d).data_1;
|
2004-08-20 13:58:25 +00:00
|
|
|
int i, y;
|
|
|
|
|
2005-04-13 23:03:31 +00:00
|
|
|
if (_news_ticker_sound) SETBIT(w->click_state, 25);
|
2004-08-20 13:58:25 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0);
|
|
|
|
|
2005-04-13 23:03:31 +00:00
|
|
|
/* XXX - Draw the fake widgets-buttons. Can't add these to the widget-desc since
|
|
|
|
* openttd currently can only handle 32 widgets. So hack it *g* */
|
|
|
|
for (i = 0, y = 26; i != 10; i++, y += 12, click_state >>= 1, val >>= 2) {
|
|
|
|
bool clicked = !!(click_state & 1);
|
|
|
|
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(13, y, 89, 11 + y, 3, (clicked) ? FR_LOWERED : 0);
|
2005-04-13 23:03:31 +00:00
|
|
|
DrawStringCentered(((13 + 89 + 1) >> 1) + clicked, ((y + 11 + y + 1) >> 1) - 5 + clicked, message_opt[val & 0x3], 0x10);
|
|
|
|
DrawString(103, y + 1, i + STR_0206_ARRIVAL_OF_FIRST_VEHICLE, 0);
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-20 13:58:25 +00:00
|
|
|
|
2005-04-13 23:03:31 +00:00
|
|
|
DrawString( 8, y + 9, message_opt[WP(w, def_d).data_2], 0x10);
|
|
|
|
DrawString(103, y + 9, STR_MESSAGES_ALL, 0);
|
|
|
|
DrawString(103, y + 9 + 12, STR_MESSAGE_SOUND, 0);
|
2004-08-20 13:58:25 +00:00
|
|
|
|
|
|
|
} break;
|
2005-04-13 23:03:31 +00:00
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->click.widget) {
|
|
|
|
case 2: /* Clicked on any of the fake widgets */
|
|
|
|
if (e->click.pt.x > 13 && e->click.pt.x < 89 && e->click.pt.y > 26 && e->click.pt.y < 146) {
|
|
|
|
int element = (e->click.pt.y - 26) / 12;
|
|
|
|
byte val = (GetNewsDisplayValue(element) + 1) % 3;
|
|
|
|
|
|
|
|
SetMessageButtonStates(w, val, element);
|
|
|
|
SetNewsDisplayValue(element, val);
|
|
|
|
|
|
|
|
WP(w, def_d).data_1 |= (1 << element);
|
|
|
|
w->flags4 |= 5 << WF_TIMEOUT_SHL; // XXX - setup unclick (fake widget)
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 23: case 24: /* Dropdown menu for all settings */
|
|
|
|
ShowDropDownMenu(w, message_opt, WP(w, def_d).data_2, 24, 0, 0);
|
|
|
|
break;
|
|
|
|
case 25: /* Change ticker sound on/off */
|
|
|
|
_news_ticker_sound ^= 1;
|
|
|
|
TOGGLEBIT(w->click_state, e->click.widget);
|
|
|
|
InvalidateWidget(w, e->click.widget);
|
|
|
|
break;
|
|
|
|
default: { /* Clicked on the [<] .. [>] widgets */
|
|
|
|
int wid = e->click.widget;
|
|
|
|
if (wid > 2 && wid < 23) {
|
|
|
|
int element = (wid - 3) / 2;
|
|
|
|
byte val = (GetNewsDisplayValue(element) + ((wid & 1) ? -1 : 1)) % 3;
|
|
|
|
|
|
|
|
SetMessageButtonStates(w, val, element);
|
|
|
|
SetNewsDisplayValue(element, val);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_DROPDOWN_SELECT: /* Select all settings for newsmessages */
|
|
|
|
WP(w, def_d).data_2 = e->dropdown.index;
|
|
|
|
_news_display_opt = message_val[WP(w, def_d).data_2];
|
|
|
|
w->disabled_state = message_dis[WP(w, def_d).data_2];
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_TIMEOUT: /* XXX - Hack to animate 'fake' buttons */
|
|
|
|
WP(w, def_d).data_1 = 0;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
2004-08-20 13:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _message_options_widgets[] = {
|
2005-04-13 23:03:31 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 409, 0, 13, STR_0204_MESSAGE_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 409, 14, 184, STR_NULL, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 26, 37, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 26, 37, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 38, 49, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 38, 49, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 50, 61, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 50, 61, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 62, 73, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 62, 73, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 74, 85, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 74, 85, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 86, 97, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 86, 97, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 98, 109, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 98, 109, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 110, 121, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 110, 121, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 122, 133, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 122, 133, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 4, 12, 134, 145, SPR_ARROW_LEFT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_NONE, 3, 90, 98, 134, 145, SPR_ARROW_RIGHT, STR_HSCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 3, 4, 86, 154, 165, STR_NULL, STR_NULL},
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 3, 87, 98, 154, 165, STR_0225, STR_NULL},
|
|
|
|
{ WWT_4, RESIZE_NONE, 3, 4, 98, 166, 177, STR_02DB_OFF, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
|
|
|
|
{ WIDGETS_END},
|
2004-08-20 13:58:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _message_options_desc = {
|
2005-04-13 23:03:31 +00:00
|
|
|
270, 22, 410, 185,
|
2004-11-15 12:05:01 +00:00
|
|
|
WC_GAME_OPTIONS, 0,
|
2004-08-20 13:58:25 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_message_options_widgets,
|
|
|
|
MessageOptionsWndProc
|
|
|
|
};
|
|
|
|
|
2004-11-15 12:05:01 +00:00
|
|
|
void ShowMessageOptions(void)
|
2004-08-20 13:58:25 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
|
|
|
AllocateWindowDesc(&_message_options_desc);
|
|
|
|
}
|