diff options
author | Rogier Polak <rogier.l.a.polak@gmail.com> | 2007-02-23 19:18:28 +0000 |
---|---|---|
committer | Rogier Polak <rogier.l.a.polak@gmail.com> | 2007-02-23 19:18:28 +0000 |
commit | 775404c84c3250225d43f10c4a5363e997618cb2 (patch) | |
tree | 38393287d1554d8e19471f24bc65525c79efeccb /src/gui | |
parent | fee8461a594770f8ef2bd826868a4ae81270a666 (diff) | |
download | mana-775404c84c3250225d43f10c4a5363e997618cb2.tar.gz mana-775404c84c3250225d43f10c4a5363e997618cb2.tar.bz2 mana-775404c84c3250225d43f10c4a5363e997618cb2.tar.xz mana-775404c84c3250225d43f10c4a5363e997618cb2.zip |
Added unregistering, logout_then_exit, switch_character and switch_accountserver.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/char_select.cpp | 23 | ||||
-rw-r--r-- | src/gui/char_select.h | 8 | ||||
-rw-r--r-- | src/gui/login.cpp | 2 | ||||
-rw-r--r-- | src/gui/quitdialog.cpp | 129 | ||||
-rw-r--r-- | src/gui/quitdialog.h | 71 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 2 | ||||
-rw-r--r-- | src/gui/unregisterdialog.cpp | 171 | ||||
-rw-r--r-- | src/gui/unregisterdialog.h | 73 |
8 files changed, 472 insertions, 7 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 4c4b99e5..5e329598 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -33,9 +33,12 @@ #include "playerbox.h" #include "textfield.h" +#include "unregisterdialog.h" + #include "../game.h" #include "../localplayer.h" #include "../main.h" +#include "../logindata.h" #include "../net/accountserver/account.h" @@ -54,8 +57,8 @@ class CharDeleteConfirm : public ConfirmDialog }; CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): - ConfirmDialog("Confirm", "Are you sure you want to delete this character?", - m), + ConfirmDialog("Confirm", + "Are you sure you want to delete this character?", m), master(m) { } @@ -69,16 +72,19 @@ void CharDeleteConfirm::action(const gcn::ActionEvent &event) ConfirmDialog::action(event); } -CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo): +CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, + LoginData *loginData): Window("Select Character"), - mCharInfo(charInfo), mCharSelected(false) + mCharInfo(charInfo), mCharSelected(false), mLoginData(loginData) { + 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); + mUnRegisterButton = new Button("Unregister", "unregister", this); mNameLabel = new gcn::Label("Name"); mLevelLabel = new gcn::Label("Level"); @@ -104,10 +110,14 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo): mSelectButton->setPosition( mCancelButton->getX() - 5 - mSelectButton->getWidth(), mNewCharButton->getY()); + mUnRegisterButton->setPosition( + w - 5 - mUnRegisterButton->getWidth(), + mCancelButton->getY() - 5 - mUnRegisterButton->getHeight()); add(mPlayerBox); add(mSelectButton); add(mCancelButton); + add(mUnRegisterButton); add(mNewCharButton); add(mDelCharButton); add(mPreviousButton); @@ -130,6 +140,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) mNewCharButton->setEnabled(false); mDelCharButton->setEnabled(false); mSelectButton->setEnabled(false); + mUnRegisterButton->setEnabled(false); mPreviousButton->setEnabled(false); mNextButton->setEnabled(false); mCharSelected = true; @@ -166,6 +177,10 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) { mCharInfo->next(); } + else if (event.getId() == "unregister") + { + new UnRegisterDialog(this, mLoginData); + } } void CharSelectDialog::updatePlayerInfo() diff --git a/src/gui/char_select.h b/src/gui/char_select.h index dbce2cbf..7136f301 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -31,6 +31,8 @@ #include <guichan/actionlistener.hpp> +#include "../logindata.h" + class Player; class LocalPlayer; class PlayerBox; @@ -47,7 +49,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharSelectDialog(LockedArray<LocalPlayer*> *charInfo); + CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, + LoginData *loginData); void action(const gcn::ActionEvent &event); @@ -71,6 +74,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener gcn::Button *mDelCharButton; gcn::Button *mPreviousButton; gcn::Button *mNextButton; + gcn::Button *mUnRegisterButton; gcn::Label *mNameLabel; gcn::Label *mLevelLabel; @@ -80,6 +84,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener bool mCharSelected; + LoginData *mLoginData; /** * Communicate character deletion to the server. */ @@ -130,6 +135,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener int mSlot; + /** * Communicate character creation to the server. */ diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 664074aa..9df3b489 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -144,7 +144,7 @@ LoginDialog::action(const gcn::ActionEvent &event) } else if (event.getId() == "cancel") { - state = STATE_EXIT; + state = STATE_FORCE_QUIT; } else if (event.getId() == "register") { diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp new file mode 100644 index 00000000..97be5f46 --- /dev/null +++ b/src/gui/quitdialog.cpp @@ -0,0 +1,129 @@ +/* + * The Mana World + * Copyright 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 + * 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, + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "quitdialog.h" +#include <iostream> +#include <string> + +#include <guichan/widgets/label.hpp> + +#include "../main.h" + +#include "button.h" +#include "radiobutton.h" + +QuitDialog::QuitDialog(bool* quitGame, QuitDialog** pointerToMe): + Window("Quit", true, NULL), mQuitGame(quitGame), mMyPointer(pointerToMe) +{ + + mLogoutQuit = new RadioButton("Quit", "quitdialog"); + mForceQuit = new RadioButton("Quit", "quitdialog"); + mSwitchAccountServer = new RadioButton("Switch server", "quitdialog"); + mSwitchCharacter = new RadioButton("Switch character", "quitdialog"); + mOkButton = new Button("OK", "ok", this); + mCancelButton = new Button("Cancel", "cancel", this); + + setContentSize(200, 91); + + mLogoutQuit->setPosition(5, 5); + mForceQuit->setPosition(5, 5); + mSwitchAccountServer->setPosition(5, 14 + mLogoutQuit->getHeight()); + mSwitchCharacter->setPosition(5, + 23 + mLogoutQuit->getHeight() + mSwitchAccountServer->getHeight()); + mCancelButton->setPosition( + 200 - mCancelButton->getWidth() - 5, + 91 - mCancelButton->getHeight() - 5); + mOkButton->setPosition( + mCancelButton->getX() - mOkButton->getWidth() - 5, + 91 - mOkButton->getHeight() - 5); + + //All states, when we're not logged in to someone. + if (state == STATE_CHOOSE_SERVER || + state == STATE_CONNECT_ACCOUNT || + state == STATE_LOGIN || + state == STATE_LOGIN_ATTEMPT || + state == STATE_UPDATE) + { + mForceQuit->setMarked(true); + add(mForceQuit); + } + else + { + // Only added if we are connected to an accountserver or gameserver + mLogoutQuit->setMarked(true); + add(mLogoutQuit); + add(mSwitchAccountServer); + + // Only added if we are connected to a gameserver + if (state == STATE_GAME) add(mSwitchCharacter); + } + + add(mOkButton); + add(mCancelButton); + + setLocationRelativeTo(getParent()); + setVisible(true); + + mOkButton->requestFocus(); + +} + +QuitDialog::~QuitDialog() +{ + if (mMyPointer) *mMyPointer = NULL; +} + +void +QuitDialog::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "ok") + { + if (mForceQuit->isMarked()) + { + state = STATE_FORCE_QUIT; + } + else if (mLogoutQuit->isMarked()) + { + if ((state == STATE_GAME) && (mQuitGame)) + { + *mQuitGame = true; + } + state = STATE_EXIT; + } + else if (mSwitchAccountServer->isMarked()) + { + if ((state == STATE_GAME) && (mQuitGame)) + { + *mQuitGame = true; + } + state = STATE_SWITCH_ACCOUNTSERVER_ATTEMPT; + } + else if (mSwitchCharacter->isMarked()) + { + if (mQuitGame) *mQuitGame = true; + + state = STATE_SWITCH_CHARACTER; + } + + } + scheduleDelete(); +} diff --git a/src/gui/quitdialog.h b/src/gui/quitdialog.h new file mode 100644 index 00000000..97a03f2e --- /dev/null +++ b/src/gui/quitdialog.h @@ -0,0 +1,71 @@ +/* + * The Mana World + * Copyright 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 + * 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, + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMW_QUITDIALOG_H +#define _TMW_QUITDIALOG_H + +#include <iosfwd> +#include <guichan/actionlistener.hpp> + +#include "window.h" +#include "../guichanfwd.h" +#include "../main.h" + +/** + * The quit dialog. + * + * \ingroup Interface + */ +class QuitDialog : public Window, public gcn::ActionListener { + public: + /** + * Constructor + * + * @quitGame; to be used for getting out of the while loop in Game + * @pointerToMe; will be set to NULL when the QuitDialog is destroyed + */ + QuitDialog(bool* quitGame, QuitDialog** pointerToMe); + + /** + * Destructor + */ + ~QuitDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + private: + gcn::RadioButton *mLogoutQuit; + gcn::RadioButton *mForceQuit; + gcn::RadioButton *mSwitchAccountServer; + gcn::RadioButton *mSwitchCharacter; + gcn::Button *mOkButton; + gcn::Button *mCancelButton; + + bool* mQuitGame; + QuitDialog** mMyPointer; + +}; + +#endif diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index bf29f0d3..b47ce749 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -243,6 +243,6 @@ ServerDialog::action(const gcn::ActionEvent &event) } else if (event.getId() == "cancel") { - state = STATE_EXIT; + state = STATE_FORCE_QUIT; } } diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp new file mode 100644 index 00000000..03e4880f --- /dev/null +++ b/src/gui/unregisterdialog.cpp @@ -0,0 +1,171 @@ +/* + * The Mana World + * Copyright 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 + * 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, + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "unregisterdialog.h" + +#include <string> +#include <sstream> + +#include <guichan/widgets/label.hpp> + +#include "../main.h" +#include "../log.h" +#include "../logindata.h" + +#include "button.h" +#include "checkbox.h" +#include "login.h" +#include "passwordfield.h" +#include "textfield.h" +#include "ok_dialog.h" + +UnRegisterDialog::UnRegisterDialog(Window *parent, LoginData *loginData): + Window("Unregister", true, parent), + mWrongDataNoticeListener(new WrongDataNoticeListener()), + mLoginData(loginData) +{ + gcn::Label *userLabel = new gcn::Label("Name:"); + gcn::Label *passwordLabel = new gcn::Label("Password:"); + mUserField = new TextField(mLoginData->username); + mPasswordField = new PasswordField(mLoginData->password); + mUnRegisterButton = new Button("Unregister", "unregister", this); + mCancelButton = new Button("Cancel", "cancel", this); + + const int width = 200; + const int height = 70; + setContentSize(width, height); + + mUserField->setPosition(65, 5); + mUserField->setWidth(130); + mPasswordField->setPosition( + 65, mUserField->getY() + mUserField->getHeight() + 7); + mPasswordField->setWidth(130); + + userLabel->setPosition(5, mUserField->getY() + 1); + passwordLabel->setPosition(5, mPasswordField->getY() + 1); + + mCancelButton->setPosition( + width - 5 - mCancelButton->getWidth(), + height - 5 - mCancelButton->getHeight()); + mUnRegisterButton->setPosition( + mCancelButton->getX() - 5 - mUnRegisterButton->getWidth(), + mCancelButton->getY()); + + add(userLabel); + add(passwordLabel); + add(mUserField); + add(mPasswordField); + add(mUnRegisterButton); + add(mCancelButton); + + setLocationRelativeTo(getParent()); + setVisible(true); + mPasswordField->requestFocus(); +} + +UnRegisterDialog::~UnRegisterDialog() +{ + delete mWrongDataNoticeListener; +} + +void +UnRegisterDialog::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "cancel") + { + scheduleDelete(); + } + else if (event.getId() == "unregister") + { + const std::string username = mUserField->getText(); + const std::string password = mPasswordField->getText(); + logger->log("UnregisterDialog::unregistered, Username is %s", + username.c_str()); + + std::stringstream errorMsg; + int error = 0; + + // Check login + if (username.empty()) + { + // No username + errorMsg << "Enter your username first."; + error = 1; + } + else if (username.length() < LEN_MIN_USERNAME) + { + // Name too short + errorMsg << "The username needs to be at least " + << LEN_MIN_USERNAME + << " characters long."; + error = 1; + } + else if (username.length() > LEN_MAX_USERNAME - 1 ) + { + // Name too long + errorMsg << "The username needs to be less than " + << LEN_MAX_USERNAME + << " characters long."; + error = 1; + } + else if (password.length() < LEN_MIN_PASSWORD) + { + // Pass too short + errorMsg << "The password needs to be at least " + << LEN_MIN_PASSWORD + << " characters long."; + error = 2; + } + else if (password.length() > LEN_MAX_PASSWORD - 1 ) + { + // Pass too long + errorMsg << "The password needs to be less than " + << LEN_MAX_PASSWORD + << " characters long."; + error = 2; + } + + if (error > 0) + { + if (error == 1) + { + mWrongDataNoticeListener->setTarget(this->mUserField); + } + else if (error == 2) + { + mWrongDataNoticeListener->setTarget(this->mPasswordField); + } + + OkDialog *dlg = new OkDialog("Error", errorMsg.str()); + dlg->addActionListener(mWrongDataNoticeListener); + } + else + { + // No errors detected, unregister the new user. + mUnRegisterButton->setEnabled(false); + mLoginData->username = username; + mLoginData->password = password; + state = STATE_UNREGISTER_ATTEMPT; + scheduleDelete(); + } + } +} diff --git a/src/gui/unregisterdialog.h b/src/gui/unregisterdialog.h new file mode 100644 index 00000000..40fdf7fe --- /dev/null +++ b/src/gui/unregisterdialog.h @@ -0,0 +1,73 @@ +/* + * The Mana World + * Copyright 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 + * 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, + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: register.h 3036 2007-01-14 16:45:13Z b_lindeijer $ + */ + +#ifndef _TMW_UNREGISTERDIALOG_H +#define _TMW_UNREGISTERDIALOG_H + +#include <iosfwd> +#include <guichan/actionlistener.hpp> + +#include "window.h" +#include "../guichanfwd.h" + +class LoginData; +class OkDialog; +class WrongDataNoticeListener; + +/** + * The Unregister dialog. + * + * \ingroup Interface + */ +class UnRegisterDialog : public Window, public gcn::ActionListener { + public: + /** + * Constructor + * + * @see Window::Window + */ + UnRegisterDialog(Window *parent,LoginData *loginData); + + /** + * Destructor + */ + ~UnRegisterDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + private: + gcn::TextField *mUserField; + gcn::TextField *mPasswordField; + + gcn::Button *mUnRegisterButton; + gcn::Button *mCancelButton; + + WrongDataNoticeListener *mWrongDataNoticeListener; + + LoginData *mLoginData; +}; + +#endif |