diff options
author | Darkvater <Darkvater@openttd.org> | 2007-01-11 01:21:55 +0000 |
---|---|---|
committer | Darkvater <Darkvater@openttd.org> | 2007-01-11 01:21:55 +0000 |
commit | e29124d48b794153be2f3c0e9772cbbda851727d (patch) | |
tree | 7a5f8fe5c665872fd359fd378a30b8de3416bf27 | |
parent | b32054b6d7be5668cc521a067a081cfd4c91c068 (diff) | |
download | openttd-e29124d48b794153be2f3c0e9772cbbda851727d.tar.xz |
(svn r8049) -Regression (r7369): Removing certain news windows could cause a crash due to only
one MoveToNextItem() in DeleteVehicleNews (added in r3757). To work correctly do not
reset _forced_news to INVALID_NEWS when a new item is added, but leave it.
-Codechange: ShowLastNewsMessage has been changed so that it actually works, wraps
around correctly (array as FIFO) and shows the previous news item if the current
news item is open (previously this was doubly shown).
-rw-r--r-- | src/news_gui.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp index df3936af1..c8357396a 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -273,7 +273,6 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b) if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) MoveToNextItem(); - _forced_news = INVALID_NEWS; if (_total_news < MAX_NEWS) _total_news++; /* Increase _latest_news. If we have no news yet, use _oldest news as an @@ -288,8 +287,8 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b) _oldest_news = increaseIndex(_oldest_news); } - /*DEBUG(misc, 0) ("+cur %3d, old %2d, lat %3d, for %3d, tot %2d", - _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ + /*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d", + _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/ { /* Add news to _latest_news */ Window *w; @@ -443,8 +442,8 @@ static void ShowNewspaper(NewsItem *ni) } } - /*DEBUG(misc, 0) (" cur %3d, old %2d, lat %3d, for %3d, tot %2d", - _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ + /*DEBUG(misc, 0, " cur %3d, old %2d, lat %3d, for %3d, tot %2d", + _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/ WP(w, news_d).ni = &_news_items[_forced_news == INVALID_NEWS ? _current_news : _forced_news]; w->flags4 |= WF_DISABLE_VP_SCROLL; @@ -556,16 +555,17 @@ static void ShowNewsMessage(NewsID i) void ShowLastNewsMessage(void) { - switch (_forced_news) { - case INVALID_NEWS: // Not forced any news yet, show the current one - ShowNewsMessage(_current_news); - break; - case 0: // - ShowNewsMessage(_total_news != MAX_NEWS ? _latest_news : MAX_NEWS - 1); - break; - default: // 'Scrolling' through news history show each one in turn - ShowNewsMessage(_forced_news - 1); - break; + if (_forced_news == INVALID_NEWS) { + /* Not forced any news yet, show the current one, unless a news window is + * open (which can only be the current one), then show the previous item */ + const Window *w = FindWindowById(WC_NEWS_WINDOW, 0); + ShowNewsMessage((w == NULL) ? _current_news : decreaseIndex(_current_news)); + } else if (_forced_news == _oldest_news) { + /* We have reached the oldest news, start anew with the latest */ + ShowNewsMessage(_latest_news); + } else { + /* 'Scrolling' through news history show each one in turn */ + ShowNewsMessage(decreaseIndex(_forced_news)); } } @@ -890,7 +890,10 @@ void DeleteVehicleNews(VehicleID vid, StringID news) (news == INVALID_STRING_ID || ni->string_id == news)) { Window *w; - if (_forced_news == n || _current_news == n) MoveToNextItem(); + /* If we delete a forced news and it is just before the current news + * then we need to advance to the next news (if any) */ + if (_forced_news == n) MoveToNextItem(); + if (_forced_news == INVALID_NEWS && _current_news == n) MoveToNextItem(); _total_news--; /* If this is the last news item, invalidate _latest_news */ @@ -909,11 +912,10 @@ void DeleteVehicleNews(VehicleID vid, StringID news) * We also need an update of the current, forced and visible (open window) * news's as this shifting could change the items they were pointing to */ if (_total_news != 0) { - NewsID i, visible_news; w = FindWindowById(WC_NEWS_WINDOW, 0); - visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS; + NewsID visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS; - for (i = n;; i = decreaseIndex(i)) { + for (NewsID i = n;; i = decreaseIndex(i)) { _news_items[i] = _news_items[decreaseIndex(i)]; if (i == _current_news) _current_news = increaseIndex(_current_news); @@ -925,8 +927,8 @@ void DeleteVehicleNews(VehicleID vid, StringID news) _oldest_news = increaseIndex(_oldest_news); } - /*DEBUG(misc, 0) ("-cur %3d, old %2d, lat %3d, for %3d, tot %2d", - _current_news, _oldest_news, _latest_news, _forced_news, _total_news); */ + /*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d", + _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/ w = FindWindowById(WC_MESSAGE_HISTORY, 0); if (w != NULL) { |