summaryrefslogtreecommitdiff
path: root/src/news_gui.cpp
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2018-05-04 21:29:22 +0100
committerPeterN <peter@fuzzle.org>2019-01-11 11:56:21 +0000
commit2a8fa5fef9021bff67a13899832bf6f0a18e6ea1 (patch)
treec712f1973d6c74938e968f752a069b499dde7266 /src/news_gui.cpp
parent916e911806083a2fe06a79f6f10e275015079149 (diff)
downloadopenttd-2a8fa5fef9021bff67a13899832bf6f0a18e6ea1.tar.xz
Change: Split up Window::OnTick into OnGameTick and OnRealtimeTick. Adjust timers to work with milliseconds instead of ticks.
Diffstat (limited to 'src/news_gui.cpp')
-rw-r--r--src/news_gui.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 71a39eb3a..183b27b90 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -260,11 +260,13 @@ struct NewsWindow : Window {
uint16 chat_height; ///< Height of the chat window.
uint16 status_height; ///< Height of the status bar window
const NewsItem *ni; ///< News item to display.
- static uint duration; ///< Remaining time for showing current news message (may only be accessed while a news item is displayed).
+ static int duration; ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
+
+ uint timer;
NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
{
- NewsWindow::duration = 555;
+ NewsWindow::duration = 16650;
const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
this->chat_height = (w != NULL) ? w->height : 0;
this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
@@ -485,11 +487,18 @@ struct NewsWindow : Window {
this->SetWindowTop(newtop);
}
- virtual void OnTick()
+ virtual void OnRealtimeTick(uint delta_ms)
{
- /* Scroll up newsmessages from the bottom in steps of 4 pixels */
- int newtop = max(this->top - 4, _screen.height - this->height - this->status_height - this->chat_height);
- this->SetWindowTop(newtop);
+ int count = CountIntervalElapsed(this->timer, delta_ms, 15);
+ if (count > 0) {
+ /* Scroll up newsmessages from the bottom */
+ int newtop = max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
+ this->SetWindowTop(newtop);
+ }
+
+ /* Decrement the news timer. We don't need to action an elapsed event here,
+ * so no need to use TimerElapsed(). */
+ if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
}
private:
@@ -536,7 +545,7 @@ private:
}
};
-/* static */ uint NewsWindow::duration = 0; // Instance creation.
+/* static */ int NewsWindow::duration = 0; // Instance creation.
/** Open up an own newspaper window for the news item */
@@ -588,11 +597,8 @@ static bool ReadyForNextItem()
* Check if the status bar message is still being displayed? */
if (IsNewsTickerShown()) return false;
- /* Newspaper message, decrement duration counter */
- if (NewsWindow::duration != 0) NewsWindow::duration--;
-
/* neither newsticker nor newspaper are running */
- return (NewsWindow::duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
+ return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
}
/** Move to the next news item */