summaryrefslogtreecommitdiff
path: root/src/npc.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/npc.cpp
parent9a8456c6c95f5d95c568664ba5adaeb466cfbb0d (diff)
downloadMana-bdb09d26fc6c489228cb2c28be75024f9a49eb75.tar.gz
Mana-bdb09d26fc6c489228cb2c28be75024f9a49eb75.tar.bz2
Mana-bdb09d26fc6c489228cb2c28be75024f9a49eb75.tar.xz
Mana-bdb09d26fc6c489228cb2c28be75024f9a49eb75.zip
Accepted Patch by Scraggy that moves text in such a way that no text overlaps
Diffstat (limited to 'src/npc.cpp')
-rw-r--r--src/npc.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/npc.cpp b/src/npc.cpp
index 2177aedc..ab3c6970 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -26,6 +26,7 @@
#include "animatedsprite.h"
#include "graphics.h"
#include "particle.h"
+#include "text.h"
#include "net/messageout.h"
#include "net/protocol.h"
@@ -35,12 +36,15 @@
NPC *current_npc = 0;
+static const int NAME_X_OFFSET = 15;
+static const int NAME_Y_OFFSET = 30;
+
NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
Being(id, job, map), mNetwork(network)
{
NPCInfo info = NPCDB::get(job);
- //setup NPC sprites
+ // Setup NPC sprites
int c = BASE_SPRITE;
for (std::list<NPCsprite*>::const_iterator i = info.sprites.begin();
i != info.sprites.end();
@@ -54,7 +58,7 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
c++;
}
- //setup particle effects
+ // Setup particle effects
for (std::list<std::string>::const_iterator i = info.particles.begin();
i != info.particles.end();
i++)
@@ -62,23 +66,26 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
Particle *p = particleEngine->addEffect(*i, 0, 0);
this->controlParticle(p);
}
+ mName = 0;
}
-Being::Type
-NPC::getType() const
+NPC::~NPC()
{
- return Being::NPC;
+ delete mName;
}
-void
-NPC::drawName(Graphics *graphics, Sint32 offsetX, Sint32 offsetY)
+void NPC::setName(const std::string &name)
{
- int px = mPx + offsetX;
- int py = mPy + offsetY;
+ delete mName;
+ mName = new Text(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET,
+ gcn::Graphics::CENTER, speechFont,
+ gcn::Color(200, 200, 255));
+}
- graphics->setFont(speechFont);
- graphics->setColor(gcn::Color(200, 200, 255));
- graphics->drawText(mName, px + 15, py + 30, gcn::Graphics::CENTER);
+Being::Type
+NPC::getType() const
+{
+ return Being::NPC;
}
void
@@ -129,3 +136,11 @@ NPC::sell()
outMsg.writeInt32(mId);
outMsg.writeInt8(1);
}
+
+void NPC::updateCoords()
+{
+ if (mName)
+ {
+ mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET);
+ }
+}