diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-10-01 19:09:25 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-10-01 19:10:06 -0600 |
commit | 50ff91186126a0e9cc7e216552c349d60d31f451 (patch) | |
tree | 918e10a585bf5685f76720f41844bba8fef4e67d /src/gui | |
parent | d974f23b42ddeca3c9cf0d8489dc38d8524c5f12 (diff) | |
download | mana-client-50ff91186126a0e9cc7e216552c349d60d31f451.tar.gz mana-client-50ff91186126a0e9cc7e216552c349d60d31f451.tar.bz2 mana-client-50ff91186126a0e9cc7e216552c349d60d31f451.tar.xz mana-client-50ff91186126a0e9cc7e216552c349d60d31f451.zip |
Redesign CharSelectDialog
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/charselectdialog.cpp | 389 | ||||
-rw-r--r-- | src/gui/charselectdialog.h | 37 |
2 files changed, 171 insertions, 255 deletions
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 680c6500..da2e0d9b 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -21,18 +21,25 @@ #include "gui/charselectdialog.h" +#include "gui/widgets/button.h" +#include "gui/widgets/container.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layout.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/textfield.h" + +#include "gui/changeemaildialog.h" +#include "gui/changepassworddialog.h" #include "gui/charcreatedialog.h" #include "gui/confirmdialog.h" #include "gui/okdialog.h" #include "gui/playerbox.h" -#include "gui/changepassworddialog.h" -#include "net/logindata.h" - -#include "gui/widgets/radiobutton.h" -#include "gui/widgets/slider.h" - #include "gui/unregisterdialog.h" -#include "gui/changeemaildialog.h" + +#include "game.h" +#include "localplayer.h" +#include "main.h" +#include "units.h" #ifdef TMWSERV_SUPPORT #include "net/tmwserv/accountserver/account.h" @@ -40,17 +47,8 @@ #include "net/ea/protocol.h" #endif -#include "gui/widgets/button.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/textfield.h" - -#include "game.h" -#include "localplayer.h" -#include "main.h" -#include "units.h" - #include "net/charhandler.h" +#include "net/logindata.h" #include "net/messageout.h" #include "net/net.h" @@ -69,28 +67,50 @@ class CharDeleteConfirm : public ConfirmDialog { public: - CharDeleteConfirm(CharSelectDialog *master); - void action(const gcn::ActionEvent &event); + CharDeleteConfirm(CharSelectDialog *m): + ConfirmDialog(_("Confirm Character Delete"), + _("Are you sure you want to delete this character?"), m), + master(m) + { + } + void action(const gcn::ActionEvent &event) + { + //ConfirmDialog::action(event); + if (event.getId() == "yes") + { + master->attemptCharDelete(); + } + ConfirmDialog::action(event); + } private: CharSelectDialog *master; }; -CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): - ConfirmDialog(_("Confirm Character Delete"), - _("Are you sure you want to delete this character?"), m), - master(m) +class CharEntry : public Container { -} + public: + CharEntry(CharSelectDialog *m, char slot, LocalPlayer *chr); -void CharDeleteConfirm::action(const gcn::ActionEvent &event) -{ - //ConfirmDialog::action(event); - if (event.getId() == "yes") - { - master->attemptCharDelete(); - } - ConfirmDialog::action(event); -} + char getSlot() + { return mSlot; } + + LocalPlayer *getChar() + { return mChr; } + + void requestFocus(); + + void update(); + + protected: + friend class CharSelectDialog; + char mSlot; + LocalPlayer *mChr; + + PlayerBox *mPlayerBox; + Label *mName; + Label *mMoney; + Button *mButton; +}; bool CharSelectDialog::doAllowUnregister = true; bool CharSelectDialog::doAllowChangeEmail = true; @@ -99,129 +119,78 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, LoginData *loginData): Window(_("Account and Character Management")), mCharInfo(charInfo), - mLoginData(loginData), - mCharSelected(false) + mLoginData(loginData) { - mSelectButton = new Button(_("OK"), "ok", this); - mCancelButton = new Button(_("Cancel"), "cancel", this); - mPreviousButton = new Button(_("Previous"), "previous", this); - mNextButton = new Button(_("Next"), "next", this); - mAccountNameLabel = new Label(strprintf(_("Account: %s"), mLoginData->username.c_str())); - mNameLabel = new Label(strprintf(_("Name: %s"), "")); - mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); - mChangePasswordButton = new Button(_("Change Password"), "change_password", this); -#ifdef TMWSERV_SUPPORT - mNewCharButton = new Button(_("New"), "new", this); - mDelCharButton = new Button(_("Delete"), "delete", this); - mUnRegisterButton = new Button(_("Unregister"), "unregister", this); - mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this); - - mNameLabel = new Label(strprintf(_("Name: %s"), "")); - mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); - mMoneyLabel = new Label(strprintf(_("Money: %s"), "")); - - // 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->getMoney()); - // Control that shows the Player - mPlayerBox = new PlayerBox; - mPlayerBox->setWidth(74); - - mJobLevelLabel = new Label(strprintf(_("Job Level: %d"), 0)); - mMoneyLabel = new 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, mAccountNameLabel); - place(0, 1, mChangePasswordButton); - place = getPlacer(0, 1); - place(0, 0, mPlayerBox, 1, 6).setPadding(3); - place(1, 0, mNameLabel, 5); - place(1, 1, mLevelLabel, 5); - place(1, 2, mJobLevelLabel, 5); - place(1, 3, mMoneyLabel, 5); - place(1, 4, mNewDelCharButton); - 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(270, 0); -#endif + setCloseButton(false); + + mAccountNameLabel = new Label(loginData->username); + + mSwitchLoginButton = new Button(_("Switch Login"), "switch", this); + mUnregisterButton = new Button(_("Unregister"), "unregister", this); + + mChangePasswordButton = new Button(_("Change Password"), "change_password", + this); + mChangeEmailButton = new Button(_("Change Email"), "change_email", this); + + for (int i = 0; i < MAX_CHARACTER_COUNT; i++) + { + charInfo->select(i); + mCharEntries[i] = new CharEntry(this, i, charInfo->getEntry()); + } + + place(0, 0, mAccountNameLabel, 6); + + place(0, 1, mSwitchLoginButton, 3); + + if (doAllowUnregister) + place(3, 1, mUnregisterButton, 3); + + place(0, 2, mChangePasswordButton, 3); + + if (doAllowChangeEmail) + place(3, 2, mChangeEmailButton, 3); + + place(0, 3, mCharEntries[0], 2, 3); + place(2, 3, mCharEntries[1], 2, 3); + place(4, 3, mCharEntries[2], 2, 3); + + int width = mAccountNameLabel->getWidth(); + width = std::max(width, mSwitchLoginButton->getWidth() + + mUnregisterButton->getWidth()); + width = std::max(width, mChangePasswordButton->getWidth() + + mChangeEmailButton->getWidth()); + width = std::max(width, 3 * mCharEntries[0]->getWidth()); + + reflowLayout(width + 10, mAccountNameLabel->getHeight() + + mSwitchLoginButton->getHeight() + + mChangePasswordButton->getHeight() + + mCharEntries[0]->getHeight() + 20); center(); + mCharEntries[0]->requestFocus(); setVisible(true); - mSelectButton->requestFocus(); - updatePlayerInfo(); } 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 + CharEntry *entry = dynamic_cast<CharEntry*>(event.getSource()->getParent()); + + // Update the locked array + if (entry) + mCharInfo->select(entry->getSlot()); + + if (event.getId() == "use") { - // 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); - mCharSelected = true; + setVisible(false); attemptCharSelect(); } - else if (event.getId() == "cancel") + else if (event.getId() == "switch") { mCharInfo->clear(); state = STATE_SWITCH_SERVER_ATTEMPT; } -#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 @@ -232,102 +201,23 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) } else if (event.getId() == "delete") { - // Delete character - if (mCharInfo->getEntry()) - { - new CharDeleteConfirm(this); - } - } -#else - else if (event.getId() == "newdel") - { - // Check for a character if (mCharInfo->getEntry()) { new CharDeleteConfirm(this); } - else if (n_character < MAX_CHARACTER_COUNT) - { - // Start new character dialog - CharCreateDialog *charCreateDialog = - new CharCreateDialog(this, mCharInfo->getPos()); - Net::getCharHandler()->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()); } else if (event.getId() == "change_password") { new ChangePasswordDialog(this, mLoginData); } -#ifdef TMWSERV_SUPPORT - else if (event.getId() == "unregister") - { - new UnRegisterDialog(this, mLoginData); - } else if (event.getId() == "change_email") { new ChangeEmailDialog(this, mLoginData); } -#endif -} - -void CharSelectDialog::updatePlayerInfo() -{ - LocalPlayer *pi = mCharInfo->getEntry(); - - if (pi) - { - mNameLabel->setCaption(strprintf(_("Name: %s"), - pi->getName().c_str())); - mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->getLevel())); -#ifdef EATHENA_SUPPORT - mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), - pi->getAttributeBase(JOB))); -#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 if (event.getId() == "unregister") { - 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); + new UnRegisterDialog(this, mLoginData); } - - mPlayerBox->setPlayer(pi); } void CharSelectDialog::attemptCharDelete() @@ -342,11 +232,6 @@ void CharSelectDialog::attemptCharSelect() mCharInfo->lock(); } -void CharSelectDialog::logic() -{ - updatePlayerInfo(); -} - bool CharSelectDialog::selectByName(const std::string &name) { if (mCharInfo->isLocked()) @@ -361,8 +246,7 @@ bool CharSelectDialog::selectByName(const std::string &name) if (player && player->getName() == name) { - mMoney = Units::formatCurrency(player->getMoney()); - return true; + mCharEntries[mCharInfo->getPos()]->requestFocus(); } mCharInfo->next(); @@ -376,6 +260,57 @@ bool CharSelectDialog::selectByName(const std::string &name) void CharSelectDialog::setNetworkOptions(bool allowUnregister, bool allowChangeEmail) { + printf("Network options: %d, %d\n", allowUnregister, allowChangeEmail); doAllowUnregister = allowUnregister; doAllowChangeEmail = allowChangeEmail; } + +CharEntry::CharEntry(CharSelectDialog *m, char slot, LocalPlayer *chr): + mSlot(slot), + mChr(chr), + mPlayerBox(new PlayerBox(chr)) +{ + mButton = new Button("wwwwwwwww", "go", m); + mName = new Label("wwwwwwwwwwwwwwwwwwwwwwww (888)"); + mMoney = new Label("wwwwwwwww"); + + LayoutHelper h(this); + ContainerPlacer place = h.getPlacer(0, 0); + + place(0, 0, mPlayerBox, 3, 5); + place(0, 5, mName, 3); + place(0, 6, mMoney, 3); + place(0, 7, mButton, 3); + + h.reflowLayout(65, 120 + mName->getHeight() + mMoney->getHeight() + + mButton->getHeight()); + + update(); +} + +void CharEntry::requestFocus() +{ + mButton->requestFocus(); +} + +void CharEntry::update() +{ + if (mChr) + { + mButton->setCaption(_("Choose")); + mButton->setActionEventId("use"); + mName->setCaption(strprintf("%s (%d)", mChr->getName().c_str(), + mChr->getLevel())); + mMoney->setCaption(Units::formatCurrency(mChr->getMoney())); + } + else + { + mButton->setCaption(_("Create")); + mButton->setActionEventId("new"); + mName->setCaption(_("(empty)")); + mMoney->setCaption(Units::formatCurrency(0)); + } + + // Recompute layout + distributeResizedEvent(); +} diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h index cfd36390..965b4abf 100644 --- a/src/gui/charselectdialog.h +++ b/src/gui/charselectdialog.h @@ -24,12 +24,14 @@ #include "gui/widgets/window.h" -#include "player.h" #include "guichanfwd.h" #include "lockedarray.h" +#include "main.h" +#include "player.h" #include <guichan/actionlistener.hpp> +class CharEntry; class LocalPlayer; class LoginData; class PlayerBox; @@ -51,10 +53,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener void action(const gcn::ActionEvent &event); - void updatePlayerInfo(); - - void logic(); - bool selectByName(const std::string &name); static void setNetworkOptions(bool allowUnregister, @@ -63,33 +61,16 @@ class CharSelectDialog : public Window, public gcn::ActionListener private: LockedArray<LocalPlayer*> *mCharInfo; - gcn::Button *mSelectButton; - gcn::Button *mCancelButton; - gcn::Button *mPreviousButton; - gcn::Button *mNextButton; - gcn::Button *mChangePasswordButton; - - gcn::Label *mNameLabel; - gcn::Label *mLevelLabel; - gcn::Label *mMoneyLabel; gcn::Label *mAccountNameLabel; - std::string mMoney; - LoginData *mLoginData; - - PlayerBox *mPlayerBox; + gcn::Button *mSwitchLoginButton; + gcn::Button *mChangePasswordButton; + gcn::Button *mChangeEmailButton; + gcn::Button *mUnregisterButton; - bool mCharSelected; + CharEntry *mCharEntries[MAX_CHARACTER_COUNT]; -#ifdef TMWSERV_SUPPORT - gcn::Button *mNewCharButton; - gcn::Button *mDelCharButton; - gcn::Button *mUnRegisterButton; - gcn::Button *mChangeEmailButton; -#else - gcn::Button *mNewDelCharButton; - gcn::Label *mJobLevelLabel; -#endif + LoginData *mLoginData; /** * Communicate character deletion to the server. |