diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-01-31 04:48:00 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-31 16:29:22 +0300 |
commit | 670304fefa71e2b25b264066aaf0d69fde95bced (patch) | |
tree | c949ba1faf68579f0b3c786aac3f69152eec3f15 | |
parent | c01b3f215a9ec7e5ebceac8550c1e18c0a2b7435 (diff) | |
download | mv-670304fefa71e2b25b264066aaf0d69fde95bced.tar.gz mv-670304fefa71e2b25b264066aaf0d69fde95bced.tar.bz2 mv-670304fefa71e2b25b264066aaf0d69fde95bced.tar.xz mv-670304fefa71e2b25b264066aaf0d69fde95bced.zip |
Redesing char creation dialog.
Add support for reading all information about hair colors.
-rw-r--r-- | src/gui/charcreatedialog.cpp | 158 | ||||
-rw-r--r-- | src/gui/charcreatedialog.h | 12 | ||||
-rw-r--r-- | src/resources/colordb.cpp | 27 | ||||
-rw-r--r-- | src/resources/colordb.h | 4 |
4 files changed, 151 insertions, 50 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 74a5a1f1f..8d4767a15 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -56,14 +56,27 @@ #include "debug.h" +const static Being::Action actions[] = +{ + Being::STAND, Being::SIT, Being::MOVE, Being::ATTACK, Being::DEAD +}; + +const static int directions[] = +{ + Being::DOWN, Being::RIGHT, Being::UP, Being::LEFT +}; + CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): - Window(_("Create Character"), true, parent, "charcreate.xml"), + Window(_("New Character"), true, parent, "charcreate.xml"), mCharSelectDialog(parent), mRace(0), - mSlot(slot) + mSlot(slot), + mAction(0), + mDirection(0) { setStickyButtonLock(true); setSticky(true); + setWindowName("NewCharacter"); mPlayer = new Being(0, ActorSprite::PLAYER, mRace, nullptr); mPlayer->setGender(GENDER_MALE); @@ -80,7 +93,6 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mHairStyle = (rand() % maxHairStyle) + minHairStyle; mHairColor = (rand() % maxHairColor) + minHairColor; - updateHair(); mNameField = new TextField(""); mNameField->setMaximum(24); @@ -92,16 +104,20 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): // You may change this symbol if your language uses another. mPrevHairColorButton = new Button(_("<"), "prevcolor", this); mHairColorLabel = new Label(_("Hair color:")); + mHairColorNameLabel = new Label(""); mNextHairStyleButton = new Button(_(">"), "nextstyle", this); mPrevHairStyleButton = new Button(_("<"), "prevstyle", this); mHairStyleLabel = new Label(_("Hair style:")); + mHairStyleNameLabel = new Label(""); + mActionButton = new Button(_("^"), "action", this); + mRotateButton = new Button(_(">"), "rotate", this); if (serverVersion >= 2) { mNextRaceButton = new Button(_(">"), "nextrace", this); mPrevRaceButton = new Button(_("<"), "prevrace", this); mRaceLabel = new Label(_("Race:")); - mRaceNameLabel = new Label("qwerty"); + mRaceNameLabel = new Label(""); } mCreateButton = new Button(_("Create"), "create", this); @@ -127,32 +143,42 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mAttributesLeft = new Label( strprintf(_("Please distribute %d points"), 99)); - int w = 280; - int h = 330; + int w = 480; + int h = 350; setContentSize(w, h); - mPlayerBox->setDimension(gcn::Rectangle(145, 35, 110, 87)); - mNameLabel->setPosition(5, 5); + mPlayerBox->setDimension(gcn::Rectangle(350, 40, 110, 90)); + mActionButton->setPosition(375, 140); + mRotateButton->setPosition(405, 140); + + mNameLabel->setPosition(5, 10); mNameField->setDimension( - gcn::Rectangle(60, 5, w - 60 - 7, mNameField->getHeight())); - mPrevHairColorButton->setPosition(155, 35); - mNextHairColorButton->setPosition(230, 35); - mHairColorLabel->setPosition(5, 40); - mPrevHairStyleButton->setPosition(155, 64); - mNextHairStyleButton->setPosition(230, 64); - mHairStyleLabel->setPosition(5, 70); + gcn::Rectangle(60, 10, 300, mNameField->getHeight())); + + int leftX = 120; + int rightX = 300; + int labelX = 5; + int nameX = 145; + mPrevHairColorButton->setPosition(leftX, 40); + mNextHairColorButton->setPosition(rightX, 40); + mHairColorLabel->setPosition(labelX, 45); + mHairColorNameLabel->setPosition(nameX, 45); + mPrevHairStyleButton->setPosition(leftX, 69); + mNextHairStyleButton->setPosition(rightX, 69); + mHairStyleLabel->setPosition(labelX, 74); + mHairStyleNameLabel->setPosition(nameX, 74); if (serverVersion >= 2) { - mPrevRaceButton->setPosition(155, 93); - mNextRaceButton->setPosition(230, 93); - mRaceLabel->setPosition(5, 100); - mRaceNameLabel->setPosition(5, 118); + mPrevRaceButton->setPosition(leftX, 103); + mNextRaceButton->setPosition(rightX, 103); + mRaceLabel->setPosition(labelX, 108); + mRaceNameLabel->setPosition(nameX, 108); } mAttributesLeft->setPosition(15, 280); updateSliders(); mCancelButton->setPosition( - w - 5 - mCancelButton->getWidth(), + w / 2, h - 5 - mCancelButton->getHeight()); mCreateButton->setPosition( mCancelButton->getX() - 5 - mCreateButton->getWidth(), @@ -167,9 +193,13 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): add(mNextHairColorButton); add(mPrevHairColorButton); add(mHairColorLabel); + add(mHairColorNameLabel); add(mNextHairStyleButton); add(mPrevHairStyleButton); add(mHairStyleLabel); + add(mHairStyleNameLabel); + add(mActionButton); + add(mRotateButton); if (serverVersion >= 2) { @@ -189,8 +219,12 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): center(); setVisible(true); mNameField->requestFocus(); + + updateHair(); if (serverVersion >= 2) updateRace(); + + updatePlayer(); } CharCreateDialog::~CharCreateDialog() @@ -204,7 +238,8 @@ CharCreateDialog::~CharCreateDialog() void CharCreateDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "create") + const std::string id = event.getId(); + if (id == "create") { if ( #ifdef MANASERV_SUPPORT @@ -239,51 +274,65 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) true, this); } } - else if (event.getId() == "cancel") + else if (id == "cancel") { scheduleDelete(); } - else if (event.getId() == "nextcolor") + else if (id == "nextcolor") { - mHairColor++; + mHairColor ++; updateHair(); } - else if (event.getId() == "prevcolor") + else if (id == "prevcolor") { - mHairColor--; + mHairColor --; updateHair(); } - else if (event.getId() == "nextstyle") + else if (id == "nextstyle") { - mHairStyle++; + mHairStyle ++; updateHair(); } - else if (event.getId() == "prevstyle") + else if (id == "prevstyle") { - mHairStyle--; + mHairStyle --; updateHair(); } - else if (event.getId() == "nextrace") + else if (id == "nextrace") { - mRace++; + mRace ++; updateRace(); } - else if (event.getId() == "prevrace") + else if (id == "prevrace") { - mRace--; + mRace --; updateRace(); } - else if (event.getId() == "statslider") + else if (id == "statslider") { updateSliders(); } - else if (event.getId() == "gender") + else if (id == "gender") { if (mMale->isSelected()) mPlayer->setGender(GENDER_MALE); else mPlayer->setGender(GENDER_FEMALE); } + else if (id == "action") + { + mAction ++; + if (mAction >= 5) + mAction = 0; + updatePlayer(); + } + else if (id == "rotate") + { + mDirection ++; + if (mDirection >= 4) + mDirection = 0; + updatePlayer(); + } } std::string CharCreateDialog::getName() const @@ -364,34 +413,34 @@ void CharCreateDialog::setAttributes(const std::vector<std::string> &labels, mAttributeSlider.resize(labels.size()); mAttributeValue.resize(labels.size()); - int w = 200; - int h = 330; + int w = 480; + int h = 350; for (unsigned i = 0; i < labels.size(); i++) { mAttributeLabel[i] = new Label(labels[i]); mAttributeLabel[i]->setWidth(70); - mAttributeLabel[i]->setPosition(5, 140 + i*20); + mAttributeLabel[i]->setPosition(5, 145 + i * 24); mAttributeLabel[i]->adjustSize(); add(mAttributeLabel[i]); mAttributeSlider[i] = new Slider(min, max); - mAttributeSlider[i]->setDimension(gcn::Rectangle(140, 140 + i * 20, - 100, 10)); + mAttributeSlider[i]->setDimension(gcn::Rectangle(140, 145 + i * 24, + 150, 12)); mAttributeSlider[i]->setActionEventId("statslider"); mAttributeSlider[i]->addActionListener(this); add(mAttributeSlider[i]); mAttributeValue[i] = new Label(toString(min)); - mAttributeValue[i]->setPosition(245, 140 + i*20); + mAttributeValue[i]->setPosition(295, 145 + i * 24); add(mAttributeValue[i]); } - mAttributesLeft->setPosition(15, 280); + mAttributesLeft->setPosition(15, 300); updateSliders(); mCancelButton->setPosition( - w - 5 - mCancelButton->getWidth(), + w / 2, h - 5 - mCancelButton->getHeight()); mCreateButton->setPosition( mCancelButton->getX() - 5 - mCreateButton->getWidth(), @@ -427,12 +476,17 @@ void CharCreateDialog::updateHair() mHairStyle += Being::getNumOfHairstyles(); if (mHairStyle < (signed)minHairStyle || mHairStyle > (signed)maxHairStyle) mHairStyle = minHairStyle; + const ItemInfo &item = ItemDB::get(-mHairStyle); + mHairStyleNameLabel->setCaption(item.getName()); + mHairStyleNameLabel->adjustSize(); mHairColor %= ColorDB::getHairSize(); if (mHairColor < 0) mHairColor += ColorDB::getHairSize(); if (mHairColor < (signed)minHairColor || mHairColor > (signed)maxHairColor) mHairColor = minHairColor; + mHairColorNameLabel->setCaption(ColorDB::getHairColorName(mHairColor)); + mHairColorNameLabel->adjustSize(); mPlayer->setSprite(Net::getCharHandler()->hairSprite(), mHairStyle * -1, ColorDB::getHairColor(mHairColor)); @@ -457,4 +511,20 @@ void CharCreateDialog::updateRace() mPlayer->setSubtype(mRace); const ItemInfo &item = ItemDB::get(id); mRaceNameLabel->setCaption(item.getName()); + mRaceNameLabel->adjustSize(); +} + +void CharCreateDialog::logic() +{ + if (mPlayer) + mPlayer->logic(); +} + +void CharCreateDialog::updatePlayer() +{ + if (mPlayer) + { + mPlayer->setDirection(directions[mDirection]); + mPlayer->setAction(actions[mAction]); + } } diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index 7bb7b7fed..ceafcc08e 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -70,6 +70,10 @@ class CharCreateDialog : public Window, public gcn::ActionListener void setFixedGender(bool fixed, Gender gender = GENDER_FEMALE); + void logic(); + + void updatePlayer(); + private: int getDistributedPoints() const; @@ -96,14 +100,19 @@ class CharCreateDialog : public Window, public gcn::ActionListener gcn::Button *mNextHairColorButton; gcn::Button *mPrevHairColorButton; gcn::Label *mHairColorLabel; + gcn::Label *mHairColorNameLabel; gcn::Button *mNextHairStyleButton; gcn::Button *mPrevHairStyleButton; gcn::Label *mHairStyleLabel; + gcn::Label *mHairStyleNameLabel; gcn::Button *mNextRaceButton; gcn::Button *mPrevRaceButton; gcn::Label *mRaceLabel; gcn::Label *mRaceNameLabel; + gcn::Button *mActionButton; + gcn::Button *mRotateButton; + gcn::RadioButton *mMale; gcn::RadioButton *mFemale; @@ -131,6 +140,9 @@ class CharCreateDialog : public Window, public gcn::ActionListener unsigned minHairColor; unsigned maxHairStyle; unsigned minHairStyle; + + unsigned mAction; + unsigned mDirection; }; #endif // CHAR_CREATE_DIALOG_H diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 1ffe507b2..bce768d6d 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -65,7 +65,7 @@ void ColorDB::loadHair() if (!root || !xmlNameEqual(root, "colors")) { logger->log1("ColorDB: Failed to find any color files."); - mHairColors[0] = mFail; + mHairColors[0] = ItemColor(0, "", ""); mLoaded = true; delete doc; @@ -83,9 +83,8 @@ void ColorDB::loadHair() if (mHairColors.find(id) != mHairColors.end()) logger->log("ColorDB: Redefinition of dye ID %d", id); - mHairColors[id] = hairXml ? - XML::getProperty(node, "value", "#FFFFFF") : - XML::getProperty(node, "dye", "#FFFFFF"); + mHairColors[id] = ItemColor(id, XML::getProperty(node, "name", ""), + XML::getProperty(node, hairXml ? "value" : "dye", "#FFFFFF")); } } @@ -158,7 +157,25 @@ std::string &ColorDB::getHairColor(int id) } else { - return i->second; + return i->second.color; + } +} + +std::string &ColorDB::getHairColorName(int id) +{ + if (!mLoaded) + load(); + + ColorIterator i = mHairColors.find(id); + + if (i == mHairColors.end()) + { + logger->log("ColorDB: Error, unknown dye ID# %d", id); + return mFail; + } + else + { + return i->second.name; } } diff --git a/src/resources/colordb.h b/src/resources/colordb.h index 36907095e..ade4227f8 100644 --- a/src/resources/colordb.h +++ b/src/resources/colordb.h @@ -70,12 +70,14 @@ namespace ColorDB std::string &getHairColor(int id); + std::string &getHairColorName(int id); + int getHairSize(); std::map <int, ItemColor> *getColorsList(std::string name); // Color DB - typedef std::map<int, std::string> Colors; + typedef std::map<int, ItemColor> Colors; typedef Colors::iterator ColorIterator; typedef std::map <std::string, std::map <int, ItemColor> > ColorLists; typedef ColorLists::iterator ColorListsIterator; |