summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-04-06 16:05:54 -0600
committerJared Adams <jaxad0127@gmail.com>2009-04-06 16:07:03 -0600
commit8209e4672c5e11e5d7bbfb1fcfb081eda1763a6d (patch)
tree461c06a2e42fc54684bd61ef5ae9ff8cc83d8f07 /src/gui
parentbbebd24b5561e9cd806dca8ccd6fe4b4dcb1301d (diff)
downloadmana-8209e4672c5e11e5d7bbfb1fcfb081eda1763a6d.tar.gz
mana-8209e4672c5e11e5d7bbfb1fcfb081eda1763a6d.tar.bz2
mana-8209e4672c5e11e5d7bbfb1fcfb081eda1763a6d.tar.xz
mana-8209e4672c5e11e5d7bbfb1fcfb081eda1763a6d.zip
Implement TMWServ's CharHandler
Also cleanup character creation, which isn't functional at the moment.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/char_select.cpp325
-rw-r--r--src/gui/char_select.h77
-rw-r--r--src/gui/charcreatedialog.cpp329
-rw-r--r--src/gui/charcreatedialog.h112
4 files changed, 451 insertions, 392 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 595d6043..ca8ba2e0 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -19,8 +19,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "gui/button.h"
#include "gui/char_select.h"
+
+#include "gui/button.h"
+#include "gui/charcreatedialog.h"
#include "gui/confirm_dialog.h"
#include "gui/label.h"
#include "gui/ok_dialog.h"
@@ -38,14 +40,8 @@
#include "logindata.h"
#include "net/tmwserv/accountserver/account.h"
-#include "net/tmwserv/charserverhandler.h"
-#else
-#include "net/ea/charserverhandler.h"
#endif
-#include "net/charhandler.h"
-#include "net/net.h"
-
#include "gui/widgets/layout.h"
#include "game.h"
@@ -53,7 +49,9 @@
#include "main.h"
#include "units.h"
+#include "net/charhandler.h"
#include "net/messageout.h"
+#include "net/net.h"
#include "resources/colordb.h"
@@ -65,9 +63,6 @@
#include <string>
-// Defined in main.cpp, used here for setting the char create dialog
-extern CharServerHandler charServerHandler;
-
/**
* Listener for confirming character deletion.
*/
@@ -240,7 +235,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
// Start new character dialog
CharCreateDialog *charCreateDialog =
new CharCreateDialog(this, mCharInfo->getPos());
- charServerHandler.setCharCreateDialog(charCreateDialog);
+ Net::getCharHandler()->setCharCreateDialog(charCreateDialog);
}
}
else if (event.getId() == "delete")
@@ -263,8 +258,8 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
{
// Start new character dialog
CharCreateDialog *charCreateDialog =
- new CharCreateDialog(this, mCharInfo->getPos(), mGender);
- charServerHandler.setCharCreateDialog(charCreateDialog);
+ new CharCreateDialog(this, mCharInfo->getPos());
+ Net::getCharHandler()->setCharCreateDialog(charCreateDialog);
}
}
#endif
@@ -345,23 +340,13 @@ void CharSelectDialog::updatePlayerInfo()
void CharSelectDialog::attemptCharDelete()
{
- // Net::getCharHandler()->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
-#ifdef TMWSERV_SUPPORT
- Net::AccountServer::Account::deleteCharacter(mCharInfo->getPos());
-#else
- charHandler->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
-#endif
+ Net::getCharHandler()->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
mCharInfo->lock();
}
void CharSelectDialog::attemptCharSelect()
{
- // Net::getCharHandler()->chooseCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
-#ifdef TMWSERV_SUPPORT
- Net::AccountServer::Account::selectCharacter(mCharInfo->getPos());
-#else
- charHandler->chooseCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
-#endif
+ Net::getCharHandler()->chooseCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
mCharInfo->lock();
}
@@ -392,293 +377,3 @@ bool CharSelectDialog::selectByName(const std::string &name)
return false;
}
-
-#ifdef TMWSERV_SUPPORT
-CharCreateDialog::CharCreateDialog(Window *parent, int slot):
-#else
-CharCreateDialog::CharCreateDialog(Window *parent, int slot,
- Gender gender):
-#endif
- Window(_("Create Character"), true, parent),
- mSlot(slot)
-{
- mPlayer = new Player(0, 0, NULL);
-#ifdef TMWSERV_SUPPORT
- mPlayer->setGender(GENDER_MALE);
-#else
- mPlayer->setGender(gender);
-#endif
-
- int numberOfHairColors = ColorDB::size();
-
- mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(),
- rand() % numberOfHairColors);
-
- mNameField = new TextField("");
- mNameLabel = new Label(_("Name:"));
- mNextHairColorButton = new Button(">", "nextcolor", this);
- mPrevHairColorButton = new Button("<", "prevcolor", this);
- mHairColorLabel = new Label(_("Hair Color:"));
- mNextHairStyleButton = new Button(">", "nextstyle", this);
- mPrevHairStyleButton = new Button("<", "prevstyle", this);
- mHairStyleLabel = new Label(_("Hair Style:"));
- mCreateButton = new Button(_("Create"), "create", this);
- mCancelButton = new Button(_("Cancel"), "cancel", this);
-#ifdef TMWSERV_SUPPORT
- mMale = new RadioButton(_("Male"), "gender");
- mFemale = new RadioButton(_("Female"), "gender");
-
- // Default to a Male character
- mMale->setSelected(true);
-
- mMale->setActionEventId("gender");
- mFemale->setActionEventId("gender");
-
- mMale->addActionListener(this);
- mFemale->addActionListener(this);
-#endif
- mPlayerBox = new PlayerBox(mPlayer);
-
- mPlayerBox->setWidth(74);
-
- mNameField->setActionEventId("create");
- mNameField->addActionListener(this);
-
-#ifdef TMWSERV_SUPPORT
- mAttributeLabel[0] = new gcn::Label(_("Strength:"));
- mAttributeLabel[1] = new gcn::Label(_("Agility:"));
- mAttributeLabel[2] = new gcn::Label(_("Dexterity:"));
- mAttributeLabel[3] = new gcn::Label(_("Vitality:"));
- mAttributeLabel[4] = new gcn::Label(_("Intelligence:"));
- mAttributeLabel[5] = new gcn::Label(_("Willpower:"));
- for (int i = 0; i < 6; i++)
- {
- mAttributeLabel[i]->setWidth(70);
- mAttributeSlider[i] = new Slider(1, 20);
- mAttributeValue[i] = new gcn::Label("1");
- };
-
- mAttributesLeft = new gcn::Label(strprintf(_("Please distribute %d points"), 99));
-
- int w = 200;
- int h = 330;
- setContentSize(w, h);
- mPlayerBox->setDimension(gcn::Rectangle(80, 30, 110, 85));
- mNameLabel->setPosition(5, 5);
- mNameField->setDimension(
- gcn::Rectangle(45, 5, w - 45 - 7, mNameField->getHeight()));
- mPrevHairColorButton->setPosition(90, 35);
- mNextHairColorButton->setPosition(165, 35);
- mHairColorLabel->setPosition(5, 40);
- mPrevHairStyleButton->setPosition(90, 64);
- mNextHairStyleButton->setPosition(165, 64);
- mHairStyleLabel->setPosition(5, 70);
- for (int i=0; i<6; i++)
- {
- mAttributeSlider[i]->setValue(10);
- mAttributeSlider[i]->setDimension(gcn::Rectangle( 75, 140 + i*20,
- 100, 10));
- mAttributeSlider[i]->setActionEventId("statslider");
- mAttributeSlider[i]->addActionListener(this);
- mAttributeValue[i]->setPosition(180, 140 + i*20);
- mAttributeLabel[i]->setPosition(5, 140 + i*20);
- };
- mAttributesLeft->setPosition(15, 280);
- updateSliders();
- mCancelButton->setPosition(
- w - 5 - mCancelButton->getWidth(),
- h - 5 - mCancelButton->getHeight());
- mCreateButton->setPosition(
- mCancelButton->getX() - 5 - mCreateButton->getWidth(),
- h - 5 - mCancelButton->getHeight());
-
- mMale->setPosition(30, 120);
- mFemale->setPosition(100, 120);
-
- add(mPlayerBox);
- add(mNameField);
- add(mNameLabel);
- add(mNextHairColorButton);
- add(mPrevHairColorButton);
- add(mHairColorLabel);
- add(mNextHairStyleButton);
- add(mPrevHairStyleButton);
- add(mHairStyleLabel);
- for (int i = 0; i < 6; i++)
- {
- add(mAttributeSlider[i]);
- add(mAttributeValue[i]);
- add(mAttributeLabel[i]);
- };
- add(mAttributesLeft);
- add(mCreateButton);
- add(mCancelButton);
-
- add(mMale);
- add(mFemale);
-
-#else
-
- ContainerPlacer place;
- place = getPlacer(0, 0);
-
- place(0, 0, mNameLabel, 1);
- place(1, 0, mNameField, 6);
- place(0, 1, mHairStyleLabel, 1);
- place(1, 1, mPrevHairStyleButton);
- place(2, 1, mPlayerBox, 1, 8).setPadding(3);
- place(3, 1, mNextHairStyleButton);
- place(0, 2, mHairColorLabel, 1);
- place(1, 2, mPrevHairColorButton);
- place(3, 2, mNextHairColorButton);
- place.getCell().matchColWidth(0, 2);
- place = getPlacer(0, 2);
- place(4, 0, mCancelButton);
- place(5, 0, mCreateButton);
-
- reflowLayout(225, 0);
-#endif
-
- center();
- setVisible(true);
- mNameField->requestFocus();
-}
-
-CharCreateDialog::~CharCreateDialog()
-{
- delete mPlayer;
-
- // Make sure the char server handler knows that we're gone
- charServerHandler.setCharCreateDialog(0);
-}
-
-void CharCreateDialog::action(const gcn::ActionEvent &event)
-{
- int numberOfColors = ColorDB::size();
- if (event.getId() == "create")
- {
- if (getName().length() >= 4)
- {
- // Attempt to create the character
- mCreateButton->setEnabled(false);
-#ifdef TMWSERV_SUPPORT
- unsigned int genderSelected;
- if (mMale->isSelected()) {
- genderSelected = GENDER_MALE;
- } else {
- genderSelected = GENDER_FEMALE;
- }
-
- Net::AccountServer::Account::createCharacter(
- getName(),
- mPlayer->getHairStyle(),
- mPlayer->getHairColor(),
- genderSelected, // gender
- (int) mAttributeSlider[0]->getValue(), // STR
- (int) mAttributeSlider[1]->getValue(), // AGI
- (int) mAttributeSlider[2]->getValue(), // DEX
- (int) mAttributeSlider[3]->getValue(), // VIT
- (int) mAttributeSlider[4]->getValue(), // INT
- (int) mAttributeSlider[5]->getValue() // WILL
- );
-#else
- charHandler->newCharacter(getName(), mSlot, false,
- mPlayer->getHairStyle(), mPlayer->getHairColor());
-#endif
- }
- else
- {
- new OkDialog(_("Error"),
- _("Your name needs to be at least 4 characters."),
- this);
- }
- }
- else if (event.getId() == "cancel")
- scheduleDelete();
- else if (event.getId() == "nextcolor")
- mPlayer->setHairStyle(mPlayer->getHairStyle(),
- (mPlayer->getHairColor() + 1) % numberOfColors);
- else if (event.getId() == "prevcolor")
- mPlayer->setHairStyle(mPlayer->getHairStyle(),
- (mPlayer->getHairColor() + numberOfColors - 1) %
- numberOfColors);
- else if (event.getId() == "nextstyle")
- mPlayer->setHairStyle(mPlayer->getHairStyle() + 1,
- mPlayer->getHairColor());
- else if (event.getId() == "prevstyle")
- mPlayer->setHairStyle(mPlayer->getHairStyle() +
- mPlayer->getNumOfHairstyles() - 1,
- mPlayer->getHairColor());
-#ifdef TMWSERV_SUPPORT
- else if (event.getId() == "statslider") {
- updateSliders();
- }
- else if (event.getId() == "gender"){
- if (mMale->isSelected()) {
- mPlayer->setGender(GENDER_MALE);
- } else {
- mPlayer->setGender(GENDER_FEMALE);
- }
- }
-#endif
-}
-
-std::string CharCreateDialog::getName()
-{
- std::string name = mNameField->getText();
- trim(name);
- return name;
-}
-
-#ifdef TMWSERV_SUPPORT
-void CharCreateDialog::updateSliders()
-{
- for (int i = 0; i < 6; i++)
- {
- // Update captions
- mAttributeValue[i]->setCaption(
- toString((int) (mAttributeSlider[i]->getValue())));
- mAttributeValue[i]->adjustSize();
- }
-
- // Update distributed points
- int pointsLeft = 60 - getDistributedPoints();
- if (pointsLeft == 0)
- {
- mAttributesLeft->setCaption(_("Character stats OK"));
- mCreateButton->setEnabled(true);
- }
- else
- {
- mCreateButton->setEnabled(false);
- if (pointsLeft > 0)
- {
- mAttributesLeft->setCaption(strprintf(_("Please distribute %d points"), pointsLeft));
- }
- else
- {
- mAttributesLeft->setCaption(strprintf(_("Please remove %d points"), -pointsLeft));
- }
- }
-
- mAttributesLeft->adjustSize();
-}
-#endif
-
-void CharCreateDialog::unlock()
-{
- mCreateButton->setEnabled(true);
-}
-
-#ifdef TMWSERV_SUPPORT
-int CharCreateDialog::getDistributedPoints()
-{
- int points = 0;
-
- for (int i = 0; i < 6; i++)
- {
- points += (int) mAttributeSlider[i]->getValue();
- }
- return points;
-}
-#endif
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index cf770010..171c49f6 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -109,81 +109,4 @@ class CharSelectDialog : public Window, public gcn::ActionListener
void attemptCharSelect();
};
-/**
- * Character creation dialog.
- *
- * \ingroup Interface
- */
-class CharCreateDialog : public Window, public gcn::ActionListener
-{
- public:
- /**
- * Constructor.
- */
-#ifdef TMWSERV_SUPPORT
- CharCreateDialog(Window *parent, int slot);
-#else
- CharCreateDialog(Window *parent, int slot, Gender gender);
-#endif
-
- /**
- * Destructor.
- */
- ~CharCreateDialog();
-
- void action(const gcn::ActionEvent &event);
-
- /**
- * Unlocks the dialog, enabling the create character button again.
- */
- void unlock();
-
- private:
-#ifdef TMWSERV_SUPPORT
- int getDistributedPoints();
-
- void updateSliders();
-#endif
-
- /**
- * Returns the name of the character to create.
- */
- std::string getName();
-
- /**
- * Communicate character creation to the server.
- */
- void attemptCharCreate();
-
- gcn::TextField *mNameField;
- gcn::Label *mNameLabel;
- gcn::Button *mNextHairColorButton;
- gcn::Button *mPrevHairColorButton;
- gcn::Label *mHairColorLabel;
- gcn::Button *mNextHairStyleButton;
- gcn::Button *mPrevHairStyleButton;
- gcn::Label *mHairStyleLabel;
-
-#ifdef TMWSERV_SUPPORT
- gcn::RadioButton *mMale;
- gcn::RadioButton *mFemale;
-
- gcn::Slider *mAttributeSlider[6];
- gcn::Label *mAttributeLabel[6];
- gcn::Label *mAttributeValue[6];
- gcn::Label *mAttributesLeft;
-
- static const int mMaxPoints = 60;
- int mUsedPoints;
-#endif
-
- gcn::Button *mCreateButton;
- gcn::Button *mCancelButton;
-
- Player *mPlayer;
- PlayerBox *mPlayerBox;
-
- int mSlot;
-};
-
#endif
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
new file mode 100644
index 00000000..662bebb7
--- /dev/null
+++ b/src/gui/charcreatedialog.cpp
@@ -0,0 +1,329 @@
+/*
+ * The Mana World
+ * Copyright (C) 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "gui/charcreatedialog.h"
+
+#include "gui/button.h"
+#include "gui/char_select.h"
+#include "gui/confirm_dialog.h"
+#include "gui/label.h"
+#include "gui/ok_dialog.h"
+#include "gui/playerbox.h"
+#include "gui/textfield.h"
+
+#include "gui/radiobutton.h"
+#include "gui/slider.h"
+
+#include "gui/widgets/layout.h"
+
+#include "game.h"
+#include "localplayer.h"
+#include "main.h"
+#include "units.h"
+
+#include "net/charhandler.h"
+#include "net/messageout.h"
+#include "net/net.h"
+
+#include "resources/colordb.h"
+
+#include "utils/gettext.h"
+#include "utils/strprintf.h"
+#include "utils/stringutils.h"
+
+#include <guichan/font.hpp>
+
+#include <string>
+
+CharCreateDialog::CharCreateDialog(Window *parent, int slot):
+ Window(_("Create Character"), true, parent),
+ mSlot(slot)
+{
+ mPlayer = new Player(0, 0, NULL);
+ mPlayer->setGender(GENDER_MALE);
+
+ int numberOfHairColors = ColorDB::size();
+
+ mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(),
+ rand() % numberOfHairColors);
+
+ mNameField = new TextField("");
+ mNameLabel = new Label(_("Name:"));
+ mNextHairColorButton = new Button(">", "nextcolor", this);
+ mPrevHairColorButton = new Button("<", "prevcolor", this);
+ mHairColorLabel = new Label(_("Hair Color:"));
+ mNextHairStyleButton = new Button(">", "nextstyle", this);
+ mPrevHairStyleButton = new Button("<", "prevstyle", this);
+ mHairStyleLabel = new Label(_("Hair Style:"));
+ mCreateButton = new Button(_("Create"), "create", this);
+ mCancelButton = new Button(_("Cancel"), "cancel", this);
+ mMale = new RadioButton(_("Male"), "gender");
+ mFemale = new RadioButton(_("Female"), "gender");
+
+ // Default to a Male character
+ mMale->setSelected(true);
+
+ mMale->setActionEventId("gender");
+ mFemale->setActionEventId("gender");
+
+ mMale->addActionListener(this);
+ mFemale->addActionListener(this);
+
+ mPlayerBox = new PlayerBox(mPlayer);
+
+ mPlayerBox->setWidth(74);
+
+ mNameField->setActionEventId("create");
+ mNameField->addActionListener(this);
+
+ mAttributesLeft = new gcn::Label(strprintf(_("Please distribute %d points"), 99));
+
+ int w = 200;
+ int h = 330;
+ setContentSize(w, h);
+ mPlayerBox->setDimension(gcn::Rectangle(80, 30, 110, 85));
+ mNameLabel->setPosition(5, 5);
+ mNameField->setDimension(
+ gcn::Rectangle(45, 5, w - 45 - 7, mNameField->getHeight()));
+ mPrevHairColorButton->setPosition(90, 35);
+ mNextHairColorButton->setPosition(165, 35);
+ mHairColorLabel->setPosition(5, 40);
+ mPrevHairStyleButton->setPosition(90, 64);
+ mNextHairStyleButton->setPosition(165, 64);
+ mHairStyleLabel->setPosition(5, 70);
+ mAttributesLeft->setPosition(15, 280);
+ updateSliders();
+ mCancelButton->setPosition(
+ w - 5 - mCancelButton->getWidth(),
+ h - 5 - mCancelButton->getHeight());
+ mCreateButton->setPosition(
+ mCancelButton->getX() - 5 - mCreateButton->getWidth(),
+ h - 5 - mCancelButton->getHeight());
+
+ mMale->setPosition(30, 120);
+ mFemale->setPosition(100, 120);
+
+ add(mPlayerBox);
+ add(mNameField);
+ add(mNameLabel);
+ add(mNextHairColorButton);
+ add(mPrevHairColorButton);
+ add(mHairColorLabel);
+ add(mNextHairStyleButton);
+ add(mPrevHairStyleButton);
+ add(mHairStyleLabel);
+ add(mAttributesLeft);
+ add(mCreateButton);
+ add(mCancelButton);
+
+ add(mMale);
+ add(mFemale);
+
+ center();
+ setVisible(true);
+ mNameField->requestFocus();
+}
+
+CharCreateDialog::~CharCreateDialog()
+{
+ delete mPlayer;
+
+ // Make sure the char server handler knows that we're gone
+ Net::getCharHandler()->setCharCreateDialog(0);
+}
+
+void CharCreateDialog::action(const gcn::ActionEvent &event)
+{
+ int numberOfColors = ColorDB::size();
+ if (event.getId() == "create")
+ {
+ if (getName().length() >= 4)
+ {
+ // Attempt to create the character
+ mCreateButton->setEnabled(false);
+
+ std::vector<int> atts;
+ for (int i = 0; i < mAttributeSlider.size(); i++)
+ {
+ atts[i] = (int) mAttributeSlider[i]->getValue();
+ }
+
+ Net::getCharHandler()->newCharacter(getName(), mSlot,
+ mFemale->isSelected(), mPlayer->getHairStyle(),
+ mPlayer->getHairColor(), atts);
+ }
+ else
+ {
+ new OkDialog(_("Error"),
+ _("Your name needs to be at least 4 characters."),
+ this);
+ }
+ }
+ else if (event.getId() == "cancel")
+ scheduleDelete();
+ else if (event.getId() == "nextcolor")
+ mPlayer->setHairStyle(mPlayer->getHairStyle(),
+ (mPlayer->getHairColor() + 1) % numberOfColors);
+ else if (event.getId() == "prevcolor")
+ mPlayer->setHairStyle(mPlayer->getHairStyle(),
+ (mPlayer->getHairColor() + numberOfColors - 1) %
+ numberOfColors);
+ else if (event.getId() == "nextstyle")
+ mPlayer->setHairStyle(mPlayer->getHairStyle() + 1,
+ mPlayer->getHairColor());
+ else if (event.getId() == "prevstyle")
+ mPlayer->setHairStyle(mPlayer->getHairStyle() +
+ mPlayer->getNumOfHairstyles() - 1,
+ mPlayer->getHairColor());
+ else if (event.getId() == "statslider") {
+ updateSliders();
+ }
+ else if (event.getId() == "gender"){
+ if (mMale->isSelected()) {
+ mPlayer->setGender(GENDER_MALE);
+ } else {
+ mPlayer->setGender(GENDER_FEMALE);
+ }
+ }
+}
+
+std::string CharCreateDialog::getName()
+{
+ std::string name = mNameField->getText();
+ trim(name);
+ return name;
+}
+
+void CharCreateDialog::updateSliders()
+{
+ for (int i = 0; i < mAttributeSlider.size(); i++)
+ {
+ // Update captions
+ mAttributeValue[i]->setCaption(
+ toString((int) (mAttributeSlider[i]->getValue())));
+ mAttributeValue[i]->adjustSize();
+ }
+
+ // Update distributed points
+ int pointsLeft = mMaxPoints - getDistributedPoints();
+ if (pointsLeft == 0)
+ {
+ mAttributesLeft->setCaption(_("Character stats OK"));
+ mCreateButton->setEnabled(true);
+ }
+ else
+ {
+ mCreateButton->setEnabled(false);
+ if (pointsLeft > 0)
+ {
+ mAttributesLeft->setCaption(strprintf(_("Please distribute %d points"), pointsLeft));
+ }
+ else
+ {
+ mAttributesLeft->setCaption(strprintf(_("Please remove %d points"), -pointsLeft));
+ }
+ }
+
+ mAttributesLeft->adjustSize();
+}
+
+void CharCreateDialog::unlock()
+{
+ mCreateButton->setEnabled(true);
+}
+
+int CharCreateDialog::getDistributedPoints()
+{
+ int points = 0;
+
+ for (int i = 0; i < mAttributeSlider.size(); i++)
+ {
+ points += (int) mAttributeSlider[i]->getValue();
+ }
+ return points;
+}
+
+void CharCreateDialog::setAttributes(std::vector<std::string> labels,
+ int available, int min, int max)
+{
+ mMaxPoints = available;
+
+ for (int i = 0; i < mAttributeLabel.size(); i++)
+ {
+ remove(mAttributeLabel[i]);
+ delete mAttributeLabel[i];
+ remove(mAttributeSlider[i]);
+ delete mAttributeSlider[i];
+ remove(mAttributeValue[i]);
+ delete mAttributeValue[i];
+ }
+
+ int w = 200;
+ int h = 330;
+
+ for (int i = 0; i < labels.size(); i++)
+ {
+ mAttributeLabel[i] = new gcn::Label(labels[i]);
+ mAttributeLabel[i]->setWidth(70);
+ mAttributeLabel[i]->setPosition(5, 140 + i*20);
+ add(mAttributeLabel[i]);
+
+ mAttributeSlider[i] = new gcn::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 gcn::Label(toString(min));
+ mAttributeValue[i]->setPosition(180, 140 + i*20);
+ add(mAttributeValue[i]);
+ }
+
+ mAttributesLeft->setPosition(15, 280);
+ updateSliders();
+
+ mCancelButton->setPosition(
+ w - 5 - mCancelButton->getWidth(),
+ h - 5 - mCancelButton->getHeight());
+ mCreateButton->setPosition(
+ mCancelButton->getX() - 5 - mCreateButton->getWidth(),
+ h - 5 - mCancelButton->getHeight());
+}
+
+void CharCreateDialog::setFixedGender(bool fixed, bool gender)
+{
+ if (gender)
+ {
+ mFemale->setSelected(true);
+ mMale->setSelected(false);
+ }
+ else
+ {
+ mMale->setSelected(true);
+ mFemale->setSelected(false);
+ }
+
+ if (fixed)
+ {
+ mMale->setEnabled(false);
+ mFemale->setEnabled(false);
+ }
+}
diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h
new file mode 100644
index 00000000..89509701
--- /dev/null
+++ b/src/gui/charcreatedialog.h
@@ -0,0 +1,112 @@
+/*
+ * The Mana World
+ * Copyright (C) 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef CHAR_CREATE_H
+#define CHAR_CREATE_H
+
+#include "being.h"
+#include "guichanfwd.h"
+#include "lockedarray.h"
+
+#include "gui/window.h"
+
+#include <guichan/actionlistener.hpp>
+#include <vector>
+
+class LocalPlayer;
+class Player;
+class PlayerBox;
+
+/**
+ * Character creation dialog.
+ *
+ * \ingroup Interface
+ */
+class CharCreateDialog : public Window, public gcn::ActionListener
+{
+ public:
+ /**
+ * Constructor.
+ */
+ CharCreateDialog(Window *parent, int slot);
+
+ /**
+ * Destructor.
+ */
+ ~CharCreateDialog();
+
+ void action(const gcn::ActionEvent &event);
+
+ /**
+ * Unlocks the dialog, enabling the create character button again.
+ */
+ void unlock();
+
+ void setAttributes(std::vector<std::string> labels, int available,
+ int min, int max);
+
+ void setFixedGender(bool fixed, bool gender = false);
+
+ private:
+ int getDistributedPoints();
+
+ void updateSliders();
+
+ /**
+ * Returns the name of the character to create.
+ */
+ std::string getName();
+
+ /**
+ * Communicate character creation to the server.
+ */
+ void attemptCharCreate();
+
+ gcn::TextField *mNameField;
+ gcn::Label *mNameLabel;
+ gcn::Button *mNextHairColorButton;
+ gcn::Button *mPrevHairColorButton;
+ gcn::Label *mHairColorLabel;
+ gcn::Button *mNextHairStyleButton;
+ gcn::Button *mPrevHairStyleButton;
+ gcn::Label *mHairStyleLabel;
+
+ gcn::RadioButton *mMale;
+ gcn::RadioButton *mFemale;
+
+ std::vector<gcn::Slider*> mAttributeSlider;
+ std::vector<gcn::Label*> mAttributeLabel;
+ std::vector<gcn::Label*> mAttributeValue;
+ gcn::Label *mAttributesLeft;
+
+ int mMaxPoints;
+ int mUsedPoints;
+
+ gcn::Button *mCreateButton;
+ gcn::Button *mCancelButton;
+
+ Player *mPlayer;
+ PlayerBox *mPlayerBox;
+
+ int mSlot;
+};
+
+#endif // CHAR_CREATE_H