From 82c7ecf7a838c43771a676bb9311f9a1fc403f67 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 22 Mar 2007 23:53:13 +0000 Subject: Clarified the error message when character creation fails and made sure the character creation dialog doesn't close when creation failed. --- src/gui/char_select.cpp | 37 ++++++++++++++++++++++++++----------- src/gui/char_select.h | 12 ++++++++++-- 2 files changed, 36 insertions(+), 13 deletions(-) (limited to 'src/gui') diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index eb9ce31d..845c6d64 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -37,10 +37,14 @@ #include "../localplayer.h" #include "../main.h" +#include "../net/charserverhandler.h" #include "../net/messageout.h" #include "../utils/tostring.h" +// Defined in main.cpp, used here for setting the char create dialog +extern CharServerHandler charServerHandler; + /** * Listener for confirming character deletion. */ @@ -144,15 +148,14 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) { state = EXIT_STATE; } - else if (event.getId() == "new") + else if (event.getId() == "new" && n_character <= MAX_SLOT) { - if (n_character < MAX_SLOT + 1) - { - // Start new character dialog - mCharInfo->lock(); + // Start new character dialog + mCharInfo->lock(); + CharCreateDialog *charCreateDialog = new CharCreateDialog(this, mCharInfo->getPos(), mNetwork, mSex); - mCharInfo->unlock(); - } + charServerHandler.setCharCreateDialog(charCreateDialog); + mCharInfo->unlock(); } else if (event.getId() == "delete") { @@ -312,21 +315,25 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, setLocationRelativeTo(getParent()); 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) +void +CharCreateDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "create") { if (getName().length() >= 4) { // Attempt to create the character mCreateButton->setEnabled(false); attemptCharCreate(); - scheduleDelete(); } else { new OkDialog("Error", @@ -352,12 +359,20 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) } } -std::string CharCreateDialog::getName() +const std::string& +CharCreateDialog::getName() { return mNameField->getText(); } -void CharCreateDialog::attemptCharCreate() +void +CharCreateDialog::unlock() +{ + mCreateButton->setEnabled(true); +} + +void +CharCreateDialog::attemptCharCreate() { // Send character infos MessageOut outMsg(mNetwork); diff --git a/src/gui/char_select.h b/src/gui/char_select.h index d6b53044..754362c3 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -116,9 +116,17 @@ class CharCreateDialog : public Window, public gcn::ActionListener */ ~CharCreateDialog(); - void action(const gcn::ActionEvent &event); + void + action(const gcn::ActionEvent &event); - std::string getName(); + const std::string& + getName(); + + /** + * Unlocks the dialog, enabling the create character button again. + */ + void + unlock(); private: Network *mNetwork; -- cgit v1.2.3-60-g2f50