From afbf6a59182d9b1ca36b9dab9bd391ad0ae6222f Mon Sep 17 00:00:00 2001 From: "Johannes E. Krause" Date: Thu, 30 May 2019 00:11:20 +0200 Subject: [PATCH] Feature: Allow showing Newspaper and Ticker messages in parallel --- src/news_gui.cpp | 82 ++++++++++++++++++++++++++++++++++--------- src/statusbar_gui.cpp | 2 +- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 7e99939b17..34cfa7a589 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -593,38 +593,46 @@ void InitNewsItemStructs() } /** - * Are we ready to show another news item? - * Only if nothing is in the newsticker and no newspaper is displayed + * Are we ready to show another ticker item? + * Only if nothing is in the newsticker is displayed */ -static bool ReadyForNextItem() +static bool ReadyForNextTickerItem() { - const NewsItem *ni = _forced_news == nullptr ? _current_news : _forced_news; + const NewsItem *ni = _statusbar_news_item; if (ni == nullptr) return true; /* Ticker message * Check if the status bar message is still being displayed? */ if (IsNewsTickerShown()) return false; + return true; +} + +/** + * Are we ready to show another news item? + * Only if no newspaper is displayed + */ +static bool ReadyForNextNewsItem() +{ + const NewsItem *ni = _forced_news == nullptr ? _current_news : _forced_news; + if (ni == nullptr) return true; /* neither newsticker nor newspaper are running */ return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == nullptr); } -/** Move to the next news item */ -static void MoveToNextItem() +/** Move to the next ticker item */ +static void MoveToNextTickerItem() { InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar - DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown - _forced_news = nullptr; - _statusbar_news_item = nullptr; /* if we're not at the last item, then move on */ - if (_current_news != _latest_news) { - _current_news = (_current_news == nullptr) ? _oldest_news : _current_news->next; - const NewsItem *ni = _current_news; + while (_statusbar_news_item != _latest_news) { + _statusbar_news_item = (_statusbar_news_item == nullptr) ? _oldest_news : _statusbar_news_item->next; + const NewsItem *ni = _statusbar_news_item; const NewsType type = ni->type; /* check the date, don't show too old items */ - if (_date - _news_type_data[type].age > ni->date) return; + if (_date - _news_type_data[type].age > ni->date) continue; switch (_news_type_data[type].GetDisplay()) { default: NOT_REACHED(); @@ -636,6 +644,36 @@ static void MoveToNextItem() ShowTicker(ni); break; + case ND_FULL: // Full - show newspaper, skipped here + continue; + } + return; + } +} + +/** Move to the next news item */ +static void MoveToNextNewsItem() +{ + DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown + _forced_news = nullptr; + + /* if we're not at the last item, then move on */ + while (_current_news != _latest_news) { + _current_news = (_current_news == nullptr) ? _oldest_news : _current_news->next; + const NewsItem *ni = _current_news; + const NewsType type = ni->type; + + /* check the date, don't show too old items */ + if (_date - _news_type_data[type].age > ni->date) continue; + + switch (_news_type_data[type].GetDisplay()) { + default: NOT_REACHED(); + case ND_OFF: // Off - show nothing only a small reminder in the status bar, skipped here + continue; + + case ND_SUMMARY: // Summary - show ticker, skipped here + continue; + case ND_FULL: // Full - show newspaper ShowNewspaper(ni); break; @@ -778,14 +816,23 @@ static void DeleteNewsItem(NewsItem *ni) _total_news--; - if (_forced_news == ni || _current_news == ni || _statusbar_news_item == ni) { + if (_forced_news == ni || _current_news == ni) { /* When we're the current news, go to the previous item first; * we just possibly made that the last news item. */ if (_current_news == ni) _current_news = ni->prev; /* About to remove the currently forced item (shown as newspapers) || - * about to remove the currently displayed item (newspapers, ticker, or just a reminder) */ - MoveToNextItem(); + * about to remove the currently displayed item (newspapers) */ + MoveToNextNewsItem(); + } + + if (_statusbar_news_item == ni) { + /* When we're the current news, go to the previous item first; + * we just possibly made that the last news item. */ + _statusbar_news_item = ni->prev; + + /* About to remove the currently displayed item (ticker, or just a reminder) */ + MoveToNextTickerItem(); } delete ni; @@ -906,7 +953,8 @@ void NewsLoop() _last_clean_month = _cur_month; } - if (ReadyForNextItem()) MoveToNextItem(); + if (ReadyForNextTickerItem()) MoveToNextTickerItem(); + if (ReadyForNextNewsItem()) MoveToNextNewsItem(); } /** Do a forced show of a specific message */ diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index a3a9e2c424..82939e8961 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -165,7 +165,7 @@ struct StatusBarWindow : Window { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_HOR_CENTER); } else if (_pause_mode != PM_UNPAUSED) { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_PAUSED, TC_FROMSTRING, SA_HOR_CENTER); - } else if (this->ticker_scroll < TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == nullptr && _statusbar_news_item != nullptr && _statusbar_news_item->string_id != 0) { + } else if (this->ticker_scroll < TICKER_STOP && _statusbar_news_item != nullptr && _statusbar_news_item->string_id != 0) { /* Draw the scrolling news text */ if (!DrawScrollingStatusText(_statusbar_news_item, ScaleGUITrad(this->ticker_scroll), r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) { InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED);