diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-11-03 09:58:25 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-11-03 09:58:25 +0000 |
commit | 8a60e11684e84807f3526b37afa8cbf6f103b8fd (patch) | |
tree | 202058890ef2f8f2c5e9873acbb6f59327b28762 /src | |
parent | 8a0e94b31be13ef9c52b281c32095279d7fa1ca7 (diff) | |
download | mana-client-8a60e11684e84807f3526b37afa8cbf6f103b8fd.tar.gz mana-client-8a60e11684e84807f3526b37afa8cbf6f103b8fd.tar.bz2 mana-client-8a60e11684e84807f3526b37afa8cbf6f103b8fd.tar.xz mana-client-8a60e11684e84807f3526b37afa8cbf6f103b8fd.zip |
Fixed double load of hair graphics.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/char_select.cpp | 13 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 4 | ||||
-rw-r--r-- | src/net/charserverhandler.cpp | 4 | ||||
-rw-r--r-- | src/player.cpp | 45 | ||||
-rw-r--r-- | src/player.h | 9 |
5 files changed, 25 insertions, 50 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index c2306880..ccdf20c8 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -245,8 +245,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): Window(_("Create Character"), true, parent), mSlot(slot) { mPlayer = new Player(0, 0, NULL); - mPlayer->setHairStyle(rand() % NR_HAIR_STYLES); - mPlayer->setHairColor(rand() % NR_HAIR_COLORS); + mPlayer->setHairStyle(rand() % NR_HAIR_STYLES, rand() % NR_HAIR_COLORS); mNameField = new TextField(""); mNameLabel = new gcn::Label(_("Name:")); @@ -373,18 +372,16 @@ CharCreateDialog::action(const gcn::ActionEvent &event) scheduleDelete(); } else if (event.getId() == "nextcolor") { - mPlayer->setHairColor((mPlayer->getHairColor() + 1) % NR_HAIR_COLORS); + mPlayer->setHairStyle(-1, mPlayer->getHairColor() + 1); } else if (event.getId() == "prevcolor") { - int prevColor = mPlayer->getHairColor() + NR_HAIR_COLORS - 1; - mPlayer->setHairColor(prevColor % NR_HAIR_COLORS); + mPlayer->setHairStyle(-1, mPlayer->getHairColor() + NR_HAIR_COLORS - 1); } else if (event.getId() == "nextstyle") { - mPlayer->setHairStyle((mPlayer->getHairStyle() + 1) % NR_HAIR_STYLES); + mPlayer->setHairStyle(mPlayer->getHairStyle() + 1, -1); } else if (event.getId() == "prevstyle") { - int prevStyle = mPlayer->getHairStyle() + NR_HAIR_STYLES - 1; - mPlayer->setHairStyle(prevStyle % NR_HAIR_STYLES); + mPlayer->setHairStyle(mPlayer->getHairStyle() + NR_HAIR_STYLES - 1, -1); } else if (event.getId() == "statslider") { UpdateSliders(); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 6bd31c9f..56ec0192 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -472,8 +472,8 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg) being->setName(name); } Player *p = static_cast< Player * >(being); - p->setHairStyle(msg.readByte()); - p->setHairColor(msg.readByte()); + int hs = msg.readByte(), hc = msg.readByte(); + p->setHairStyle(hs, hc); p->setGender(msg.readByte()); handleLooks(p, msg); } break; diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 1cfd815b..76311266 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -217,8 +217,8 @@ CharServerHandler::readPlayerData(MessageIn &msg, int &slot) slot = msg.readByte(); // character slot tempPlayer->mName = msg.readString(); tempPlayer->setGender(msg.readByte()); - tempPlayer->setHairStyle(msg.readByte()); - tempPlayer->setHairColor(msg.readByte()); + int hs = msg.readByte(), hc = msg.readByte(); + tempPlayer->setHairStyle(hs, hc); tempPlayer->setLevel(msg.readByte()); tempPlayer->setMoney(msg.readLong()); diff --git a/src/player.cpp b/src/player.cpp index 0fe6460c..062c1135 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -31,7 +31,7 @@ #include "resources/itemdb.h" #include "resources/iteminfo.h" -#include "utils/tostring.h" +#include "utils/strprintf.h" #include "gui/gui.h" @@ -103,42 +103,25 @@ void Player::setGender(int sex) } } -void Player::setHairColor(int color) +void Player::setHairStyle(int style, int color) { - if (color != mHairColor) - { - mHairColor = color < NR_HAIR_COLORS ? color : 0; - - AnimatedSprite *newHairSprite = AnimatedSprite::load( - "graphics/sprites/hairstyle" + toString(getHairStyle()) + ".xml", - mHairColor); - if (newHairSprite) - newHairSprite->setDirection(getSpriteDirection()); - - delete mSprites[HAIR_SPRITE]; - mSprites[HAIR_SPRITE] = newHairSprite; + style = style < 0 ? mHairStyle : style % NR_HAIR_STYLES; + color = color < 0 ? mHairColor : color % NR_HAIR_COLORS; + if (style == mHairStyle && color == mHairColor) return; - setAction(mAction); - } -} + mHairStyle = style; + mHairColor = color; -void Player::setHairStyle(int style) -{ - if (style != mHairStyle) - { - mHairStyle = style < NR_HAIR_STYLES ? style : 0; + AnimatedSprite *newHairSprite = AnimatedSprite::load + (strprintf("graphics/sprites/hairstyle%d.xml", style), color); - AnimatedSprite *newHairSprite = AnimatedSprite::load( - "graphics/sprites/hairstyle" + toString(getHairStyle()) + ".xml", - mHairColor); - if (newHairSprite) - newHairSprite->setDirection(getSpriteDirection()); + if (newHairSprite) + newHairSprite->setDirection(getSpriteDirection()); - delete mSprites[HAIR_SPRITE]; - mSprites[HAIR_SPRITE] = newHairSprite; + delete mSprites[HAIR_SPRITE]; + mSprites[HAIR_SPRITE] = newHairSprite; - setAction(mAction); - } + setAction(mAction); } void Player::setVisibleEquipment(int slot, int id) diff --git a/src/player.h b/src/player.h index e6d3743a..4d4f53f5 100644 --- a/src/player.h +++ b/src/player.h @@ -60,20 +60,15 @@ class Player : public Being { return mHairColor; } /** - * Sets the hair color for this player. - */ - void setHairColor(int color); - - /** * Gets the hair style for this player. */ int getHairStyle() const { return mHairStyle; } /** - * Sets the hair style for this player. + * Sets the hair style and color for this player. */ - void setHairStyle(int style); + void setHairStyle(int style, int color); /** * Sets visible equipments for this player. |