truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" truelight@0: truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "viewport.h" truelight@0: #include "gfx.h" truelight@0: #include "news.h" truelight@0: #include "vehicle.h" truelight@0: truelight@0: static NewsItem _news_items[10]; truelight@0: static NewsItem _active_news_items[20]; truelight@0: truelight@0: void ExpireNewsItem(); truelight@0: truelight@0: void DrawNewsNewTrainAvail(Window *w); truelight@0: void DrawNewsNewRoadVehAvail(Window *w); truelight@0: void DrawNewsNewShipAvail(Window *w); truelight@0: void DrawNewsNewAircraftAvail(Window *w); truelight@0: void DrawNewsBankrupcy(Window *w); truelight@0: truelight@0: StringID GetNewsStringNewTrainAvail(NewsItem *ni); truelight@0: StringID GetNewsStringNewRoadVehAvail(NewsItem *ni); truelight@0: StringID GetNewsStringNewShipAvail(NewsItem *ni); truelight@0: StringID GetNewsStringNewAircraftAvail(NewsItem *ni); truelight@0: StringID GetNewsStringBankrupcy(NewsItem *ni); truelight@0: truelight@0: static DrawNewsCallbackProc * const _draw_news_callback[] = { truelight@0: DrawNewsNewTrainAvail, /* DNC_TRAINAVAIL */ truelight@0: DrawNewsNewRoadVehAvail, /* DNC_ROADAVAIL */ truelight@0: DrawNewsNewShipAvail, /* DNC_SHIPAVAIL */ truelight@0: DrawNewsNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */ truelight@0: DrawNewsBankrupcy, /* DNC_BANKRUPCY */ truelight@0: }; truelight@0: truelight@0: GetNewsStringCallbackProc * const _get_news_string_callback[] = { truelight@0: GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */ truelight@0: GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */ truelight@0: GetNewsStringNewShipAvail, /* DNC_SHIPAVAIL */ truelight@0: GetNewsStringNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */ truelight@0: GetNewsStringBankrupcy, /* DNC_BANKRUPCY */ truelight@0: }; truelight@0: truelight@0: truelight@0: void DrawNewsBorder(Window *w) truelight@0: { truelight@0: int left = 0; truelight@0: int right = w->width - 1; truelight@0: int top = 0; truelight@0: int bottom = w->height - 1; truelight@0: truelight@0: GfxFillRect(left, top, right, bottom, 0xF); truelight@0: truelight@0: GfxFillRect(left, top, left, bottom, 0xD7); truelight@0: GfxFillRect(right, top, right, bottom, 0xD7); truelight@0: GfxFillRect(left, top, right, top, 0xD7); truelight@0: GfxFillRect(left, bottom, right, bottom, 0xD7); truelight@0: truelight@0: DrawString(left + 2, top + 1, STR_00C6, 0); truelight@0: } truelight@0: truelight@0: static void NewsWindowProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: NewsItem *ni = WP(w,news_d).ni; truelight@0: ViewPort *vp; truelight@0: truelight@0: if (ni->display_mode == NM_NORMAL || ni->display_mode == NM_THIN) { truelight@0: DrawNewsBorder(w); truelight@0: truelight@0: DrawString(2, 1, STR_00C6, 0); truelight@0: truelight@0: SET_DPARAM16(0, ni->date); truelight@0: DrawStringRightAligned(428, 1, STR_01FF, 0); truelight@0: truelight@0: if (!(ni->flags & NF_VIEWPORT)) { truelight@0: COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); truelight@0: DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56, ni->string_id, 426); truelight@0: } else { truelight@0: byte bk = _display_opt; truelight@0: _display_opt |= DO_TRANS_BUILDINGS; truelight@0: DrawWindowViewport(w); truelight@0: _display_opt = bk; truelight@0: truelight@0: /* Shade the viewport into gray, or color*/ truelight@0: vp = w->viewport; truelight@0: GfxFillRect(vp->left - w->left, vp->top - w->top, vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1, truelight@0: ni->flags & NF_INCOLOR ? 0x4322:0x4323 truelight@0: ); truelight@0: truelight@0: COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); truelight@0: DrawStringMultiCenter((w->width>>1), 20, ni->string_id, 428); truelight@0: } truelight@0: } else if (ni->display_mode == NM_CALLBACK) { truelight@0: _draw_news_callback[ni->callback](w); truelight@0: } else { truelight@0: DrawWindowWidgets(w); truelight@0: if (!(ni->flags & NF_VIEWPORT)) { truelight@0: COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); truelight@0: DrawStringMultiCenter(140,38, ni->string_id, 276); truelight@0: } else { truelight@0: DrawWindowViewport(w); truelight@0: COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); truelight@0: DrawStringMultiCenter((w->width>>1), w->height - 16, ni->string_id, 276); truelight@0: } truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 1:DeleteWindow(w); ExpireNewsItem(); break; truelight@0: case 0: { truelight@0: NewsItem *ni = WP(w,news_d).ni; truelight@0: if (ni->flags & NF_VEHICLE) { truelight@0: Vehicle *v = &_vehicles[ni->data_a]; truelight@0: ScrollMainWindowTo(v->x_pos, v->y_pos); truelight@0: } else if (ni->flags & NF_TILE) { truelight@0: if (!ScrollMainWindowToTile(ni->data_a) && ni->data_b != 0) truelight@0: ScrollMainWindowToTile(ni->data_b); truelight@0: } truelight@0: } break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_KEYPRESS: truelight@0: if (e->keypress.keycode == WKC_SPACE) { truelight@0: // Don't continue. truelight@0: e->keypress.cont = false; truelight@0: DeleteWindow(w); truelight@0: ExpireNewsItem(); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_TICK: { truelight@0: int y = max(w->top - 4, _screen.height - w->height); truelight@0: if (y == w->top) truelight@0: return; truelight@0: truelight@0: if (w->viewport != NULL) truelight@0: w->viewport->top += y - w->top; truelight@0: truelight@0: w->top = y; truelight@0: truelight@0: SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height + 4); truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b) truelight@0: { truelight@0: NewsItem *ni; truelight@0: truelight@0: if (_game_mode == GM_MENU) truelight@0: return; truelight@0: truelight@0: // Find a free place and add it there. truelight@0: for(ni=_news_items; ni!=endof(_news_items); ni++) { truelight@0: if (ni->string_id==0) { truelight@0: ni->string_id = string; truelight@0: ni->display_mode = (byte)flags; truelight@0: ni->flags = (byte)(flags >> 8) | NF_NOEXPIRE; truelight@0: truelight@0: // show this news message in color? truelight@0: if (_date >= ConvertIntDate(_patches.colored_news_date)) truelight@0: ni->flags |= NF_INCOLOR; truelight@0: truelight@0: ni->type = (byte)(flags >> 16); truelight@0: ni->callback = (byte)(flags >> 24); truelight@0: ni->duration = 555; truelight@0: ni->data_a = data_a; truelight@0: ni->data_b = data_b; truelight@0: ni->date = _date; truelight@0: COPY_OUT_DPARAM(ni->params, 0, lengthof(ni->params)); truelight@0: break; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: // _active_news_items 0..9 are the ones that have already been shown truelight@0: // _active_news_items 10..19 are the ones that are to be shown next truelight@0: truelight@0: static void MoveNewsItems() truelight@0: { truelight@0: Window *w; truelight@0: NewsItem *ni; truelight@0: truelight@0: // No new news item? truelight@0: if (_news_items[0].string_id == 0) truelight@0: return; truelight@0: truelight@0: // Check if the status bar message is still being displayed? truelight@0: w = FindWindowById(WC_STATUS_BAR, 0); truelight@0: if (w != NULL && WP(w,def_d).data_1 > -1280) truelight@0: return; truelight@0: truelight@0: // Add the news items to the list of pending ones. truelight@0: for(ni=_active_news_items + 10; ni != _active_news_items + 20; ni++) { truelight@0: if (ni->string_id == 0) { truelight@0: *ni = _news_items[0]; truelight@0: memcpy_overlapping(_news_items, _news_items+1, sizeof(_news_items) - sizeof(_news_items[0]) * 1); truelight@0: endof(_news_items)[-1].string_id = 0; truelight@0: break; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: void ExpireNewsItem() truelight@0: { truelight@0: memcpy_overlapping(_active_news_items, _active_news_items + 1, sizeof(_active_news_items) - sizeof(_active_news_items[0])); truelight@0: endof(_active_news_items)[-1].string_id = 0; truelight@0: } truelight@0: truelight@0: static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180}; truelight@0: truelight@0: static void RemoveOldNewsItems() truelight@0: { truelight@0: NewsItem *ni, *nit; truelight@0: truelight@0: ni = _active_news_items; truelight@0: do { truelight@0: if (ni->string_id != 0 && truelight@0: ni != _active_news_items + 10 && truelight@0: _date - _news_items_age[ni->type] > ni->date) { truelight@0: truelight@0: if (ni >= _active_news_items + 10) { truelight@0: nit = ni; truelight@0: while (nit != _active_news_items + 19) { truelight@0: nit[0] = nit[1]; truelight@0: nit++; truelight@0: } truelight@0: nit->string_id = 0; truelight@0: } else { truelight@0: nit = ni + 1; truelight@0: while (nit != _active_news_items + 1) { truelight@0: nit--; truelight@0: nit[0] = nit[-1]; truelight@0: } truelight@0: _active_news_items[0].string_id = 0; truelight@0: } truelight@0: } truelight@0: } while (++ni != endof(_active_news_items) ); truelight@0: } truelight@0: truelight@0: static const Widget _news_type13_widgets[] = { truelight@0: { WWT_PANEL, 15, 0, 429, 0, 169, 0x0}, truelight@0: { WWT_PANEL, 15, 0, 10, 0, 11, 0x0}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static WindowDesc _news_type13_desc = { truelight@0: WDP_CENTER, 476, 430, 170, truelight@0: WC_NEWS_WINDOW,0, truelight@0: WDF_DEF_WIDGET, truelight@0: _news_type13_widgets, truelight@0: NewsWindowProc truelight@0: }; truelight@0: truelight@0: static const Widget _news_type2_widgets[] = { truelight@0: { WWT_PANEL, 15, 0, 429, 0, 129, 0x0}, truelight@0: { WWT_PANEL, 15, 0, 10, 0, 11, 0x0}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static WindowDesc _news_type2_desc = { truelight@0: WDP_CENTER, 476, 430, 130, truelight@0: WC_NEWS_WINDOW,0, truelight@0: WDF_DEF_WIDGET, truelight@0: _news_type2_widgets, truelight@0: NewsWindowProc truelight@0: }; truelight@0: truelight@0: static const Widget _news_type0_widgets[] = { truelight@0: { WWT_PANEL, 5, 0, 279, 14, 86, 0x0}, truelight@0: { WWT_CLOSEBOX, 5, 0, 10, 0, 13, STR_00C5}, truelight@0: { WWT_CAPTION, 5, 11, 279, 0, 13, STR_012C_MESSAGE}, truelight@0: { WWT_6, 5, 2, 277, 16, 64, 0}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static WindowDesc _news_type0_desc = { truelight@0: WDP_CENTER, 476, 280, 87, truelight@0: WC_NEWS_WINDOW,0, truelight@0: WDF_DEF_WIDGET, truelight@0: _news_type0_widgets, truelight@0: NewsWindowProc truelight@0: }; truelight@0: truelight@0: static byte _news_sounds[] = { 27, 27, 0, 0, 0, 0, 28, 0, 0, 0 }; truelight@0: truelight@0: static void ProcessNewsItem(NewsItem *ni) truelight@0: { truelight@0: Window *w; truelight@0: int sound; truelight@0: truelight@0: // No news item, quit truelight@0: if (ni->string_id == 0) truelight@0: return; truelight@0: truelight@0: // Delete the item once the duration reaches 0 truelight@0: if (ni->duration == 0) { truelight@0: DeleteWindowById(WC_NEWS_WINDOW, 0); truelight@0: ExpireNewsItem(); truelight@0: return; truelight@0: } truelight@0: ni->duration--; truelight@0: truelight@0: // As long as the window still is shown, don't go further truelight@0: w = FindWindowById(WC_NEWS_WINDOW, 0); truelight@0: if (w != NULL) truelight@0: return; truelight@0: truelight@0: // Expire the item if NF_NOEXPIRE was removed truelight@0: if (!(ni->flags & NF_NOEXPIRE)) { truelight@0: ExpireNewsItem(); truelight@0: return; truelight@0: } truelight@0: truelight@0: if (!HASBIT(_news_display_opt, ni->type) && !(ni->flags&NF_FORCE_BIG)) { truelight@0: SndPlayFx(20); truelight@0: _statusbar_news_item = *ni; truelight@0: w = FindWindowById(WC_STATUS_BAR, 0); truelight@0: if (w != 0) truelight@0: WP(w,def_d).data_1 = 360; truelight@0: ExpireNewsItem(); truelight@0: } else { truelight@0: int top; truelight@0: truelight@0: ni->flags &= ~(NF_NOEXPIRE|NF_FORCE_BIG); truelight@0: truelight@0: sound = _news_sounds[ni->type]; truelight@0: if (sound != 0) truelight@0: SndPlayFx(sound); truelight@0: truelight@0: top = _screen.height - 4; truelight@0: if (ni->display_mode == NM_NORMAL || ni->display_mode == NM_CALLBACK) { truelight@0: _news_type13_desc.top = top; truelight@0: w = AllocateWindowDesc(&_news_type13_desc); truelight@0: if (ni->flags & NF_VIEWPORT) { truelight@0: AssignWindowViewport(w, 2, 58, 0x1AA, 0x6E, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0); truelight@0: } truelight@0: } else if (ni->display_mode == NM_THIN) { truelight@0: _news_type2_desc.top = top; truelight@0: w = AllocateWindowDesc(&_news_type2_desc); truelight@0: if (ni->flags & NF_VIEWPORT) { truelight@0: AssignWindowViewport(w, 2, 58, 0x1AA, 0x46, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0); truelight@0: } truelight@0: } else { truelight@0: _news_type0_desc.top = top; truelight@0: w = AllocateWindowDesc(&_news_type0_desc); truelight@0: if (ni->flags & NF_VIEWPORT) { truelight@0: AssignWindowViewport(w, 3, 17, 0x112, 0x2F, ni->data_a | ((ni->flags&NF_VEHICLE) ? 0x80000000 : 0), 0); truelight@0: } truelight@0: } truelight@0: WP(w,news_d).ni = _active_news_items + 10; truelight@0: w->flags4 |= WF_DISABLE_VP_SCROLL; truelight@0: } truelight@0: } truelight@0: truelight@0: void NewsLoop() truelight@0: { truelight@0: RemoveOldNewsItems(); truelight@0: MoveNewsItems(); truelight@0: ProcessNewsItem(_active_news_items + 10); truelight@0: } truelight@0: truelight@0: void ShowLastNewsMessage() truelight@0: { truelight@0: // No news item immediately before 10? truelight@0: if (_active_news_items[9].string_id == 0) truelight@0: return; truelight@0: truelight@0: // Delete the news window truelight@0: DeleteWindowById(WC_NEWS_WINDOW, 0); truelight@0: truelight@0: // Move all items one step truelight@0: memmove(_active_news_items+1, _active_news_items, sizeof(NewsItem)*19); truelight@0: _active_news_items[0].string_id = 0; truelight@0: truelight@0: // Default duration and flags for re-shown items truelight@0: _active_news_items[10].duration = 555; truelight@0: _active_news_items[10].flags |= NF_NOEXPIRE | NF_FORCE_BIG; truelight@0: } truelight@0: truelight@0: void InitNewsItemStructs() truelight@0: { truelight@0: memset(_news_items, 0, sizeof(_news_items)); truelight@0: memset(_active_news_items, 0, sizeof(_active_news_items)); truelight@0: } truelight@0: truelight@0: static void MessageOptionsWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: uint16 x = _news_display_opt; truelight@0: uint32 cs = 0; truelight@0: int i, y; truelight@0: truelight@0: for(i=3; i!=23; i+=2) { truelight@0: cs |= 1 << (i + (x&1)); truelight@0: x >>= 1; truelight@0: } truelight@0: cs |= (w->click_state >> 23) << 23; truelight@0: truelight@0: w->click_state = cs; truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: DrawStringCentered(185, 15, STR_0205_MESSAGE_TYPES, 0); truelight@0: truelight@0: y = 27; truelight@0: for(i=STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) { truelight@0: DrawString(124, y, i, 0); truelight@0: y += 12; truelight@0: } truelight@0: truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_CLICK: { truelight@0: int wid; truelight@0: if ( (uint)(wid=e->click.widget - 3) < 20) { truelight@0: if (!(wid & 1)) { truelight@0: _news_display_opt &= ~(1 << (wid>>1)); truelight@0: } else { truelight@0: _news_display_opt |= (1 << (wid>>1)); truelight@0: } truelight@0: SetWindowDirty(w); truelight@0: /* XXX: write settings */ truelight@0: } truelight@0: if( e->click.widget == 23) { truelight@0: _news_display_opt = 0; truelight@0: HandleButtonClick(w, 23); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: if( e->click.widget == 24) { truelight@0: _news_display_opt = ~0; truelight@0: HandleButtonClick(w, 24); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _message_options_widgets[] = { truelight@0: { WWT_CLOSEBOX, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 13, 11, 369, 0, 13, STR_0204_MESSAGE_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 13, 0, 369, 14, 172, 0x0}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 26, 37, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 26, 37, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 38, 49, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 38, 49, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 50, 61, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 50, 61, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 62, 73, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 62, 73, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 74, 85, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 74, 85, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 86, 97, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 86, 97, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 98, 109, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 98, 109, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 110, 121, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 110, 121, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 122, 133, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 122, 133, STR_02B9_FULL}, truelight@0: { WWT_CLOSEBOX, 3, 2, 61, 134, 145, STR_02B8_SUMMARY}, truelight@0: { WWT_CLOSEBOX, 3, 62, 121, 134, 145, STR_02B9_FULL}, truelight@0: truelight@0: { WWT_PUSHTXTBTN, 3, 15, 170, 154, 165, STR_MESSAGES_DISABLE_ALL, STR_NULL }, truelight@0: { WWT_PUSHTXTBTN, 3, 200, 355, 154, 165, STR_MESSAGES_ENABLE_ALL, STR_NULL }, truelight@0: truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _message_options_desc = { truelight@0: 270, 22, 370, 173, truelight@0: WC_GAME_OPTIONS,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _message_options_widgets, truelight@0: MessageOptionsWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: truelight@0: truelight@0: void ShowMessageOptions() truelight@0: { truelight@0: DeleteWindowById(WC_GAME_OPTIONS, 0); truelight@0: AllocateWindowDesc(&_message_options_desc); truelight@0: } truelight@0: truelight@0: truelight@0: static void GetNewsString(NewsItem *ni, byte *buffer) truelight@0: { truelight@0: StringID str; truelight@0: byte *s, *d; truelight@0: truelight@0: if (ni->display_mode == 3) { truelight@0: str = _get_news_string_callback[ni->callback](ni); truelight@0: } else { truelight@0: COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); truelight@0: str = ni->string_id; truelight@0: } truelight@0: truelight@0: GetString(str_buffr, str); truelight@0: assert(strlen(str_buffr) < sizeof(str_buffr) - 1); truelight@0: truelight@0: s = str_buffr; truelight@0: d = buffer; truelight@0: truelight@0: for(;;s++) { truelight@0: // cut strings that are too long truelight@0: if(s >= str_buffr + 55) { truelight@0: d[0] = d[1] = d[2] = '.'; truelight@0: d+=3; truelight@0: *d = 0; truelight@0: break; truelight@0: } truelight@0: truelight@0: if (*s == 0) { truelight@0: *d = 0; truelight@0: break; truelight@0: } else if (*s == 13) { truelight@0: d[0] = d[1] = d[2] = d[3] = ' '; truelight@0: d+=4; truelight@0: } else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { truelight@0: *d++ = *s; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: static void MessageHistoryWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: uint n, y, i; truelight@0: char buffer[256]; truelight@0: NewsItem *ni; truelight@0: truelight@0: for(n=10; n!=0; n--) truelight@0: if (!_active_news_items[n - 1].string_id) truelight@0: break; truelight@0: n = 10 - n; truelight@0: truelight@0: SetVScrollCount(w, n); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: y = 18; truelight@0: for(i=w->vscroll.pos; i!=n; i++) { truelight@0: ni = &_active_news_items[i + (10 - n)]; truelight@0: truelight@0: assert(ni->string_id); truelight@0: truelight@0: SET_DPARAM16(0, ni->date); truelight@0: DrawString(4, y, STR_00AF, 16); truelight@0: truelight@0: GetNewsString(ni, buffer); truelight@0: DoDrawString(buffer, 85, y, 16); truelight@0: y += 12; truelight@0: } truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 2: { truelight@0: uint y = (e->click.pt.y - 18) / 12; truelight@0: NewsItem *ni; truelight@0: truelight@0: if (y >= (uint)w->vscroll.count) truelight@0: return; truelight@0: truelight@0: ni = &_active_news_items[w->vscroll.pos + y + (10 - w->vscroll.count)]; truelight@0: truelight@0: // NOT YET... truelight@0: // ShowNewsMessage(y); truelight@0: truelight@0: break; truelight@0: } truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _message_history_widgets[] = { truelight@0: { WWT_CLOSEBOX, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 13, 11, 399, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_IMGBTN, 13, 0, 388, 14, 147, 0x0, STR_MESSAGE_HISTORY_TIP}, truelight@0: { WWT_SCROLLBAR, 13, 389, 399, 14, 147, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _message_history_desc = { truelight@0: 240, 22, 400, 148, truelight@0: WC_MESSAGE_HISTORY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _message_history_widgets, truelight@0: MessageHistoryWndProc truelight@0: }; truelight@0: truelight@0: void ShowMessageHistory() truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: DeleteWindowById(WC_MESSAGE_HISTORY, 0); truelight@0: w = AllocateWindowDesc(&_message_history_desc); truelight@0: truelight@0: if (w) { truelight@0: w->vscroll.cap = 11; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } truelight@0: