1
0
Fork 0

(svn r626) Merge r438 to trunk:

Some whitespace and magic number cleanup (in news_gui)
release/0.4.5
tron 2004-11-15 12:05:01 +00:00
parent 2f35fea097
commit a0b4161a32
2 changed files with 198 additions and 165 deletions

6
news.h
View File

@ -19,9 +19,9 @@ struct NewsItem {
#define NEWS_FLAGS(mode,flag,type,cb) ((cb)<<24 | (type)<<16 | (flag)<<8 | (mode)) #define NEWS_FLAGS(mode,flag,type,cb) ((cb)<<24 | (type)<<16 | (flag)<<8 | (mode))
void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b); void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b);
void NewsLoop(); void NewsLoop(void);
void DrawNewsBorder(Window *w); void DrawNewsBorder(const Window *w);
void InitNewsItemStructs(); void InitNewsItemStructs(void);
VARDEF NewsItem _statusbar_news_item; VARDEF NewsItem _statusbar_news_item;

View File

@ -23,14 +23,18 @@ oldest current lastest
forced forced
*/ */
# define MAX_NEWS 30 #define MAX_NEWS 30
#define INVALID_NEWS 255
static NewsItem _news_items[MAX_NEWS]; static NewsItem _news_items[MAX_NEWS];
static byte _current_news = 255; // points to news item that should be shown next static byte _current_news = INVALID_NEWS; // points to news item that should be shown next
static byte _oldest_news = 0; // points to first item in fifo queue static byte _oldest_news = 0; // points to first item in fifo queue
static byte _latest_news = 255; // points to last item in fifo queue static byte _latest_news = INVALID_NEWS; // points to last item in fifo queue
static byte _forced_news = 255; // if the message being shown was forced by the user, its index is stored in _forced_news. /* if the message being shown was forced by the user, its index is stored in
//forced_news is 255 otherwise. (Users can force messages through history or "last message") * _forced_news. forced_news is INVALID_NEWS otherwise.
* (Users can force messages through history or "last message") */
static byte _forced_news = INVALID_NEWS;
static byte _total_news = 0; // total news count static byte _total_news = 0; // total news count
@ -39,7 +43,7 @@ void DrawNewsNewRoadVehAvail(Window *w);
void DrawNewsNewShipAvail(Window *w); void DrawNewsNewShipAvail(Window *w);
void DrawNewsNewAircraftAvail(Window *w); void DrawNewsNewAircraftAvail(Window *w);
void DrawNewsBankrupcy(Window *w); void DrawNewsBankrupcy(Window *w);
static void MoveToNexItem(); static void MoveToNexItem(void);
StringID GetNewsStringNewTrainAvail(NewsItem *ni); StringID GetNewsStringNewTrainAvail(NewsItem *ni);
StringID GetNewsStringNewRoadVehAvail(NewsItem *ni); StringID GetNewsStringNewRoadVehAvail(NewsItem *ni);
@ -48,32 +52,32 @@ StringID GetNewsStringNewAircraftAvail(NewsItem *ni);
StringID GetNewsStringBankrupcy(NewsItem *ni); StringID GetNewsStringBankrupcy(NewsItem *ni);
static DrawNewsCallbackProc * const _draw_news_callback[] = { static DrawNewsCallbackProc * const _draw_news_callback[] = {
DrawNewsNewTrainAvail, /* DNC_TRAINAVAIL */ DrawNewsNewTrainAvail, /* DNC_TRAINAVAIL */
DrawNewsNewRoadVehAvail, /* DNC_ROADAVAIL */ DrawNewsNewRoadVehAvail, /* DNC_ROADAVAIL */
DrawNewsNewShipAvail, /* DNC_SHIPAVAIL */ DrawNewsNewShipAvail, /* DNC_SHIPAVAIL */
DrawNewsNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */ DrawNewsNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
DrawNewsBankrupcy, /* DNC_BANKRUPCY */ DrawNewsBankrupcy, /* DNC_BANKRUPCY */
}; };
GetNewsStringCallbackProc * const _get_news_string_callback[] = { GetNewsStringCallbackProc * const _get_news_string_callback[] = {
GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */ GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */
GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */ GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */
GetNewsStringNewShipAvail, /* DNC_SHIPAVAIL */ GetNewsStringNewShipAvail, /* DNC_SHIPAVAIL */
GetNewsStringNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */ GetNewsStringNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
GetNewsStringBankrupcy, /* DNC_BANKRUPCY */ GetNewsStringBankrupcy, /* DNC_BANKRUPCY */
}; };
void InitNewsItemStructs() void InitNewsItemStructs(void)
{ {
memset(_news_items, 0, sizeof(NewsItem)*MAX_NEWS); memset(_news_items, 0, sizeof(_news_items));
_current_news = 255; _current_news = INVALID_NEWS;
_oldest_news = 0; _oldest_news = 0;
_latest_news = 255; _latest_news = INVALID_NEWS;
_forced_news = 255; _forced_news = INVALID_NEWS;
_total_news = 0; _total_news = 0;
} }
void DrawNewsBorder(Window *w) void DrawNewsBorder(const Window *w)
{ {
int left = 0; int left = 0;
int right = w->width - 1; int right = w->width - 1;
@ -92,62 +96,74 @@ void DrawNewsBorder(Window *w)
static void NewsWindowProc(Window *w, WindowEvent *e) static void NewsWindowProc(Window *w, WindowEvent *e)
{ {
switch(e->event) { switch (e->event) {
case WE_PAINT: { case WE_PAINT: {
NewsItem *ni = WP(w,news_d).ni; const NewsItem *ni = WP(w, news_d).ni;
ViewPort *vp; ViewPort *vp;
if (ni->display_mode == NM_NORMAL || ni->display_mode == NM_THIN) { switch (ni->display_mode) {
DrawNewsBorder(w); case NM_NORMAL:
case NM_THIN: {
DrawNewsBorder(w);
DrawString(2, 1, STR_00C6, 0); DrawString(2, 1, STR_00C6, 0);
SET_DPARAM16(0, ni->date); SET_DPARAM16(0, ni->date);
DrawStringRightAligned(428, 1, STR_01FF, 0); DrawStringRightAligned(428, 1, STR_01FF, 0);
if (!(ni->flags & NF_VIEWPORT)) { if (!(ni->flags & NF_VIEWPORT)) {
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56, ni->string_id, 426); DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56,
} else { ni->string_id, 426);
byte bk = _display_opt; } else {
_display_opt |= DO_TRANS_BUILDINGS; byte bk = _display_opt;
DrawWindowViewport(w); _display_opt |= DO_TRANS_BUILDINGS;
_display_opt = bk; DrawWindowViewport(w);
_display_opt = bk;
/* Shade the viewport into gray, or color*/ /* Shade the viewport into gray, or color*/
vp = w->viewport; 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, GfxFillRect(vp->left - w->left, vp->top - w->top,
ni->flags & NF_INCOLOR ? 0x4322:0x4323 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)); COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
DrawStringMultiCenter((w->width>>1), 20, ni->string_id, 428); DrawStringMultiCenter(w->width / 2, 20, ni->string_id, 428);
}
break;
} }
} else if (ni->display_mode == NM_CALLBACK) {
_draw_news_callback[ni->callback](w); case NM_CALLBACK: {
} else { _draw_news_callback[ni->callback](w);
DrawWindowWidgets(w); break;
if (!(ni->flags & NF_VIEWPORT)) { }
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
DrawStringMultiCenter(140,38, ni->string_id, 276); default: {
} else { DrawWindowWidgets(w);
DrawWindowViewport(w); if (!(ni->flags & NF_VIEWPORT)) {
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
DrawStringMultiCenter((w->width>>1), w->height - 16, ni->string_id, 276); 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;
} }
} }
} break; } break;
case WE_CLICK: { case WE_CLICK: {
switch(e->click.widget) { switch (e->click.widget) {
case 1: { case 1: {
NewsItem *ni = WP(w,news_d).ni; NewsItem *ni = WP(w, news_d).ni;
DeleteWindow(w); DeleteWindow(w);
ni->duration = 0; ni->duration = 0;
if(_forced_news!=255) _forced_news = 255; _forced_news = INVALID_NEWS;
} break; } break;
case 0: { case 0: {
NewsItem *ni = WP(w,news_d).ni; NewsItem *ni = WP(w, news_d).ni;
if (ni->flags & NF_VEHICLE) { if (ni->flags & NF_VEHICLE) {
Vehicle *v = &_vehicles[ni->data_a]; Vehicle *v = &_vehicles[ni->data_a];
ScrollMainWindowTo(v->x_pos, v->y_pos); ScrollMainWindowTo(v->x_pos, v->y_pos);
@ -186,10 +202,10 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
// (to deal with overflows) // (to deal with overflows)
byte increaseIndex(byte i) byte increaseIndex(byte i)
{ {
if(i==255) if (i == INVALID_NEWS)
return 0; return 0;
i++; i++;
if(i >= MAX_NEWS) if (i >= MAX_NEWS)
i = i % MAX_NEWS; i = i % MAX_NEWS;
return i; return i;
} }
@ -204,17 +220,17 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
return; return;
// check the rare case that the oldest (to be overwritten) news item is open // check the rare case that the oldest (to be overwritten) news item is open
if(_oldest_news == _current_news || _oldest_news == _forced_news) if (_oldest_news == _current_news || _oldest_news == _forced_news)
MoveToNexItem(); MoveToNexItem();
_forced_news = 255; _forced_news = INVALID_NEWS;
if(_total_news < MAX_NEWS) _total_news++; if (_total_news < MAX_NEWS) _total_news++;
// make sure our pointer isn't overflowing // make sure our pointer isn't overflowing
_latest_news = increaseIndex(_latest_news); _latest_news = increaseIndex(_latest_news);
// overwrite oldest news entry // overwrite oldest news entry
if( _oldest_news == _latest_news && _news_items[_oldest_news].string_id != 0) if (_oldest_news == _latest_news && _news_items[_oldest_news].string_id != 0)
_oldest_news = increaseIndex(_oldest_news); // but make sure we're not overflowing here _oldest_news = increaseIndex(_oldest_news); // but make sure we're not overflowing here
// add news to _latest_news // add news to _latest_news
@ -236,7 +252,7 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params)); COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params));
w = FindWindowById(WC_MESSAGE_HISTORY, 0); w = FindWindowById(WC_MESSAGE_HISTORY, 0);
if(w==NULL) return; if (w == NULL) return;
SetWindowDirty(w); SetWindowDirty(w);
w->vscroll.count = _total_news; w->vscroll.count = _total_news;
} }
@ -245,28 +261,28 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180}; static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180};
static const Widget _news_type13_widgets[] = { static const Widget _news_type13_widgets[] = {
{ WWT_PANEL, 15, 0, 429, 0, 169, 0x0, STR_NULL}, { WWT_PANEL, 15, 0, 429, 0, 169, 0x0, STR_NULL},
{ WWT_PANEL, 15, 0, 10, 0, 11, 0x0, STR_NULL}, { WWT_PANEL, 15, 0, 10, 0, 11, 0x0, STR_NULL},
{ WIDGETS_END}, { WIDGETS_END},
}; };
static WindowDesc _news_type13_desc = { static WindowDesc _news_type13_desc = {
WDP_CENTER, 476, 430, 170, WDP_CENTER, 476, 430, 170,
WC_NEWS_WINDOW,0, WC_NEWS_WINDOW, 0,
WDF_DEF_WIDGET, WDF_DEF_WIDGET,
_news_type13_widgets, _news_type13_widgets,
NewsWindowProc NewsWindowProc
}; };
static const Widget _news_type2_widgets[] = { static const Widget _news_type2_widgets[] = {
{ WWT_PANEL, 15, 0, 429, 0, 129, 0x0, STR_NULL}, { WWT_PANEL, 15, 0, 429, 0, 129, 0x0, STR_NULL},
{ WWT_PANEL, 15, 0, 10, 0, 11, 0x0, STR_NULL}, { WWT_PANEL, 15, 0, 10, 0, 11, 0x0, STR_NULL},
{ WIDGETS_END}, { WIDGETS_END},
}; };
static WindowDesc _news_type2_desc = { static WindowDesc _news_type2_desc = {
WDP_CENTER, 476, 430, 130, WDP_CENTER, 476, 430, 130,
WC_NEWS_WINDOW,0, WC_NEWS_WINDOW, 0,
WDF_DEF_WIDGET, WDF_DEF_WIDGET,
_news_type2_widgets, _news_type2_widgets,
NewsWindowProc NewsWindowProc
@ -282,13 +298,24 @@ static const Widget _news_type0_widgets[] = {
static WindowDesc _news_type0_desc = { static WindowDesc _news_type0_desc = {
WDP_CENTER, 476, 280, 87, WDP_CENTER, 476, 280, 87,
WC_NEWS_WINDOW,0, WC_NEWS_WINDOW, 0,
WDF_DEF_WIDGET, WDF_DEF_WIDGET,
_news_type0_widgets, _news_type0_widgets,
NewsWindowProc NewsWindowProc
}; };
static byte _news_sounds[] = { 27, 27, 0, 0, 0, 0, 28, 0, 0, 0 }; static const SoundFx _news_sounds[] = {
SND_1D_APPLAUSE,
SND_1D_APPLAUSE,
0,
0,
0,
0,
SND_1E_OOOOH,
0,
0,
0
};
// open up an own newspaper window for the news item // open up an own newspaper window for the news item
static void ShowNewspaper(NewsItem *ni) static void ShowNewspaper(NewsItem *ni)
@ -296,7 +323,7 @@ static void ShowNewspaper(NewsItem *ni)
Window *w; Window *w;
int sound; int sound;
int top; int top;
ni->flags &= ~(NF_NOEXPIRE|NF_FORCE_BIG); ni->flags &= ~(NF_NOEXPIRE | NF_FORCE_BIG);
ni->duration = 555; ni->duration = 555;
sound = _news_sounds[ni->type]; sound = _news_sounds[ni->type];
@ -304,60 +331,68 @@ static void ShowNewspaper(NewsItem *ni)
SndPlayFx(sound); SndPlayFx(sound);
top = _screen.height - 4; top = _screen.height - 4;
if (ni->display_mode == NM_NORMAL || ni->display_mode == NM_CALLBACK) { switch (ni->display_mode) {
_news_type13_desc.top = top; case NM_NORMAL:
w = AllocateWindowDesc(&_news_type13_desc); case NM_CALLBACK: {
if (ni->flags & NF_VIEWPORT) { _news_type13_desc.top = top;
AssignWindowViewport(w, 2, 58, 0x1AA, 0x6E, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0); 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;
} }
} else if (ni->display_mode == NM_THIN) {
_news_type2_desc.top = top; case NM_THIN: {
w = AllocateWindowDesc(&_news_type2_desc); _news_type2_desc.top = top;
if (ni->flags & NF_VIEWPORT) { w = AllocateWindowDesc(&_news_type2_desc);
AssignWindowViewport(w, 2, 58, 0x1AA, 0x46, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0); if (ni->flags & NF_VIEWPORT)
AssignWindowViewport(w, 2, 58, 0x1AA, 0x46,
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
break;
} }
} else {
_news_type0_desc.top = top; default: {
w = AllocateWindowDesc(&_news_type0_desc); _news_type0_desc.top = top;
if (ni->flags & NF_VIEWPORT) { w = AllocateWindowDesc(&_news_type0_desc);
AssignWindowViewport(w, 3, 17, 0x112, 0x2F, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0); if (ni->flags & NF_VIEWPORT)
AssignWindowViewport(w, 3, 17, 0x112, 0x2F,
ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0);
break;
} }
} }
WP(w,news_d).ni = &_news_items[(_forced_news==255)?_current_news:_forced_news]; WP(w, news_d).ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news];
w->flags4 |= WF_DISABLE_VP_SCROLL; w->flags4 |= WF_DISABLE_VP_SCROLL;
} }
// show news item in the ticker // show news item in the ticker
static void ShowTicker(NewsItem *ni) static void ShowTicker(const NewsItem *ni)
{ {
Window *w; Window *w;
SndPlayFx(20); SndPlayFx(20);
_statusbar_news_item = *ni; _statusbar_news_item = *ni;
w = FindWindowById(WC_STATUS_BAR, 0); w = FindWindowById(WC_STATUS_BAR, 0);
if (w != 0) if (w != NULL)
WP(w,def_d).data_1 = 360; WP(w, def_d).data_1 = 360;
} }
// Are we ready to show another news item? // Are we ready to show another news item?
// Only if nothing is in the newsticker and no newspaper is displayed // Only if nothing is in the newsticker and no newspaper is displayed
static bool ReadyForNextItem() static bool ReadyForNextItem(void)
{ {
Window *w; const Window *w;
byte item = (_forced_news==255)?_current_news:_forced_news; byte item = _forced_news == INVALID_NEWS ? _current_news : _forced_news;
NewsItem *ni; NewsItem *ni;
if(item>=MAX_NEWS) return true; if (item >= MAX_NEWS) return true;
ni = &_news_items[item]; ni = &_news_items[item];
// Ticker message // Ticker message
// Check if the status bar message is still being displayed? // Check if the status bar message is still being displayed?
w = FindWindowById(WC_STATUS_BAR, 0); w = FindWindowById(WC_STATUS_BAR, 0);
if (w != NULL && WP(w,def_d).data_1 > -1280) if (w != NULL && WP(w, def_d).data_1 > -1280)
{
return false; return false;
}
// Newspaper message // Newspaper message
// Wait until duration reaches 0 // Wait until duration reaches 0
@ -370,44 +405,43 @@ static bool ReadyForNextItem()
return true; return true;
} }
static void MoveToNexItem() static void MoveToNexItem(void)
{ {
DeleteWindowById(WC_NEWS_WINDOW, 0); DeleteWindowById(WC_NEWS_WINDOW, 0);
_forced_news = 255; _forced_news = INVALID_NEWS;
// if we're not at the last item, than move on // if we're not at the last item, than move on
if(_current_news != _latest_news) if (_current_news != _latest_news) {
{
NewsItem *ni; NewsItem *ni;
_current_news = increaseIndex(_current_news); _current_news = increaseIndex(_current_news);
ni = &_news_items[_current_news]; ni = &_news_items[_current_news];
// check the date, don't show too old items // check the date, don't show too old items
if(_date - _news_items_age[ni->type] > ni->date) if (_date - _news_items_age[ni->type] > ni->date)
return; return;
// show newspaper or send to ticker? // show newspaper or send to ticker?
if(!HASBIT(_news_display_opt, ni->type) && !(ni->flags&NF_FORCE_BIG)) if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags & NF_FORCE_BIG))
ShowTicker(ni); ShowTicker(ni);
else else
ShowNewspaper(ni); ShowNewspaper(ni);
} }
} }
void NewsLoop() void NewsLoop(void)
{ {
// no news item yet // no news item yet
if(_total_news==0) return; if (_total_news == 0) return;
if( ReadyForNextItem() ) if (ReadyForNextItem())
MoveToNexItem(); MoveToNexItem();
} }
/* Do a forced show of a specific message */ /* Do a forced show of a specific message */
void ShowNewsMessage(byte i) void ShowNewsMessage(byte i)
{ {
if(_total_news==0) return; if (_total_news == 0) return;
// Delete the news window // Delete the news window
DeleteWindowById(WC_NEWS_WINDOW, 0); DeleteWindowById(WC_NEWS_WINDOW, 0);
@ -415,8 +449,7 @@ void ShowNewsMessage(byte i)
// setup forced news item // setup forced news item
_forced_news = i; _forced_news = i;
if(_forced_news!=255) if (_forced_news != INVALID_NEWS) {
{
NewsItem *ni = &_news_items[_forced_news]; NewsItem *ni = &_news_items[_forced_news];
ni->duration = 555; ni->duration = 555;
ni->flags |= NF_NOEXPIRE | NF_FORCE_BIG; ni->flags |= NF_NOEXPIRE | NF_FORCE_BIG;
@ -425,34 +458,34 @@ void ShowNewsMessage(byte i)
} }
} }
void ShowLastNewsMessage() void ShowLastNewsMessage(void)
{ {
if(_forced_news==255) if (_forced_news == INVALID_NEWS)
ShowNewsMessage(_current_news); ShowNewsMessage(_current_news);
else if(_forced_news!=0) else if (_forced_news != 0)
ShowNewsMessage(_forced_news-1); ShowNewsMessage(_forced_news - 1);
else { else {
if(_total_news != MAX_NEWS) if (_total_news != MAX_NEWS)
ShowNewsMessage(_latest_news); ShowNewsMessage(_latest_news);
else else
ShowNewsMessage(MAX_NEWS-1); ShowNewsMessage(MAX_NEWS - 1);
} }
} }
/* return news by number, with 0 being the most /* return news by number, with 0 being the most
recent news. Returns 255 if end of queue reached. */ recent news. Returns INVALID_NEWS if end of queue reached. */
static byte getNews(byte i) static byte getNews(byte i)
{ {
if(i>=_total_news) if (i >= _total_news)
return 255; return INVALID_NEWS;
if(_latest_news < i) if (_latest_news < i)
i = _latest_news + MAX_NEWS - i; i = _latest_news + MAX_NEWS - i;
else else
i = _latest_news - i; i = _latest_news - i;
i = i % MAX_NEWS; i %= MAX_NEWS;
return i; return i;
} }
@ -474,21 +507,21 @@ static void GetNewsString(NewsItem *ni, byte *buffer)
s = str_buffr; s = str_buffr;
d = buffer; d = buffer;
for(;;s++) { for (;; s++) {
// cut strings that are too long // cut strings that are too long
if(s >= str_buffr + 55) { if (s >= str_buffr + 55) {
d[0] = d[1] = d[2] = '.'; d[0] = d[1] = d[2] = '.';
d+=3; d += 3;
*d = 0; *d = '\0';
break; break;
} }
if (*s == 0) { if (*s == '\0') {
*d = 0; *d = '\0';
break; break;
} else if (*s == 13) { } else if (*s == '\r') {
d[0] = d[1] = d[2] = d[3] = ' '; d[0] = d[1] = d[2] = d[3] = ' ';
d+=4; d += 4;
} else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { } else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) {
*d++ = *s; *d++ = *s;
} }
@ -498,22 +531,21 @@ static void GetNewsString(NewsItem *ni, byte *buffer)
static void MessageHistoryWndProc(Window *w, WindowEvent *e) static void MessageHistoryWndProc(Window *w, WindowEvent *e)
{ {
switch(e->event) { switch (e->event) {
case WE_PAINT: { case WE_PAINT: {
byte buffer[256]; byte buffer[256];
int y=19; int y = 19;
byte p, show; byte p, show;
NewsItem *ni; NewsItem *ni;
DrawWindowWidgets(w); DrawWindowWidgets(w);
if(_total_news==0) break; if (_total_news == 0) break;
show = min(_total_news, 10); show = min(_total_news, 10);
for(p=w->vscroll.pos; p<w->vscroll.pos+show; p++) for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
{
// get news in correct order // get news in correct order
ni = &_news_items[ getNews(p) ]; ni = &_news_items[getNews(p)];
SET_DPARAM16(0, ni->date); SET_DPARAM16(0, ni->date);
DrawString(4, y, STR_00AF, 16); DrawString(4, y, STR_00AF, 16);
@ -527,28 +559,30 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
} }
case WE_CLICK: case WE_CLICK:
switch(e->click.widget) { switch (e->click.widget) {
case 2: { case 2: {
int y = (e->click.pt.y - 19) / 12; int y = (e->click.pt.y - 19) / 12;
byte p, q; byte p, q;
/* // === DEBUG code only #if 0 // === DEBUG code only
for(p=0; p<_total_news; p++) for (p = 0; p < _total_news; p++)
{ {
NewsItem *ni; NewsItem *ni;
byte buffer[256]; byte buffer[256];
ni=&_news_items[p]; ni = &_news_items[p];
GetNewsString(ni, buffer); GetNewsString(ni, buffer);
printf("%i\t%i\t%s\n", p, ni->date, buffer); printf("%i\t%i\t%s\n", p, ni->date, buffer);
} }
printf("=========================\n"); printf("=========================\n");
// === END OF DEBUG CODE */ #endif
p = y + w->vscroll.pos; p = y + w->vscroll.pos;
if( p > _total_news-1 ) break; if (p > _total_news - 1) break;
if(_latest_news >= p) q=_latest_news - p; if (_latest_news >= p)
else q=_latest_news + MAX_NEWS - p; q = _latest_news - p;
else
q = _latest_news + MAX_NEWS - p;
ShowNewsMessage(q); ShowNewsMessage(q);
break; break;
@ -568,20 +602,20 @@ static const Widget _message_history_widgets[] = {
static const WindowDesc _message_history_desc = { static const WindowDesc _message_history_desc = {
240, 22, 400, 140, 240, 22, 400, 140,
WC_MESSAGE_HISTORY,0, WC_MESSAGE_HISTORY, 0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_message_history_widgets, _message_history_widgets,
MessageHistoryWndProc MessageHistoryWndProc
}; };
void ShowMessageHistory() void ShowMessageHistory(void)
{ {
Window *w; Window *w;
DeleteWindowById(WC_MESSAGE_HISTORY, 0); DeleteWindowById(WC_MESSAGE_HISTORY, 0);
w = AllocateWindowDesc(&_message_history_desc); w = AllocateWindowDesc(&_message_history_desc);
if (w) { if (w != NULL) {
w->vscroll.cap = 10; w->vscroll.cap = 10;
w->vscroll.count = _total_news; w->vscroll.count = _total_news;
SetWindowDirty(w); SetWindowDirty(w);
@ -591,14 +625,14 @@ void ShowMessageHistory()
static void MessageOptionsWndProc(Window *w, WindowEvent *e) static void MessageOptionsWndProc(Window *w, WindowEvent *e)
{ {
switch(e->event) { switch (e->event) {
case WE_PAINT: { case WE_PAINT: {
uint16 x = _news_display_opt; uint16 x = _news_display_opt;
uint32 cs = 0; uint32 cs = 0;
int i, y; int i, y;
for(i=3; i!=23; i+=2) { for (i = 3; i != 23; i += 2) {
cs |= 1 << (i + (x&1)); cs |= 1 << (i + (x & 1));
x >>= 1; x >>= 1;
} }
cs |= (w->click_state >> 23) << 23; cs |= (w->click_state >> 23) << 23;
@ -609,31 +643,30 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0); DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0);
y = 27; y = 27;
for(i=STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) { for (i = STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) {
DrawString(124, y, i, 0); DrawString(124, y, i, 0);
y += 12; y += 12;
} }
break; break;
} }
case WE_CLICK: { case WE_CLICK: {
int wid; int wid;
if ( (uint)(wid=e->click.widget - 3) < 20) { if ((uint)(wid = e->click.widget - 3) < 20) {
if (!(wid & 1)) { if (!(wid & 1))
_news_display_opt &= ~(1 << (wid>>1)); _news_display_opt &= ~(1 << (wid / 2));
} else { else
_news_display_opt |= (1 << (wid>>1)); _news_display_opt |= (1 << (wid / 2));
}
SetWindowDirty(w); SetWindowDirty(w);
// XXX: write settings // XXX: write settings
} }
if( e->click.widget == 23) { if (e->click.widget == 23) {
_news_display_opt = 0; _news_display_opt = 0;
HandleButtonClick(w, 23); HandleButtonClick(w, 23);
SetWindowDirty(w); SetWindowDirty(w);
} }
if( e->click.widget == 24) { if (e->click.widget == 24) {
_news_display_opt = ~0; _news_display_opt = ~0;
HandleButtonClick(w, 24); HandleButtonClick(w, 24);
SetWindowDirty(w); SetWindowDirty(w);
@ -675,13 +708,13 @@ static const Widget _message_options_widgets[] = {
static const WindowDesc _message_options_desc = { static const WindowDesc _message_options_desc = {
270, 22, 370, 173, 270, 22, 370, 173,
WC_GAME_OPTIONS,0, WC_GAME_OPTIONS, 0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_message_options_widgets, _message_options_widgets,
MessageOptionsWndProc MessageOptionsWndProc
}; };
void ShowMessageOptions() void ShowMessageOptions(void)
{ {
DeleteWindowById(WC_GAME_OPTIONS, 0); DeleteWindowById(WC_GAME_OPTIONS, 0);
AllocateWindowDesc(&_message_options_desc); AllocateWindowDesc(&_message_options_desc);