diff options
Diffstat (limited to 'src/npc.cpp')
-rw-r--r-- | src/npc.cpp | 39 |
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); + } +} |