285 if (l_news != INVALID_NEWS && _latest_news == _oldest_news) { |
285 if (l_news != INVALID_NEWS && _latest_news == _oldest_news) { |
286 assert(_total_news == MAX_NEWS); |
286 assert(_total_news == MAX_NEWS); |
287 _oldest_news = increaseIndex(_oldest_news); |
287 _oldest_news = increaseIndex(_oldest_news); |
288 } |
288 } |
289 |
289 |
|
290 /*DEBUG(misc, 0) ("+cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
|
291 _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ |
|
292 |
290 { /* Add news to _latest_news */ |
293 { /* Add news to _latest_news */ |
291 Window *w; |
294 Window *w; |
292 NewsItem *ni = &_news_items[_latest_news]; |
295 NewsItem *ni = &_news_items[_latest_news]; |
293 memset(ni, 0, sizeof(*ni)); |
296 memset(ni, 0, sizeof(*ni)); |
294 |
297 |
312 w->vscroll.count = _total_news; |
315 w->vscroll.count = _total_news; |
313 } |
316 } |
314 } |
317 } |
315 |
318 |
316 |
319 |
317 // don't show item if it's older than x days |
320 /* Don't show item if it's older than x days, corresponds with NewsType in news.h */ |
318 static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180}; |
321 static const byte _news_items_age[] = {60, 60, 90, 60, 90, 30, 150, 30, 90, 180}; |
319 |
322 |
320 static const Widget _news_type13_widgets[] = { |
323 static const Widget _news_type13_widgets[] = { |
321 { WWT_PANEL, RESIZE_NONE, 15, 0, 429, 0, 169, 0x0, STR_NULL}, |
324 { WWT_PANEL, RESIZE_NONE, 15, 0, 429, 0, 169, 0x0, STR_NULL}, |
322 { WWT_PANEL, RESIZE_NONE, 15, 0, 10, 0, 11, 0x0, STR_NULL}, |
325 { WWT_PANEL, RESIZE_NONE, 15, 0, 10, 0, 11, 0x0, STR_NULL}, |
436 AssignWindowViewport(w, 3, 17, 0x112, 0x2F, |
439 AssignWindowViewport(w, 3, 17, 0x112, 0x2F, |
437 ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0); |
440 ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), 0); |
438 break; |
441 break; |
439 } |
442 } |
440 } |
443 } |
|
444 |
|
445 /*DEBUG(misc, 0) (" cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
|
446 _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ |
|
447 |
441 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]; |
442 w->flags4 |= WF_DISABLE_VP_SCROLL; |
449 w->flags4 |= WF_DISABLE_VP_SCROLL; |
443 } |
450 } |
444 |
451 |
445 // show news item in the ticker |
452 // show news item in the ticker |
883 Window *w; |
890 Window *w; |
884 |
891 |
885 if (_forced_news == n || _current_news == n) MoveToNextItem(); |
892 if (_forced_news == n || _current_news == n) MoveToNextItem(); |
886 _total_news--; |
893 _total_news--; |
887 |
894 |
888 // If this is the last news item, invalidate _latest_news |
895 /* If this is the last news item, invalidate _latest_news */ |
889 if (_latest_news == _oldest_news) { |
896 if (_total_news == 0) { |
890 assert(_total_news == 0); |
897 assert(_latest_news == _oldest_news); |
891 _latest_news = INVALID_NEWS; |
898 _latest_news = INVALID_NEWS; |
892 } |
899 } |
893 |
900 |
894 /* Since we only imitate a FIFO removing an arbitrary element does need |
901 /* Since we only imitate a FIFO removing an arbitrary element does need |
895 * some magic. Remove the item by shifting head towards the tail. eg |
902 * some magic. Remove the item by shifting head towards the tail. eg |
896 * oldest remove last |
903 * oldest remove last |
897 * | | | |
904 * | | | |
898 * [------O--------n-----L--] |
905 * [------O--------n-----L--] |
899 * will become (change dramatized to make clear) |
906 * will become (change dramatized to make clear) |
900 * [---------O-----------L--] |
907 * [---------O-----------L--] |
901 * Also update the current news item in case it was pointing to the |
908 * We also need an update of the current, forced and visible (open window) |
902 * oldest, now shifted item */ |
909 * news's as this shifting could change the items they were pointing to */ |
903 if (_total_news != 0) { |
910 if (_total_news != 0) { |
904 NewsID i; |
911 NewsID i, visible_news; |
905 for (i = n; i != _oldest_news; i = decreaseIndex(i)) { |
912 w = FindWindowById(WC_NEWS_WINDOW, 0); |
|
913 visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS; |
|
914 |
|
915 for (i = n;; i = decreaseIndex(i)) { |
906 _news_items[i] = _news_items[decreaseIndex(i)]; |
916 _news_items[i] = _news_items[decreaseIndex(i)]; |
|
917 |
|
918 if (i == _current_news) _current_news = increaseIndex(_current_news); |
|
919 if (i == _forced_news) _forced_news = increaseIndex(_forced_news); |
|
920 if (i == visible_news) WP(w, news_d).ni = &_news_items[increaseIndex(visible_news)]; |
|
921 |
|
922 if (i == _oldest_news) break; |
907 } |
923 } |
908 |
|
909 if (_current_news == _oldest_news) _current_news = increaseIndex(_current_news); |
|
910 _oldest_news = increaseIndex(_oldest_news); |
924 _oldest_news = increaseIndex(_oldest_news); |
911 } |
925 } |
|
926 |
|
927 /*DEBUG(misc, 0) ("-cur %3d, old %2d, lat %3d, for %3d, tot %2d", |
|
928 _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ |
912 |
929 |
913 w = FindWindowById(WC_MESSAGE_HISTORY, 0); |
930 w = FindWindowById(WC_MESSAGE_HISTORY, 0); |
914 if (w != NULL) { |
931 if (w != NULL) { |
915 SetWindowDirty(w); |
932 SetWindowDirty(w); |
916 w->vscroll.count = _total_news; |
933 w->vscroll.count = _total_news; |