summaryrefslogtreecommitdiff
path: root/src/gui/register.cpp
diff options
context:
space:
mode:
authorLloyd Bryant <lloyd_bryant@netzero.net>2008-07-18 00:48:14 +0000
committerLloyd Bryant <lloyd_bryant@netzero.net>2008-07-18 00:48:14 +0000
commit159285c5aa24611ceee7e3847a87bf9ea5f7fb7a (patch)
treefa48eb8bb8ed1e62ede1e7a2f95632c2243facab /src/gui/register.cpp
parent4dbc9b7af344d3ff006a40e3e0c06ce160f365f9 (diff)
downloadmana-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.tar.gz
mana-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.tar.bz2
mana-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.tar.xz
mana-159285c5aa24611ceee7e3847a87bf9ea5f7fb7a.zip
Import of client tree
Diffstat (limited to 'src/gui/register.cpp')
-rw-r--r--src/gui/register.cpp122
1 files changed, 90 insertions, 32 deletions
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index 9496da93..e0b663b8 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -18,7 +18,7 @@
* 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$
+ * $Id: register.cpp 4045 2008-04-07 15:23:07Z b_lindeijer $
*/
#include "register.h"
@@ -41,6 +41,8 @@
#include "textfield.h"
#include "ok_dialog.h"
+#include "../utils/tostring.h"
+
void
WrongDataNoticeListener::setTarget(gcn::TextField *textField)
{
@@ -65,53 +67,65 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
gcn::Label *passwordLabel = new gcn::Label("Password:");
gcn::Label *confirmLabel = new gcn::Label("Confirm:");
gcn::Label *serverLabel = new gcn::Label("Server:");
+ gcn::Label *portLabel = new gcn::Label("Port:");
+
mUserField = new TextField(loginData->username);
mPasswordField = new PasswordField(loginData->password);
mConfirmField = new PasswordField();
mServerField = new TextField(loginData->hostname);
+ mPortField = new TextField(toString(loginData->port));
mMaleButton = new RadioButton("Male", "sex", true);
mFemaleButton = new RadioButton("Female", "sex", false);
mRegisterButton = new Button("Register", "register", this);
mCancelButton = new Button("Cancel", "cancel", this);
- const int width = 220;
- const int height = 150;
- setContentSize(width, height);
-
- mUserField->setPosition(65, 5);
- mUserField->setWidth(width - 70);
- mPasswordField->setPosition(
- 65, mUserField->getY() + mUserField->getHeight() + 7);
- mPasswordField->setWidth(mUserField->getWidth());
- mConfirmField->setPosition(
- 65, mPasswordField->getY() + mPasswordField->getHeight() + 7);
- mConfirmField->setWidth(mUserField->getWidth());
- mServerField->setPosition(
- 65, 23 + mConfirmField->getY() + mConfirmField->getHeight() + 7);
- mServerField->setWidth(mUserField->getWidth());
-
- userLabel->setPosition(5, mUserField->getY() + 1);
- passwordLabel->setPosition(5, mPasswordField->getY() + 1);
- confirmLabel->setPosition(5, mConfirmField->getY() + 1);
- serverLabel->setPosition(5, mServerField->getY() + 1);
-
- mMaleButton->setPosition(
- 70, mConfirmField->getY() + mConfirmField->getHeight() + 7);
- mFemaleButton->setPosition(
- 70 + 10 + mMaleButton->getWidth(),
- mMaleButton->getY());
+ const int WIDTH = 220;
+ const int HEIGHT = 170;
+ const int FIELD_WIDTH = WIDTH - 70;
+
+ setContentSize(WIDTH, HEIGHT);
+
+ const int USER_TOP = 5;
+ userLabel->setPosition(5, USER_TOP);
+ mUserField->setPosition(65, USER_TOP);
+ mUserField->setWidth(FIELD_WIDTH);
+
+ const int PASS_TOP = 9 + USER_TOP + userLabel->getHeight();
+ passwordLabel->setPosition(5, PASS_TOP);
+ mPasswordField->setPosition(65, PASS_TOP);
+ mPasswordField->setWidth(FIELD_WIDTH);
+
+ const int CONFIRM_TOP = 9 + PASS_TOP + passwordLabel->getHeight();
+ confirmLabel->setPosition(5, CONFIRM_TOP);
+ mConfirmField->setPosition(65, CONFIRM_TOP);
+ mConfirmField->setWidth(FIELD_WIDTH);
+
+ const int SEX_TOP = 9 + CONFIRM_TOP + confirmLabel->getHeight();
+ mMaleButton->setPosition(70, SEX_TOP);
+ mFemaleButton->setPosition(80 + mMaleButton->getWidth(), SEX_TOP);
+
+ const int SERVER_TOP = 9 + SEX_TOP + mMaleButton->getHeight() + 5;
+ serverLabel->setPosition(5, SERVER_TOP);
+ mServerField->setPosition(65, SERVER_TOP);
+ mServerField->setWidth(FIELD_WIDTH);
+
+ const int PORT_TOP = 9 + SERVER_TOP + serverLabel->getHeight();
+ portLabel->setPosition(5, PORT_TOP);
+ mPortField->setPosition(65, PORT_TOP);
+ mPortField->setWidth(FIELD_WIDTH);
mCancelButton->setPosition(
- width - mCancelButton->getWidth() - 5,
- height - mCancelButton->getHeight() - 5);
+ WIDTH - mCancelButton->getWidth() - 5,
+ HEIGHT - mCancelButton->getHeight() - 5);
mRegisterButton->setPosition(
mCancelButton->getX() - mRegisterButton->getWidth() - 5,
- height - mRegisterButton->getHeight() - 5);
+ HEIGHT - mRegisterButton->getHeight() - 5);
mUserField->addKeyListener(this);
mPasswordField->addKeyListener(this);
mConfirmField->addKeyListener(this);
mServerField->addKeyListener(this);
+ mPortField->addKeyListener(this);
/* TODO:
* This is a quick and dirty way to respond to the ENTER key, regardless of
@@ -122,19 +136,26 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mPasswordField->setActionEventId("register");
mConfirmField->setActionEventId("register");
mServerField->setActionEventId("register");
+ mPortField->setActionEventId("register");
+
mUserField->addActionListener(this);
mPasswordField->addActionListener(this);
mConfirmField->addActionListener(this);
mServerField->addActionListener(this);
+ mPortField->addActionListener(this);
add(userLabel);
add(passwordLabel);
- add(serverLabel);
add(confirmLabel);
+ add(serverLabel);
+ add(portLabel);
+
add(mUserField);
add(mPasswordField);
add(mConfirmField);
add(mServerField);
+ add(mPortField);
+
add(mMaleButton);
add(mFemaleButton);
add(mRegisterButton);
@@ -232,7 +253,7 @@ RegisterDialog::action(const gcn::ActionEvent &event)
mRegisterButton->setEnabled(false);
mLoginData->hostname = mServerField->getText();
- mLoginData->port = (short) config.getValue("port", 0);
+ mLoginData->port = getUShort(mPortField->getText());
mLoginData->username = mUserField->getText();
mLoginData->password = mPasswordField->getText();
mLoginData->username += mFemaleButton->isSelected() ? "_F" : "_M";
@@ -256,5 +277,42 @@ RegisterDialog::canSubmit()
!mPasswordField->getText().empty() &&
!mConfirmField->getText().empty() &&
!mServerField->getText().empty() &&
+ isUShort(mPortField->getText()) &&
state == REGISTER_STATE;
}
+
+bool
+RegisterDialog::isUShort(const std::string &str)
+{
+ if (str == "")
+ {
+ return false;
+ }
+ unsigned long l = 0;
+ for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end();
+ strPtr != strEnd; ++strPtr)
+ {
+ if (*strPtr < '0' || *strPtr > '9')
+ {
+ return false;
+ }
+ l = l * 10 + (*strPtr - '0'); // *strPtr - '0' will never be negative
+ if (l > 65535)
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+unsigned short
+RegisterDialog::getUShort(const std::string &str)
+{
+ unsigned long l = 0;
+ for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end();
+ strPtr != strEnd; ++strPtr)
+ {
+ l = l * 10 + (*strPtr - '0');
+ }
+ return static_cast<unsigned short>(l);
+}