diff options
Diffstat (limited to 'src/gui/char_select.cpp')
-rw-r--r-- | src/gui/char_select.cpp | 347 |
1 files changed, 276 insertions, 71 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index f800c266..84270d10 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -1,57 +1,65 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright (C) 2004 The Mana World Development Team * * This file is part of The Mana World. * - * The Mana World is free software; you can redistribute it and/or modify + * 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. * - * The Mana World is distributed in the hope that it will be useful, + * 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 The Mana World; if not, write to the Free Software + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "char_select.h" - #include <string> +#include <guichan/font.hpp> + #include <guichan/widgets/label.hpp> #include "button.h" -#include "radiobutton.h" +#include "char_select.h" #include "confirm_dialog.h" #include "ok_dialog.h" #include "playerbox.h" -#include "slider.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/accountserver/account.h" +#endif + #include "widgets/layout.h" #include "../game.h" #include "../localplayer.h" #include "../main.h" -#include "../logindata.h" +#include "../units.h" -#include "../net/accountserver/account.h" #include "../net/charserverhandler.h" #include "../net/messageout.h" +#include "../resources/colordb.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" // Defined in main.cpp, used here for setting the char create dialog extern CharServerHandler charServerHandler; @@ -78,24 +86,37 @@ CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): void CharDeleteConfirm::action(const gcn::ActionEvent &event) { //ConfirmDialog::action(event); - if (event.getId() == "yes") { + if (event.getId() == "yes") + { master->attemptCharDelete(); } 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), + mCharSelected(false), + mGender(gender) +#endif { - mSelectButton = new Button(_("Ok"), "ok", this); mCancelButton = new Button(_("Cancel"), "cancel", this); - mNewCharButton = new Button(_("New"), "new", this); - mDelCharButton = new Button(_("Delete"), "delete", this); mPreviousButton = new Button(_("Previous"), "previous", this); mNextButton = new Button(_("Next"), "next", this); + mNameLabel = new gcn::Label(strprintf(_("Name: %s"), "")); + mLevelLabel = new gcn::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); @@ -129,6 +150,42 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, 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->getMoney()); + // Control that shows the Player + mPlayerBox = new PlayerBox; + mPlayerBox->setWidth(74); + + mJobLevelLabel = new gcn::Label(strprintf(_("Job Level: %d"), 0)); + mMoneyLabel = new gcn::Label(strprintf(_("Money: %s"), mMoney.c_str())); + + const std::string tempString = getFont()->getWidth(_("New")) < + getFont()->getWidth(_("Delete")) ? + _("Delete") : _("New"); + + mNewDelCharButton = new Button(tempString, "newdel", this); + + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mPlayerBox, 1, 6).setPadding(3); + place(1, 0, mNewDelCharButton); + place(1, 1, mNameLabel, 5); + place(1, 2, mLevelLabel, 5); + place(1, 3, mJobLevelLabel, 5); + place(1, 4, mMoneyLabel, 5); + place.getCell().matchColWidth(1, 4); + place = getPlacer(0, 2); + place(0, 0, mPreviousButton); + place(1, 0, mNextButton); + place(4, 0, mCancelButton); + place(5, 0, mSelectButton); + + reflowLayout(250, 0); +#endif setLocationRelativeTo(getParent()); setVisible(true); @@ -138,25 +195,37 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, 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); - mSelectButton->setEnabled(false); mUnRegisterButton->setEnabled(false); +#else + mNewDelCharButton->setEnabled(false); +#endif + mSelectButton->setEnabled(false); mPreviousButton->setEnabled(false); mNextButton->setEnabled(false); mCharSelected = true; - Net::AccountServer::Account::selectCharacter(mCharInfo->getPos()); - mCharInfo->lock(); + attemptCharSelect(); } else if (event.getId() == "cancel") { +#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 @@ -177,14 +246,39 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) new CharDeleteConfirm(this); } } +#else + else if (event.getId() == "newdel") + { + // Check for a character + if (mCharInfo->getEntry() && n_character <= MAX_SLOT + 1) + { + new CharDeleteConfirm(this); + } + else + { + // Start new character dialog + CharCreateDialog *charCreateDialog = + new CharCreateDialog(this, mCharInfo->getPos(), + mNetwork, mGender); + charServerHandler.setCharCreateDialog(charCreateDialog); + } + } +#endif else if (event.getId() == "previous") { mCharInfo->prev(); + LocalPlayer *pi = mCharInfo->getEntry(); + if (pi) + mMoney = Units::formatCurrency(pi->getMoney()); } else if (event.getId() == "next") { mCharInfo->next(); + LocalPlayer *pi = mCharInfo->getEntry(); + if (pi) + mMoney = Units::formatCurrency(pi->getMoney()); } +#ifdef TMWSERV_SUPPORT else if (event.getId() == "unregister") { new UnRegisterDialog(this, mLoginData); @@ -197,6 +291,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) { new ChangeEmailDialog(this, mLoginData); } +#endif } void CharSelectDialog::updatePlayerInfo() @@ -205,22 +300,39 @@ void CharSelectDialog::updatePlayerInfo() if (pi) { - mNameLabel->setCaption(strprintf(_("Name: %s"), pi->getName().c_str())); + mNameLabel->setCaption(strprintf(_("Name: %s"), + pi->getName().c_str())); mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->getLevel())); - mMoneyLabel->setCaption(strprintf(_("Money: %d"), pi->getMoney())); +#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); } } - else { + else + { mNameLabel->setCaption(strprintf(_("Name: %s"), "")); mLevelLabel->setCaption(strprintf(_("Level: %d"), 0)); - mMoneyLabel->setCaption(strprintf(_("Money: %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); } @@ -229,7 +341,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(); } @@ -246,7 +379,8 @@ bool CharSelectDialog::selectByName(const std::string &name) unsigned int oldPos = mCharInfo->getPos(); mCharInfo->select(0); - do { + do + { LocalPlayer *player = mCharInfo->getEntry(); if (player && player->getName() == name) @@ -260,14 +394,29 @@ bool CharSelectDialog::selectByName(const std::string &name) return false; } - +#ifdef TMWSERV_SUPPORT CharCreateDialog::CharCreateDialog(Window *parent, int slot): - Window(_("Create Character"), true, parent), mSlot(slot) +#else +CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, + Gender gender): +#endif + Window(_("Create Character"), true, parent), +#ifndef TMWSERV_SUPPORT + mNetwork(network), +#endif + mSlot(slot) { mPlayer = new Player(0, 0, NULL); - mPlayer->setHairStyle(rand() % Being::getHairStylesNr(), - rand() % Being::getHairColorsNr()); +#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 gcn::Label(_("Name:")); @@ -279,19 +428,34 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): mHairStyleLabel = new gcn::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++) + for (int i = 0; i < 6; i++) { mAttributeLabel[i]->setWidth(70); mAttributeSlider[i] = new Slider(1, 20); @@ -300,8 +464,6 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): mAttributesLeft = new gcn::Label(strprintf(_("Please distribute %d points"), 99)); - mNameField->setActionEventId("create"); - int w = 200; int h = 330; setContentSize(w, h); @@ -334,19 +496,8 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): mCancelButton->getX() - 5 - mCreateButton->getWidth(), h - 5 - mCancelButton->getHeight()); - mNameField->addActionListener(this); - - mMale->setPosition( 30, 120 ); - mFemale->setPosition( 100, 120 ); - - // Default to a Male character - mMale->setSelected(true); - - mMale->setActionEventId("gender"); - mFemale->setActionEventId("gender"); - - mMale->addActionListener(this); - mFemale->addActionListener(this); + mMale->setPosition(30, 120); + mFemale->setPosition(100, 120); add(mPlayerBox); add(mNameField); @@ -357,7 +508,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): add(mNextHairStyleButton); add(mPrevHairStyleButton); add(mHairStyleLabel); - for (int i=0; i<6; i++) + for (int i = 0; i < 6; i++) { add(mAttributeSlider[i]); add(mAttributeValue[i]); @@ -370,6 +521,28 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): 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 + setLocationRelativeTo(getParent()); setVisible(true); mNameField->requestFocus(); @@ -383,14 +556,16 @@ CharCreateDialog::~CharCreateDialog() charServerHandler.setCharCreateDialog(0); } -void -CharCreateDialog::action(const gcn::ActionEvent &event) +void CharCreateDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "create") { - if (getName().length() >= 4) { + 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; @@ -410,26 +585,34 @@ CharCreateDialog::action(const gcn::ActionEvent &event) (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); + else + { + new OkDialog(_("Error"), + _("Your name needs to be at least 4 characters."), + this); } } - else if (event.getId() == "cancel") { + else if (event.getId() == "cancel") scheduleDelete(); - } - else if (event.getId() == "nextcolor") { - mPlayer->setHairStyle(-1, mPlayer->getHairColor() + 1); - } - else if (event.getId() == "prevcolor") { - mPlayer->setHairStyle(-1, mPlayer->getHairColor() + Being::getHairColorsNr() - 1); - } - else if (event.getId() == "nextstyle") { - mPlayer->setHairStyle(mPlayer->getHairStyle() + 1, -1); - } - else if (event.getId() == "prevstyle") { - mPlayer->setHairStyle(mPlayer->getHairStyle() + Being::getHairStylesNr() - 1, -1); - } + 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(); } @@ -440,16 +623,17 @@ CharCreateDialog::action(const gcn::ActionEvent &event) mPlayer->setGender(GENDER_FEMALE); } } +#endif } -std::string -CharCreateDialog::getName() +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++) @@ -482,13 +666,14 @@ void CharCreateDialog::UpdateSliders() mAttributesLeft->adjustSize(); } +#endif -void -CharCreateDialog::unlock() +void CharCreateDialog::unlock() { mCreateButton->setEnabled(true); } +#ifdef TMWSERV_SUPPORT int CharCreateDialog::getDistributedPoints() { int points = 0; @@ -499,3 +684,23 @@ int CharCreateDialog::getDistributedPoints() } return points; } +#endif + +#ifndef TMWSERV_SUPPORT +void CharCreateDialog::attemptCharCreate() +{ + // Send character infos + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x0067); + outMsg.writeString(getName(), 24); + outMsg.writeInt8(5); + outMsg.writeInt8(5); + outMsg.writeInt8(5); + outMsg.writeInt8(5); + outMsg.writeInt8(5); + outMsg.writeInt8(5); + outMsg.writeInt8(mSlot); + outMsg.writeInt16(mPlayer->getHairColor()); + outMsg.writeInt16(mPlayer->getHairStyle()); +} +#endif |