summaryrefslogtreecommitdiff
path: root/src/player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.cpp')
-rw-r--r--src/player.cpp127
1 files changed, 36 insertions, 91 deletions
diff --git a/src/player.cpp b/src/player.cpp
index fd7cd0d6..55888654 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -40,53 +40,23 @@
Player::Player(int id, int job, Map *map):
Being(id, job, map),
- mName(0),
+ mGender(GENDER_UNSPECIFIED),
+ mSpriteIDs(VECTOREND_SPRITE, 0),
+ mSpriteColors(VECTOREND_SPRITE, ""),
mIsGM(false),
mInParty(false)
{
+ for (int i = 0; i < VECTOREND_SPRITE; i++)
+ mSprites.push_back(NULL);
mShowName = config.getValue("visiblenames", 1);
config.addListener("visiblenames", this);
+
+ updateColors();
}
Player::~Player()
{
config.removeListener("visiblenames", this);
- delete mName;
-}
-
-void Player::setName(const std::string &name)
-{
- if (!mName && mShowName)
- {
- mNameColor = &guiPalette->getColor(Palette::PLAYER);
-
- const gcn::Color *color;
- if (this == player_node)
- {
- color = &guiPalette->getColor(Palette::SELF);
- }
- else if (mIsGM)
- {
- mNameColor = &guiPalette->getColor(Palette::GM);
- color = &guiPalette->getColor(Palette::GM_NAME);
- }
- else if (mInParty)
- {
- color = &guiPalette->getColor(Palette::PARTY);
- }
- else
- {
- color = &guiPalette->getColor(Palette::PC);
- }
-
- mName = new FlashText(name,
- getPixelX(),
- getPixelY(),
- gcn::Graphics::CENTER,
- color);
- }
-
- Being::setName(name);
}
#ifdef EATHENA_SUPPORT
@@ -149,31 +119,20 @@ void Player::logic()
}
#endif
-Being::Type Player::getType() const
-{
- return PLAYER;
-}
-
-void Player::flash(int time)
-{
- if (mName)
- mName->flash(time);
-}
-
void Player::setGender(Gender gender)
{
if (gender != mGender)
{
- Being::setGender(gender);
+ mGender = gender;
/* Human base sprite. When implementing different races remove this
* line and set the base sprite when setting the race of the player
* character.
*/
- setSprite(Being::BASE_SPRITE, -100);
+ setSprite(BASE_SPRITE, -100);
// Reload all subsprites
- for (int i = 1; i < VECTOREND_SPRITE; i++)
+ for (unsigned int i = 1; i < mSprites.size(); i++)
{
if (mSpriteIDs.at(i) != 0)
setSprite(i, mSpriteIDs.at(i), mSpriteColors.at(i));
@@ -185,28 +144,12 @@ void Player::setGM(bool gm)
{
mIsGM = gm;
- if (gm && mName)
- mName->setColor(&guiPalette->getColor(Palette::GM));
-}
-
-void Player::setHairStyle(int style, int color)
-{
- style = style < 0 ? mHairStyle : style % mNumberOfHairstyles;
- color = color < 0 ? mHairColor : color % ColorDB::size();
- if (style == mHairStyle && color == mHairColor) return;
-
- Being::setHairStyle(style, color);
-
- setSprite(HAIR_SPRITE, style * -1, ColorDB::get(color));
-
- setAction(mAction);
+ updateColors();
}
void Player::setSprite(int slot, int id, const std::string &color)
{
- // TODO: Find a better way
- if (getType() == NPC)
- return;
+ assert(slot >= BASE_SPRITE && slot < VECTOREND_SPRITE);
// id = 0 means unequip
if (id == 0)
@@ -237,6 +180,7 @@ void Player::setSprite(int slot, int id, const std::string &color)
equipmentSprite->setDirection(getSpriteDirection());
delete mSprites[slot];
+
mSprites[slot] = equipmentSprite;
if (slot == WEAPON_SPRITE)
@@ -245,13 +189,8 @@ void Player::setSprite(int slot, int id, const std::string &color)
setAction(mAction);
}
- Being::setSprite(slot, id, color);
-}
-
-void Player::updateCoords()
-{
- if (mName)
- mName->adviseXY(getPixelX(), getPixelY());
+ mSpriteIDs[slot] = id;
+ mSpriteColors[slot] = color;
}
#ifdef TMWSERV_SUPPORT
@@ -305,26 +244,32 @@ void Player::setInParty(bool inParty)
{
mInParty = inParty;
- if (this != player_node && mName)
+ updateColors();
+}
+
+void Player::optionChanged(const std::string &value)
+{
+ if (value == "visiblenames")
{
- Palette::ColorType colorType = mInParty ? Palette::PARTY : Palette::PC;
- mName->setColor(&guiPalette->getColor(colorType));
+ setShowName(config.getValue("visiblenames", 1));
}
}
-void Player::optionChanged(const std::string &value)
+void Player::updateColors()
{
- if (value == "visiblenames" && getType() == Being::PLAYER && player_node != this)
+ mTextColor = &guiPalette->getColor(Palette::PLAYER);
+
+ if (mIsGM)
{
- mShowName = config.getValue("visiblenames", 1);
- if (!mShowName && mName)
- {
- delete mName;
- mName = NULL;
- }
- else if (mShowName && !mName && !(getName().empty()))
- {
- setName(getName());
- }
+ mTextColor = &guiPalette->getColor(Palette::GM);
+ mNameColor = &guiPalette->getColor(Palette::GM_NAME);
+ }
+ else if (mInParty)
+ {
+ mNameColor = &guiPalette->getColor(Palette::PARTY);
+ }
+ else
+ {
+ mNameColor = &guiPalette->getColor(Palette::PC);
}
}