summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-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
-rw-r--r--src/main.cpp4
-rw-r--r--src/net/charhandler.h8
-rw-r--r--src/net/ea/charserverhandler.cpp36
-rw-r--r--src/net/ea/charserverhandler.h10
-rw-r--r--src/net/net.cpp4
-rw-r--r--src/net/tmwserv/charserverhandler.cpp55
-rw-r--r--src/net/tmwserv/charserverhandler.h19
13 files changed, 569 insertions, 414 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b210ba6d..a3356fd2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -89,6 +89,8 @@ SET(SRCS
gui/buysell.h
gui/char_select.cpp
gui/char_select.h
+ gui/charcreatedialog.cpp
+ gui/charcreatedialog.h
gui/chat.cpp
gui/chat.h
gui/chatinput.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 7080bcf0..ec767317 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \
gui/buysell.h \
gui/char_select.cpp \
gui/char_select.h \
+ gui/charcreatedialog.cpp \
+ gui/charcreatedialog.h \
gui/chat.cpp \
gui/chat.h \
gui/chatinput.cpp \
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
diff --git a/src/main.cpp b/src/main.cpp
index feca4fa4..ca1b3bee 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -168,11 +168,13 @@ Net::Connection *chatServerConnection = 0;
Net::Connection *accountServerConnection = 0;
#endif
-CharServerHandler charServerHandler;
LoginData loginData;
#ifdef TMWSERV_SUPPORT
LoginHandler loginHandler;
LogoutHandler logoutHandler;
+TmwServ::CharServerHandler charServerHandler;
+#else
+EAthena::CharServerHandler charServerHandler;
#endif
LockedArray<LocalPlayer*> charInfo(maxSlot + 1);
diff --git a/src/net/charhandler.h b/src/net/charhandler.h
index fa2820e9..7d1b9ab2 100644
--- a/src/net/charhandler.h
+++ b/src/net/charhandler.h
@@ -25,15 +25,21 @@
#include "localplayer.h"
#include <iosfwd>
+#include <vector>
+
+class CharCreateDialog;
namespace Net {
class CharHandler
{
public:
+ virtual void setCharCreateDialog(CharCreateDialog *window) = 0;
+
virtual void chooseCharacter(int slot, LocalPlayer* character) = 0;
virtual void newCharacter(const std::string &name, int slot,
- bool gender, int hairstyle, int hairColor) = 0;
+ bool gender, int hairstyle, int hairColor,
+ std::vector<int> stats) = 0;
virtual void deleteCharacter(int slot, LocalPlayer* character) = 0;
};
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index 822c15c4..377cd2dd 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -31,7 +31,7 @@
#include "logindata.h"
#include "main.h"
-#include "gui/char_select.h"
+#include "gui/charcreatedialog.h"
#include "gui/ok_dialog.h"
#include "utils/gettext.h"
@@ -39,6 +39,8 @@
Net::CharHandler *charHandler;
+namespace EAthena {
+
CharServerHandler::CharServerHandler():
mCharCreateDialog(0)
{
@@ -239,6 +241,24 @@ LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
return tempPlayer;
}
+void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
+{
+ mCharCreateDialog = window;
+
+ if (!mCharCreateDialog) return;
+
+ std::vector<std::string> attributes;
+ attributes.push_back(_("Strength:"));
+ attributes.push_back(_("Agility:"));
+ attributes.push_back(_("Vitality:"));
+ attributes.push_back(_("Intelligence:"));
+ attributes.push_back(_("Dexterity:"));
+ attributes.push_back(_("Luck:"));
+
+ mCharCreateDialog->setAttributes(attributes, 30, 1, 9);
+ mCharCreateDialog->setFixedGender(true);
+}
+
void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character)
{
MessageOut outMsg(CMSG_CHAR_SELECT);
@@ -246,16 +266,14 @@ void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character)
}
void CharServerHandler::newCharacter(const std::string &name, int slot,
- bool gender, int hairstyle, int hairColor)
+ bool gender, int hairstyle, int hairColor, std::vector<int> stats)
{
MessageOut outMsg(CMSG_CHAR_CREATE);
outMsg.writeString(name, 24);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
+ for (int i = 0; i < 6; i++)
+ {
+ outMsg.writeInt8(stats[i]);
+ }
outMsg.writeInt8(slot);
outMsg.writeInt16(hairColor);
outMsg.writeInt16(hairstyle);
@@ -267,3 +285,5 @@ void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character)
outMsg.writeInt32(character->mCharId);
outMsg.writeString("a@a.com", 40);
}
+
+} // namespace EAthena
diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h
index e499ab74..48392ac4 100644
--- a/src/net/ea/charserverhandler.h
+++ b/src/net/ea/charserverhandler.h
@@ -27,10 +27,11 @@
#include "lockedarray.h"
-class CharCreateDialog;
class LocalPlayer;
class LoginData;
+namespace EAthena {
+
/**
* Deals with incoming messages from the character server.
*/
@@ -52,13 +53,12 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
* dialog when a new character is succesfully created, and will unlock
* the dialog when a new character failed to be created.
*/
- void setCharCreateDialog(CharCreateDialog *window)
- { mCharCreateDialog = window; }
+ void setCharCreateDialog(CharCreateDialog *window);
void chooseCharacter(int slot, LocalPlayer* character);
void newCharacter(const std::string &name, int slot, bool gender,
- int hairstyle, int hairColor);
+ int hairstyle, int hairColor, std::vector<int> stats);
void deleteCharacter(int slot, LocalPlayer* character);
@@ -70,6 +70,6 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
LocalPlayer *readPlayerData(MessageIn &msg, int &slot);
};
-extern Net::CharHandler *charHandler;
+} // namespace EAthena
#endif // NET_EA_CHARSERVERHANDLER_H
diff --git a/src/net/net.cpp b/src/net/net.cpp
index 7c5024b1..5c36f4e1 100644
--- a/src/net/net.cpp
+++ b/src/net/net.cpp
@@ -36,6 +36,7 @@
#include "net/tradehandler.h"
extern Net::AdminHandler *adminHandler;
+extern Net::CharHandler *charHandler;
extern Net::ChatHandler *chatHandler;
extern Net::InventoryHandler *inventoryHandler;
extern Net::MapHandler *mapHandler;
@@ -51,8 +52,7 @@ Net::AdminHandler *Net::getAdminHandler()
Net::CharHandler *Net::getCharHandler()
{
- // TODO
- return 0;
+ return charHandler;
}
Net::ChatHandler *Net::getChatHandler()
diff --git a/src/net/tmwserv/charserverhandler.cpp b/src/net/tmwserv/charserverhandler.cpp
index 0779e499..9739367b 100644
--- a/src/net/tmwserv/charserverhandler.cpp
+++ b/src/net/tmwserv/charserverhandler.cpp
@@ -24,6 +24,9 @@
#include "net/tmwserv/connection.h"
#include "net/tmwserv/protocol.h"
+#include "net/tmwserv/accountserver/accountserver.h"
+#include "net/tmwserv/accountserver/account.h"
+
#include "net/messagein.h"
#include "game.h"
@@ -32,12 +35,18 @@
#include "logindata.h"
#include "main.h"
+#include "gui/charcreatedialog.h"
#include "gui/ok_dialog.h"
-#include "gui/char_select.h"
+
+#include "utils/gettext.h"
extern Net::Connection *gameServerConnection;
extern Net::Connection *chatServerConnection;
+Net::CharHandler *charHandler;
+
+namespace TmwServ {
+
CharServerHandler::CharServerHandler():
mCharCreateDialog(0)
{
@@ -49,6 +58,7 @@ CharServerHandler::CharServerHandler():
0
};
handledMessages = _messages;
+ charHandler = this;
}
void CharServerHandler::handleMessage(MessageIn &msg)
@@ -226,3 +236,46 @@ LocalPlayer* CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
return tempPlayer;
}
+
+void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
+{
+ mCharCreateDialog = window;
+
+ if (!mCharCreateDialog) return;
+
+ std::vector<std::string> attributes;
+ attributes.push_back(_("Strength:"));
+ attributes.push_back(_("Agility:"));
+ attributes.push_back(_("Dexterity:"));
+ attributes.push_back(_("Vitality:"));
+ attributes.push_back(_("Intelligence:"));
+ attributes.push_back(_("Willpower:"));
+
+ mCharCreateDialog->setAttributes(attributes, 60, 1, 20);
+}
+
+void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character)
+{
+ Net::AccountServer::Account::selectCharacter(slot);
+}
+
+void CharServerHandler::newCharacter(const std::string &name, int slot, bool gender,
+ int hairstyle, int hairColor, std::vector<int> stats)
+{
+ Net::AccountServer::Account::createCharacter(name, hairstyle, hairColor,
+ gender,
+ stats[0], // STR
+ stats[1], // AGI
+ stats[2], // DEX
+ stats[3], // VIT
+ stats[4], // INT
+ stats[5] // WILL
+ );
+}
+
+void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character)
+{
+ Net::AccountServer::Account::deleteCharacter(slot);
+}
+
+} // namespace TmwServ
diff --git a/src/net/tmwserv/charserverhandler.h b/src/net/tmwserv/charserverhandler.h
index e1e13b55..a5e1fa50 100644
--- a/src/net/tmwserv/charserverhandler.h
+++ b/src/net/tmwserv/charserverhandler.h
@@ -22,18 +22,20 @@
#ifndef NET_TMWSERV_CHARSERVERHANDLER_H
#define NET_TMWSERV_CHARSERVERHANDLER_H
+#include "net/charhandler.h"
#include "net/messagehandler.h"
#include "lockedarray.h"
-class CharCreateDialog;
class LocalPlayer;
class LoginData;
+namespace TmwServ {
+
/**
* Deals with incoming messages related to character selection.
*/
-class CharServerHandler : public MessageHandler
+class CharServerHandler : public MessageHandler, public Net::CharHandler
{
public:
CharServerHandler();
@@ -50,8 +52,15 @@ class CharServerHandler : public MessageHandler
* dialog when a new character is succesfully created, and will unlock
* the dialog when a new character failed to be created.
*/
- void setCharCreateDialog(CharCreateDialog *window)
- { mCharCreateDialog = window; }
+ void setCharCreateDialog(CharCreateDialog *window);
+
+ void chooseCharacter(int slot, LocalPlayer* character);
+
+ void newCharacter(const std::string &name, int slot,
+ bool gender, int hairstyle, int hairColor,
+ std::vector<int> stats);
+
+ void deleteCharacter(int slot, LocalPlayer* character);
protected:
void handleCharCreateResponse(MessageIn &msg);
@@ -65,4 +74,6 @@ class CharServerHandler : public MessageHandler
readPlayerData(MessageIn &msg, int &slot);
};
+} // namespace TmwServ
+
#endif