From 118f7432177c1ff0262db555d56865d7cbdeedd0 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 7 Oct 2024 12:27:05 +0200 Subject: Use Timer for duration of blinking name This fixes the duration on 1500 ms, whereas before it was dependent on the framerate, blinking for 200 frames. --- src/playerrelations.cpp | 2 +- src/text.cpp | 21 +++++++++++---------- src/text.h | 18 ++++++------------ 3 files changed, 18 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 47577f9e..f949203e 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -349,7 +349,7 @@ public: void ignore(Being *being, unsigned int flags) override { - being->flashName(200); + being->flashName(1500); } }; diff --git a/src/text.cpp b/src/text.cpp index b71667c5..26124666 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -136,20 +136,21 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) *mColor, mFont, !mIsSpeech, true); } -FlashText::FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, - const gcn::Color *color, gcn::Font *font) : - Text(text, x, y, alignment, color, false, font), - mTime(0) -{ -} void FlashText::draw(gcn::Graphics *graphics, int xOff, int yOff) { - if (mTime) + if (mTimer.isSet()) { - if ((--mTime & 4) == 0) - return; + if (!mTimer.passed()) + { + if ((mTimer.elapsed() & 64) == 0) + return; + } + else + { + mTimer.reset(); + } } + Text::draw(graphics, xOff, yOff); } diff --git a/src/text.h b/src/text.h index 2a5c8dde..9fa6104f 100644 --- a/src/text.h +++ b/src/text.h @@ -25,6 +25,8 @@ #include "graphics.h" +#include "utils/time.h" + #include class TextManager; @@ -82,20 +84,12 @@ class Text class FlashText : public Text { public: - FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, - const gcn::Color* color, - gcn::Font *font = nullptr); - - /** - * Remove the text from the screen - */ - ~FlashText() override {} + using Text::Text; /** - * Flash the text for so many refreshes. + * Flash the text for so many milliseconds. */ - void flash(int time) { mTime = time; } + void flash(int time) { mTimer.set(time); } /** * Draws the text. @@ -103,7 +97,7 @@ class FlashText : public Text void draw(gcn::Graphics *graphics, int xOff, int yOff) override; private: - int mTime; /**< Time left for flashing */ + Timer mTimer; /**< Time left for flashing */ }; #endif // TEXT_H -- cgit v1.2.3-70-g09d2