summaryrefslogtreecommitdiff
path: root/src/gui/char_select.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/char_select.cpp')
-rw-r--r--src/gui/char_select.cpp360
1 files changed, 343 insertions, 17 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index aaf4e8c4..7c0e2ab2 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -31,6 +31,22 @@
#include "playerbox.h"
#include "textfield.h"
+#ifdef TMWSERV_SUPPORT
+#include "radiobutton.h"
+#include "slider.h"
+
+#include "unregisterdialog.h"
+#include "changepassworddialog.h"
+#include "changeemaildialog.h"
+
+#include "../logindata.h"
+
+#include "../net/tmwserv/accountserver/account.h"
+#include "../net/tmwserv/charserverhandler.h"
+#else
+#include "../net/ea/charserverhandler.h"
+#endif
+
#include "widgets/layout.h"
#include "../game.h"
@@ -38,7 +54,6 @@
#include "../main.h"
#include "../units.h"
-#include "../net/charserverhandler.h"
#include "../net/messageout.h"
#include "../resources/colordb.h"
@@ -47,6 +62,8 @@
#include "../utils/strprintf.h"
#include "../utils/stringutils.h"
+#define MAX_SLOT 2
+
// Defined in main.cpp, used here for setting the char create dialog
extern CharServerHandler charServerHandler;
@@ -79,22 +96,72 @@ void CharDeleteConfirm::action(const gcn::ActionEvent &event)
ConfirmDialog::action(event);
}
+#ifdef TMWSERV_SUPPORT
+CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
+ LoginData *loginData):
+ Window(_("Account and Character Management")),
+ mCharInfo(charInfo), mCharSelected(false), mLoginData(loginData)
+#else
CharSelectDialog::CharSelectDialog(Network *network,
LockedArray<LocalPlayer*> *charInfo,
Gender gender):
Window(_("Select Character")), mNetwork(network),
- mCharInfo(charInfo), mGender(gender), mCharSelected(false)
+ mCharInfo(charInfo),
+ mCharSelected(false),
+ mGender(gender)
+#endif
{
+ mSelectButton = new Button(_("Ok"), "ok", this);
+ mCancelButton = new Button(_("Cancel"), "cancel", this);
+ mPreviousButton = new Button(_("Previous"), "previous", this);
+ mNextButton = new Button(_("Next"), "next", this);
+ mNameLabel = new Label(strprintf(_("Name: %s"), ""));
+ mLevelLabel = new Label(strprintf(_("Level: %d"), 0));
+#ifdef TMWSERV_SUPPORT
+ mNewCharButton = new Button(_("New"), "new", this);
+ mDelCharButton = new Button(_("Delete"), "delete", this);
+ mUnRegisterButton = new Button(_("Unregister"), "unregister", this);
+ mChangePasswordButton = new Button(_("Change Password"), "change_password", this);
+ mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this);
+
+ mAccountNameLabel = new Label(strprintf(_("Account: %s"), mLoginData->username.c_str()));
+ mNameLabel = new Label(strprintf(_("Name: %s"), ""));
+ mLevelLabel = new Label(strprintf(_("Level: %d"), 0));
+ mMoneyLabel = new Label(strprintf(_("Money: %d"), 0));
+
+ // Control that shows the Player
+ mPlayerBox = new PlayerBox;
+ mPlayerBox->setWidth(74);
+
+ ContainerPlacer place;
+ place = getPlacer(0, 0);
+ place(0, 0, mAccountNameLabel);
+ place(0, 1, mUnRegisterButton);
+ place(0, 2, mChangePasswordButton);
+ place(1, 2, mChangeEmailButton);
+ place = getPlacer(0, 1);
+ place(0, 0, mPlayerBox, 1, 5).setPadding(3);
+ place(1, 0, mNameLabel, 3);
+ place(1, 1, mLevelLabel, 3);
+ place(1, 2, mMoneyLabel, 3);
+ place(1, 3, mPreviousButton);
+ place(2, 3, mNextButton);
+ place(1, 4, mNewCharButton);
+ place(2, 4, mDelCharButton);
+ place.getCell().matchColWidth(1, 2);
+ place = getPlacer(0, 2);
+ place(0, 0, mSelectButton);
+ place(1, 0, mCancelButton);
+ reflowLayout(265, 0);
+#else
mCharInfo->select(0);
LocalPlayer *pi = mCharInfo->getEntry();
if (pi)
- mMoney = Units::formatCurrency(pi->mGp);
+ mMoney = Units::formatCurrency(pi->getMoney());
// Control that shows the Player
mPlayerBox = new PlayerBox;
mPlayerBox->setWidth(74);
- mNameLabel = new Label(strprintf(_("Name: %s"), ""));
- mLevelLabel = new Label(strprintf(_("Level: %d"), 0));
mJobLevelLabel = new Label(strprintf(_("Job Level: %d"), 0));
mMoneyLabel = new Label(strprintf(_("Money: %s"), mMoney.c_str()));
@@ -102,11 +169,7 @@ CharSelectDialog::CharSelectDialog(Network *network,
getFont()->getWidth(_("Delete")) ?
_("Delete") : _("New");
- mPreviousButton = new Button(_("Previous"), "previous", this);
- mNextButton = new Button(_("Next"), "next", this);
mNewDelCharButton = new Button(tempString, "newdel", this);
- mSelectButton = new Button(_("Ok"), "ok", this);
- mCancelButton = new Button(_("Cancel"), "cancel", this);
ContainerPlacer place;
place = getPlacer(0, 0);
@@ -125,6 +188,7 @@ CharSelectDialog::CharSelectDialog(Network *network,
place(5, 0, mSelectButton);
reflowLayout(250, 0);
+#endif
center();
setVisible(true);
@@ -134,10 +198,21 @@ CharSelectDialog::CharSelectDialog(Network *network,
void CharSelectDialog::action(const gcn::ActionEvent &event)
{
+#ifdef TMWSERV_SUPPORT
+ // The pointers are set to NULL if there is no character stored
+ if (event.getId() == "ok" && (mCharInfo->getEntry()))
+#else
if (event.getId() == "ok" && n_character > 0)
+#endif
{
// Start game
+#ifdef TMWSERV_SUPPORT
+ mNewCharButton->setEnabled(false);
+ mDelCharButton->setEnabled(false);
+ mUnRegisterButton->setEnabled(false);
+#else
mNewDelCharButton->setEnabled(false);
+#endif
mSelectButton->setEnabled(false);
mPreviousButton->setEnabled(false);
mNextButton->setEnabled(false);
@@ -146,8 +221,35 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "cancel")
{
- state = EXIT_STATE;
+#ifdef TMWSERV_SUPPORT
+ mCharInfo->clear();
+ state = STATE_SWITCH_ACCOUNTSERVER_ATTEMPT;
+#else
+ state = STATE_EXIT;
+#endif
+ }
+#ifdef TMWSERV_SUPPORT
+ else if (event.getId() == "new")
+ {
+ // TODO: Search the first free slot, and start CharCreateDialog
+ // maybe add that search to the constructor.
+ if (!(mCharInfo->getEntry()))
+ {
+ // Start new character dialog
+ CharCreateDialog *charCreateDialog =
+ new CharCreateDialog(this, mCharInfo->getPos());
+ charServerHandler.setCharCreateDialog(charCreateDialog);
+ }
+ }
+ else if (event.getId() == "delete")
+ {
+ // Delete character
+ if (mCharInfo->getEntry())
+ {
+ new CharDeleteConfirm(this);
+ }
}
+#else
else if (event.getId() == "newdel")
{
// Check for a character
@@ -164,20 +266,35 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
charServerHandler.setCharCreateDialog(charCreateDialog);
}
}
+#endif
else if (event.getId() == "previous")
{
mCharInfo->prev();
LocalPlayer *pi = mCharInfo->getEntry();
if (pi)
- mMoney = Units::formatCurrency(pi->mGp);
+ mMoney = Units::formatCurrency(pi->getMoney());
}
else if (event.getId() == "next")
{
mCharInfo->next();
LocalPlayer *pi = mCharInfo->getEntry();
if (pi)
- mMoney = Units::formatCurrency(pi->mGp);
+ mMoney = Units::formatCurrency(pi->getMoney());
}
+#ifdef TMWSERV_SUPPORT
+ else if (event.getId() == "unregister")
+ {
+ new UnRegisterDialog(this, mLoginData);
+ }
+ else if (event.getId() == "change_password")
+ {
+ new ChangePasswordDialog(this, mLoginData);
+ }
+ else if (event.getId() == "change_email")
+ {
+ new ChangeEmailDialog(this, mLoginData);
+ }
+#endif
}
void CharSelectDialog::updatePlayerInfo()
@@ -188,13 +305,20 @@ void CharSelectDialog::updatePlayerInfo()
{
mNameLabel->setCaption(strprintf(_("Name: %s"),
pi->getName().c_str()));
- mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->mLevel));
+ mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->getLevel()));
+#ifndef TMWSERV_SUPPORT
mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"),
pi->mJobLevel));
+#endif
mMoneyLabel->setCaption(strprintf(_("Money: %s"), mMoney.c_str()));
if (!mCharSelected)
{
+#ifdef TMWSERV_SUPPORT
+ mNewCharButton->setEnabled(false);
+ mDelCharButton->setEnabled(true);
+#else
mNewDelCharButton->setCaption(_("Delete"));
+#endif
mSelectButton->setEnabled(true);
}
}
@@ -202,9 +326,16 @@ void CharSelectDialog::updatePlayerInfo()
{
mNameLabel->setCaption(strprintf(_("Name: %s"), ""));
mLevelLabel->setCaption(strprintf(_("Level: %d"), 0));
+#ifndef TMWSERV_SUPPORT
mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), 0));
+#endif
mMoneyLabel->setCaption(strprintf(_("Money: %s"), ""));
+#ifdef TMWSERV_SUPPORT
+ mNewCharButton->setEnabled(true);
+ mDelCharButton->setEnabled(false);
+#else
mNewDelCharButton->setCaption(_("New"));
+#endif
mSelectButton->setEnabled(false);
}
@@ -213,20 +344,28 @@ void CharSelectDialog::updatePlayerInfo()
void CharSelectDialog::attemptCharDelete()
{
+#ifdef TMWSERV_SUPPORT
+ Net::AccountServer::Account::deleteCharacter(mCharInfo->getPos());
+#else
// Request character deletion
MessageOut outMsg(mNetwork);
outMsg.writeInt16(0x0068);
outMsg.writeInt32(mCharInfo->getEntry()->mCharId);
outMsg.writeString("a@a.com", 40);
+#endif
mCharInfo->lock();
}
void CharSelectDialog::attemptCharSelect()
{
+#ifdef TMWSERV_SUPPORT
+ Net::AccountServer::Account::selectCharacter(mCharInfo->getPos());
+#else
// Request character selection
MessageOut outMsg(mNetwork);
outMsg.writeInt16(0x0066);
outMsg.writeInt8(mCharInfo->getPos());
+#endif
mCharInfo->lock();
}
@@ -258,16 +397,29 @@ 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, Network *network,
Gender gender):
- Window(_("Create Character"), true, parent), mNetwork(network), mSlot(slot)
+#endif
+ Window(_("Create Character"), true, parent),
+#ifndef TMWSERV_SUPPORT
+ mNetwork(network),
+#endif
+ 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);
+ mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(),
+ rand() % numberOfHairColors);
mNameField = new TextField("");
mNameLabel = new Label(_("Name:"));
@@ -279,6 +431,19 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
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);
@@ -286,6 +451,81 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
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);
@@ -304,6 +544,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
place(5, 0, mCreateButton);
reflowLayout(225, 0);
+#endif
center();
setVisible(true);
@@ -327,12 +568,35 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
{
// 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
attemptCharCreate();
+#endif
}
else
{
- new OkDialog("Error",
- "Your name needs to be at least 4 characters.", this);
+ new OkDialog(_("Error"),
+ _("Your name needs to be at least 4 characters."),
+ this);
}
}
else if (event.getId() == "cancel")
@@ -351,6 +615,18 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
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()
@@ -360,11 +636,60 @@ std::string CharCreateDialog::getName()
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
+
+#ifndef TMWSERV_SUPPORT
void CharCreateDialog::attemptCharCreate()
{
// Send character infos
@@ -381,3 +706,4 @@ void CharCreateDialog::attemptCharCreate()
outMsg.writeInt16(mPlayer->getHairColor());
outMsg.writeInt16(mPlayer->getHairStyle());
}
+#endif