summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-07 12:27:05 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-08 21:03:44 +0200
commit118f7432177c1ff0262db555d56865d7cbdeedd0 (patch)
tree6ecd8ff670b6e2ece5f23ba52a6ea67bd0f1f0f5 /src
parent2324c9ffd3e7eb1057eeb48697b7225a97438420 (diff)
downloadmana-118f7432177c1ff0262db555d56865d7cbdeedd0.tar.gz
mana-118f7432177c1ff0262db555d56865d7cbdeedd0.tar.bz2
mana-118f7432177c1ff0262db555d56865d7cbdeedd0.tar.xz
mana-118f7432177c1ff0262db555d56865d7cbdeedd0.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/playerrelations.cpp2
-rw-r--r--src/text.cpp21
-rw-r--r--src/text.h18
3 files changed, 18 insertions, 23 deletions
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 <guichan/color.hpp>
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