diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-28 22:10:37 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-30 21:21:06 +0200 |
commit | a6b11834f227b8edbfb39633380806480fd2a2c5 (patch) | |
tree | c9397013f135d61f3321c45d8b10493aecac2344 /src | |
parent | 286eb6552fa059d8e4561fb4bb13cb5266dff71d (diff) | |
download | mana-a6b11834f227b8edbfb39633380806480fd2a2c5.tar.gz mana-a6b11834f227b8edbfb39633380806480fd2a2c5.tar.bz2 mana-a6b11834f227b8edbfb39633380806480fd2a2c5.tar.xz mana-a6b11834f227b8edbfb39633380806480fd2a2c5.zip |
Hide attribute sliders on character creation when appropriate
When the minimum and maximum values of the attributes are equal, then
there is nothing for the player to customize and the sliders are not
shown.
At the same time the dialog has been fixed to resize properly to any
number of modifiable attributes.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/charcreatedialog.cpp | 112 | ||||
-rw-r--r-- | src/gui/charcreatedialog.h | 10 |
2 files changed, 69 insertions, 53 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index a3c03a31..26383d48 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -173,12 +173,6 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) // Attempt to create the character mCreateButton->setEnabled(false); - std::vector<int> atts; - for (unsigned i = 0; i < mAttributeSlider.size(); i++) - { - atts.push_back((int) mAttributeSlider[i]->getValue()); - } - int characterSlot = mSlot; // On Manaserv, the slots start at 1, so we offset them. if (Net::getNetworkType() == ServerInfo::MANASERV) @@ -191,7 +185,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) 0 : mHairColorsIds.at(mHairColorId); Net::getCharHandler()->newCharacter(getName(), characterSlot, mFemale->isSelected(), - hairStyle, hairColor, atts); + hairStyle, hairColor, + mAttributes); } else { @@ -246,16 +241,24 @@ std::string CharCreateDialog::getName() const void CharCreateDialog::updateSliders() { + int distributedPoints = 0; + + // Update captions and synchronize values for (unsigned i = 0; i < mAttributeSlider.size(); i++) { - // Update captions - mAttributeValue[i]->setCaption( - toString((int) (mAttributeSlider[i]->getValue()))); - mAttributeValue[i]->adjustSize(); + gcn::Slider *slider = mAttributeSlider[i]; + gcn::Label *valueLabel = mAttributeValue[i]; + int value = static_cast<int>(slider->getValue()); + + valueLabel->setCaption(toString(value)); + valueLabel->adjustSize(); + + mAttributes[i] = value; + distributedPoints += value; } // Update distributed points - int pointsLeft = mMaxPoints - getDistributedPoints(); + int pointsLeft = mMaxPoints - distributedPoints; if (pointsLeft == 0) { mAttributesLeft->setCaption(_("Character stats OK")); @@ -284,20 +287,9 @@ void CharCreateDialog::unlock() mCreateButton->setEnabled(true); } -int CharCreateDialog::getDistributedPoints() const -{ - int points = 0; - - for (unsigned i = 0; i < mAttributeSlider.size(); i++) - { - points += (int) mAttributeSlider[i]->getValue(); - } - return points; -} - void CharCreateDialog::setAttributes(const std::vector<std::string> &labels, - unsigned int available, unsigned int min, - unsigned int max) + unsigned available, unsigned min, + unsigned max) { mMaxPoints = available; @@ -311,34 +303,57 @@ void CharCreateDialog::setAttributes(const std::vector<std::string> &labels, delete mAttributeValue[i]; } - mAttributeLabel.resize(labels.size()); - mAttributeSlider.resize(labels.size()); - mAttributeValue.resize(labels.size()); + mAttributeLabel.clear(); + mAttributeSlider.clear(); + mAttributeValue.clear(); + + mAttributes.resize(labels.size(), min); int w = 200; - int h = 330; + int h = 190; - for (unsigned i = 0; i < labels.size(); i++) + // No attribute sliders when they can not be adapted by the user + if (min == max) { - mAttributeLabel[i] = new Label(labels[i]); - mAttributeLabel[i]->setWidth(70); - mAttributeLabel[i]->setPosition(5, 140 + i*20); - add(mAttributeLabel[i]); - - mAttributeSlider[i] = new Slider(min, max); - mAttributeSlider[i]->setDimension(gcn::Rectangle(75, 140 + i * 20, - 100, 10)); - mAttributeSlider[i]->setActionEventId("statslider"); - mAttributeSlider[i]->addActionListener(this); - add(mAttributeSlider[i]); - - mAttributeValue[i] = new Label(toString(min)); - mAttributeValue[i]->setPosition(180, 140 + i*20); - add(mAttributeValue[i]); + mAttributesLeft->setVisible(false); + mCreateButton->setEnabled(true); } + else + { + h += 20 * labels.size() + 20; - mAttributesLeft->setPosition(15, 280); - updateSliders(); + mAttributeLabel.resize(labels.size()); + mAttributeSlider.resize(labels.size()); + mAttributeValue.resize(labels.size()); + + for (unsigned i = 0; i < labels.size(); i++) + { + const int y = 140 + i * 20; + + Label *attributeLabel = new Label(labels[i]); + attributeLabel->setWidth(70); + attributeLabel->setPosition(5, y); + add(attributeLabel); + + Slider *attributeSlider = new Slider(min, max); + attributeSlider->setDimension(gcn::Rectangle(75, y, 100, 10)); + attributeSlider->setActionEventId("statslider"); + attributeSlider->addActionListener(this); + add(attributeSlider); + + Label *attributeValue = new Label(toString(min)); + attributeValue->setPosition(180, y); + add(attributeValue); + + mAttributeLabel[i] = attributeLabel; + mAttributeSlider[i] = attributeSlider; + mAttributeValue[i] = attributeValue; + } + + mAttributesLeft->setVisible(true); + mAttributesLeft->setPosition(15, h - 50); + updateSliders(); + } mCancelButton->setPosition( w - 5 - mCancelButton->getWidth(), @@ -346,6 +361,9 @@ void CharCreateDialog::setAttributes(const std::vector<std::string> &labels, mCreateButton->setPosition( mCancelButton->getX() - 5 - mCreateButton->getWidth(), h - 5 - mCancelButton->getHeight()); + + setContentSize(w, h); + center(); } void CharCreateDialog::setFixedGender(bool fixed, Gender gender) diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index 7548bbff..9f49f6c5 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -58,14 +58,12 @@ class CharCreateDialog : public Window, public gcn::ActionListener void unlock(); void setAttributes(const std::vector<std::string> &labels, - unsigned int available, - unsigned int min, unsigned int max); + unsigned available, + unsigned min, unsigned max); void setFixedGender(bool fixed, Gender gender = GENDER_FEMALE); private: - int getDistributedPoints() const; - void updateSliders(); /** @@ -94,13 +92,13 @@ class CharCreateDialog : public Window, public gcn::ActionListener gcn::RadioButton *mMale; gcn::RadioButton *mFemale; + std::vector<int> mAttributes; std::vector<gcn::Slider*> mAttributeSlider; std::vector<gcn::Label*> mAttributeLabel; std::vector<gcn::Label*> mAttributeValue; gcn::Label *mAttributesLeft; - int mMaxPoints; - int mUsedPoints; + unsigned mMaxPoints; gcn::Button *mCreateButton; gcn::Button *mCancelButton; |