summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-08-28 20:29:06 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-08-28 20:29:06 +0000
commitbdb09d26fc6c489228cb2c28be75024f9a49eb75 (patch)
tree28ea782fa98c6fe8b060da71a0bb626781ab1b5d /src/being.cpp
parent9a8456c6c95f5d95c568664ba5adaeb466cfbb0d (diff)
downloadmana-client-bdb09d26fc6c489228cb2c28be75024f9a49eb75.tar.gz
mana-client-bdb09d26fc6c489228cb2c28be75024f9a49eb75.tar.bz2
mana-client-bdb09d26fc6c489228cb2c28be75024f9a49eb75.tar.xz
mana-client-bdb09d26fc6c489228cb2c28be75024f9a49eb75.zip
Accepted Patch by Scraggy that moves text in such a way that no text overlaps
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 1880e7c0..dca87677 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -34,6 +34,7 @@
#include "particle.h"
#include "sound.h"
#include "localplayer.h"
+#include "text.h"
#include "resources/resourcemanager.h"
#include "resources/imageset.h"
@@ -51,6 +52,9 @@
int Being::instances = 0;
ImageSet *Being::emotionSet = NULL;
+static const int X_SPEECH_OFFSET = 18;
+static const int Y_SPEECH_OFFSET = 60;
+
Being::Being(int id, int job, Map *map):
mJob(job),
mX(0), mY(0),
@@ -83,6 +87,7 @@ Being::Being(int id, int job, Map *map):
}
instances++;
+ mSpeech = 0;
}
Being::~Being()
@@ -106,6 +111,8 @@ Being::~Being()
emotionSet->decRef();
emotionSet = NULL;
}
+
+ delete mSpeech;
}
void
@@ -153,7 +160,12 @@ Being::setSprite(int slot, int id, std::string color)
void
Being::setSpeech(const std::string &text, Uint32 time)
{
- mSpeech = text;
+ // don't introduce a memory leak
+ delete mSpeech;
+
+ mSpeech = new Text(text, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET,
+ gcn::Graphics::CENTER, speechFont,
+ gcn::Color(255, 255, 255));
mSpeechTime = 500;
}
@@ -361,13 +373,28 @@ void
Being::logic()
{
// Reduce the time that speech is still displayed
- if (mSpeechTime > 0)
- mSpeechTime--;
+ if (mSpeechTime > 0 && mSpeech)
+ {
+ if (--mSpeechTime == 0)
+ {
+ delete mSpeech;
+ mSpeech = 0;
+ }
+ }
+ int oldPx = mPx;
+ int oldPy = mPy;
// Update pixel coordinates
mPx = mX * 32 + getXOffset();
mPy = mY * 32 + getYOffset();
-
+ if (mPx != oldPx || mPy != oldPy)
+ {
+ if (mSpeech)
+ {
+ mSpeech->adviseXY(mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET);
+ }
+ updateCoords();
+ }
if (mEmotion != 0)
{
mEmotionTime--;
@@ -432,21 +459,6 @@ Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
graphics->drawImage(emotionSet->get(emotionIndex), px, py);
}
-void
-Being::drawSpeech(Graphics *graphics, int offsetX, int offsetY)
-{
- int px = mPx + offsetX;
- int py = mPy + offsetY;
-
- // Draw speech above this being
- if (mSpeechTime > 0)
- {
- graphics->setFont(speechFont);
- graphics->setColor(gcn::Color(255, 255, 255));
- graphics->drawText(mSpeech, px + 18, py - 60, gcn::Graphics::CENTER);
- }
-}
-
Being::Type
Being::getType() const
{