summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-07 23:37:50 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-07 23:37:50 +0300
commit725c8a943ca6ce33a6abefe08003d619de312ddc (patch)
tree9fb38e38771416936e59bd5f51627367e7b8c149 /src/gui
parent2a4649185cda0788444452168ddcf665af7f17b5 (diff)
downloadmanaverse-725c8a943ca6ce33a6abefe08003d619de312ddc.tar.gz
manaverse-725c8a943ca6ce33a6abefe08003d619de312ddc.tar.bz2
manaverse-725c8a943ca6ce33a6abefe08003d619de312ddc.tar.xz
manaverse-725c8a943ca6ce33a6abefe08003d619de312ddc.zip
Ask account password before deleting char.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/charselectdialog.cpp32
-rw-r--r--src/gui/charselectdialog.h5
-rw-r--r--src/gui/textdialog.cpp44
-rw-r--r--src/gui/textdialog.h4
4 files changed, 76 insertions, 9 deletions
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 3179085cc..0e12f024a 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -32,8 +32,10 @@
#include "gui/changepassworddialog.h"
#include "gui/charcreatedialog.h"
#include "gui/confirmdialog.h"
+#include "gui/login.h"
#include "gui/okdialog.h"
#include "gui/sdlinput.h"
+#include "gui/textdialog.h"
#include "gui/unregisterdialog.h"
#include "gui/widgets/button.h"
@@ -81,7 +83,7 @@ class CharDeleteConfirm : public ConfirmDialog
void action(const gcn::ActionEvent &event)
{
if (event.getId() == "yes" && mMaster)
- mMaster->attemptCharacterDelete(mIndex);
+ mMaster->askPasswordForDeletion(mIndex);
ConfirmDialog::action(event);
}
@@ -125,7 +127,9 @@ CharSelectDialog::CharSelectDialog(LoginData *loginData):
mChangeEmailButton(0),
mCharacterEntries(0),
mLoginData(loginData),
- mCharHandler(Net::getCharHandler())
+ mCharHandler(Net::getCharHandler()),
+ mDeleteDialog(0),
+ mDeleteIndex(-1)
{
setCloseButton(false);
@@ -235,6 +239,20 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
{
Client::setState(STATE_UNREGISTER);
}
+ else if (eventId == "try delete character")
+ {
+ if (mDeleteDialog && mDeleteIndex != -1 && mDeleteDialog->getText()
+ == LoginDialog::savedPassword)
+ {
+ attemptCharacterDelete(mDeleteIndex);
+ mDeleteDialog = 0;
+ }
+ else
+ {
+ new OkDialog(_("Error"), _("Incorrect password"));
+ }
+ mDeleteIndex = -1;
+ }
}
void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
@@ -260,6 +278,16 @@ void CharSelectDialog::attemptCharacterDelete(int index)
lock();
}
+void CharSelectDialog::askPasswordForDeletion(int index)
+{
+ mDeleteIndex = index;
+ mDeleteDialog = new TextDialog(
+ _("Enter password for deleting character"), _("Enter password:"),
+ this, true);
+ mDeleteDialog->setActionEventId("try delete character");
+ mDeleteDialog->addActionListener(this);
+}
+
/**
* Communicate character selection to the server.
*/
diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h
index 9db688800..bcbbb7679 100644
--- a/src/gui/charselectdialog.h
+++ b/src/gui/charselectdialog.h
@@ -38,6 +38,7 @@ class CharacterDisplay;
class LocalPlayer;
class LoginData;
class PlayerBox;
+class TextDialog;
namespace Net
{
@@ -84,6 +85,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener,
bool selectByName(const std::string &name,
SelectAction action = Focus);
+ void askPasswordForDeletion(int index);
+
private:
void attemptCharacterDelete(int index);
void attemptCharacterSelect(int index);
@@ -109,6 +112,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener,
LoginData *mLoginData;
Net::CharHandler *mCharHandler;
+ TextDialog *mDeleteDialog;
+ int mDeleteIndex;
};
#endif
diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp
index c75e47bd3..f8d3588fb 100644
--- a/src/gui/textdialog.cpp
+++ b/src/gui/textdialog.cpp
@@ -26,16 +26,20 @@
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
+#include "gui/widgets/passwordfield.h"
#include "gui/widgets/textfield.h"
#include "utils/gettext.h"
+#include <guichan/font.hpp>
+
int TextDialog::instances = 0;
TextDialog::TextDialog(const std::string &title, const std::string &msg,
- Window *parent):
+ Window *parent, bool isPassword):
Window(title, true, parent),
- mTextField(new TextField)
+ mTextField(0),
+ mPasswordField(0)
{
mEnabledKeyboard = keyboard.isEnabled();
keyboard.setEnabled(false);
@@ -45,11 +49,31 @@ TextDialog::TextDialog(const std::string &title, const std::string &msg,
gcn::Button *cancelButton = new Button(_("Cancel"), "CANCEL", this);
place(0, 0, textLabel, 4);
- place(0, 1, mTextField, 4);
+ if (isPassword)
+ {
+ mPasswordField = new PasswordField;
+ place(0, 1, mPasswordField, 4);
+ }
+ else
+ {
+ mTextField = new TextField;
+ place(0, 1, mTextField, 4);
+ }
place(2, 2, mOkButton);
place(3, 2, cancelButton);
- reflowLayout(static_cast<short>(textLabel->getWidth() + 20));
+ gcn::Font *font = getFont();
+ if (font)
+ {
+ int width = font->getWidth(title);
+ if (width < textLabel->getWidth())
+ width = textLabel->getWidth();
+ reflowLayout(static_cast<short>(width + 20));
+ }
+ else
+ {
+ reflowLayout(static_cast<short>(textLabel->getWidth() + 20));
+ }
if (getParent())
{
@@ -58,7 +82,10 @@ TextDialog::TextDialog(const std::string &title, const std::string &msg,
}
setVisible(true);
requestModalFocus();
- mTextField->requestFocus();
+ if (isPassword)
+ mPasswordField->requestFocus();
+ else
+ mTextField->requestFocus();
instances++;
}
@@ -79,13 +106,18 @@ void TextDialog::action(const gcn::ActionEvent &event)
const std::string &TextDialog::getText() const
{
- return mTextField->getText();
+ if (mTextField)
+ return mTextField->getText();
+ else
+ return mPasswordField->getText();
}
void TextDialog::setText(std::string text)
{
if (mTextField)
mTextField->setText(text);
+ else
+ mPasswordField->setText(text);
}
void TextDialog::close()
diff --git a/src/gui/textdialog.h b/src/gui/textdialog.h
index bacc4dfb7..aed26c1e9 100644
--- a/src/gui/textdialog.h
+++ b/src/gui/textdialog.h
@@ -27,6 +27,7 @@
#include <guichan/actionlistener.hpp>
+class PasswordField;
class TextField;
/**
@@ -43,7 +44,7 @@ public:
* @see Window::Window
*/
TextDialog(const std::string &title, const std::string &msg,
- Window *parent = 0);
+ Window *parent = 0, bool isPassword = false);
~TextDialog();
@@ -68,6 +69,7 @@ private:
static int instances;
TextField *mTextField;
+ PasswordField *mPasswordField;
gcn::Button *mOkButton;
bool mEnabledKeyboard;
};