271 |
271 |
272 // check the rare case that the oldest (to be overwritten) news item is open |
272 // check the rare case that the oldest (to be overwritten) news item is open |
273 if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) |
273 if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) |
274 MoveToNextItem(); |
274 MoveToNextItem(); |
275 |
275 |
276 _forced_news = INVALID_NEWS; |
|
277 if (_total_news < MAX_NEWS) _total_news++; |
276 if (_total_news < MAX_NEWS) _total_news++; |
278 |
277 |
279 /* Increase _latest_news. If we have no news yet, use _oldest news as an |
278 /* Increase _latest_news. If we have no news yet, use _oldest news as an |
280 * index. We cannot use 0 as _oldest_news can jump around due to |
279 * index. We cannot use 0 as _oldest_news can jump around due to |
281 * DeleteVehicleNews */ |
280 * DeleteVehicleNews */ |
286 if (l_news != INVALID_NEWS && _latest_news == _oldest_news) { |
285 if (l_news != INVALID_NEWS && _latest_news == _oldest_news) { |
287 assert(_total_news == MAX_NEWS); |
286 assert(_total_news == MAX_NEWS); |
288 _oldest_news = increaseIndex(_oldest_news); |
287 _oldest_news = increaseIndex(_oldest_news); |
289 } |
288 } |
290 |
289 |
291 /*DEBUG(misc, 0) ("+cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
290 /*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
292 _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ |
291 _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/ |
293 |
292 |
294 { /* Add news to _latest_news */ |
293 { /* Add news to _latest_news */ |
295 Window *w; |
294 Window *w; |
296 NewsItem *ni = &_news_items[_latest_news]; |
295 NewsItem *ni = &_news_items[_latest_news]; |
297 memset(ni, 0, sizeof(*ni)); |
296 memset(ni, 0, sizeof(*ni)); |
441 ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0); |
440 ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0); |
442 break; |
441 break; |
443 } |
442 } |
444 } |
443 } |
445 |
444 |
446 /*DEBUG(misc, 0) (" cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
445 /*DEBUG(misc, 0, " cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
447 _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ |
446 _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/ |
448 |
447 |
449 WP(w, news_d).ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news]; |
448 WP(w, news_d).ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news]; |
450 w->flags4 |= WF_DISABLE_VP_SCROLL; |
449 w->flags4 |= WF_DISABLE_VP_SCROLL; |
451 } |
450 } |
452 |
451 |
554 } |
553 } |
555 } |
554 } |
556 |
555 |
557 void ShowLastNewsMessage(void) |
556 void ShowLastNewsMessage(void) |
558 { |
557 { |
559 switch (_forced_news) { |
558 if (_forced_news == INVALID_NEWS) { |
560 case INVALID_NEWS: // Not forced any news yet, show the current one |
559 /* Not forced any news yet, show the current one, unless a news window is |
561 ShowNewsMessage(_current_news); |
560 * open (which can only be the current one), then show the previous item */ |
562 break; |
561 const Window *w = FindWindowById(WC_NEWS_WINDOW, 0); |
563 case 0: // |
562 ShowNewsMessage((w == NULL) ? _current_news : decreaseIndex(_current_news)); |
564 ShowNewsMessage(_total_news != MAX_NEWS ? _latest_news : MAX_NEWS - 1); |
563 } else if (_forced_news == _oldest_news) { |
565 break; |
564 /* We have reached the oldest news, start anew with the latest */ |
566 default: // 'Scrolling' through news history show each one in turn |
565 ShowNewsMessage(_latest_news); |
567 ShowNewsMessage(_forced_news - 1); |
566 } else { |
568 break; |
567 /* 'Scrolling' through news history show each one in turn */ |
|
568 ShowNewsMessage(decreaseIndex(_forced_news)); |
569 } |
569 } |
570 } |
570 } |
571 |
571 |
572 |
572 |
573 /* return news by number, with 0 being the most |
573 /* return news by number, with 0 being the most |
888 if (ni->flags & NF_VEHICLE && |
888 if (ni->flags & NF_VEHICLE && |
889 ni->data_a == vid && |
889 ni->data_a == vid && |
890 (news == INVALID_STRING_ID || ni->string_id == news)) { |
890 (news == INVALID_STRING_ID || ni->string_id == news)) { |
891 Window *w; |
891 Window *w; |
892 |
892 |
893 if (_forced_news == n || _current_news == n) MoveToNextItem(); |
893 /* If we delete a forced news and it is just before the current news |
|
894 * then we need to advance to the next news (if any) */ |
|
895 if (_forced_news == n) MoveToNextItem(); |
|
896 if (_forced_news == INVALID_NEWS && _current_news == n) MoveToNextItem(); |
894 _total_news--; |
897 _total_news--; |
895 |
898 |
896 /* If this is the last news item, invalidate _latest_news */ |
899 /* If this is the last news item, invalidate _latest_news */ |
897 if (_total_news == 0) { |
900 if (_total_news == 0) { |
898 assert(_latest_news == _oldest_news); |
901 assert(_latest_news == _oldest_news); |
907 * will become (change dramatized to make clear) |
910 * will become (change dramatized to make clear) |
908 * [---------O-----------L--] |
911 * [---------O-----------L--] |
909 * We also need an update of the current, forced and visible (open window) |
912 * We also need an update of the current, forced and visible (open window) |
910 * news's as this shifting could change the items they were pointing to */ |
913 * news's as this shifting could change the items they were pointing to */ |
911 if (_total_news != 0) { |
914 if (_total_news != 0) { |
912 NewsID i, visible_news; |
|
913 w = FindWindowById(WC_NEWS_WINDOW, 0); |
915 w = FindWindowById(WC_NEWS_WINDOW, 0); |
914 visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS; |
916 NewsID visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS; |
915 |
917 |
916 for (i = n;; i = decreaseIndex(i)) { |
918 for (NewsID i = n;; i = decreaseIndex(i)) { |
917 _news_items[i] = _news_items[decreaseIndex(i)]; |
919 _news_items[i] = _news_items[decreaseIndex(i)]; |
918 |
920 |
919 if (i == _current_news) _current_news = increaseIndex(_current_news); |
921 if (i == _current_news) _current_news = increaseIndex(_current_news); |
920 if (i == _forced_news) _forced_news = increaseIndex(_forced_news); |
922 if (i == _forced_news) _forced_news = increaseIndex(_forced_news); |
921 if (i == visible_news) WP(w, news_d).ni = &_news_items[increaseIndex(visible_news)]; |
923 if (i == visible_news) WP(w, news_d).ni = &_news_items[increaseIndex(visible_news)]; |
923 if (i == _oldest_news) break; |
925 if (i == _oldest_news) break; |
924 } |
926 } |
925 _oldest_news = increaseIndex(_oldest_news); |
927 _oldest_news = increaseIndex(_oldest_news); |
926 } |
928 } |
927 |
929 |
928 /*DEBUG(misc, 0) ("-cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
930 /*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
929 _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ |
931 _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/ |
930 |
932 |
931 w = FindWindowById(WC_MESSAGE_HISTORY, 0); |
933 w = FindWindowById(WC_MESSAGE_HISTORY, 0); |
932 if (w != NULL) { |
934 if (w != NULL) { |
933 SetWindowDirty(w); |
935 SetWindowDirty(w); |
934 w->vscroll.count = _total_news; |
936 w->vscroll.count = _total_news; |