diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2012-01-18 19:20:34 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2012-02-02 15:31:41 +0100 |
commit | f5de9ae444f1bca1f6ba6969214e9a8cacb15f68 (patch) | |
tree | f9b9c699c52d279cdc4d93b09f48dd3b24403f5b /src/gui | |
parent | 7cc504d993fa948ae2e10848993f4552b2d6daaa (diff) | |
download | mana-f5de9ae444f1bca1f6ba6969214e9a8cacb15f68.tar.gz mana-f5de9ae444f1bca1f6ba6969214e9a8cacb15f68.tar.bz2 mana-f5de9ae444f1bca1f6ba6969214e9a8cacb15f68.tar.xz mana-f5de9ae444f1bca1f6ba6969214e9a8cacb15f68.zip |
Fix to the hair colors and styles handling.
- I made the charCreatedialog handle a possible
max permitted color Id and a minimum hair style id for tA.
- Added a foundation to later load the styles and colors from
the same file, to handle the Mana-issue #224 for manaserv.
- Support for non-contiguous hair color and style ids
has also been added.
- I also replaced the < and > arrow signs with images.
Reviewed-by: Ben Longbons, Thorbjørn Lindeijer
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/charcreatedialog.cpp | 73 | ||||
-rw-r--r-- | src/gui/charcreatedialog.h | 16 |
2 files changed, 55 insertions, 34 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 99a8800a..84bce434 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -57,23 +57,30 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mPlayer = new Being(0, ActorSprite::PLAYER, 0, NULL); mPlayer->setGender(GENDER_MALE); - int numberOfHairColors = HairDB::size(); + mHairStylesIds = hairDB.getHairStyleIds( + Net::getCharHandler()->getCharCreateMaxHairStyleId()); + mHairStyleId = rand() * mHairStylesIds.size() / RAND_MAX; + + mHairColorsIds = hairDB.getHairColorIds( + Net::getCharHandler()->getCharCreateMaxHairColorId()); + mHairColorId = rand() * mHairColorsIds.size() / RAND_MAX; - mHairStyle = rand() % mPlayer->getNumOfHairstyles(); - mHairColor = rand() % numberOfHairColors; updateHair(); mNameField = new TextField(""); mNameLabel = new Label(_("Name:")); - // TRANSLATORS: This is an arrow symbol used to denote 'next'. - // You may change this symbol if your language uses another. - mNextHairColorButton = new Button(_(">"), "nextcolor", this); - // TRANSLATORS: This is an arrow symbol used to denote 'previous'. - // You may change this symbol if your language uses another. - mPrevHairColorButton = new Button(_("<"), "prevcolor", this); + + mNextHairColorButton = new Button("", "nextcolor", this); + mPrevHairColorButton = new Button("", "prevcolor", this); + mPrevHairColorButton->setButtonIcon("tab_arrows_left.png"); + mNextHairColorButton->setButtonIcon("tab_arrows_right.png"); + mHairColorLabel = new Label(_("Hair color:")); - mNextHairStyleButton = new Button(_(">"), "nextstyle", this); - mPrevHairStyleButton = new Button(_("<"), "prevstyle", this); + mNextHairStyleButton = new Button("", "nextstyle", this); + mPrevHairStyleButton = new Button("", "prevstyle", this); + mPrevHairStyleButton->setButtonIcon("tab_arrows_left.png"); + mNextHairStyleButton->setButtonIcon("tab_arrows_right.png"); + mHairStyleLabel = new Label(_("Hair style:")); mCreateButton = new Button(_("Create"), "create", this); mCancelButton = new Button(_("Cancel"), "cancel", this); @@ -173,10 +180,14 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) if (Net::getNetworkType() == ServerInfo::MANASERV) ++characterSlot; + // Should avoid the most common crash case + int hairStyle = mHairStylesIds.empty() ? + 0 : mHairStylesIds.at(mHairStyleId); + int hairColor = mHairColorsIds.empty() ? + 0 : mHairColorsIds.at(mHairColorId); Net::getCharHandler()->newCharacter(getName(), characterSlot, mFemale->isSelected(), - mHairStyle, - mHairColor, atts); + hairStyle, hairColor, atts); } else { @@ -189,22 +200,22 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) scheduleDelete(); else if (event.getId() == "nextcolor") { - mHairColor++; + ++mHairColorId; updateHair(); } else if (event.getId() == "prevcolor") { - mHairColor--; + --mHairColorId; updateHair(); } else if (event.getId() == "nextstyle") { - mHairStyle++; + ++mHairStyleId; updateHair(); } else if (event.getId() == "prevstyle") { - mHairStyle--; + --mHairStyleId; updateHair(); } else if (event.getId() == "statslider") @@ -214,13 +225,9 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) else if (event.getId() == "gender") { if (mMale->isSelected()) - { mPlayer->setGender(GENDER_MALE); - } else - { mPlayer->setGender(GENDER_FEMALE); - } } } @@ -359,14 +366,24 @@ void CharCreateDialog::setFixedGender(bool fixed, Gender gender) void CharCreateDialog::updateHair() { - mHairStyle %= Being::getNumOfHairstyles(); - if (mHairStyle < 0) - mHairStyle += Being::getNumOfHairstyles(); + if (mHairColorId < 0) + mHairColorId = mHairColorsIds.size() - 1; + + if (mHairColorId > (int)mHairColorsIds.size() - 1) + mHairColorId = 0; + + if (mHairStyleId < 0) + mHairStyleId = mHairStylesIds.size() - 1; + + if (mHairStyleId > (int)mHairStylesIds.size() - 1) + mHairStyleId = 0; - mHairColor %= HairDB::size(); - if (mHairColor < 0) - mHairColor += HairDB::size(); + // Should avoid the most common crash case + int hairStyle = mHairStylesIds.empty() ? + 0 : mHairStylesIds.at(mHairStyleId); + int hairColor = mHairColorsIds.empty() ? + 0 : mHairColorsIds.at(mHairColorId); mPlayer->setSprite(Net::getCharHandler()->hairSprite(), - mHairStyle * -1, HairDB::get(mHairColor)); + hairStyle * -1, hairDB.getHairColor(hairColor)); } diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index 42a57ab5..7548bbff 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -34,6 +34,7 @@ #include <string> #include <vector> +class Button; class LocalPlayer; class PlayerBox; @@ -83,11 +84,11 @@ class CharCreateDialog : public Window, public gcn::ActionListener gcn::TextField *mNameField; gcn::Label *mNameLabel; - gcn::Button *mNextHairColorButton; - gcn::Button *mPrevHairColorButton; + Button *mNextHairColorButton; + Button *mPrevHairColorButton; gcn::Label *mHairColorLabel; - gcn::Button *mNextHairStyleButton; - gcn::Button *mPrevHairStyleButton; + Button *mNextHairStyleButton; + Button *mPrevHairStyleButton; gcn::Label *mHairStyleLabel; gcn::RadioButton *mMale; @@ -107,8 +108,11 @@ class CharCreateDialog : public Window, public gcn::ActionListener Being *mPlayer; PlayerBox *mPlayerBox; - int mHairStyle; - int mHairColor; + // A vector containing the available hair color or style ids + std::vector<int> mHairColorsIds; + std::vector<int> mHairStylesIds; + int mHairStyleId; + int mHairColorId; int mSlot; }; |