diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-18 13:40:58 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-18 13:40:58 +0000 |
commit | 55372882029946d8193ca4414091b65abd64a6ae (patch) | |
tree | 61395d66a6de7a308979acde1551447a85b17025 /src/gui/login.cpp | |
parent | 6f44dd9fd801bf279034f5cebb5dc83c8a504799 (diff) | |
download | mana-55372882029946d8193ca4414091b65abd64a6ae.tar.gz mana-55372882029946d8193ca4414091b65abd64a6ae.tar.bz2 mana-55372882029946d8193ca4414091b65abd64a6ae.tar.xz mana-55372882029946d8193ca4414091b65abd64a6ae.zip |
Made login dialog and server select dialog into classes.
Diffstat (limited to 'src/gui/login.cpp')
-rw-r--r-- | src/gui/login.cpp | 139 |
1 files changed, 70 insertions, 69 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 32039294..511b45b6 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -25,53 +25,12 @@ #include "gui.h" #include "button.h" #include "checkbox.h" -#include "window.h" #include "../graphic/graphic.h" -// Dialog parts -gcn::Container *dialog; -gcn::Label *userLabel; -gcn::Label *passLabel; -gcn::TextField *userField; -gcn::TextField *passField; -gcn::CheckBox *keepCheck; -gcn::Button *okButton; -gcn::Button *cancelButton; - -void LoginActionListener::action(const std::string& eventId) -{ - if (eventId == "ok") { - const std::string user = userField->getText(); - log("Network", "Username is %s", user.c_str()); - // Store config settings - set_config_int("login", "remember", keepCheck->isMarked()); - if (keepCheck->isMarked()) { - set_config_string("login", "username", user.c_str()); - } else { - set_config_string("login", "username", ""); - } - - // Check login - if (user.length() == 0) { - ok("Error", "Enter your username first"); - warning("Enter your username first"); - state = LOGIN; - } else { - server_login(user, passField->getText()); - close_session(); - } - } else if (eventId == "cancel") { - state = EXIT; - } -} - -/* - * Display login GUI - */ -void login() { - // Create dialog - dialog = new Window("Login"); +LoginDialog::LoginDialog(): + Window("Login") +{ userLabel = new gcn::Label("Name:"); passLabel = new gcn::Label("Password:"); userField = new gcn::TextField("player"); @@ -80,7 +39,7 @@ void login() { okButton = new Button("OK"); cancelButton = new Button("Cancel"); - dialog->setDimension(gcn::Rectangle(300, 250, 200, 80)); + setDimension(gcn::Rectangle(300, 250, 200, 80)); userLabel->setPosition(4, 11); passLabel->setPosition(4, 31); userField->setPosition(60, 10); @@ -97,23 +56,34 @@ void login() { okButton->setEventId("ok"); cancelButton->setEventId("cancel"); - LoginActionListener *loginActionListener = new LoginActionListener(); - userField->addActionListener(loginActionListener); - passField->addActionListener(loginActionListener); - keepCheck->addActionListener(loginActionListener); - okButton->addActionListener(loginActionListener); - cancelButton->addActionListener(loginActionListener); - - dialog->add(userLabel); - dialog->add(passLabel); - dialog->add(userField); - dialog->add(passField); - dialog->add(keepCheck); - dialog->add(okButton); - dialog->add(cancelButton); + userField->addActionListener(this); + passField->addActionListener(this); + keepCheck->addActionListener(this); + okButton->addActionListener(this); + cancelButton->addActionListener(this); + + add(userLabel); + add(passLabel); + add(userField); + add(passField); + add(keepCheck); + add(okButton); + add(cancelButton); +} - guiTop->add(dialog); +LoginDialog::~LoginDialog() +{ + delete userLabel; + delete passLabel; + delete userField; + delete passField; + delete keepCheck; + delete okButton; + delete cancelButton; +} +void LoginDialog::init() +{ userField->requestFocus(); userField->setCaretPosition(userField->getText().length()); @@ -123,6 +93,43 @@ void login() { passField->requestFocus(); } } +} + +void LoginDialog::action(const std::string& eventId) +{ + if (eventId == "ok") { + const std::string user = userField->getText(); + log("Network", "Username is %s", user.c_str()); + + // Store config settings + set_config_int("login", "remember", keepCheck->isMarked()); + if (keepCheck->isMarked()) { + set_config_string("login", "username", user.c_str()); + } else { + set_config_string("login", "username", ""); + } + + // Check login + if (user.length() == 0) { + ok("Error", "Enter your username first"); + warning("Enter your username first"); + state = LOGIN; + } else { + server_login(user, passField->getText()); + close_session(); + } + } else if (eventId == "cancel") { + state = EXIT; + } +} + +/** + * Display login dialog + */ +void login() { + LoginDialog *dialog = new LoginDialog(); + guiTop->add(dialog); + dialog->init(); while (state == LOGIN) { clear_bitmap(buffer); @@ -135,17 +142,11 @@ void login() { } delete dialog; - delete userLabel; - delete passLabel; - delete userField; - delete passField; - delete keepCheck; - delete okButton; - delete cancelButton; - delete loginActionListener; } -/** Attempt to login to login server */ +/** + * Attempt to login to login server + */ void server_login(const std::string& user, const std::string& pass) { strncpy(username, user.c_str(), LEN_USERNAME); strncpy(password, pass.c_str(), LEN_PASSWORD); |