diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2005-08-24 20:02:36 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2005-08-24 20:02:36 +0000 |
commit | 276ce34d9646305c58ca7ce51cc9f1d53b60a24f (patch) | |
tree | 57eec04d3e64109361151056d8dc70c25f508d8e | |
parent | 4683edefdede2f482cc43c4fb516dba9ce50318c (diff) | |
download | mana-276ce34d9646305c58ca7ce51cc9f1d53b60a24f.tar.gz mana-276ce34d9646305c58ca7ce51cc9f1d53b60a24f.tar.bz2 mana-276ce34d9646305c58ca7ce51cc9f1d53b60a24f.tar.xz mana-276ce34d9646305c58ca7ce51cc9f1d53b60a24f.zip |
Simply don't show equipped items in sell dialog since it's annoying. Code cleanups and improvements to the login sequence.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | src/gui/login.cpp | 84 | ||||
-rw-r--r-- | src/gui/login.h | 30 |
4 files changed, 91 insertions, 32 deletions
@@ -1,3 +1,10 @@ +2005-08-22 Ferreira Yohann <bertram@cegetel.net> + + * src/game.cpp: Simply don't show + equipped items in sell dialog as it's annoying. + * src/gui/login.h, src/gui/login.cpp: Code cleanups and improvements + to the login sequence. + 2005-08-23 Björn Steinbrink <B.Steinbrink@gmx.de> * src/gui/shop.h: Fixed using a forward declaration for std::string, where diff --git a/src/game.cpp b/src/game.cpp index 3dd254ef..bbfbee9e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1607,7 +1607,7 @@ void do_parse() sellDialog->setVisible(true); for (int k = 0; k < n_items; k++) { Item *item = inventory->getItem(RFIFOW(4 + 10 * k)); - if (item) { + if (item && !(item->isEquipped())) { sellDialog->addItem(item, RFIFOL(4 + 10 * k + 2)); } } diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 23897e83..f60d0dc9 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -29,23 +29,47 @@ #include <guichan/widgets/label.hpp> +#include "../main.h" + #include "button.h" #include "checkbox.h" #include "gui.h" -#include "ok_dialog.h" #include "passwordfield.h" #include "textfield.h" +#include "ok_dialog.h" #include "../configuration.h" #include "../graphics.h" #include "../log.h" -#include "../main.h" #include "../serverinfo.h" #include "../net/network.h" extern Graphics *graphics; +OkDialog *wrongLoginNotice = NULL; +LoginDialog *loginDialog = NULL; + +WrongUsernameNoticeListener wrongUsernameNoticeListener; +WrongPasswordNoticeListener wrongPasswordNoticeListener; + +void WrongPasswordNoticeListener::action(const std::string &eventId) +{ + // Reset the password and put the caret ready to retype it. + loginDialog->passField->setText(""); + loginDialog->passField->setCaretPosition(0); + loginDialog->passField->requestFocus(); + wrongLoginNotice = NULL; +} + +void WrongUsernameNoticeListener::action(const std::string &eventId) +{ + // Set the focus on the username Field + loginDialog->userField->setCaretPosition(LEN_USERNAME - 1); + loginDialog->userField->requestFocus(); + wrongLoginNotice = NULL; +} + LoginDialog::LoginDialog(): Window("Login") { @@ -156,20 +180,40 @@ void LoginDialog::action(const std::string& eventId) // Check login if (user.length() == 0) { - new OkDialog("Error", "Enter your username first"); - userField->setCaretPosition(0); + wrongLoginNotice = new OkDialog("Error", "Enter your username first", &wrongUsernameNoticeListener); } else { - switch (server_login(user, passField->getText()) ) + switch (attemptLogin(user, passField->getText()) ) { case LOGIN_UNKNOWN_ERROR: + wrongLoginNotice = new OkDialog("Error", "Unknown Error."); default: break; case LOGIN_WRONG_PASSWORD: - passField->setText(""); - passField->setCaretPosition(0); + wrongLoginNotice = new OkDialog("Error", "Wrong Password", &wrongPasswordNoticeListener); + break; + + case LOGIN_UNREGISTERED_ID: + wrongLoginNotice = new OkDialog("Error", "Unregistered ID."); + break; + + case LOGIN_EXPIRED: + wrongLoginNotice = new OkDialog("Error", "This ID is expired"); + break; + + case LOGIN_REJECTED: + wrongLoginNotice = new OkDialog("Error", "Rejected from server"); + break; + + case LOGIN_BLOCKED: + wrongLoginNotice = new OkDialog("Error", "You have been blocked by the GM Team"); break; + case LOGIN_USERNAME_TWICE: + wrongLoginNotice = new OkDialog("Error", "The username does already exist."); + break; + + } close_session(); } @@ -189,16 +233,13 @@ void LoginDialog::action(const std::string& eventId) // Check login if (user.length() == 0) { - new OkDialog("Error", "Enter a username first"); - userField->setCaretPosition(0); + wrongLoginNotice = new OkDialog("Error", "Enter your username first.", &wrongUsernameNoticeListener); } else if (user.length() < 4) { - new OkDialog("Error", "The username needs to be at least 4 characters"); - userField->setCaretPosition(4); + wrongLoginNotice = new OkDialog("Error", "The username needs to be at least 4 characters.", &wrongUsernameNoticeListener); } else if (user.length() > LEN_USERNAME -1 ) { - new OkDialog("Error", "The username needs to be less than 25 characters long."); - userField->setCaretPosition(LEN_USERNAME - 1); + wrongLoginNotice = new OkDialog("Error", "The username needs to be less than 25 characters long.", &wrongUsernameNoticeListener); } else { - server_login(user + "_M", passField->getText()); + attemptLogin(user + "_M", passField->getText()); close_session(); } } @@ -207,7 +248,7 @@ void LoginDialog::action(const std::string& eventId) void login() { - LoginDialog *dialog = new LoginDialog(); + loginDialog = new LoginDialog(); while (state == LOGIN) { @@ -237,11 +278,11 @@ void login() graphics->updateScreen(); } - delete dialog; + delete loginDialog; } -int server_login(const std::string& user, const std::string& pass) { +int attemptLogin(const std::string& user, const std::string& pass) { strncpy(username, user.c_str(), LEN_USERNAME); strncpy(password, pass.c_str(), LEN_PASSWORD); int ret; @@ -253,7 +294,7 @@ int server_login(const std::string& user, const std::string& pass) { if (ret == SOCKET_ERROR) { state = LOGIN; - new OkDialog("Error", "Unable to connect to login server"); + wrongLoginNotice = new OkDialog("Error", "Unable to connect to login server"); return LOGIN_NO_CONNECTION; } @@ -300,27 +341,21 @@ int server_login(const std::string& user, const std::string& pass) { ret = 0; switch (RFIFOB(2)) { case 0: - new OkDialog("Error", "Unregistered ID"); ret = LOGIN_UNREGISTERED_ID; break; case 1: - new OkDialog("Error", "Wrong password"); ret = LOGIN_WRONG_PASSWORD; break; case 2: - new OkDialog("Error", "This ID is expired"); ret = LOGIN_EXPIRED; break; case 3: - new OkDialog("Error", "Rejected from server"); ret = LOGIN_REJECTED; break; case 4: - new OkDialog("Error", "You have been blocked by the GM Team"); ret = LOGIN_BLOCKED; break; case 9: - new OkDialog("Error", "The username does already exist."); ret = LOGIN_USERNAME_TWICE; break; } @@ -329,7 +364,6 @@ int server_login(const std::string& user, const std::string& pass) { return ret; } else { - new OkDialog("Error", "Unknown error"); state = LOGIN; return LOGIN_UNKNOWN_ERROR; } diff --git a/src/gui/login.h b/src/gui/login.h index 002004c4..1322a1c3 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -25,11 +25,9 @@ #define _TMW_LOGIN_H #include <iosfwd> - #include <guichan/actionlistener.hpp> #include "window.h" - #include "../guichanfwd.h" /** @@ -56,12 +54,15 @@ class LoginDialog : public Window, public gcn::ActionListener { */ void action(const std::string& eventId); + // Made them public to have the possibility to request focus + // from external functions. + gcn::TextField *userField; + gcn::TextField *passField; + private: gcn::Label *userLabel; gcn::Label *passLabel; gcn::Label *serverLabel; - gcn::TextField *userField; - gcn::TextField *passField; gcn::TextField *serverField; gcn::CheckBox *keepCheck; gcn::Button *okButton; @@ -70,6 +71,23 @@ class LoginDialog : public Window, public gcn::ActionListener { }; /** + * Listener used for handling wrong password. + */ +class WrongPasswordNoticeListener : public gcn::ActionListener { + public: + void action(const std::string &eventId); +}; + +/** + * Listener used for handling wrong username. + */ +class WrongUsernameNoticeListener : public gcn::ActionListener { + public: + void action(const std::string &eventId); +}; + + +/** * Display login dialog */ void login(); @@ -87,6 +105,8 @@ void login(); * 9 means username already existing * -1 means unknown error */ +int attemptLogin(const std::string& user, const std::string& pass); + enum { LOGIN_OK = 0, @@ -101,6 +121,4 @@ enum }; -int server_login(const std::string& user, const std::string& pass); - #endif |