diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-08-28 20:29:06 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-08-28 20:29:06 +0000 |
commit | bdb09d26fc6c489228cb2c28be75024f9a49eb75 (patch) | |
tree | 28ea782fa98c6fe8b060da71a0bb626781ab1b5d /src/player.cpp | |
parent | 9a8456c6c95f5d95c568664ba5adaeb466cfbb0d (diff) | |
download | mana-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/player.cpp')
-rw-r--r-- | src/player.cpp | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/src/player.cpp b/src/player.cpp index d0c6bdc6..f86e7179 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -34,11 +34,34 @@ #include "utils/strprintf.h" #include "gui/gui.h" +#include <iostream> + +static const int NAME_X_OFFSET = 15; +static const int NAME_Y_OFFSET = 30; Player::Player(int id, int job, Map *map): - Being(id, job, map), - mDrawStrategy(NULL) + Being(id, job, map) { + mName = 0; +} + +Player::~Player() +{ + if (mName) + { + delete mName; + } +} + +void Player::setName(const std::string &name) +{ + if (mName == 0) + { + mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, + gcn::Graphics::CENTER, + speechFont, gcn::Color(255, 255, 255)); + Being::setName(name); + } } void @@ -75,37 +98,13 @@ Player::getType() const return PLAYER; } - void -Player::setNameDrawStrategy(PlayerNameDrawStrategy *draw_strategy) +Player::flash(int time) { - if (mDrawStrategy) - delete mDrawStrategy; - mDrawStrategy = draw_strategy; -} - -class -DefaultPlayerNameDrawStrategy : public PlayerNameDrawStrategy -{ -public: - virtual void draw(Player *player, Graphics *graphics, int px, int py) + if (mName) { - graphics->setFont(speechFont); - graphics->setColor(gcn::Color(255, 255, 255)); - graphics->drawText(player->getName(), px + 15, py + 30, gcn::Graphics::CENTER); + mName->flash(time); } -}; - -void -Player::drawName(Graphics *graphics, int offsetX, int offsetY) -{ - int px = mPx + offsetX; - int py = mPy + offsetY; - - if (mDrawStrategy) - mDrawStrategy->draw(this, graphics, px, py); - else - DefaultPlayerNameDrawStrategy().draw(this, graphics, px, py); } void Player::setGender(int gender) @@ -202,3 +201,11 @@ void Player::setSprite(int slot, int id, std::string color) Being::setSprite(slot, id, color); } + +void Player::updateCoords() +{ + if (mName) + { + mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); + } +} |