summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/charcreatedialog.cpp127
-rw-r--r--src/gui/charcreatedialog.h10
-rw-r--r--src/gui/ministatuswindow.cpp2
-rw-r--r--src/gui/skilldialog.cpp3
4 files changed, 83 insertions, 59 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index 931735f8..a7e76989 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -41,6 +41,7 @@
#include "net/charhandler.h"
#include "net/net.h"
+#include "resources/chardb.h"
#include "resources/hairdb.h"
#include "utils/gettext.h"
@@ -56,6 +57,10 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
mPlayer = new Being(0, ActorSprite::PLAYER, 0, NULL);
mPlayer->setGender(GENDER_MALE);
+ const std::vector<int> &items = CharDB::getDefaultItems();
+ for (size_t i = 0; i < items.size(); ++i)
+ mPlayer->setSprite(i + 1, items.at(i));
+
mHairStylesIds = hairDB.getHairStyleIds(
Net::getCharHandler()->getCharCreateMaxHairStyleId());
mHairStyleId = rand() * mHairStylesIds.size() / RAND_MAX;
@@ -101,8 +106,11 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
mNameField->setActionEventId("create");
mNameField->addActionListener(this);
+ mAttributesLeft = new Label(
+ strprintf(_("Please distribute %d points"), 99));
+
int w = 200;
- int h = 160;
+ int h = 330;
setContentSize(w, h);
mPlayerBox->setDimension(gcn::Rectangle(80, 30, 110, 85));
mNameLabel->setPosition(5, 5);
@@ -114,6 +122,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
mPrevHairStyleButton->setPosition(90, 64);
mNextHairStyleButton->setPosition(165, 64);
mHairStyleLabel->setPosition(5, 70);
+ mAttributesLeft->setPosition(15, 280);
updateSliders();
mCancelButton->setPosition(
w - 5 - mCancelButton->getWidth(),
@@ -134,6 +143,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
add(mNextHairStyleButton);
add(mPrevHairStyleButton);
add(mHairStyleLabel);
+ add(mAttributesLeft);
add(mCreateButton);
add(mCancelButton);
@@ -164,12 +174,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)
@@ -182,7 +186,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
{
@@ -192,7 +197,9 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
}
}
else if (event.getId() == "cancel")
+ {
scheduleDelete();
+ }
else if (event.getId() == "nextcolor")
{
++mHairColorId;
@@ -235,19 +242,24 @@ std::string CharCreateDialog::getName() const
void CharCreateDialog::updateSliders()
{
- if (Net::getNetworkType() == ServerInfo::MANASERV)
- return;
+ 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"));
@@ -276,20 +288,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;
@@ -303,34 +304,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(),
@@ -338,6 +362,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;
diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp
index ac0ae5d7..e050563f 100644
--- a/src/gui/ministatuswindow.cpp
+++ b/src/gui/ministatuswindow.cpp
@@ -162,8 +162,6 @@ void MiniStatusWindow::event(Event::Channel channel,
AnimatedSprite *sprite = effect->getIcon();
- typedef std::vector<int> IntMap;
-
if (!sprite)
{
// delete sprite, if necessary
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 98db3cc1..fb5067a5 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -352,7 +352,8 @@ void SkillDialog::loadSkills()
for_each_xml_child_node(set, root)
{
- if (xmlStrEqual(set->name, BAD_CAST "set"))
+ if (xmlStrEqual(set->name, BAD_CAST "set") ||
+ xmlStrEqual(set->name, BAD_CAST "skill-set"))
{
setCount++;
setName = XML::getProperty(set, "name", strprintf(_("Skill Set %d"), setCount));